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

Adds MaxRank Config in pallet-core-fellowship #3393

Merged
merged 45 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2e527a3
adds max_rank()
Doordashcon Feb 19, 2024
28cdd10
modify original test cases
Doordashcon Feb 26, 2024
277345e
includes prdoc
Doordashcon Feb 26, 2024
696aafb
add higher rank
Doordashcon Feb 27, 2024
5a6a64f
fix benchmark
Doordashcon Feb 28, 2024
6f78f77
Merge branch 'master' into ddc-max-rank
Doordashcon Feb 28, 2024
4117b94
xcm & salary
Mar 11, 2024
26e9a15
Merge branch 'master' into ddc-max-rank
Doordashcon Mar 11, 2024
1352159
benchmaek: set_params
Doordashcon Mar 12, 2024
d72a5bd
adjust promote benchmark
Doordashcon Mar 14, 2024
1cd019b
Merge branch 'master' into ddc-max-rank
Doordashcon Mar 14, 2024
72ecddb
revised implementation
Doordashcon Apr 8, 2024
083669a
Merge branch 'master' into ddc-max-rank
Doordashcon Apr 8, 2024
8a5c550
westend + fmt
Doordashcon Apr 8, 2024
abc2092
fix benchmarks
Doordashcon Apr 8, 2024
6d77c6c
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Apr 12, 2024
dd0e5a9
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 12, 2024
afe16a5
init migration
Doordashcon Apr 15, 2024
4e53b70
Merge branch 'ddc-max-rank' of https://github.com/Doordashcon/polkado…
Doordashcon Apr 15, 2024
a746913
remove migration test
Doordashcon Apr 15, 2024
23a0d06
no truncate
Doordashcon Apr 15, 2024
e4fc2a1
remove nesting
Doordashcon Apr 18, 2024
548b0f7
Merge branch 'master' into ddc-max-rank
Doordashcon Apr 18, 2024
11c73be
adds header
Doordashcon Apr 19, 2024
9eb769f
Merge branch 'master' into ddc-max-rank
Doordashcon Apr 22, 2024
a93fdca
MigrateToV1>>>
Doordashcon Apr 22, 2024
7da28ff
doc update Migration to MigrateToV1
Doordashcon Apr 22, 2024
252d152
westend core pallet migration
Doordashcon Apr 26, 2024
fb1a240
Merge branch 'master' into ddc-max-rank
Doordashcon Apr 26, 2024
137b5f4
Merge branch 'master' into ddc-max-rank
Doordashcon Apr 26, 2024
2aca81a
doc add westend-collective
Doordashcon Apr 26, 2024
8cebd55
Merge branch 'master' into ddc-max-rank
Doordashcon Apr 26, 2024
4d798a4
nit
Doordashcon Apr 27, 2024
fc72258
max_rank in Ranked Member not needed
Doordashcon Apr 30, 2024
093232f
remove Config salary pallet test
Doordashcon Apr 30, 2024
3f21602
ranked remove MaxRank in test
Doordashcon Apr 30, 2024
6c76c06
Merge branch 'master' into ddc-max-rank
Doordashcon Apr 30, 2024
f9724a2
clippy
Doordashcon Apr 30, 2024
105109c
Merge branch 'master' into ddc-max-rank
Doordashcon Apr 30, 2024
25f0d06
similar import for benchmarks
Doordashcon Apr 30, 2024
2afaa8f
sp_runtime::bounded_vec
Doordashcon Apr 30, 2024
ee9f047
sp_core
Doordashcon May 1, 2024
4a31d0a
back to BoundedVec::try_from..
Doordashcon May 3, 2024
5071cb9
Update substrate/frame/core-fellowship/src/lib.rs
bkchr May 16, 2024
9af1d88
Merge branch 'master' into ddc-max-rank
bkchr May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl pallet_ranked_collective::Config<AmbassadorCollectiveInstance> for Runtime
type VoteWeight = pallet_ranked_collective::Linear;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetup = (crate::AmbassadorCore, crate::AmbassadorSalary);
type MaxRank = ConstU32<9>;
}

