From d870387ffe214d8cad752d31be9a3c104ed7e055 Mon Sep 17 00:00:00 2001 From: serkul Date: Fri, 23 Dec 2022 15:29:35 +0100 Subject: [PATCH 1/3] 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 in xcm configs. --- runtime/kusama/src/xcm_config.rs | 2 ++ runtime/polkadot/src/xcm_config.rs | 2 ++ runtime/rococo/src/xcm_config.rs | 2 ++ runtime/test-runtime/src/xcm_config.rs | 2 ++ runtime/westend/src/xcm_config.rs | 2 ++ xcm/pallet-xcm/src/lib.rs | 11 +++++++---- xcm/pallet-xcm/src/mock.rs | 2 ++ xcm/xcm-builder/tests/mock/mod.rs | 2 ++ xcm/xcm-simulator/example/src/parachain.rs | 3 +++ xcm/xcm-simulator/example/src/relay_chain.rs | 3 +++ xcm/xcm-simulator/fuzzer/src/parachain.rs | 3 +++ xcm/xcm-simulator/fuzzer/src/relay_chain.rs | 3 +++ 12 files changed, 33 insertions(+), 4 deletions(-) diff --git a/runtime/kusama/src/xcm_config.rs b/runtime/kusama/src/xcm_config.rs index 33ca3a810aea..57b7dfe6ceca 100644 --- a/runtime/kusama/src/xcm_config.rs +++ b/runtime/kusama/src/xcm_config.rs @@ -26,6 +26,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::*; @@ -456,6 +457,7 @@ impl pallet_xcm::Config for Runtime { type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; + type AdminOrigin = EnsureRoot; } #[test] diff --git a/runtime/polkadot/src/xcm_config.rs b/runtime/polkadot/src/xcm_config.rs index 4f817093703a..f3b11b4576b5 100644 --- a/runtime/polkadot/src/xcm_config.rs +++ b/runtime/polkadot/src/xcm_config.rs @@ -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::*; @@ -389,4 +390,5 @@ impl pallet_xcm::Config for Runtime { type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; + type AdminOrigin = EnsureRoot; } diff --git a/runtime/rococo/src/xcm_config.rs b/runtime/rococo/src/xcm_config.rs index 229df3a5df95..73408566b408 100644 --- a/runtime/rococo/src/xcm_config.rs +++ b/runtime/rococo/src/xcm_config.rs @@ -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::*; @@ -364,4 +365,5 @@ impl pallet_xcm::Config for Runtime { type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; + type AdminOrigin = EnsureRoot; } diff --git a/runtime/test-runtime/src/xcm_config.rs b/runtime/test-runtime/src/xcm_config.rs index bfe9c6ad1ad8..e346f54a1575 100644 --- a/runtime/test-runtime/src/xcm_config.rs +++ b/runtime/test-runtime/src/xcm_config.rs @@ -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, @@ -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; } diff --git a/runtime/westend/src/xcm_config.rs b/runtime/westend/src/xcm_config.rs index ef38ca5d2970..411291c3e7f8 100644 --- a/runtime/westend/src/xcm_config.rs +++ b/runtime/westend/src/xcm_config.rs @@ -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::*; @@ -279,4 +280,5 @@ impl pallet_xcm::Config for Runtime { type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; + type AdminOrigin = EnsureRoot; } diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index 47a9d7d75d0a..0bf61355615f 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -231,6 +231,9 @@ pub mod pallet { /// `pallet_xcm::CurrentXcmVersion`. type AdvertisedXcmVersion: Get; + /// The origin that is allowed to call privileged operations on the XCM pallet + type AdminOrigin: EnsureOrigin<::RuntimeOrigin>; + /// The assets which we consider a given origin is trusted if they claim to have placed a /// lock. type TrustedLockers: ContainsPair; @@ -915,7 +918,7 @@ pub mod pallet { location: Box, xcm_version: XcmVersion, ) -> DispatchResult { - ensure_root(origin)?; + T::AdminOrigin::ensure_origin(origin)?; let location = *location; SupportedVersion::::insert( XCM_VERSION, @@ -937,7 +940,7 @@ pub mod pallet { origin: OriginFor, maybe_xcm_version: Option, ) -> DispatchResult { - ensure_root(origin)?; + T::AdminOrigin::ensure_origin(origin)?; SafeXcmVersion::::set(maybe_xcm_version); Ok(()) } @@ -952,7 +955,7 @@ pub mod pallet { origin: OriginFor, location: Box, ) -> DispatchResult { - ensure_root(origin)?; + T::AdminOrigin::ensure_origin(origin)?; let location: MultiLocation = (*location).try_into().map_err(|()| Error::::BadLocation)?; Self::request_version_notify(location).map_err(|e| { @@ -976,7 +979,7 @@ pub mod pallet { origin: OriginFor, location: Box, ) -> DispatchResult { - ensure_root(origin)?; + T::AdminOrigin::ensure_origin(origin)?; let location: MultiLocation = (*location).try_into().map_err(|()| Error::::BadLocation)?; Self::unrequest_version_notify(location).map_err(|e| { diff --git a/xcm/pallet-xcm/src/mock.rs b/xcm/pallet-xcm/src/mock.rs index 1e23af66b2fc..9544538ef280 100644 --- a/xcm/pallet-xcm/src/mock.rs +++ b/xcm/pallet-xcm/src/mock.rs @@ -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; @@ -344,6 +345,7 @@ impl pallet_xcm::Config for Test { type WeightInfo = TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; + type AdminOrigin = EnsureRoot; } impl origin::Config for Test {} diff --git a/xcm/xcm-builder/tests/mock/mod.rs b/xcm/xcm-builder/tests/mock/mod.rs index 450ef181869d..9c0086e34c90 100644 --- a/xcm/xcm-builder/tests/mock/mod.rs +++ b/xcm/xcm-builder/tests/mock/mod.rs @@ -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}; @@ -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; } impl origin::Config for Runtime {} diff --git a/xcm/xcm-simulator/example/src/parachain.rs b/xcm/xcm-simulator/example/src/parachain.rs index 344ccfb9dbcc..338095c5d0de 100644 --- a/xcm/xcm-simulator/example/src/parachain.rs +++ b/xcm/xcm-simulator/example/src/parachain.rs @@ -22,7 +22,9 @@ use frame_support::{ traits::{EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; + use sp_core::{ConstU32, H256}; +use frame_system::EnsureRoot; use sp_runtime::{ testing::Header, traits::{Hash, IdentityLookup}, @@ -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; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/xcm/xcm-simulator/example/src/relay_chain.rs b/xcm/xcm-simulator/example/src/relay_chain.rs index b44200378a8b..1467335af48e 100644 --- a/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/xcm/xcm-simulator/example/src/relay_chain.rs @@ -21,7 +21,9 @@ use frame_support::{ traits::{AsEnsureOriginWithArg, Everything, Nothing}, weights::Weight, }; + use sp_core::{ConstU32, H256}; +use frame_system::EnsureRoot; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; use polkadot_parachain::primitives::Id as ParaId; @@ -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; } parameter_types! { diff --git a/xcm/xcm-simulator/fuzzer/src/parachain.rs b/xcm/xcm-simulator/fuzzer/src/parachain.rs index 66e9673394af..f4f451aa5a48 100644 --- a/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -22,7 +22,9 @@ use frame_support::{ traits::{Everything, Nothing}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; + use sp_core::{ConstU32, H256}; +use frame_system::EnsureRoot; use sp_runtime::{ testing::Header, traits::{Hash, IdentityLookup}, @@ -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; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index 3d49a71cc98a..b3166dbecfa8 100644 --- a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -21,7 +21,9 @@ use frame_support::{ traits::{Everything, Nothing}, weights::Weight, }; + use sp_core::{ConstU32, H256}; +use frame_system::EnsureRoot; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; use polkadot_parachain::primitives::Id as ParaId; @@ -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; } parameter_types! { From b76281cd377578caab6936e5dfb11b9f64970d76 Mon Sep 17 00:00:00 2001 From: Just van Stam Date: Tue, 21 Mar 2023 12:31:33 +0100 Subject: [PATCH 2/3] cargo fmt --- xcm/pallet-xcm/src/lib.rs | 2 +- xcm/xcm-simulator/example/src/parachain.rs | 2 +- xcm/xcm-simulator/example/src/relay_chain.rs | 2 +- xcm/xcm-simulator/fuzzer/src/parachain.rs | 2 +- xcm/xcm-simulator/fuzzer/src/relay_chain.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index 0bf61355615f..f84c94a063e8 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -231,7 +231,7 @@ pub mod pallet { /// `pallet_xcm::CurrentXcmVersion`. type AdvertisedXcmVersion: Get; - /// The origin that is allowed to call privileged operations on the XCM pallet + /// The origin that is allowed to call privileged operations on the XCM pallet type AdminOrigin: EnsureOrigin<::RuntimeOrigin>; /// The assets which we consider a given origin is trusted if they claim to have placed a diff --git a/xcm/xcm-simulator/example/src/parachain.rs b/xcm/xcm-simulator/example/src/parachain.rs index 338095c5d0de..4cd4094b3328 100644 --- a/xcm/xcm-simulator/example/src/parachain.rs +++ b/xcm/xcm-simulator/example/src/parachain.rs @@ -23,8 +23,8 @@ use frame_support::{ weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; -use sp_core::{ConstU32, H256}; use frame_system::EnsureRoot; +use sp_core::{ConstU32, H256}; use sp_runtime::{ testing::Header, traits::{Hash, IdentityLookup}, diff --git a/xcm/xcm-simulator/example/src/relay_chain.rs b/xcm/xcm-simulator/example/src/relay_chain.rs index 1467335af48e..5db399717fc1 100644 --- a/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/xcm/xcm-simulator/example/src/relay_chain.rs @@ -22,8 +22,8 @@ use frame_support::{ weights::Weight, }; -use sp_core::{ConstU32, H256}; use frame_system::EnsureRoot; +use sp_core::{ConstU32, H256}; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; use polkadot_parachain::primitives::Id as ParaId; diff --git a/xcm/xcm-simulator/fuzzer/src/parachain.rs b/xcm/xcm-simulator/fuzzer/src/parachain.rs index f4f451aa5a48..8480713347c0 100644 --- a/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -23,8 +23,8 @@ use frame_support::{ weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; -use sp_core::{ConstU32, H256}; use frame_system::EnsureRoot; +use sp_core::{ConstU32, H256}; use sp_runtime::{ testing::Header, traits::{Hash, IdentityLookup}, diff --git a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index b3166dbecfa8..962c22297a8e 100644 --- a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -22,8 +22,8 @@ use frame_support::{ weights::Weight, }; -use sp_core::{ConstU32, H256}; use frame_system::EnsureRoot; +use sp_core::{ConstU32, H256}; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; use polkadot_parachain::primitives::Id as ParaId; From a913cb1b5cf0858703ef331b2eb1a6f450946256 Mon Sep 17 00:00:00 2001 From: Just van Stam Date: Wed, 22 Mar 2023 10:29:57 +0100 Subject: [PATCH 3/3] small stylistic change --- runtime/polkadot/src/xcm_config.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/polkadot/src/xcm_config.rs b/runtime/polkadot/src/xcm_config.rs index be81eccdc321..585197a475fb 100644 --- a/runtime/polkadot/src/xcm_config.rs +++ b/runtime/polkadot/src/xcm_config.rs @@ -26,7 +26,6 @@ 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};