Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ranked collective Add+Remove origins #3212

Merged
merged 12 commits into from
Feb 6, 2024
Prev Previous commit
Next Next commit
Review fixes and cleanup
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
ggwpez committed Feb 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6241a8891f5f9550f42100a7d829783d4df32b83
Original file line number Diff line number Diff line change
@@ -109,17 +109,17 @@ impl pallet_ranked_collective::Config<FellowshipCollectiveInstance> for Runtime
type WeightInfo = weights::pallet_ranked_collective::WeightInfo<Runtime>;
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<pallet_ranked_collective::Rank>;

type AddOrigin = frame_system::EnsureNever<()>;
#[cfg(feature = "runtime-benchmarks")]
type AddOrigin = frame_system::EnsureRoot<Self::AccountId>;
#[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<pallet_ranked_collective::Rank>;
#[cfg(feature = "runtime-benchmarks")]
type PromoteOrigin = EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>;

// Demotion is by any of:
4 changes: 2 additions & 2 deletions polkadot/runtime/kusama/src/governance/fellowship.rs
Original file line number Diff line number Diff line change
@@ -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<FellowshipCollectiveInstance> for Runtime
// - Root.
// - the FellowshipAdmin origin.
// - a Fellowship origin.
type AddOrigin = MapSuccess<Self::PromoteOrigin, Ignore>;
type AddOrigin = MapSuccess<Self::PromoteOrigin, Replace<()>>;
// Promotion is by any of:
// - Root can demote arbitrarily.
// - the FellowshipAdmin origin (i.e. token holder referendum);
18 changes: 3 additions & 15 deletions substrate/frame/ranked-collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -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::<T, I>::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::<T, I>::promote_member(
T::PromoteOrigin::try_successful_origin()
.expect("PromoteOrigin has no successful origin required for the benchmark"),
caller_lookup.clone(),
));
}

let caller = make_member::<T, I>(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");

5 changes: 3 additions & 2 deletions substrate/frame/ranked-collective/src/lib.rs
Original file line number Diff line number Diff line change
@@ -385,8 +385,9 @@ pub mod pallet {
/// The origin required to add a member.
type AddOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = ()>;

/// 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<Self::RuntimeOrigin, Success = Rank>;

/// The origin required to promote a member. The success value indicates the
4 changes: 2 additions & 2 deletions substrate/frame/ranked-collective/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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<Self::PromoteOrigin, Ignore>;
type AddOrigin = MapSuccess<Self::PromoteOrigin, ReplaceWithDefault<()>>;
type RemoveOrigin = Self::DemoteOrigin;
type PromoteOrigin = EitherOf<
// Root can promote arbitrarily.
4 changes: 2 additions & 2 deletions substrate/primitives/runtime/src/traits.rs
Original file line number Diff line number Diff line change
@@ -540,8 +540,8 @@ morph_types! {
/// Morpher to disregard the source value and replace with another.
pub type Replace<V: TypedGet> = |_| -> 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> = |_| -> V { Default::default() };

/// Mutator which reduces a scalar by a particular amount.
pub type ReduceBy<N: TypedGet> = |r: N::Type| -> N::Type {