From dbdb056bcfc13df81e582c623ae61a0558c81fb6 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 29 Aug 2023 12:41:23 +0700 Subject: [PATCH 1/8] feat(rank-collective): added new assoc. types Added associated types( `AddOrigin` & `RemoveOrigin`) to Config --- .../src/fellowship/mod.rs | 10 +++++-- .../kusama/src/governance/fellowship.rs | 12 ++++++++- substrate/bin/node/runtime/src/lib.rs | 2 ++ .../ranked-collective/src/benchmarking.rs | 12 ++++----- substrate/frame/ranked-collective/src/lib.rs | 26 ++++++++++++------- .../frame/ranked-collective/src/tests.rs | 4 ++- substrate/primitives/runtime/src/traits.rs | 3 +++ 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs index 489b868eff34..7432d6558c1a 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -29,7 +29,7 @@ use frame_support::{ parameter_types, traits::{EitherOf, EitherOfDiverse, MapSuccess, OriginTrait, TryWithMorphedArg}, }; -use frame_system::EnsureRootWithSuccess; +use frame_system::{EnsureNever, EnsureRootWithSuccess}; pub use origins::{ pallet_origins as pallet_fellowship_origins, Architects, EnsureCanPromoteTo, EnsureCanRetainAt, EnsureFellowship, Fellows, Masters, Members, ToVoice, @@ -111,7 +111,12 @@ impl pallet_ranked_collective::Config for Runtime #[cfg(not(feature = "runtime-benchmarks"))] // Promotions and the induction of new members are serviced by `FellowshipCore` pallet instance. - type PromoteOrigin = frame_system::EnsureNever; + type AddOrigin = EnsureNever<()>; + #[cfg(not(feature = "runtime-benchmarks"))] + type PromoteOrigin = EnsureNever; + + #[cfg(feature = "runtime-benchmarks")] + type AddOrigin = EnsureRoot; #[cfg(feature = "runtime-benchmarks")] // The maximum value of `u16` set as a success value for the root to ensure the benchmarks will // pass. @@ -123,6 +128,7 @@ impl pallet_ranked_collective::Config for Runtime // // The maximum value of `u16` set as a success value for the root to ensure the benchmarks will // pass. + type RemoveOrigin = Self::DemoteOrigin; type DemoteOrigin = EitherOf< EnsureRootWithSuccess>, MapSuccess< diff --git a/polkadot/runtime/kusama/src/governance/fellowship.rs b/polkadot/runtime/kusama/src/governance/fellowship.rs index 8837c19e0eb1..fbedf8190d41 100644 --- a/polkadot/runtime/kusama/src/governance/fellowship.rs +++ b/polkadot/runtime/kusama/src/governance/fellowship.rs @@ -23,7 +23,7 @@ use frame_support::traits::{MapSuccess, TryMapSuccess}; use sp_arithmetic::traits::CheckedSub; use sp_runtime::{ morph_types, - traits::{ConstU16, Replace, TypedGet}, + traits::{ConstU16, Ignore, Replace, TypedGet}, }; use super::*; @@ -330,6 +330,11 @@ morph_types! { impl pallet_ranked_collective::Config for Runtime { type WeightInfo = weights::pallet_ranked_collective::WeightInfo; type RuntimeEvent = RuntimeEvent; + // Adding is by any of: + // - Root. + // - the FellowshipAdmin origin. + // - a Fellowship origin. + type AddOrigin = MapSuccess; // Promotion is by any of: // - Root can demote arbitrarily. // - the FellowshipAdmin origin (i.e. token holder referendum); @@ -341,6 +346,11 @@ impl pallet_ranked_collective::Config for Runtime TryMapSuccess>>, >, >; + // Removing is by any of: + // - Root can remove arbitrarily. + // - the FellowshipAdmin origin (i.e. token holder referendum); + // - a vote by the rank two above the current rank. + type RemoveOrigin = Self::DemoteOrigin; // Demotion is by any of: // - Root can demote arbitrarily. // - the FellowshipAdmin origin (i.e. token holder referendum); diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 4f34e4ecd812..f1c6ecb113e0 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -990,6 +990,8 @@ impl pallet_referenda::Config for Runtime { impl pallet_ranked_collective::Config for Runtime { type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight; type RuntimeEvent = RuntimeEvent; + type AddOrigin = EnsureRoot; + type RemoveOrigin = Self::DemoteOrigin; type PromoteOrigin = EnsureRootWithSuccess>; type DemoteOrigin = EnsureRootWithSuccess>; type Polls = RankedPolls; diff --git a/substrate/frame/ranked-collective/src/benchmarking.rs b/substrate/frame/ranked-collective/src/benchmarking.rs index b610d10009a0..74bf32b93776 100644 --- a/substrate/frame/ranked-collective/src/benchmarking.rs +++ b/substrate/frame/ranked-collective/src/benchmarking.rs @@ -37,8 +37,8 @@ fn make_member, I: 'static>(rank: Rank) -> T::AccountId { let who = account::("member", MemberCount::::get(0), SEED); let who_lookup = T::Lookup::unlookup(who.clone()); assert_ok!(Pallet::::add_member( - T::PromoteOrigin::try_successful_origin() - .expect("PromoteOrigin has no successful origin required for the benchmark"), + T::AddOrigin::try_successful_origin() + .expect("AddOrigin has no successful origin required for the benchmark"), who_lookup.clone(), )); for _ in 0..rank { @@ -56,7 +56,7 @@ benchmarks_instance_pallet! { let who = account::("member", 0, SEED); let who_lookup = T::Lookup::unlookup(who.clone()); let origin = - T::PromoteOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + T::AddOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let call = Call::::add_member { who: who_lookup }; }: { call.dispatch_bypass_filter(origin)? } verify { @@ -73,7 +73,7 @@ benchmarks_instance_pallet! { let last = make_member::(rank); let last_index = (0..=rank).map(|r| IdToIndex::::get(r, &last).unwrap()).collect::>(); let origin = - T::DemoteOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + T::RemoveOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let call = Call::::remove_member { who: who_lookup, min_rank: rank }; }: { call.dispatch_bypass_filter(origin)? } verify { @@ -124,8 +124,8 @@ benchmarks_instance_pallet! { let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); assert_ok!(Pallet::::add_member( - T::PromoteOrigin::try_successful_origin() - .expect("PromoteOrigin has no successful origin required for the benchmark"), + T::AddOrigin::try_successful_origin() + .expect("AddOrigin has no successful origin required for the benchmark"), caller_lookup.clone(), )); // Create a poll diff --git a/substrate/frame/ranked-collective/src/lib.rs b/substrate/frame/ranked-collective/src/lib.rs index d94932a1dac7..eff8ca3ca764 100644 --- a/substrate/frame/ranked-collective/src/lib.rs +++ b/substrate/frame/ranked-collective/src/lib.rs @@ -382,12 +382,19 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// The origin required to add or promote a mmember. The success value indicates the + /// The origin required to add a member. + type AddOrigin: EnsureOrigin; + + /// The origin required to remove a member. The success value indicates the + /// maximum rank *from which* the removal may be. + type RemoveOrigin: EnsureOrigin; + + /// The origin required to promote a member. The success value indicates the /// maximum rank *to which* the promotion may be. type PromoteOrigin: EnsureOrigin; - /// The origin required to demote or remove a member. The success value indicates the - /// maximum rank *from which* the demotion/removal may be. + /// The origin required to demote a member. The success value indicates the + /// maximum rank *from which* the demotion may be. type DemoteOrigin: EnsureOrigin; /// The polling system used for our voting. @@ -482,22 +489,21 @@ pub mod pallet { impl, I: 'static> Pallet { /// Introduce a new member. /// - /// - `origin`: Must be the `AdminOrigin`. + /// - `origin`: Must be the `AddOrigin`. /// - `who`: Account of non-member which will become a member. - /// - `rank`: The rank to give the new member. /// /// Weight: `O(1)` #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::add_member())] pub fn add_member(origin: OriginFor, who: AccountIdLookupOf) -> DispatchResult { - let _ = T::PromoteOrigin::ensure_origin(origin)?; + T::AddOrigin::ensure_origin(origin)?; let who = T::Lookup::lookup(who)?; Self::do_add_member(who) } /// Increment the rank of an existing member by one. /// - /// - `origin`: Must be the `AdminOrigin`. + /// - `origin`: Must be the `PromoteOrigin`. /// - `who`: Account of existing member. /// /// Weight: `O(1)` @@ -512,7 +518,7 @@ pub mod pallet { /// Decrement the rank of an existing member by one. If the member is already at rank zero, /// then they are removed entirely. /// - /// - `origin`: Must be the `AdminOrigin`. + /// - `origin`: Must be the `DemoteOrigin`. /// - `who`: Account of existing member of rank greater than zero. /// /// Weight: `O(1)`, less if the member's index is highest in its rank. @@ -526,7 +532,7 @@ pub mod pallet { /// Remove the member entirely. /// - /// - `origin`: Must be the `AdminOrigin`. + /// - `origin`: Must be the `RemoveOrigin`. /// - `who`: Account of existing member of rank greater than zero. /// - `min_rank`: The rank of the member or greater. /// @@ -538,7 +544,7 @@ pub mod pallet { who: AccountIdLookupOf, min_rank: Rank, ) -> DispatchResultWithPostInfo { - let max_rank = T::DemoteOrigin::ensure_origin(origin)?; + let max_rank = T::RemoveOrigin::ensure_origin(origin)?; let who = T::Lookup::lookup(who)?; let MemberRecord { rank, .. } = Self::ensure_member(&who)?; ensure!(min_rank >= rank, Error::::InvalidWitness); diff --git a/substrate/frame/ranked-collective/src/tests.rs b/substrate/frame/ranked-collective/src/tests.rs index ba8c5a0f937b..98644033e7cf 100644 --- a/substrate/frame/ranked-collective/src/tests.rs +++ b/substrate/frame/ranked-collective/src/tests.rs @@ -27,7 +27,7 @@ use frame_support::{ }; use sp_core::{Get, H256}; use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup, ReduceBy}, + traits::{BlakeTwo256, IdentityLookup, Ignore, ReduceBy}, BuildStorage, }; @@ -176,6 +176,8 @@ parameter_types! { impl Config for Test { type WeightInfo = (); type RuntimeEvent = RuntimeEvent; + type AddOrigin = MapSuccess; + type RemoveOrigin = Self::DemoteOrigin; type PromoteOrigin = EitherOf< // Root can promote arbitrarily. frame_system::EnsureRootWithSuccess>, diff --git a/substrate/primitives/runtime/src/traits.rs b/substrate/primitives/runtime/src/traits.rs index 17dc7ce50ea8..078a21dff1d9 100644 --- a/substrate/primitives/runtime/src/traits.rs +++ b/substrate/primitives/runtime/src/traits.rs @@ -540,6 +540,9 @@ morph_types! { /// Morpher to disregard the source value and replace with another. pub type Replace = |_| -> V::Type { V::get() }; + /// Morpher to disregard the source value. + pub type Ignore = |_| -> () {}; + /// Mutator which reduces a scalar by a particular amount. pub type ReduceBy = |r: N::Type| -> N::Type { r.checked_sub(&N::get()).unwrap_or(Zero::zero()) From 8a6c5d62042b5e4fd9c9c0240f4727a045b0642c Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 29 Aug 2023 18:49:43 +0700 Subject: [PATCH 2/8] fix(cumulus): added feature use --- .../collectives/collectives-polkadot/src/fellowship/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs index 7432d6558c1a..3d35c8ec907d 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -29,6 +29,8 @@ use frame_support::{ parameter_types, traits::{EitherOf, EitherOfDiverse, MapSuccess, OriginTrait, TryWithMorphedArg}, }; +#[cfg(feature = "runtime-benchmarks")] +use frame_system::EnsureRoot; use frame_system::{EnsureNever, EnsureRootWithSuccess}; pub use origins::{ pallet_origins as pallet_fellowship_origins, Architects, EnsureCanPromoteTo, EnsureCanRetainAt, From a1d6f3649665d5b00b465ad15e6ca9df581345e7 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 29 Aug 2023 21:03:54 +0700 Subject: [PATCH 3/8] fix(cumulus): unused error --- .../collectives-polkadot/src/fellowship/mod.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs index 3d35c8ec907d..adbe2358c318 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -29,9 +29,7 @@ use frame_support::{ parameter_types, traits::{EitherOf, EitherOfDiverse, MapSuccess, OriginTrait, TryWithMorphedArg}, }; -#[cfg(feature = "runtime-benchmarks")] -use frame_system::EnsureRoot; -use frame_system::{EnsureNever, EnsureRootWithSuccess}; +use frame_system::EnsureRootWithSuccess; pub use origins::{ pallet_origins as pallet_fellowship_origins, Architects, EnsureCanPromoteTo, EnsureCanRetainAt, EnsureFellowship, Fellows, Masters, Members, ToVoice, @@ -113,12 +111,12 @@ impl pallet_ranked_collective::Config for Runtime #[cfg(not(feature = "runtime-benchmarks"))] // Promotions and the induction of new members are serviced by `FellowshipCore` pallet instance. - type AddOrigin = EnsureNever<()>; + type AddOrigin = frame_system::EnsureNever<()>; #[cfg(not(feature = "runtime-benchmarks"))] - type PromoteOrigin = EnsureNever; + type PromoteOrigin = frame_system::EnsureNever; #[cfg(feature = "runtime-benchmarks")] - type AddOrigin = EnsureRoot; + type AddOrigin = frame_system::EnsureRoot; #[cfg(feature = "runtime-benchmarks")] // The maximum value of `u16` set as a success value for the root to ensure the benchmarks will // pass. From 6241a8891f5f9550f42100a7d829783d4df32b83 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 5 Feb 2024 13:05:07 +0100 Subject: [PATCH 4/8] Review fixes and cleanup Signed-off-by: Oliver Tale-Yazdi --- .../collectives-polkadot/src/fellowship/mod.rs | 10 +++++----- .../kusama/src/governance/fellowship.rs | 4 ++-- .../ranked-collective/src/benchmarking.rs | 18 +++--------------- substrate/frame/ranked-collective/src/lib.rs | 5 +++-- substrate/frame/ranked-collective/src/tests.rs | 4 ++-- substrate/primitives/runtime/src/traits.rs | 4 ++-- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs index 45a07c9b6177..69275637bcea 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -109,17 +109,17 @@ impl pallet_ranked_collective::Config for Runtime type WeightInfo = weights::pallet_ranked_collective::WeightInfo; type RuntimeEvent = RuntimeEvent; - #[cfg(not(feature = "runtime-benchmarks"))] // Promotions and the induction of new members are serviced by `FellowshipCore` pallet instance. - type AddOrigin = frame_system::EnsureNever<()>; #[cfg(not(feature = "runtime-benchmarks"))] - type PromoteOrigin = frame_system::EnsureNever; - + type AddOrigin = frame_system::EnsureNever<()>; #[cfg(feature = "runtime-benchmarks")] type AddOrigin = frame_system::EnsureRoot; - #[cfg(feature = "runtime-benchmarks")] + // The maximum value of `u16` set as a success value for the root to ensure the benchmarks will // pass. + #[cfg(not(feature = "runtime-benchmarks"))] + type PromoteOrigin = frame_system::EnsureNever; + #[cfg(feature = "runtime-benchmarks")] type PromoteOrigin = EnsureRootWithSuccess>; // Demotion is by any of: diff --git a/polkadot/runtime/kusama/src/governance/fellowship.rs b/polkadot/runtime/kusama/src/governance/fellowship.rs index fbedf8190d41..9e4eed7f7c53 100644 --- a/polkadot/runtime/kusama/src/governance/fellowship.rs +++ b/polkadot/runtime/kusama/src/governance/fellowship.rs @@ -23,7 +23,7 @@ use frame_support::traits::{MapSuccess, TryMapSuccess}; use sp_arithmetic::traits::CheckedSub; use sp_runtime::{ morph_types, - traits::{ConstU16, Ignore, Replace, TypedGet}, + traits::{ConstU16, Replace, TypedGet}, }; use super::*; @@ -334,7 +334,7 @@ impl pallet_ranked_collective::Config for Runtime // - Root. // - the FellowshipAdmin origin. // - a Fellowship origin. - type AddOrigin = MapSuccess; + type AddOrigin = MapSuccess>; // Promotion is by any of: // - Root can demote arbitrarily. // - the FellowshipAdmin origin (i.e. token holder referendum); diff --git a/substrate/frame/ranked-collective/src/benchmarking.rs b/substrate/frame/ranked-collective/src/benchmarking.rs index 74bf32b93776..823a6d27f189 100644 --- a/substrate/frame/ranked-collective/src/benchmarking.rs +++ b/substrate/frame/ranked-collective/src/benchmarking.rs @@ -121,23 +121,11 @@ benchmarks_instance_pallet! { } vote { - let caller: T::AccountId = whitelisted_caller(); - let caller_lookup = T::Lookup::unlookup(caller.clone()); - assert_ok!(Pallet::::add_member( - T::AddOrigin::try_successful_origin() - .expect("AddOrigin has no successful origin required for the benchmark"), - caller_lookup.clone(), - )); - // Create a poll let class = T::Polls::classes().into_iter().next().unwrap(); let rank = T::MinRankOfClass::convert(class.clone()); - for _ in 0..rank { - assert_ok!(Pallet::::promote_member( - T::PromoteOrigin::try_successful_origin() - .expect("PromoteOrigin has no successful origin required for the benchmark"), - caller_lookup.clone(), - )); - } + + let caller = make_member::(rank); + let caller_lookup = T::Lookup::unlookup(caller.clone()); let poll = T::Polls::create_ongoing(class).expect("Must always be able to create a poll for rank 0"); diff --git a/substrate/frame/ranked-collective/src/lib.rs b/substrate/frame/ranked-collective/src/lib.rs index eff8ca3ca764..7b868bcab6ab 100644 --- a/substrate/frame/ranked-collective/src/lib.rs +++ b/substrate/frame/ranked-collective/src/lib.rs @@ -385,8 +385,9 @@ pub mod pallet { /// The origin required to add a member. type AddOrigin: EnsureOrigin; - /// The origin required to remove a member. The success value indicates the - /// maximum rank *from which* the removal may be. + /// The origin required to remove a member. + /// + /// The success value indicates the maximum rank *from which* the removal may be. type RemoveOrigin: EnsureOrigin; /// The origin required to promote a member. The success value indicates the diff --git a/substrate/frame/ranked-collective/src/tests.rs b/substrate/frame/ranked-collective/src/tests.rs index 98644033e7cf..69ee04e31d55 100644 --- a/substrate/frame/ranked-collective/src/tests.rs +++ b/substrate/frame/ranked-collective/src/tests.rs @@ -27,7 +27,7 @@ use frame_support::{ }; use sp_core::{Get, H256}; use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup, Ignore, ReduceBy}, + traits::{BlakeTwo256, IdentityLookup, ReduceBy, ReplaceWithDefault}, BuildStorage, }; @@ -176,7 +176,7 @@ parameter_types! { impl Config for Test { type WeightInfo = (); type RuntimeEvent = RuntimeEvent; - type AddOrigin = MapSuccess; + type AddOrigin = MapSuccess>; type RemoveOrigin = Self::DemoteOrigin; type PromoteOrigin = EitherOf< // Root can promote arbitrarily. diff --git a/substrate/primitives/runtime/src/traits.rs b/substrate/primitives/runtime/src/traits.rs index 078a21dff1d9..bbff1e734a08 100644 --- a/substrate/primitives/runtime/src/traits.rs +++ b/substrate/primitives/runtime/src/traits.rs @@ -540,8 +540,8 @@ morph_types! { /// Morpher to disregard the source value and replace with another. pub type Replace = |_| -> V::Type { V::get() }; - /// Morpher to disregard the source value. - pub type Ignore = |_| -> () {}; + /// Morpher to disregard the source value and replace with the default of `V`. + pub type ReplaceWithDefault = |_| -> V { Default::default() }; /// Mutator which reduces a scalar by a particular amount. pub type ReduceBy = |r: N::Type| -> N::Type { From cfeed6c992eaed2bee82e533e7ba811fa6bffdf3 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 5 Feb 2024 13:06:15 +0100 Subject: [PATCH 5/8] fmt Signed-off-by: Oliver Tale-Yazdi --- substrate/frame/ranked-collective/src/tests.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/substrate/frame/ranked-collective/src/tests.rs b/substrate/frame/ranked-collective/src/tests.rs index a11b5c5dd8b5..c5fccd3f7724 100644 --- a/substrate/frame/ranked-collective/src/tests.rs +++ b/substrate/frame/ranked-collective/src/tests.rs @@ -23,16 +23,13 @@ use frame_support::{ assert_noop, assert_ok, derive_impl, error::BadOrigin, parameter_types, - traits::{ConstU16, ConstU32, ConstU64, EitherOf, Everything, MapSuccess, Polling}, + traits::{ConstU16, EitherOf, MapSuccess, Polling}, }; -use sp_core::{Get, H256}; +use sp_core::Get; use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup, ReduceBy, ReplaceWithDefault}, + traits::{ReduceBy, ReplaceWithDefault}, BuildStorage, - traits::{ConstU16, EitherOf, MapSuccess, Polling}, }; -use sp_core::Get; -use sp_runtime::{traits::ReduceBy, BuildStorage}; use super::*; use crate as pallet_ranked_collective; From bf691c1996d64f05866d1687e89205879e3aca87 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 5 Feb 2024 14:10:07 +0100 Subject: [PATCH 6/8] Make stuff compile Signed-off-by: Oliver Tale-Yazdi --- .../collectives/collectives-westend/src/ambassador/mod.rs | 4 +++- polkadot/runtime/rococo/src/governance/fellowship.rs | 4 ++-- substrate/frame/core-fellowship/src/tests/integration.rs | 4 +++- substrate/frame/salary/src/tests/integration.rs | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs index d9042f2a5568..0c9f428c1396 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs @@ -40,7 +40,7 @@ use origins::pallet_origins::{ EnsureAmbassadorsVoice, EnsureAmbassadorsVoiceFrom, EnsureHeadAmbassadorsVoice, Origin, }; use sp_core::ConstU128; -use sp_runtime::traits::{CheckedReduceBy, ConstU16, ConvertToValue, Replace}; +use sp_runtime::traits::{CheckedReduceBy, ConstU16, ConvertToValue, Replace, ReplaceWithDefault}; use xcm::prelude::*; use xcm_builder::{AliasesIntoAccountId32, PayOverXcm}; @@ -108,8 +108,10 @@ pub type ExchangeOrigin = EitherOf for Runtime { type WeightInfo = weights::pallet_ranked_collective_ambassador_collective::WeightInfo; type RuntimeEvent = RuntimeEvent; + type AddOrigin = MapSuccess>; type PromoteOrigin = PromoteOrigin; type DemoteOrigin = DemoteOrigin; + type RemoveOrigin = Self::DemoteOrigin; type ExchangeOrigin = ExchangeOrigin; type Polls = AmbassadorReferenda; type MinRankOfClass = sp_runtime::traits::Identity; diff --git a/polkadot/runtime/rococo/src/governance/fellowship.rs b/polkadot/runtime/rococo/src/governance/fellowship.rs index 34c7f3005a0e..a589b768afde 100644 --- a/polkadot/runtime/rococo/src/governance/fellowship.rs +++ b/polkadot/runtime/rococo/src/governance/fellowship.rs @@ -17,7 +17,7 @@ //! Elements of governance concerning the Rococo Fellowship. use frame_support::traits::{MapSuccess, TryMapSuccess}; -use sp_runtime::traits::{CheckedReduceBy, ConstU16, Replace}; +use sp_runtime::traits::{CheckedReduceBy, ConstU16, Replace, ReplaceWithDefault}; use super::*; use crate::{CENTS, DAYS}; @@ -319,7 +319,7 @@ impl pallet_ranked_collective::Config for Runtime // - Root. // - the FellowshipAdmin origin. // - a Fellowship origin. - type AddOrigin = MapSuccess>; + type AddOrigin = MapSuccess>; // Promotion is by any of: // - Root can demote arbitrarily. // - the FellowshipAdmin origin (i.e. token holder referendum); diff --git a/substrate/frame/core-fellowship/src/tests/integration.rs b/substrate/frame/core-fellowship/src/tests/integration.rs index 57f9cad3dcb3..6f177ba66db3 100644 --- a/substrate/frame/core-fellowship/src/tests/integration.rs +++ b/substrate/frame/core-fellowship/src/tests/integration.rs @@ -27,7 +27,7 @@ use frame_system::EnsureSignedBy; use pallet_ranked_collective::{EnsureRanked, Geometric, Rank, TallyOf, Votes}; use sp_core::Get; use sp_runtime::{ - traits::{Convert, ReduceBy, TryMorphInto}, + traits::{Convert, ReduceBy, ReplaceWithDefault, TryMorphInto}, BuildStorage, DispatchError, }; type Class = Rank; @@ -137,12 +137,14 @@ impl pallet_ranked_collective::Config for Test { // Members can promote up to the rank of 2 below them. MapSuccess, ReduceBy>>, >; + type AddOrigin = MapSuccess>; type DemoteOrigin = EitherOf< // Root can demote arbitrarily. frame_system::EnsureRootWithSuccess>, // Members can demote up to the rank of 3 below them. MapSuccess, ReduceBy>>, >; + type RemoveOrigin = Self::DemoteOrigin; type ExchangeOrigin = EitherOf< // Root can exchange arbitrarily. frame_system::EnsureRootWithSuccess>, diff --git a/substrate/frame/salary/src/tests/integration.rs b/substrate/frame/salary/src/tests/integration.rs index bf1e82b028c6..a49b5637b8ae 100644 --- a/substrate/frame/salary/src/tests/integration.rs +++ b/substrate/frame/salary/src/tests/integration.rs @@ -26,7 +26,7 @@ use frame_support::{ use pallet_ranked_collective::{EnsureRanked, Geometric, TallyOf, Votes}; use sp_core::{ConstU16, Get}; use sp_runtime::{ - traits::{Convert, ReduceBy}, + traits::{Convert, ReduceBy, ReplaceWithDefault}, BuildStorage, DispatchError, }; @@ -162,12 +162,14 @@ impl pallet_ranked_collective::Config for Test { // Members can promote up to the rank of 2 below them. MapSuccess, ReduceBy>>, >; + type AddOrigin = MapSuccess>; type DemoteOrigin = EitherOf< // Root can demote arbitrarily. frame_system::EnsureRootWithSuccess>, // Members can demote up to the rank of 3 below them. MapSuccess, ReduceBy>>, >; + type RemoveOrigin = Self::DemoteOrigin; type ExchangeOrigin = EitherOf< // Root can exchange arbitrarily. frame_system::EnsureRootWithSuccess>, From c4d6f7bd97a23c3de5122b1817fb3e219926d180 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 5 Feb 2024 14:15:18 +0100 Subject: [PATCH 7/8] Add prdoc Signed-off-by: Oliver Tale-Yazdi --- prdoc/pr_3212.prdoc | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 prdoc/pr_3212.prdoc diff --git a/prdoc/pr_3212.prdoc b/prdoc/pr_3212.prdoc new file mode 100644 index 000000000000..a9de1e28cdfe --- /dev/null +++ b/prdoc/pr_3212.prdoc @@ -0,0 +1,9 @@ +title: "Ranked collective introduce `Add` and `Remove` origins" + +doc: + - audience: Runtime Dev + description: | + Add two new origins to the ranked-collective pallet. One to add new members and one to remove members, named `AddOrigin` and `RemoveOrigin` respectively. + +crates: + - name: pallet-ranked-collective From 49457fbf8c7f6b60ca149f5782e7d7800e7bdc46 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 5 Feb 2024 14:19:28 +0100 Subject: [PATCH 8/8] Cleanup Signed-off-by: Oliver Tale-Yazdi --- substrate/frame/ranked-collective/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/ranked-collective/src/lib.rs b/substrate/frame/ranked-collective/src/lib.rs index 1c1db08f935d..65ea886acc4f 100644 --- a/substrate/frame/ranked-collective/src/lib.rs +++ b/substrate/frame/ranked-collective/src/lib.rs @@ -394,7 +394,7 @@ pub mod pallet { + IsType<::RuntimeEvent>; /// The origin required to add a member. - type AddOrigin: EnsureOrigin; + type AddOrigin: EnsureOrigin; /// The origin required to remove a member. ///