parameter_types! {
Expand Down Expand Up @@ -220,6 +221,8 @@ impl pallet_core_fellowship::Config<AmbassadorCoreInstance> for Runtime {
type ApproveOrigin = PromoteOrigin;
type PromoteOrigin = PromoteOrigin;
type EvidenceSize = ConstU32<65536>;
type MaxRank =
<Self as pallet_ranked_collective::Config<AmbassadorCollectiveInstance>>::MaxRank;
}

pub type AmbassadorSalaryInstance = pallet_salary::Instance2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl pallet_ranked_collective::Config<FellowshipCollectiveInstance> for Runtime
type VoteWeight = pallet_ranked_collective::Geometric;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetup = (crate::FellowshipCore, crate::FellowshipSalary);
type MaxRank = ConstU32<9>;
}

pub type FellowshipCoreInstance = pallet_core_fellowship::Instance1;
Expand Down Expand Up @@ -210,6 +211,7 @@ impl pallet_core_fellowship::Config<FellowshipCoreInstance> for Runtime {
EnsureCanPromoteTo,
>;
type EvidenceSize = ConstU32<65536>;
type MaxRank = <Self as pallet_ranked_collective::Config<FellowshipCoreInstance>>::MaxRank;
}

pub type FellowshipSalaryInstance = pallet_salary::Instance1;
Expand Down
3 changes: 2 additions & 1 deletion polkadot/runtime/rococo/src/governance/fellowship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
// It is important that this is not available in production!
let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();
if &root == id {
return Ok(9)
return Ok(9);
}
}

Expand Down Expand Up @@ -358,4 +358,5 @@ impl pallet_ranked_collective::Config<FellowshipCollectiveInstance> for Runtime
type VoteWeight = pallet_ranked_collective::Geometric;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetup = ();
type MaxRank = ConstU32<9>;
}
3 changes: 3 additions & 0 deletions polkadot/xcm/xcm-builder/src/tests/pay/salary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ impl RankedMembers for TestClub {
},
})
}
fn max_rank() -> Self::Rank {
CLUB.with(|club| club.borrow().values().max().cloned().unwrap_or(Self::min_rank()))
}
}

