Vstam1/xcm admin origin (#6928)

* Ensure for a configurable origin in XCM (#6442), cherry picked from
5ae05e1a957857c449a43d8759a21292d03fd049

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 <serkul@pop-os.localdomain>
This commit is contained in:
Just van Stam
2023-03-23 10:58:12 +01:00
committed by GitHub
parent c7b3352b79
commit f989b2bb1a
12 changed files with 33 additions and 4 deletions
@@ -25,6 +25,7 @@ use frame_support::{
traits::{Contains, Everything, Nothing}, traits::{Contains, Everything, Nothing},
weights::Weight, weights::Weight,
}; };
use frame_system::EnsureRoot;
use runtime_common::{paras_registrar, xcm_sender, ToAuthor}; use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
use sp_core::ConstU32; use sp_core::ConstU32;
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
@@ -398,6 +399,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>; type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
} }
#[test] #[test]
@@ -26,6 +26,7 @@ use frame_support::{
traits::{Contains, Everything, Nothing}, traits::{Contains, Everything, Nothing},
weights::Weight, weights::Weight,
}; };
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough; use pallet_xcm::XcmPassthrough;
use polkadot_runtime_constants::{system_parachain::*, xcm::body::FELLOWSHIP_ADMIN_INDEX}; use polkadot_runtime_constants::{system_parachain::*, xcm::body::FELLOWSHIP_ADMIN_INDEX};
use runtime_common::{paras_registrar, xcm_sender, ToAuthor}; use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
@@ -425,4 +426,5 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>; type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
} }
@@ -25,6 +25,7 @@ use frame_support::{
traits::{Contains, Everything, Nothing}, traits::{Contains, Everything, Nothing},
weights::Weight, weights::Weight,
}; };
use frame_system::EnsureRoot;
use runtime_common::{paras_registrar, xcm_sender, ToAuthor}; use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
use sp_core::ConstU32; use sp_core::ConstU32;
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
@@ -364,4 +365,5 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>; type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
} }
@@ -19,6 +19,7 @@ use frame_support::{
traits::{Everything, Nothing}, traits::{Everything, Nothing},
weights::Weight, weights::Weight,
}; };
use frame_system::EnsureRoot;
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
use xcm_builder::{ use xcm_builder::{
AllowUnpaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, SignedAccountId32AsNative, AllowUnpaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, SignedAccountId32AsNative,
@@ -146,4 +147,5 @@ impl pallet_xcm::Config for crate::Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo; type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<crate::AccountId>;
} }
@@ -24,6 +24,7 @@ use frame_support::{
parameter_types, parameter_types,
traits::{Contains, Everything, Nothing}, traits::{Contains, Everything, Nothing},
}; };
use frame_system::EnsureRoot;
use runtime_common::{paras_registrar, xcm_sender, ToAuthor}; use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
use sp_core::ConstU32; use sp_core::ConstU32;
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
@@ -279,4 +280,5 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>; type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
} }
+7 -4
View File
@@ -231,6 +231,9 @@ pub mod pallet {
/// `pallet_xcm::CurrentXcmVersion`. /// `pallet_xcm::CurrentXcmVersion`.
type AdvertisedXcmVersion: Get<XcmVersion>; 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 /// The assets which we consider a given origin is trusted if they claim to have placed a
/// lock. /// lock.
type TrustedLockers: ContainsPair<MultiLocation, MultiAsset>; type TrustedLockers: ContainsPair<MultiLocation, MultiAsset>;
@@ -915,7 +918,7 @@ pub mod pallet {
location: Box<MultiLocation>, location: Box<MultiLocation>,
xcm_version: XcmVersion, xcm_version: XcmVersion,
) -> DispatchResult { ) -> DispatchResult {
ensure_root(origin)?; T::AdminOrigin::ensure_origin(origin)?;
let location = *location; let location = *location;
SupportedVersion::<T>::insert( SupportedVersion::<T>::insert(
XCM_VERSION, XCM_VERSION,
@@ -937,7 +940,7 @@ pub mod pallet {
origin: OriginFor<T>, origin: OriginFor<T>,
maybe_xcm_version: Option<XcmVersion>, maybe_xcm_version: Option<XcmVersion>,
) -> DispatchResult { ) -> DispatchResult {
ensure_root(origin)?; T::AdminOrigin::ensure_origin(origin)?;
SafeXcmVersion::<T>::set(maybe_xcm_version); SafeXcmVersion::<T>::set(maybe_xcm_version);
Ok(()) Ok(())
} }
@@ -952,7 +955,7 @@ pub mod pallet {
origin: OriginFor<T>, origin: OriginFor<T>,
location: Box<VersionedMultiLocation>, location: Box<VersionedMultiLocation>,
) -> DispatchResult { ) -> DispatchResult {
ensure_root(origin)?; T::AdminOrigin::ensure_origin(origin)?;
let location: MultiLocation = let location: MultiLocation =
(*location).try_into().map_err(|()| Error::<T>::BadLocation)?; (*location).try_into().map_err(|()| Error::<T>::BadLocation)?;
Self::request_version_notify(location).map_err(|e| { Self::request_version_notify(location).map_err(|e| {
@@ -976,7 +979,7 @@ pub mod pallet {
origin: OriginFor<T>, origin: OriginFor<T>,
location: Box<VersionedMultiLocation>, location: Box<VersionedMultiLocation>,
) -> DispatchResult { ) -> DispatchResult {
ensure_root(origin)?; T::AdminOrigin::ensure_origin(origin)?;
let location: MultiLocation = let location: MultiLocation =
(*location).try_into().map_err(|()| Error::<T>::BadLocation)?; (*location).try_into().map_err(|()| Error::<T>::BadLocation)?;
Self::unrequest_version_notify(location).map_err(|e| { Self::unrequest_version_notify(location).map_err(|e| {
+2
View File
@@ -20,6 +20,7 @@ use frame_support::{
traits::{ConstU32, Everything, Nothing}, traits::{ConstU32, Everything, Nothing},
weights::Weight, weights::Weight,
}; };
use frame_system::EnsureRoot;
use polkadot_parachain::primitives::Id as ParaId; use polkadot_parachain::primitives::Id as ParaId;
use polkadot_runtime_parachains::origin; use polkadot_runtime_parachains::origin;
use sp_core::H256; use sp_core::H256;
@@ -344,6 +345,7 @@ impl pallet_xcm::Config for Test {
type WeightInfo = TestWeightInfo; type WeightInfo = TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
} }
impl origin::Config for Test {} impl origin::Config for Test {}
@@ -19,6 +19,7 @@ use frame_support::{
traits::{ConstU32, Everything, Nothing}, traits::{ConstU32, Everything, Nothing},
weights::Weight, weights::Weight,
}; };
use frame_system::EnsureRoot;
use parity_scale_codec::Encode; use parity_scale_codec::Encode;
use primitive_types::H256; use primitive_types::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
@@ -235,6 +236,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo; type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
} }
impl origin::Config for Runtime {} impl origin::Config for Runtime {}
@@ -22,6 +22,8 @@ use frame_support::{
traits::{EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing}, traits::{EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
}; };
use frame_system::EnsureRoot;
use sp_core::{ConstU32, H256}; use sp_core::{ConstU32, H256};
use sp_runtime::{ use sp_runtime::{
testing::Header, testing::Header,
@@ -424,6 +426,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo; type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
} }
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
@@ -21,6 +21,8 @@ use frame_support::{
traits::{AsEnsureOriginWithArg, Everything, Nothing}, traits::{AsEnsureOriginWithArg, Everything, Nothing},
weights::Weight, weights::Weight,
}; };
use frame_system::EnsureRoot;
use sp_core::{ConstU32, H256}; use sp_core::{ConstU32, H256};
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
@@ -221,6 +223,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo; type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
} }
parameter_types! { parameter_types! {
@@ -22,6 +22,8 @@ use frame_support::{
traits::{Everything, Nothing}, traits::{Everything, Nothing},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
}; };
use frame_system::EnsureRoot;
use sp_core::{ConstU32, H256}; use sp_core::{ConstU32, H256};
use sp_runtime::{ use sp_runtime::{
testing::Header, testing::Header,
@@ -339,6 +341,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo; type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
} }
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
@@ -21,6 +21,8 @@ use frame_support::{
traits::{Everything, Nothing}, traits::{Everything, Nothing},
weights::Weight, weights::Weight,
}; };
use frame_system::EnsureRoot;
use sp_core::{ConstU32, H256}; use sp_core::{ConstU32, H256};
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
@@ -185,6 +187,7 @@ impl pallet_xcm::Config for Runtime {
type WeightInfo = pallet_xcm::TestWeightInfo; type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest; type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
} }
parameter_types! { parameter_types! {