Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Vstam1/xcm admin origin (#6928)
Browse files Browse the repository at this point in the history
* Ensure for a configurable origin in XCM (#6442), cherry picked from
5ae05e1

Add new associated type, AdminOrigin, bounded by EnsureOrigin trait in
XCM pallet. Replace ensure_root() with ensure_origin() from a
EnsureOrigin trait. Set AdminOrigin as EnsureRoot<AccountId> in xcm
configs.

* cargo fmt

* small stylistic change

---------

Co-authored-by: serkul <[email protected]>
  • Loading branch information
vstam1 and serkul authored Mar 23, 2023
1 parent bee5c7e commit d8e6ca5
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 4 deletions.
2 changes: 2 additions & 0 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use frame_support::{
traits::{Contains, Everything, Nothing},
weights::Weight,
};
use frame_system::EnsureRoot;
use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
use sp_core::ConstU32;
use xcm::latest::prelude::*;
Expand Down Expand Up @@ -398,6 +399,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions runtime/polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use frame_support::{
traits::{Contains, Everything, Nothing},
weights::Weight,
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use polkadot_runtime_constants::{system_parachain::*, xcm::body::FELLOWSHIP_ADMIN_INDEX};
use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
Expand Down Expand Up @@ -425,4 +426,5 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}
2 changes: 2 additions & 0 deletions runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use frame_support::{
traits::{Contains, Everything, Nothing},
weights::Weight,
};
use frame_system::EnsureRoot;
use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
use sp_core::ConstU32;
use xcm::latest::prelude::*;
Expand Down Expand Up @@ -364,4 +365,5 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}
2 changes: 2 additions & 0 deletions runtime/test-runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use frame_support::{
traits::{Everything, Nothing},
weights::Weight,
};
use frame_system::EnsureRoot;
use xcm::latest::prelude::*;
use xcm_builder::{
AllowUnpaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, SignedAccountId32AsNative,
Expand Down Expand Up @@ -146,4 +147,5 @@ impl pallet_xcm::Config for crate::Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<crate::AccountId>;
}
2 changes: 2 additions & 0 deletions runtime/westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use frame_support::{
parameter_types,
traits::{Contains, Everything, Nothing},
};
use frame_system::EnsureRoot;
use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
use sp_core::ConstU32;
use xcm::latest::prelude::*;
Expand Down Expand Up @@ -279,4 +280,5 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}
11 changes: 7 additions & 4 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ pub mod pallet {
/// `pallet_xcm::CurrentXcmVersion`.
type AdvertisedXcmVersion: Get<XcmVersion>;

/// The origin that is allowed to call privileged operations on the XCM pallet
type AdminOrigin: EnsureOrigin<<Self as SysConfig>::RuntimeOrigin>;

/// The assets which we consider a given origin is trusted if they claim to have placed a
/// lock.
type TrustedLockers: ContainsPair<MultiLocation, MultiAsset>;
Expand Down Expand Up @@ -915,7 +918,7 @@ pub mod pallet {
location: Box<MultiLocation>,
xcm_version: XcmVersion,
) -> DispatchResult {
ensure_root(origin)?;
T::AdminOrigin::ensure_origin(origin)?;
let location = *location;
SupportedVersion::<T>::insert(
XCM_VERSION,
Expand All @@ -937,7 +940,7 @@ pub mod pallet {
origin: OriginFor<T>,
maybe_xcm_version: Option<XcmVersion>,
) -> DispatchResult {
ensure_root(origin)?;
T::AdminOrigin::ensure_origin(origin)?;
SafeXcmVersion::<T>::set(maybe_xcm_version);
Ok(())
}
Expand All @@ -952,7 +955,7 @@ pub mod pallet {
origin: OriginFor<T>,
location: Box<VersionedMultiLocation>,
) -> DispatchResult {
ensure_root(origin)?;
T::AdminOrigin::ensure_origin(origin)?;
let location: MultiLocation =
(*location).try_into().map_err(|()| Error::<T>::BadLocation)?;
Self::request_version_notify(location).map_err(|e| {
Expand All @@ -976,7 +979,7 @@ pub mod pallet {
origin: OriginFor<T>,
location: Box<VersionedMultiLocation>,
) -> DispatchResult {
ensure_root(origin)?;
T::AdminOrigin::ensure_origin(origin)?;
let location: MultiLocation =
(*location).try_into().map_err(|()| Error::<T>::BadLocation)?;
Self::unrequest_version_notify(location).map_err(|e| {
Expand Down
2 changes: 2 additions & 0 deletions xcm/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use frame_support::{
traits::{ConstU32, Everything, Nothing},
weights::Weight,
};
use frame_system::EnsureRoot;
use polkadot_parachain::primitives::Id as ParaId;
use polkadot_runtime_parachains::origin;
use sp_core::H256;
Expand Down Expand Up @@ -344,6 +345,7 @@ impl pallet_xcm::Config for Test {
type WeightInfo = TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}

impl origin::Config for Test {}
Expand Down
2 changes: 2 additions & 0 deletions xcm/xcm-builder/tests/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use frame_support::{
traits::{ConstU32, Everything, Nothing},
weights::Weight,
};
use frame_system::EnsureRoot;
use parity_scale_codec::Encode;
use primitive_types::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
Expand Down Expand Up @@ -235,6 +236,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}

impl origin::Config for Runtime {}
Expand Down
3 changes: 3 additions & 0 deletions xcm/xcm-simulator/example/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use frame_support::{
traits::{EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};

use frame_system::EnsureRoot;
use sp_core::{ConstU32, H256};
use sp_runtime::{
testing::Header,
Expand Down Expand Up @@ -424,6 +426,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
Expand Down
3 changes: 3 additions & 0 deletions xcm/xcm-simulator/example/src/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use frame_support::{
traits::{AsEnsureOriginWithArg, Everything, Nothing},
weights::Weight,
};

use frame_system::EnsureRoot;
use sp_core::{ConstU32, H256};
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};

Expand Down Expand Up @@ -221,6 +223,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}

parameter_types! {
Expand Down
3 changes: 3 additions & 0 deletions xcm/xcm-simulator/fuzzer/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use frame_support::{
traits::{Everything, Nothing},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};

use frame_system::EnsureRoot;
use sp_core::{ConstU32, H256};
use sp_runtime::{
testing::Header,
Expand Down Expand Up @@ -339,6 +341,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
Expand Down
3 changes: 3 additions & 0 deletions xcm/xcm-simulator/fuzzer/src/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use frame_support::{
traits::{Everything, Nothing},
weights::Weight,
};

use frame_system::EnsureRoot;
use sp_core::{ConstU32, H256};
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};

Expand Down Expand Up @@ -185,6 +187,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}

parameter_types! {
Expand Down

0 comments on commit d8e6ca5

Please sign in to comment.