fn set_rank(who: AccountId, rank: u128) {
Expand Down
14 changes: 14 additions & 0 deletions prdoc/pr_3393.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Add `max_rank()` method to `RankedMember`

doc:
- audience: Runtime User
description: |
This PR adds a new method named max_rank to the RankedMember trait. This method retrievs the maximum rank within a ranked collective. Initially, the maximum rank was set to IX (Grand Master) on the core-fellowship pallet, corresponding to the establishment of the Technical Fellowship and setting the default member count to nine. However, with the introduction of new collectives, this maximum rank is expected to evolve.

crates:
- name: pallet-core-fellowship
- name: pallet-ranked-collective
- name: pallet-salary
2 changes: 2 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ impl pallet_ranked_collective::Config for Runtime {
type MemberSwappedHandler = (CoreFellowship, Salary);
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetup = (CoreFellowship, Salary);
type MaxRank = ConstU32<9>;
}

impl pallet_remark::Config for Runtime {
Expand Down Expand Up @@ -1870,6 +1871,7 @@ impl pallet_core_fellowship::Config for Runtime {
type ApproveOrigin = EnsureRootWithSuccess<AccountId, ConstU16<9>>;
type PromoteOrigin = EnsureRootWithSuccess<AccountId, ConstU16<9>>;
type EvidenceSize = ConstU32<16_384>;
type MaxRank = <Self as pallet_ranked_collective::Config>::MaxRank;
}

parameter_types! {
Expand Down
24 changes: 15 additions & 9 deletions substrate/frame/core-fellowship/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ mod benchmarks {
}

fn set_benchmark_params<T: Config<I>, I: 'static>() -> Result<(), BenchmarkError> {
let max_rank: usize = T::Members::max_rank().into();
let params = ParamsType {
active_salary: [100u32.into(); 9],
passive_salary: [10u32.into(); 9],
demotion_period: [100u32.into(); 9],
min_promotion_period: [100u32.into(); 9],
active_salary: BoundedVec::try_from(vec![100u32.into(); max_rank]).unwrap(),
passive_salary: BoundedVec::try_from(vec![10u32.into(); max_rank]).unwrap(),
demotion_period: BoundedVec::try_from(vec![100u32.into(); max_rank]).unwrap(),
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
min_promotion_period: BoundedVec::try_from(vec![100u32.into(); max_rank]).unwrap(),
offboard_timeout: 1u32.into(),
};

Expand All @@ -68,11 +69,12 @@ mod benchmarks {

#[benchmark]
fn set_params() -> Result<(), BenchmarkError> {
let max_rank: usize = T::Members::max_rank().into();
let params = ParamsType {
active_salary: [100u32.into(); 9],
passive_salary: [10u32.into(); 9],
demotion_period: [100u32.into(); 9],
min_promotion_period: [100u32.into(); 9],
active_salary: BoundedVec::try_from(vec![100u32.into(); max_rank]).unwrap(),
passive_salary: BoundedVec::try_from(vec![10u32.into(); max_rank]).unwrap(),
demotion_period: BoundedVec::try_from(vec![100u32.into(); max_rank]).unwrap(),
min_promotion_period: BoundedVec::try_from(vec![100u32.into(); max_rank]).unwrap(),
offboard_timeout: 1u32.into(),
};

Expand Down Expand Up @@ -151,10 +153,14 @@ mod benchmarks {
fn promote() -> Result<(), BenchmarkError> {
// Ensure that the `min_promotion_period` wont get in our way.
let mut params = Params::<T, I>::get();
params.min_promotion_period = [Zero::zero(); RANK_COUNT];
let max_rank: usize = T::Members::max_rank().into();
params.min_promotion_period = BoundedVec::try_from(vec![Zero::zero(); max_rank]).unwrap();
Params::<T, I>::put(&params);

let member = make_member::<T, I>(1)?;

// Set it to the max value to ensure that any possible auto-demotion period has passed.
frame_system::Pallet::<T>::set_block_number(BlockNumberFor::<T>::max_value());
ensure_evidence::<T, I>(&member)?;

#[extrinsic_call]
Expand Down
76 changes: 50 additions & 26 deletions substrate/frame/core-fellowship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_arithmetic::traits::{Saturating, Zero};
use sp_runtime::RuntimeDebug;
use sp_std::{marker::PhantomData, prelude::*};
use sp_std::{fmt::Debug, marker::PhantomData, prelude::*};

use frame_support::{
defensive,
Expand All @@ -71,18 +71,19 @@ use frame_support::{
tokens::Balance as BalanceTrait, EnsureOrigin, EnsureOriginWithArg, Get, RankedMembers,
RankedMembersSwapHandler,
},
BoundedVec,
BoundedVec, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound,
};

#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod migration;
pub mod weights;

pub use pallet::*;
pub use weights::WeightInfo;
pub use weights::*;

/// The desired outcome for which evidence is presented.
#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, TypeInfo, MaxEncodedLen, RuntimeDebug)]
Expand All @@ -100,29 +101,46 @@ pub enum Wish {
pub type Evidence<T, I> = BoundedVec<u8, <T as Config<I>>::EvidenceSize>;

/// The status of the pallet instance.
#[derive(Encode, Decode, Eq, PartialEq, Clone, TypeInfo, MaxEncodedLen, RuntimeDebug)]
pub struct ParamsType<Balance, BlockNumber, const RANKS: usize> {
#[derive(
Encode,
Decode,
CloneNoBound,
EqNoBound,
PartialEqNoBound,
RuntimeDebugNoBound,
TypeInfo,
MaxEncodedLen,
)]
#[scale_info(skip_type_params(Ranks))]
pub struct ParamsType<
Balance: Clone + Eq + PartialEq + Debug,
BlockNumber: Clone + Eq + PartialEq + Debug,
Ranks: Get<u32>,
> {
/// The amounts to be paid when a member of a given rank (-1) is active.
active_salary: [Balance; RANKS],
pub active_salary: BoundedVec<Balance, Ranks>,
/// The amounts to be paid when a member of a given rank (-1) is passive.
passive_salary: [Balance; RANKS],
pub passive_salary: BoundedVec<Balance, Ranks>,
/// The period between which unproven members become demoted.
demotion_period: [BlockNumber; RANKS],
pub demotion_period: BoundedVec<BlockNumber, Ranks>,
/// The period between which members must wait before they may proceed to this rank.
min_promotion_period: [BlockNumber; RANKS],
pub min_promotion_period: BoundedVec<BlockNumber, Ranks>,
/// Amount by which an account can remain at rank 0 (candidate before being offboard entirely).
offboard_timeout: BlockNumber,
pub offboard_timeout: BlockNumber,
}

impl<Balance: Default + Copy, BlockNumber: Default + Copy, const RANKS: usize> Default
for ParamsType<Balance, BlockNumber, RANKS>
impl<
Balance: Default + Copy + Eq + Debug,
BlockNumber: Default + Copy + Eq + Debug,
Ranks: Get<u32>,
> Default for ParamsType<Balance, BlockNumber, Ranks>
{
fn default() -> Self {
Self {
active_salary: [Balance::default(); RANKS],
passive_salary: [Balance::default(); RANKS],
demotion_period: [BlockNumber::default(); RANKS],
min_promotion_period: [BlockNumber::default(); RANKS],
active_salary: Default::default(),
passive_salary: Default::default(),
demotion_period: Default::default(),
min_promotion_period: Default::default(),
offboard_timeout: BlockNumber::default(),
}
}
Expand All @@ -148,11 +166,11 @@ pub mod pallet {
traits::{tokens::GetSalary, EnsureOrigin},
};
use frame_system::{ensure_root, pallet_prelude::*};

/// Number of available ranks.
pub(crate) const RANK_COUNT: usize = 9;
/// The in-code storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);

#[pallet::config]
Expand Down Expand Up @@ -194,9 +212,13 @@ pub mod pallet {
/// The maximum size in bytes submitted evidence is allowed to be.
#[pallet::constant]
type EvidenceSize: Get<u32>;

#[pallet::constant]
type MaxRank: Get<u32>;
Doordashcon marked this conversation as resolved.
Show resolved Hide resolved
}

pub type ParamsOf<T, I> = ParamsType<<T as Config<I>>::Balance, BlockNumberFor<T>, RANK_COUNT>;
pub type ParamsOf<T, I> =
ParamsType<<T as Config<I>>::Balance, BlockNumberFor<T>, <T as Config<I>>::MaxRank>;
pub type MemberStatusOf<T> = MemberStatus<BlockNumberFor<T>>;
pub type RankOf<T, I> = <<T as Config<I>>::Members as RankedMembers>::Rank;

Expand Down Expand Up @@ -304,7 +326,7 @@ pub mod pallet {
};

if demotion_period.is_zero() {
return Err(Error::<T, I>::NothingDoing.into())
return Err(Error::<T, I>::NothingDoing.into());
Doordashcon marked this conversation as resolved.
Show resolved Hide resolved
}

let demotion_block = member.last_proof.saturating_add(demotion_period);
Expand All @@ -324,7 +346,7 @@ pub mod pallet {
Event::<T, I>::Offboarded { who }
};
Self::deposit_event(event);
return Ok(Pays::No.into())
return Ok(Pays::No.into());
}

Err(Error::<T, I>::NothingDoing.into())
Expand All @@ -338,8 +360,10 @@ pub mod pallet {
#[pallet::call_index(1)]
pub fn set_params(origin: OriginFor<T>, params: Box<ParamsOf<T, I>>) -> DispatchResult {
T::ParamsOrigin::ensure_origin_or_root(origin)?;

Params::<T, I>::put(params.as_ref());
Self::deposit_event(Event::<T, I>::ParamsChanged { params: *params });

Ok(())
}

Expand Down Expand Up @@ -540,7 +564,7 @@ pub mod pallet {
/// in the range `1..=RANK_COUNT` is `None`.
pub(crate) fn rank_to_index(rank: RankOf<T, I>) -> Option<usize> {
match TryInto::<usize>::try_into(rank) {
Ok(r) if r <= RANK_COUNT && r > 0 => Some(r - 1),
Ok(r) if r <= T::Members::max_rank().into() && r > 0 => Some(r - 1),
_ => return None,
}
}
Expand Down Expand Up @@ -612,15 +636,15 @@ impl<T: Config<I>, I: 'static> RankedMembersSwapHandler<T::AccountId, u16> for P
fn swapped(old: &T::AccountId, new: &T::AccountId, _rank: u16) {
if old == new {
defensive!("Should not try to swap with self");
return
return;
}
if !Member::<T, I>::contains_key(old) {
defensive!("Should not try to swap non-member");
return
return;
}
if Member::<T, I>::contains_key(new) {
defensive!("Should not try to overwrite existing member");
return
return;
}

if let Some(member) = Member::<T, I>::take(old) {
Expand Down
Loading
Loading