From 46ac12c81f04b4edfe1385f6e6217ec91ec0e0e1 Mon Sep 17 00:00:00 2001 From: girazoki Date: Tue, 17 Jan 2023 10:28:51 +0100 Subject: [PATCH 1/3] SetMembers configurable origin --- bin/node/runtime/src/lib.rs | 3 +++ frame/alliance/src/mock.rs | 1 + frame/collective/src/lib.rs | 5 ++++- frame/collective/src/tests.rs | 5 ++++- frame/utility/src/tests.rs | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index a9e93a16f0713..767eccc7a3095 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -995,6 +995,7 @@ impl pallet_collective::Config for Runtime { type MaxMembers = CouncilMaxMembers; type DefaultVote = pallet_collective::PrimeDefaultVote; type WeightInfo = pallet_collective::weights::SubstrateWeight; + type SetMembersOrigin = EnsureRoot; } parameter_types! { @@ -1052,6 +1053,7 @@ impl pallet_collective::Config for Runtime { type MaxMembers = TechnicalMaxMembers; type DefaultVote = pallet_collective::PrimeDefaultVote; type WeightInfo = pallet_collective::weights::SubstrateWeight; + type SetMembersOrigin = EnsureRoot; } type EnsureRootOrHalfCouncil = EitherOfDiverse< @@ -1646,6 +1648,7 @@ impl pallet_collective::Config for Runtime { type MaxMembers = AllianceMaxMembers; type DefaultVote = pallet_collective::PrimeDefaultVote; type WeightInfo = pallet_collective::weights::SubstrateWeight; + type SetMembersOrigin = EnsureRoot; } parameter_types! { diff --git a/frame/alliance/src/mock.rs b/frame/alliance/src/mock.rs index e708d29d529fe..0f774dc4853fa 100644 --- a/frame/alliance/src/mock.rs +++ b/frame/alliance/src/mock.rs @@ -104,6 +104,7 @@ impl pallet_collective::Config for Test { type MaxMembers = MaxMembers; type DefaultVote = pallet_collective::PrimeDefaultVote; type WeightInfo = (); + type SetMembersOrigin = EnsureRoot; } parameter_types! { diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index 0fe05dbb01ac0..c7758781c995d 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -215,6 +215,9 @@ pub mod pallet { /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; + + /// Origin allowed to set collective members + type SetMembersOrigin: EnsureOrigin<::RuntimeOrigin>; } #[pallet::genesis_config] @@ -389,7 +392,7 @@ pub mod pallet { prime: Option, old_count: MemberCount, ) -> DispatchResultWithPostInfo { - ensure_root(origin)?; + T::SetMembersOrigin::ensure_origin(origin)?; if new_members.len() > T::MaxMembers::get() as usize { log::error!( target: LOG_TARGET, diff --git a/frame/collective/src/tests.rs b/frame/collective/src/tests.rs index 5c90de9f91bf7..d6a8ac2dc4712 100644 --- a/frame/collective/src/tests.rs +++ b/frame/collective/src/tests.rs @@ -24,7 +24,7 @@ use frame_support::{ traits::{ConstU32, ConstU64, GenesisBuild, StorageVersion}, Hashable, }; -use frame_system::{EventRecord, Phase}; +use frame_system::{EventRecord, Phase, EnsureRoot}; use sp_core::H256; use sp_runtime::{ testing::Header, @@ -127,6 +127,7 @@ impl Config for Test { type MaxMembers = MaxMembers; type DefaultVote = PrimeDefaultVote; type WeightInfo = (); + type SetMembersOrigin = EnsureRoot; } impl Config for Test { type RuntimeOrigin = RuntimeOrigin; @@ -137,6 +138,7 @@ impl Config for Test { type MaxMembers = MaxMembers; type DefaultVote = MoreThanMajorityThenPrimeDefaultVote; type WeightInfo = (); + type SetMembersOrigin = EnsureRoot; } impl mock_democracy::Config for Test { type RuntimeEvent = RuntimeEvent; @@ -151,6 +153,7 @@ impl Config for Test { type MaxMembers = MaxMembers; type DefaultVote = PrimeDefaultVote; type WeightInfo = (); + type SetMembersOrigin = EnsureRoot; } pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index f9d6a16c1a0d4..c63ed24c6aafb 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -217,6 +217,7 @@ impl pallet_collective::Config for Test { type MaxMembers = MaxMembers; type DefaultVote = pallet_collective::PrimeDefaultVote; type WeightInfo = (); + type SetMembersOrigin = frame_system::EnsureRoot; } impl example::Config for Test {} From 9ef9f08ed03024317d83135756c38fb1ee0ed8cf Mon Sep 17 00:00:00 2001 From: girazoki Date: Fri, 20 Jan 2023 11:43:18 +0100 Subject: [PATCH 2/3] root origin comment replaced --- frame/collective/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index c7758781c995d..e4d7e35a9ecac 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -352,7 +352,7 @@ pub mod pallet { /// - `old_count`: The upper bound for the previous number of members in storage. Used for /// weight estimation. /// - /// Requires root origin. + /// The dispatch of this call must be `SetMembersOrigin`. /// /// NOTE: Does not enforce the expected `MaxMembers` limit on the amount of members, but /// the weight estimations rely on it to estimate dispatchable weight. From 841b55bb363e8ef09903a40172a1293f07b402cb Mon Sep 17 00:00:00 2001 From: girazoki Date: Tue, 24 Jan 2023 12:54:10 +0100 Subject: [PATCH 3/3] fmt --- frame/collective/src/lib.rs | 2 +- frame/collective/src/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index e4d7e35a9ecac..7d625a69a4bf7 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -217,7 +217,7 @@ pub mod pallet { type WeightInfo: WeightInfo; /// Origin allowed to set collective members - type SetMembersOrigin: EnsureOrigin<::RuntimeOrigin>; + type SetMembersOrigin: EnsureOrigin<::RuntimeOrigin>; } #[pallet::genesis_config] diff --git a/frame/collective/src/tests.rs b/frame/collective/src/tests.rs index d6a8ac2dc4712..b7cdeb3383375 100644 --- a/frame/collective/src/tests.rs +++ b/frame/collective/src/tests.rs @@ -24,7 +24,7 @@ use frame_support::{ traits::{ConstU32, ConstU64, GenesisBuild, StorageVersion}, Hashable, }; -use frame_system::{EventRecord, Phase, EnsureRoot}; +use frame_system::{EnsureRoot, EventRecord, Phase}; use sp_core::H256; use sp_runtime::{ testing::Header,