From 2e527a32d77d1bdddd7672ee309d0cb20afa4ff2 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 19 Feb 2024 16:17:19 +0100 Subject: [PATCH 01/31] adds max_rank() --- substrate/frame/core-fellowship/src/lib.rs | 45 ++++++++++++------- substrate/frame/ranked-collective/src/lib.rs | 7 +++ substrate/frame/support/src/traits/members.rs | 3 ++ 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index d1b81c3ca134..a8be69957ee0 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -101,28 +101,28 @@ pub type Evidence = BoundedVec>::EvidenceSize>; /// The status of the pallet instance. #[derive(Encode, Decode, Eq, PartialEq, Clone, TypeInfo, MaxEncodedLen, RuntimeDebug)] -pub struct ParamsType { +pub struct ParamsType { /// The amounts to be paid when a member of a given rank (-1) is active. - active_salary: [Balance; RANKS], + active_salary: Vec, /// The amounts to be paid when a member of a given rank (-1) is passive. - passive_salary: [Balance; RANKS], + passive_salary: Vec, /// The period between which unproven members become demoted. - demotion_period: [BlockNumber; RANKS], + demotion_period: Vec, /// The period between which members must wait before they may proceed to this rank. - min_promotion_period: [BlockNumber; RANKS], + min_promotion_period: Vec, /// Amount by which an account can remain at rank 0 (candidate before being offboard entirely). offboard_timeout: BlockNumber, } -impl Default - for ParamsType +impl Default + for ParamsType { 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: Vec::new(), + passive_salary: Vec::new(), + demotion_period: Vec::new(), + min_promotion_period: Vec::new(), offboard_timeout: BlockNumber::default(), } } @@ -149,9 +149,8 @@ pub mod pallet { }; use frame_system::{ensure_root, pallet_prelude::*}; - const RANK_COUNT: usize = 9; - #[pallet::pallet] + #[pallet::without_storage_info] pub struct Pallet(PhantomData<(T, I)>); #[pallet::config] @@ -195,7 +194,7 @@ pub mod pallet { type EvidenceSize: Get; } - pub type ParamsOf = ParamsType<>::Balance, BlockNumberFor, RANK_COUNT>; + pub type ParamsOf = ParamsType<>::Balance, BlockNumberFor>; pub type MemberStatusOf = MemberStatus>; pub type RankOf = <>::Members as RankedMembers>::Rank; @@ -276,6 +275,8 @@ pub mod pallet { NotTracked, /// Operation cannot be done yet since not enough time has passed. TooSoon, + /// Length of parameters are incompatible. + IncorrectParamsLength, } #[pallet::call] @@ -337,8 +338,22 @@ pub mod pallet { #[pallet::call_index(1)] pub fn set_params(origin: OriginFor, params: Box>) -> DispatchResult { T::ParamsOrigin::ensure_origin_or_root(origin)?; + //Params::::put(params.as_ref()); + //Self::deposit_event(Event::::ParamsChanged { params: *params }); + // Assume get_max_rank() is a function that retrieves the current max rank allowed. + let max_rank = T::Members::max_rank(); + + // Validate the lengths of the vectors in params are equal to max_rank. + let expected_length = max_rank as usize; // Convert max_rank to usize for comparison. + ensure!(params.active_salary.len() == expected_length && + params.passive_salary.len() == expected_length && + params.demotion_period.len() == expected_length && + params.min_promotion_period.len() == expected_length, + Error::::IncorrectParamsLength); // Ensure this error is defined in your pallet. + Params::::put(params.as_ref()); Self::deposit_event(Event::::ParamsChanged { params: *params }); + Ok(()) } @@ -539,7 +554,7 @@ pub mod pallet { /// in the range `1..=RANK_COUNT` is `None`. pub(crate) fn rank_to_index(rank: RankOf) -> Option { match TryInto::::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, } } diff --git a/substrate/frame/ranked-collective/src/lib.rs b/substrate/frame/ranked-collective/src/lib.rs index ceaf03de2110..986060ad29c8 100644 --- a/substrate/frame/ranked-collective/src/lib.rs +++ b/substrate/frame/ranked-collective/src/lib.rs @@ -1003,5 +1003,12 @@ pub mod pallet { fn demote(who: &Self::AccountId) -> DispatchResult { Self::do_demote_member(who.clone(), None) } + + fn max_rank() -> Self::Rank { + MemberCount::::iter() + .map(|(rank, _)| rank) + .max() + .unwrap_or(Self::min_rank()) + } } } diff --git a/substrate/frame/support/src/traits/members.rs b/substrate/frame/support/src/traits/members.rs index 3a6e3719593a..c681bdd987bd 100644 --- a/substrate/frame/support/src/traits/members.rs +++ b/substrate/frame/support/src/traits/members.rs @@ -295,6 +295,9 @@ pub trait RankedMembers { /// Demote a member to the next lower rank; demoting beyond the `min_rank` removes the /// member entirely. fn demote(who: &Self::AccountId) -> DispatchResult; + + /// The maximum rank possible in this membership organisation. + fn max_rank() -> Self::Rank; } /// Handler that can deal with the swap of two members. From 28cdd10dccfd8a0534da844890d089de32e341cf Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 26 Feb 2024 10:47:50 +0100 Subject: [PATCH 02/31] modify original test cases --- substrate/frame/core-fellowship/src/lib.rs | 6 ++-- .../core-fellowship/src/tests/integration.rs | 10 +++--- .../frame/core-fellowship/src/tests/unit.rs | 35 ++++++++++++------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index a8be69957ee0..5ab483c8699a 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -338,9 +338,7 @@ pub mod pallet { #[pallet::call_index(1)] pub fn set_params(origin: OriginFor, params: Box>) -> DispatchResult { T::ParamsOrigin::ensure_origin_or_root(origin)?; - //Params::::put(params.as_ref()); - //Self::deposit_event(Event::::ParamsChanged { params: *params }); - // Assume get_max_rank() is a function that retrieves the current max rank allowed. + // Retrieves the current max rank allowed. let max_rank = T::Members::max_rank(); // Validate the lengths of the vectors in params are equal to max_rank. @@ -349,7 +347,7 @@ pub mod pallet { params.passive_salary.len() == expected_length && params.demotion_period.len() == expected_length && params.min_promotion_period.len() == expected_length, - Error::::IncorrectParamsLength); // Ensure this error is defined in your pallet. + Error::::IncorrectParamsLength); Params::::put(params.as_ref()); Self::deposit_event(Event::::ParamsChanged { params: *params }); diff --git a/substrate/frame/core-fellowship/src/tests/integration.rs b/substrate/frame/core-fellowship/src/tests/integration.rs index 6f177ba66db3..2826250ca1fb 100644 --- a/substrate/frame/core-fellowship/src/tests/integration.rs +++ b/substrate/frame/core-fellowship/src/tests/integration.rs @@ -163,11 +163,13 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| { + assert_ok!(Club::add_member(RuntimeOrigin::root(), 100)); + promote_n_times(100, 9); let params = ParamsType { - active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90], - passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9], - demotion_period: [2, 4, 6, 8, 10, 12, 14, 16, 18], - min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27], + active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90].to_vec(), + passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9].to_vec(), + demotion_period: [2, 4, 6, 8, 10, 12, 14, 16, 18].to_vec(), + min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27].to_vec(), offboard_timeout: 1, }; assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); diff --git a/substrate/frame/core-fellowship/src/tests/unit.rs b/substrate/frame/core-fellowship/src/tests/unit.rs index de8cd858bdfc..ddcffb081891 100644 --- a/substrate/frame/core-fellowship/src/tests/unit.rs +++ b/substrate/frame/core-fellowship/src/tests/unit.rs @@ -89,6 +89,15 @@ 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: u64, rank: u16) { @@ -122,13 +131,15 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| { + set_rank(100, 9); let params = ParamsType { - active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90], - passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9], - demotion_period: [2, 4, 6, 8, 10, 12, 14, 16, 18], - min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27], + active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90].to_vec(), + passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9].to_vec(), + demotion_period: [2, 4, 6, 8, 10, 12, 14, 16, 18].to_vec(), + min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27].to_vec(), offboard_timeout: 1, }; + assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); System::set_block_number(1); }); @@ -170,10 +181,10 @@ fn basic_stuff() { fn set_params_works() { new_test_ext().execute_with(|| { let params = ParamsType { - active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90], - passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9], - demotion_period: [1, 2, 3, 4, 5, 6, 7, 8, 9], - min_promotion_period: [1, 2, 3, 4, 5, 10, 15, 20, 30], + active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90].to_vec(), + passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9].to_vec(), + demotion_period: [1, 2, 3, 4, 5, 6, 7, 8, 9].to_vec(), + min_promotion_period: [1, 2, 3, 4, 5, 10, 15, 20, 30].to_vec(), offboard_timeout: 1, }; assert_noop!( @@ -284,10 +295,10 @@ fn offboard_works() { fn infinite_demotion_period_works() { new_test_ext().execute_with(|| { let params = ParamsType { - active_salary: [10; 9], - passive_salary: [10; 9], - min_promotion_period: [10; 9], - demotion_period: [0; 9], + active_salary: [10; 9].to_vec(), + passive_salary: [10; 9].to_vec(), + min_promotion_period: [10; 9].to_vec(), + demotion_period: [0; 9].to_vec(), offboard_timeout: 0, }; assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); From 277345e6bcc6ce62d232a95b90a7be520ddeafba Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 26 Feb 2024 17:33:49 +0100 Subject: [PATCH 03/31] includes prdoc --- prdoc/pr_3393.prdoc | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 prdoc/pr_3393.prdoc diff --git a/prdoc/pr_3393.prdoc b/prdoc/pr_3393.prdoc new file mode 100644 index 000000000000..6a62053537f8 --- /dev/null +++ b/prdoc/pr_3393.prdoc @@ -0,0 +1,13 @@ +# 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 facilitates the expansion of rank numbers within a collective. Initially, the maximum rank was set to IX (Grand Master), 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 \ No newline at end of file From 696aafbd705690c580b8306391e36cf7d1a8b585 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 27 Feb 2024 11:10:36 +0100 Subject: [PATCH 04/31] add higher rank --- prdoc/pr_3393.prdoc | 2 +- .../core-fellowship/src/tests/integration.rs | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/prdoc/pr_3393.prdoc b/prdoc/pr_3393.prdoc index 6a62053537f8..b384085401b8 100644 --- a/prdoc/pr_3393.prdoc +++ b/prdoc/pr_3393.prdoc @@ -6,7 +6,7 @@ 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 facilitates the expansion of rank numbers within a collective. Initially, the maximum rank was set to IX (Grand Master), 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. + This PR adds a new method named max_rank to the RankedMember trait. This method facilitates the expansion of rank numbers within a 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 diff --git a/substrate/frame/core-fellowship/src/tests/integration.rs b/substrate/frame/core-fellowship/src/tests/integration.rs index 2826250ca1fb..03f8a647fbb0 100644 --- a/substrate/frame/core-fellowship/src/tests/integration.rs +++ b/substrate/frame/core-fellowship/src/tests/integration.rs @@ -24,7 +24,7 @@ use frame_support::{ traits::{ConstU16, EitherOf, IsInVec, MapSuccess, PollStatus, Polling, TryMapSuccess}, }; use frame_system::EnsureSignedBy; -use pallet_ranked_collective::{EnsureRanked, Geometric, Rank, TallyOf, Votes}; +use pallet_ranked_collective::{EnsureRanked, Geometric, Rank, TallyOf, Votes, MemberCount}; use sp_core::Get; use sp_runtime::{ traits::{Convert, ReduceBy, ReplaceWithDefault, TryMorphInto}, @@ -280,3 +280,35 @@ fn swap_bad_noops() { ); }); } + +#[test] +fn add_higher_rank() { + new_test_ext().execute_with(|| { + assert_ok!(Club::add_member(RuntimeOrigin::root(), 7)); + assert_ok!(Club::add_member(RuntimeOrigin::root(), 5)); + promote_n_times(7, 9); + promote_n_times(5, 9); + + System::set_block_number(3); + assert_ok!(CoreFellowship::import(signed(7))); + assert_ok!(CoreFellowship::import(signed(5))); + + // MemberCount still reads previous max rank as 9 + assert_noop!(CoreFellowship::promote(RuntimeOrigin::root(), 7, 10), Error::::InvalidRank); + + assert_ok!(Club::promote_member(RuntimeOrigin::root(), 7)); + assert_eq!(MemberCount::::get(10), 1); + + let params = ParamsType { + active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100].to_vec(), + passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].to_vec(), + demotion_period: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20].to_vec(), + min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30].to_vec(), + offboard_timeout: 1, + }; + assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); + + System::set_block_number(30); + assert_ok!(CoreFellowship::promote(RuntimeOrigin::root(), 5, 10)); + }) +} From 5a6a64f44c9e14c36b7dd15a78602ddedc4547a2 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Wed, 28 Feb 2024 20:58:47 +0100 Subject: [PATCH 05/31] fix benchmark --- .../frame/core-fellowship/src/benchmarking.rs | 21 ++++++++++++------- substrate/frame/core-fellowship/src/lib.rs | 10 +++++---- .../core-fellowship/src/tests/integration.rs | 7 +++++-- .../frame/core-fellowship/src/tests/unit.rs | 12 +++-------- substrate/frame/ranked-collective/src/lib.rs | 6 +++--- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index ddde70bd7ce1..dc5a72323fd7 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -54,11 +54,12 @@ mod benchmarks { } fn set_benchmark_params, 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: vec![100u32.into(); max_rank], + passive_salary: vec![10u32.into(); max_rank], + demotion_period: vec![100u32.into(); max_rank], + min_promotion_period: vec![100u32.into(); max_rank], offboard_timeout: 1u32.into(), }; @@ -69,10 +70,10 @@ mod benchmarks { #[benchmark] fn set_params() -> Result<(), BenchmarkError> { 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: [100u32.into(); 9].to_vec(), + passive_salary: [10u32.into(); 9].to_vec(), + demotion_period: [100u32.into(); 9].to_vec(), + min_promotion_period: [100u32.into(); 9].to_vec(), offboard_timeout: 1u32.into(), }; @@ -149,9 +150,13 @@ mod benchmarks { #[benchmark] fn promote() -> Result<(), BenchmarkError> { + set_benchmark_params::()?; + let member = make_member::(1)?; ensure_evidence::(&member)?; + frame_system::Pallet::::set_block_number(BlockNumberFor::::max_value()); + #[extrinsic_call] _(RawOrigin::Root, member.clone(), 2u8.into()); diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index 5ab483c8699a..f4ae0b060623 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -343,15 +343,17 @@ pub mod pallet { // Validate the lengths of the vectors in params are equal to max_rank. let expected_length = max_rank as usize; // Convert max_rank to usize for comparison. - ensure!(params.active_salary.len() == expected_length && + ensure!( + params.active_salary.len() == expected_length && params.passive_salary.len() == expected_length && params.demotion_period.len() == expected_length && params.min_promotion_period.len() == expected_length, - Error::::IncorrectParamsLength); - + Error::::IncorrectParamsLength + ); + Params::::put(params.as_ref()); Self::deposit_event(Event::::ParamsChanged { params: *params }); - + Ok(()) } diff --git a/substrate/frame/core-fellowship/src/tests/integration.rs b/substrate/frame/core-fellowship/src/tests/integration.rs index 03f8a647fbb0..47aa950dab91 100644 --- a/substrate/frame/core-fellowship/src/tests/integration.rs +++ b/substrate/frame/core-fellowship/src/tests/integration.rs @@ -24,7 +24,7 @@ use frame_support::{ traits::{ConstU16, EitherOf, IsInVec, MapSuccess, PollStatus, Polling, TryMapSuccess}, }; use frame_system::EnsureSignedBy; -use pallet_ranked_collective::{EnsureRanked, Geometric, Rank, TallyOf, Votes, MemberCount}; +use pallet_ranked_collective::{EnsureRanked, Geometric, MemberCount, Rank, TallyOf, Votes}; use sp_core::Get; use sp_runtime::{ traits::{Convert, ReduceBy, ReplaceWithDefault, TryMorphInto}, @@ -294,7 +294,10 @@ fn add_higher_rank() { assert_ok!(CoreFellowship::import(signed(5))); // MemberCount still reads previous max rank as 9 - assert_noop!(CoreFellowship::promote(RuntimeOrigin::root(), 7, 10), Error::::InvalidRank); + assert_noop!( + CoreFellowship::promote(RuntimeOrigin::root(), 7, 10), + Error::::InvalidRank + ); assert_ok!(Club::promote_member(RuntimeOrigin::root(), 7)); assert_eq!(MemberCount::::get(10), 1); diff --git a/substrate/frame/core-fellowship/src/tests/unit.rs b/substrate/frame/core-fellowship/src/tests/unit.rs index ddcffb081891..aca04f6c8a33 100644 --- a/substrate/frame/core-fellowship/src/tests/unit.rs +++ b/substrate/frame/core-fellowship/src/tests/unit.rs @@ -90,14 +90,8 @@ impl RankedMembers for TestClub { }) } fn max_rank() -> Self::Rank { - CLUB.with(|club| { - club.borrow() - .values() - .max() - .cloned() - .unwrap_or(Self::min_rank()) - }) - } + CLUB.with(|club| club.borrow().values().max().cloned().unwrap_or(Self::min_rank())) + } } fn set_rank(who: u64, rank: u16) { @@ -139,7 +133,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27].to_vec(), offboard_timeout: 1, }; - + assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); System::set_block_number(1); }); diff --git a/substrate/frame/ranked-collective/src/lib.rs b/substrate/frame/ranked-collective/src/lib.rs index 986060ad29c8..638537b9dbad 100644 --- a/substrate/frame/ranked-collective/src/lib.rs +++ b/substrate/frame/ranked-collective/src/lib.rs @@ -1006,9 +1006,9 @@ pub mod pallet { fn max_rank() -> Self::Rank { MemberCount::::iter() - .map(|(rank, _)| rank) - .max() - .unwrap_or(Self::min_rank()) + .map(|(rank, _)| rank) + .max() + .unwrap_or(Self::min_rank()) } } } From 4117b949a960c91d240a966a99212a83f3ddb272 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 11 Mar 2024 12:03:18 +0100 Subject: [PATCH 06/31] xcm & salary --- polkadot/xcm/xcm-builder/src/tests/pay/salary.rs | 3 +++ substrate/frame/salary/src/tests/unit.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs index 6a2945c6a9b9..d40db26b4f90 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs @@ -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) { diff --git a/substrate/frame/salary/src/tests/unit.rs b/substrate/frame/salary/src/tests/unit.rs index b3fd00ec76b9..a4724be179a5 100644 --- a/substrate/frame/salary/src/tests/unit.rs +++ b/substrate/frame/salary/src/tests/unit.rs @@ -135,6 +135,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: u64, rank: u64) { From 13521599e6c2b3924161eae4e293a002a5f4c093 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 12 Mar 2024 14:56:37 +0100 Subject: [PATCH 07/31] benchmaek: set_params --- substrate/frame/core-fellowship/src/benchmarking.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index dc5a72323fd7..5cc88457dafb 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -69,6 +69,7 @@ mod benchmarks { #[benchmark] fn set_params() -> Result<(), BenchmarkError> { + make_member::(9)?; let params = ParamsType { active_salary: [100u32.into(); 9].to_vec(), passive_salary: [10u32.into(); 9].to_vec(), From d72a5bdbed765090d1af4bdc6dd29ca7f7018373 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Thu, 14 Mar 2024 08:44:45 +0100 Subject: [PATCH 08/31] adjust promote benchmark --- .../frame/core-fellowship/src/benchmarking.rs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index 5cc88457dafb..073472fb09fe 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -106,10 +106,10 @@ mod benchmarks { #[benchmark] fn bump_demote() -> Result<(), BenchmarkError> { - set_benchmark_params::()?; - let member = make_member::(2)?; + set_benchmark_params::()?; + // Set it to the max value to ensure that any possible auto-demotion period has passed. frame_system::Pallet::::set_block_number(BlockNumberFor::::max_value()); ensure_evidence::(&member)?; @@ -151,18 +151,27 @@ mod benchmarks { #[benchmark] fn promote() -> Result<(), BenchmarkError> { + let candidate: T::AccountId = account("candidate", 0, SEED); + + T::Members::induct(&candidate)?; + + CoreFellowship::::import(RawOrigin::Signed(candidate.clone()).into())?; + + T::Members::promote(&candidate)?; + + make_member::(2)?; + set_benchmark_params::()?; - let member = make_member::(1)?; - ensure_evidence::(&member)?; + ensure_evidence::(&candidate)?; frame_system::Pallet::::set_block_number(BlockNumberFor::::max_value()); #[extrinsic_call] - _(RawOrigin::Root, member.clone(), 2u8.into()); + _(RawOrigin::Root, candidate.clone(), 2u8.into()); - assert_eq!(T::Members::rank_of(&member), Some(2)); - assert!(!MemberEvidence::::contains_key(&member)); + assert_eq!(T::Members::rank_of(&candidate), Some(2)); + assert!(!MemberEvidence::::contains_key(&candidate)); Ok(()) } From 72ecddb62645093f60696aadc9b43fbf2daa2008 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 8 Apr 2024 16:10:39 +0100 Subject: [PATCH 09/31] revised implementation --- .../rococo/src/governance/fellowship.rs | 3 +- prdoc/pr_3393.prdoc | 5 +- substrate/bin/node/runtime/src/lib.rs | 2 + .../frame/core-fellowship/src/benchmarking.rs | 43 +++++------ substrate/frame/core-fellowship/src/lib.rs | 76 ++++++++++--------- .../core-fellowship/src/tests/integration.rs | 53 +++---------- .../frame/core-fellowship/src/tests/unit.rs | 37 ++++++--- substrate/frame/ranked-collective/src/lib.rs | 16 ++-- .../frame/ranked-collective/src/tests.rs | 13 ++-- .../frame/salary/src/tests/integration.rs | 3 +- 10 files changed, 121 insertions(+), 130 deletions(-) diff --git a/polkadot/runtime/rococo/src/governance/fellowship.rs b/polkadot/runtime/rococo/src/governance/fellowship.rs index a589b768afde..79f7012d2648 100644 --- a/polkadot/runtime/rococo/src/governance/fellowship.rs +++ b/polkadot/runtime/rococo/src/governance/fellowship.rs @@ -266,7 +266,7 @@ impl pallet_referenda::TracksInfo 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); } } @@ -358,4 +358,5 @@ impl pallet_ranked_collective::Config for Runtime type VoteWeight = pallet_ranked_collective::Geometric; #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = (); + type MaxRank = ConstU32<9>; } diff --git a/prdoc/pr_3393.prdoc b/prdoc/pr_3393.prdoc index b384085401b8..815250f26d06 100644 --- a/prdoc/pr_3393.prdoc +++ b/prdoc/pr_3393.prdoc @@ -6,8 +6,9 @@ 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 facilitates the expansion of rank numbers within a 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. + 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 \ No newline at end of file + - name: pallet-ranked-collective + - name: pallet-salary \ No newline at end of file diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 437f76c9d5fb..fbca9ee35b8d 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1027,6 +1027,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 { @@ -1815,6 +1816,7 @@ impl pallet_core_fellowship::Config for Runtime { type ApproveOrigin = EnsureRootWithSuccess>; type PromoteOrigin = EnsureRootWithSuccess>; type EvidenceSize = ConstU32<16_384>; + type MaxRank = ::MaxRank; } parameter_types! { diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index 073472fb09fe..d8a5ce7f1c2a 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -56,10 +56,10 @@ mod benchmarks { fn set_benchmark_params, I: 'static>() -> Result<(), BenchmarkError> { let max_rank: usize = T::Members::max_rank().into(); let params = ParamsType { - active_salary: vec![100u32.into(); max_rank], - passive_salary: vec![10u32.into(); max_rank], - demotion_period: vec![100u32.into(); max_rank], - min_promotion_period: vec![100u32.into(); max_rank], + 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(), }; @@ -70,11 +70,12 @@ mod benchmarks { #[benchmark] fn set_params() -> Result<(), BenchmarkError> { make_member::(9)?; + let max_rank: usize = T::Members::max_rank().into(); let params = ParamsType { - active_salary: [100u32.into(); 9].to_vec(), - passive_salary: [10u32.into(); 9].to_vec(), - demotion_period: [100u32.into(); 9].to_vec(), - min_promotion_period: [100u32.into(); 9].to_vec(), + 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(), }; @@ -106,10 +107,10 @@ mod benchmarks { #[benchmark] fn bump_demote() -> Result<(), BenchmarkError> { - let member = make_member::(2)?; - set_benchmark_params::()?; + let member = make_member::(2)?; + // Set it to the max value to ensure that any possible auto-demotion period has passed. frame_system::Pallet::::set_block_number(BlockNumberFor::::max_value()); ensure_evidence::(&member)?; @@ -151,27 +152,17 @@ mod benchmarks { #[benchmark] fn promote() -> Result<(), BenchmarkError> { - let candidate: T::AccountId = account("candidate", 0, SEED); - - T::Members::induct(&candidate)?; - - CoreFellowship::::import(RawOrigin::Signed(candidate.clone()).into())?; - - T::Members::promote(&candidate)?; - - make_member::(2)?; - - set_benchmark_params::()?; - - ensure_evidence::(&candidate)?; + let member = make_member::(1)?; + // Set it to the max value to ensure that any possible auto-demotion period has passed. frame_system::Pallet::::set_block_number(BlockNumberFor::::max_value()); + ensure_evidence::(&member)?; #[extrinsic_call] - _(RawOrigin::Root, candidate.clone(), 2u8.into()); + _(RawOrigin::Root, member.clone(), 2u8.into()); - assert_eq!(T::Members::rank_of(&candidate), Some(2)); - assert!(!MemberEvidence::::contains_key(&candidate)); + assert_eq!(T::Members::rank_of(&member), Some(2)); + assert!(!MemberEvidence::::contains_key(&member)); Ok(()) } diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index f4ae0b060623..b1ad3099a357 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -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, @@ -71,7 +71,7 @@ use frame_support::{ tokens::Balance as BalanceTrait, EnsureOrigin, EnsureOriginWithArg, Get, RankedMembers, RankedMembersSwapHandler, }, - BoundedVec, + BoundedVec, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound, }; #[cfg(test)] @@ -100,29 +100,46 @@ pub enum Wish { pub type Evidence = BoundedVec>::EvidenceSize>; /// The status of the pallet instance. -#[derive(Encode, Decode, Eq, PartialEq, Clone, TypeInfo, MaxEncodedLen, RuntimeDebug)] -pub struct ParamsType { +#[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, +> { /// The amounts to be paid when a member of a given rank (-1) is active. - active_salary: Vec, + active_salary: BoundedVec, /// The amounts to be paid when a member of a given rank (-1) is passive. - passive_salary: Vec, + passive_salary: BoundedVec, /// The period between which unproven members become demoted. - demotion_period: Vec, + demotion_period: BoundedVec, /// The period between which members must wait before they may proceed to this rank. - min_promotion_period: Vec, + min_promotion_period: BoundedVec, /// Amount by which an account can remain at rank 0 (candidate before being offboard entirely). offboard_timeout: BlockNumber, } -impl Default - for ParamsType +impl< + Balance: Default + Copy + Eq + Debug, + BlockNumber: Default + Copy + Eq + Debug, + Ranks: Get, + > Default for ParamsType { fn default() -> Self { Self { - active_salary: Vec::new(), - passive_salary: Vec::new(), - demotion_period: Vec::new(), - min_promotion_period: Vec::new(), + active_salary: Default::default(), + passive_salary: Default::default(), + demotion_period: Default::default(), + min_promotion_period: Default::default(), offboard_timeout: BlockNumber::default(), } } @@ -150,7 +167,6 @@ pub mod pallet { use frame_system::{ensure_root, pallet_prelude::*}; #[pallet::pallet] - #[pallet::without_storage_info] pub struct Pallet(PhantomData<(T, I)>); #[pallet::config] @@ -192,9 +208,13 @@ pub mod pallet { /// The maximum size in bytes submitted evidence is allowed to be. #[pallet::constant] type EvidenceSize: Get; + + #[pallet::constant] + type MaxRank: Get; } - pub type ParamsOf = ParamsType<>::Balance, BlockNumberFor>; + pub type ParamsOf = + ParamsType<>::Balance, BlockNumberFor, >::MaxRank>; pub type MemberStatusOf = MemberStatus>; pub type RankOf = <>::Members as RankedMembers>::Rank; @@ -275,8 +295,6 @@ pub mod pallet { NotTracked, /// Operation cannot be done yet since not enough time has passed. TooSoon, - /// Length of parameters are incompatible. - IncorrectParamsLength, } #[pallet::call] @@ -304,7 +322,7 @@ pub mod pallet { }; if demotion_period.is_zero() { - return Err(Error::::NothingDoing.into()) + return Err(Error::::NothingDoing.into()); } let demotion_block = member.last_proof.saturating_add(demotion_period); @@ -324,7 +342,7 @@ pub mod pallet { Event::::Offboarded { who } }; Self::deposit_event(event); - return Ok(Pays::No.into()) + return Ok(Pays::No.into()); } Err(Error::::NothingDoing.into()) @@ -338,18 +356,6 @@ pub mod pallet { #[pallet::call_index(1)] pub fn set_params(origin: OriginFor, params: Box>) -> DispatchResult { T::ParamsOrigin::ensure_origin_or_root(origin)?; - // Retrieves the current max rank allowed. - let max_rank = T::Members::max_rank(); - - // Validate the lengths of the vectors in params are equal to max_rank. - let expected_length = max_rank as usize; // Convert max_rank to usize for comparison. - ensure!( - params.active_salary.len() == expected_length && - params.passive_salary.len() == expected_length && - params.demotion_period.len() == expected_length && - params.min_promotion_period.len() == expected_length, - Error::::IncorrectParamsLength - ); Params::::put(params.as_ref()); Self::deposit_event(Event::::ParamsChanged { params: *params }); @@ -626,15 +632,15 @@ impl, I: 'static> RankedMembersSwapHandler 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::::contains_key(old) { defensive!("Should not try to swap non-member"); - return + return; } if Member::::contains_key(new) { defensive!("Should not try to overwrite existing member"); - return + return; } if let Some(member) = Member::::take(old) { diff --git a/substrate/frame/core-fellowship/src/tests/integration.rs b/substrate/frame/core-fellowship/src/tests/integration.rs index 47aa950dab91..c9e79d0f2410 100644 --- a/substrate/frame/core-fellowship/src/tests/integration.rs +++ b/substrate/frame/core-fellowship/src/tests/integration.rs @@ -24,8 +24,8 @@ use frame_support::{ traits::{ConstU16, EitherOf, IsInVec, MapSuccess, PollStatus, Polling, TryMapSuccess}, }; use frame_system::EnsureSignedBy; -use pallet_ranked_collective::{EnsureRanked, Geometric, MemberCount, Rank, TallyOf, Votes}; -use sp_core::Get; +use pallet_ranked_collective::{EnsureRanked, Geometric, Rank, TallyOf, Votes}; +use sp_core::{ConstU32, Get}; use sp_runtime::{ traits::{Convert, ReduceBy, ReplaceWithDefault, TryMorphInto}, BuildStorage, DispatchError, @@ -78,6 +78,7 @@ impl Config for Test { type ApproveOrigin = TryMapSuccess, u64>, TryMorphInto>; type PromoteOrigin = TryMapSuccess, u64>, TryMorphInto>; type EvidenceSize = EvidenceSize; + type MaxRank = ::MaxRank; } pub struct TestPolls; @@ -157,6 +158,7 @@ impl pallet_ranked_collective::Config for Test { type VoteWeight = Geometric; #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = CoreFellowship; + type MaxRank = ConstU32<9>; } pub fn new_test_ext() -> sp_io::TestExternalities { @@ -166,10 +168,14 @@ pub fn new_test_ext() -> sp_io::TestExternalities { assert_ok!(Club::add_member(RuntimeOrigin::root(), 100)); promote_n_times(100, 9); let params = ParamsType { - active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90].to_vec(), - passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9].to_vec(), - demotion_period: [2, 4, 6, 8, 10, 12, 14, 16, 18].to_vec(), - min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27].to_vec(), + active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]) + .expect("Within bounds"), + passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]) + .expect("Within bounds"), + demotion_period: BoundedVec::try_from(vec![2, 4, 6, 8, 10, 12, 14, 16, 18]) + .expect("Within bounds"), + min_promotion_period: BoundedVec::try_from(vec![3, 6, 9, 12, 15, 18, 21, 24, 27]) + .expect("Within bounds"), offboard_timeout: 1, }; assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); @@ -280,38 +286,3 @@ fn swap_bad_noops() { ); }); } - -#[test] -fn add_higher_rank() { - new_test_ext().execute_with(|| { - assert_ok!(Club::add_member(RuntimeOrigin::root(), 7)); - assert_ok!(Club::add_member(RuntimeOrigin::root(), 5)); - promote_n_times(7, 9); - promote_n_times(5, 9); - - System::set_block_number(3); - assert_ok!(CoreFellowship::import(signed(7))); - assert_ok!(CoreFellowship::import(signed(5))); - - // MemberCount still reads previous max rank as 9 - assert_noop!( - CoreFellowship::promote(RuntimeOrigin::root(), 7, 10), - Error::::InvalidRank - ); - - assert_ok!(Club::promote_member(RuntimeOrigin::root(), 7)); - assert_eq!(MemberCount::::get(10), 1); - - let params = ParamsType { - active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100].to_vec(), - passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].to_vec(), - demotion_period: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20].to_vec(), - min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30].to_vec(), - offboard_timeout: 1, - }; - assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); - - System::set_block_number(30); - assert_ok!(CoreFellowship::promote(RuntimeOrigin::root(), 5, 10)); - }) -} diff --git a/substrate/frame/core-fellowship/src/tests/unit.rs b/substrate/frame/core-fellowship/src/tests/unit.rs index aca04f6c8a33..76c5f410c49b 100644 --- a/substrate/frame/core-fellowship/src/tests/unit.rs +++ b/substrate/frame/core-fellowship/src/tests/unit.rs @@ -119,6 +119,7 @@ impl Config for Test { type ApproveOrigin = TryMapSuccess, u64>, TryMorphInto>; type PromoteOrigin = TryMapSuccess, u64>, TryMorphInto>; type EvidenceSize = ConstU32<1024>; + type MaxRank = ConstU32<9>; } pub fn new_test_ext() -> sp_io::TestExternalities { @@ -127,10 +128,14 @@ pub fn new_test_ext() -> sp_io::TestExternalities { ext.execute_with(|| { set_rank(100, 9); let params = ParamsType { - active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90].to_vec(), - passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9].to_vec(), - demotion_period: [2, 4, 6, 8, 10, 12, 14, 16, 18].to_vec(), - min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27].to_vec(), + active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]) + .expect("Within bounds"), + passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]) + .expect("Within bounds"), + demotion_period: BoundedVec::try_from(vec![2, 4, 6, 8, 10, 12, 14, 16, 18]) + .expect("Within bounds"), + min_promotion_period: BoundedVec::try_from(vec![3, 6, 9, 12, 15, 18, 21, 24, 27]) + .expect("Within bounds"), offboard_timeout: 1, }; @@ -175,10 +180,14 @@ fn basic_stuff() { fn set_params_works() { new_test_ext().execute_with(|| { let params = ParamsType { - active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90].to_vec(), - passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9].to_vec(), - demotion_period: [1, 2, 3, 4, 5, 6, 7, 8, 9].to_vec(), - min_promotion_period: [1, 2, 3, 4, 5, 10, 15, 20, 30].to_vec(), + active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]) + .expect("Within bounds"), + passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]) + .expect("Within bounds"), + demotion_period: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]) + .expect("Within bounds"), + min_promotion_period: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 10, 15, 20, 30]) + .expect("Within bounds"), offboard_timeout: 1, }; assert_noop!( @@ -289,10 +298,14 @@ fn offboard_works() { fn infinite_demotion_period_works() { new_test_ext().execute_with(|| { let params = ParamsType { - active_salary: [10; 9].to_vec(), - passive_salary: [10; 9].to_vec(), - min_promotion_period: [10; 9].to_vec(), - demotion_period: [0; 9].to_vec(), + active_salary: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]) + .expect("Within bounds"), + passive_salary: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]) + .expect("Within bounds"), + min_promotion_period: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]) + .expect("Within bounds"), + demotion_period: BoundedVec::try_from(vec![0, 0, 0, 0, 0, 0, 0, 0, 0]) + .expect("Within bounds"), offboard_timeout: 0, }; assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); diff --git a/substrate/frame/ranked-collective/src/lib.rs b/substrate/frame/ranked-collective/src/lib.rs index 638537b9dbad..85fcfac59bfa 100644 --- a/substrate/frame/ranked-collective/src/lib.rs +++ b/substrate/frame/ranked-collective/src/lib.rs @@ -434,6 +434,10 @@ pub mod pallet { /// Setup a member for benchmarking. #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup: BenchmarkSetup; + + /// The maximum number of members. + #[pallet::constant] + type MaxRank: Get; } /// The number of members in the collective who have at least the rank according to the index @@ -613,8 +617,9 @@ pub mod pallet { poll, |mut status| -> Result<(TallyOf, VoteRecord), DispatchError> { match status { - PollStatus::None | PollStatus::Completed(..) => - Err(Error::::NotPolling)?, + PollStatus::None | PollStatus::Completed(..) => { + Err(Error::::NotPolling)? + }, PollStatus::Ongoing(ref mut tally, class) => { match Voting::::get(&poll, &who) { Some(Aye(votes)) => { @@ -671,7 +676,7 @@ pub mod pallet { ); if r.unique == 0 { // return Err(Error::::NoneRemaining) - return Ok(Pays::Yes.into()) + return Ok(Pays::Yes.into()); } if let Some(cursor) = r.maybe_cursor { VotingCleanup::::insert(poll_index, BoundedVec::truncate_from(cursor)); @@ -1005,10 +1010,7 @@ pub mod pallet { } fn max_rank() -> Self::Rank { - MemberCount::::iter() - .map(|(rank, _)| rank) - .max() - .unwrap_or(Self::min_rank()) + T::MaxRank::get() as Rank } } } diff --git a/substrate/frame/ranked-collective/src/tests.rs b/substrate/frame/ranked-collective/src/tests.rs index 31add52d90af..88e0e2519452 100644 --- a/substrate/frame/ranked-collective/src/tests.rs +++ b/substrate/frame/ranked-collective/src/tests.rs @@ -23,7 +23,7 @@ use frame_support::{ assert_noop, assert_ok, derive_impl, error::BadOrigin, parameter_types, - traits::{ConstU16, EitherOf, MapSuccess, Polling}, + traits::{ConstU16, ConstU32, EitherOf, MapSuccess, Polling}, }; use sp_core::Get; use sp_runtime::{ @@ -90,8 +90,9 @@ impl Polling> for TestPolls { let mut polls = Polls::get(); let entry = polls.get_mut(&index); let r = match entry { - Some(Ongoing(ref mut tally_mut_ref, class)) => - f(PollStatus::Ongoing(tally_mut_ref, *class)), + Some(Ongoing(ref mut tally_mut_ref, class)) => { + f(PollStatus::Ongoing(tally_mut_ref, *class)) + }, Some(Completed(when, succeeded)) => f(PollStatus::Completed(*when, *succeeded)), None => f(PollStatus::None), }; @@ -107,8 +108,9 @@ impl Polling> for TestPolls { let mut polls = Polls::get(); let entry = polls.get_mut(&index); let r = match entry { - Some(Ongoing(ref mut tally_mut_ref, class)) => - f(PollStatus::Ongoing(tally_mut_ref, *class)), + Some(Ongoing(ref mut tally_mut_ref, class)) => { + f(PollStatus::Ongoing(tally_mut_ref, *class)) + }, Some(Completed(when, succeeded)) => f(PollStatus::Completed(*when, *succeeded)), None => f(PollStatus::None), }?; @@ -181,6 +183,7 @@ impl Config for Test { type VoteWeight = Geometric; #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = (); + type MaxRank = ConstU32<9>; } pub struct ExtBuilder {} diff --git a/substrate/frame/salary/src/tests/integration.rs b/substrate/frame/salary/src/tests/integration.rs index a49b5637b8ae..45c558a2bb21 100644 --- a/substrate/frame/salary/src/tests/integration.rs +++ b/substrate/frame/salary/src/tests/integration.rs @@ -24,7 +24,7 @@ use frame_support::{ traits::{ConstU64, EitherOf, MapSuccess, PollStatus, Polling}, }; use pallet_ranked_collective::{EnsureRanked, Geometric, TallyOf, Votes}; -use sp_core::{ConstU16, Get}; +use sp_core::{ConstU16, ConstU32, Get}; use sp_runtime::{ traits::{Convert, ReduceBy, ReplaceWithDefault}, BuildStorage, DispatchError, @@ -182,6 +182,7 @@ impl pallet_ranked_collective::Config for Test { type VoteWeight = Geometric; #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = Salary; + type MaxRank = ConstU32<9>; } pub fn new_test_ext() -> sp_io::TestExternalities { From 8a5c550a80fb9063926d397d02ceada0f9060ec4 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 8 Apr 2024 19:11:26 +0100 Subject: [PATCH 10/31] westend + fmt --- .../collectives-westend/src/ambassador/mod.rs | 3 +++ .../collectives-westend/src/fellowship/mod.rs | 2 ++ substrate/frame/ranked-collective/src/lib.rs | 5 ++--- substrate/frame/ranked-collective/src/tests.rs | 10 ++++------ 4 files changed, 11 insertions(+), 9 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 0c9f428c1396..dbeea6ba7487 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs @@ -119,6 +119,7 @@ impl pallet_ranked_collective::Config for Runtime type VoteWeight = pallet_ranked_collective::Linear; #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = (crate::AmbassadorCore, crate::AmbassadorSalary); + type MaxRank = ConstU32<9>; } parameter_types! { @@ -220,6 +221,8 @@ impl pallet_core_fellowship::Config for Runtime { type ApproveOrigin = PromoteOrigin; type PromoteOrigin = PromoteOrigin; type EvidenceSize = ConstU32<65536>; + type MaxRank = + >::MaxRank; } pub type AmbassadorSalaryInstance = pallet_salary::Instance2; diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs index 3816d2ed848e..9f7e0823ffb6 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs @@ -151,6 +151,7 @@ impl pallet_ranked_collective::Config 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; @@ -207,6 +208,7 @@ impl pallet_core_fellowship::Config for Runtime { EnsureCanPromoteTo, >; type EvidenceSize = ConstU32<65536>; + type MaxRank = >::MaxRank; } pub type FellowshipSalaryInstance = pallet_salary::Instance1; diff --git a/substrate/frame/ranked-collective/src/lib.rs b/substrate/frame/ranked-collective/src/lib.rs index 85fcfac59bfa..7065e86b33f8 100644 --- a/substrate/frame/ranked-collective/src/lib.rs +++ b/substrate/frame/ranked-collective/src/lib.rs @@ -617,9 +617,8 @@ pub mod pallet { poll, |mut status| -> Result<(TallyOf, VoteRecord), DispatchError> { match status { - PollStatus::None | PollStatus::Completed(..) => { - Err(Error::::NotPolling)? - }, + PollStatus::None | PollStatus::Completed(..) => + Err(Error::::NotPolling)?, PollStatus::Ongoing(ref mut tally, class) => { match Voting::::get(&poll, &who) { Some(Aye(votes)) => { diff --git a/substrate/frame/ranked-collective/src/tests.rs b/substrate/frame/ranked-collective/src/tests.rs index 4001d9419802..a3609f14c0d8 100644 --- a/substrate/frame/ranked-collective/src/tests.rs +++ b/substrate/frame/ranked-collective/src/tests.rs @@ -90,9 +90,8 @@ impl Polling> for TestPolls { let mut polls = Polls::get(); let entry = polls.get_mut(&index); let r = match entry { - Some(Ongoing(ref mut tally_mut_ref, class)) => { - f(PollStatus::Ongoing(tally_mut_ref, *class)) - }, + Some(Ongoing(ref mut tally_mut_ref, class)) => + f(PollStatus::Ongoing(tally_mut_ref, *class)), Some(Completed(when, succeeded)) => f(PollStatus::Completed(*when, *succeeded)), None => f(PollStatus::None), }; @@ -108,9 +107,8 @@ impl Polling> for TestPolls { let mut polls = Polls::get(); let entry = polls.get_mut(&index); let r = match entry { - Some(Ongoing(ref mut tally_mut_ref, class)) => { - f(PollStatus::Ongoing(tally_mut_ref, *class)) - }, + Some(Ongoing(ref mut tally_mut_ref, class)) => + f(PollStatus::Ongoing(tally_mut_ref, *class)), Some(Completed(when, succeeded)) => f(PollStatus::Completed(*when, *succeeded)), None => f(PollStatus::None), }?; From abc2092af8aa9efb6374535bfd8d2ea992a6244c Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 8 Apr 2024 20:14:33 +0100 Subject: [PATCH 11/31] fix benchmarks --- .../frame/core-fellowship/src/benchmarking.rs | 3 +- .../core-fellowship/src/tests/integration.rs | 11 +++---- .../frame/core-fellowship/src/tests/unit.rs | 33 +++++++------------ 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index f45fbdd7b34d..504a158274fe 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -154,7 +154,8 @@ mod benchmarks { fn promote() -> Result<(), BenchmarkError> { // Ensure that the `min_promotion_period` wont get in our way. let mut params = Params::::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::::put(¶ms); let member = make_member::(1)?; diff --git a/substrate/frame/core-fellowship/src/tests/integration.rs b/substrate/frame/core-fellowship/src/tests/integration.rs index 4abc542c299e..bd18355e9186 100644 --- a/substrate/frame/core-fellowship/src/tests/integration.rs +++ b/substrate/frame/core-fellowship/src/tests/integration.rs @@ -168,14 +168,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities { assert_ok!(Club::add_member(RuntimeOrigin::root(), 100)); promote_n_times(100, 9); let params = ParamsType { - active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]) - .expect("Within bounds"), - passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]) - .expect("Within bounds"), - demotion_period: BoundedVec::try_from(vec![2, 4, 6, 8, 10, 12, 14, 16, 18]) - .expect("Within bounds"), + active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]).unwrap(), + passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(), + demotion_period: BoundedVec::try_from(vec![2, 4, 6, 8, 10, 12, 14, 16, 18]).unwrap(), min_promotion_period: BoundedVec::try_from(vec![3, 6, 9, 12, 15, 18, 21, 24, 27]) - .expect("Within bounds"), + .unwrap(), offboard_timeout: 1, }; assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); diff --git a/substrate/frame/core-fellowship/src/tests/unit.rs b/substrate/frame/core-fellowship/src/tests/unit.rs index a1e5eb95a18e..8695b118616c 100644 --- a/substrate/frame/core-fellowship/src/tests/unit.rs +++ b/substrate/frame/core-fellowship/src/tests/unit.rs @@ -128,14 +128,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities { ext.execute_with(|| { set_rank(100, 9); let params = ParamsType { - active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]) - .expect("Within bounds"), - passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]) - .expect("Within bounds"), - demotion_period: BoundedVec::try_from(vec![2, 4, 6, 8, 10, 12, 14, 16, 18]) - .expect("Within bounds"), + active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]).unwrap(), + passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(), + demotion_period: BoundedVec::try_from(vec![2, 4, 6, 8, 10, 12, 14, 16, 18]).unwrap(), min_promotion_period: BoundedVec::try_from(vec![3, 6, 9, 12, 15, 18, 21, 24, 27]) - .expect("Within bounds"), + .unwrap(), offboard_timeout: 1, }; @@ -180,14 +177,11 @@ fn basic_stuff() { fn set_params_works() { new_test_ext().execute_with(|| { let params = ParamsType { - active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]) - .expect("Within bounds"), - passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]) - .expect("Within bounds"), - demotion_period: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]) - .expect("Within bounds"), + active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]).unwrap(), + passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(), + demotion_period: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(), min_promotion_period: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 10, 15, 20, 30]) - .expect("Within bounds"), + .unwrap(), offboard_timeout: 1, }; assert_noop!( @@ -298,14 +292,11 @@ fn offboard_works() { fn infinite_demotion_period_works() { new_test_ext().execute_with(|| { let params = ParamsType { - active_salary: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]) - .expect("Within bounds"), - passive_salary: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]) - .expect("Within bounds"), + active_salary: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]).unwrap(), + passive_salary: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]).unwrap(), min_promotion_period: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]) - .expect("Within bounds"), - demotion_period: BoundedVec::try_from(vec![0, 0, 0, 0, 0, 0, 0, 0, 0]) - .expect("Within bounds"), + .unwrap(), + demotion_period: BoundedVec::try_from(vec![0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(), offboard_timeout: 0, }; assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); From dd0e5a9256e1e4043b75dfe1bf17278e4e892de3 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 12 Apr 2024 10:56:29 +0000 Subject: [PATCH 12/31] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_core_fellowship --- .../frame/core-fellowship/src/weights.rs | 122 +++++++++--------- 1 file changed, 60 insertions(+), 62 deletions(-) diff --git a/substrate/frame/core-fellowship/src/weights.rs b/substrate/frame/core-fellowship/src/weights.rs index 1e42335067a4..8fad6f585c11 100644 --- a/substrate/frame/core-fellowship/src/weights.rs +++ b/substrate/frame/core-fellowship/src/weights.rs @@ -18,27 +18,25 @@ //! Autogenerated weights for `pallet_core_fellowship` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-04-08, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-04-12, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `runner-anb7yjbi-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: -// ./target/production/substrate-node +// target/production/substrate-node // benchmark // pallet -// --chain=dev // --steps=50 // --repeat=20 -// --pallet=pallet_core_fellowship -// --no-storage-info -// --no-median-slopes -// --no-min-squares // --extrinsic=* // --wasm-execution=compiled // --heap-pages=4096 -// --output=./substrate/frame/core-fellowship/src/weights.rs +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=pallet_core_fellowship +// --chain=dev // --header=./substrate/HEADER-APACHE2 +// --output=./substrate/frame/core-fellowship/src/weights.rs // --template=./substrate/.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -67,13 +65,13 @@ pub trait WeightInfo { pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { /// Storage: `CoreFellowship::Params` (r:0 w:1) - /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) fn set_params() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 6_836_000 picoseconds. - Weight::from_parts(7_057_000, 0) + // Minimum execution time: 7_633_000 picoseconds. + Weight::from_parts(8_018_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `CoreFellowship::Member` (r:1 w:1) @@ -81,7 +79,7 @@ impl WeightInfo for SubstrateWeight { /// Storage: `RankedCollective::Members` (r:1 w:1) /// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) /// Storage: `CoreFellowship::Params` (r:1 w:0) - /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `RankedCollective::MemberCount` (r:1 w:1) /// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) /// Storage: `RankedCollective::IdToIndex` (r:1 w:1) @@ -92,10 +90,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn bump_offboard() -> Weight { // Proof Size summary in bytes: - // Measured: `17274` + // Measured: `17278` // Estimated: `19894` - // Minimum execution time: 55_535_000 picoseconds. - Weight::from_parts(57_104_000, 19894) + // Minimum execution time: 57_597_000 picoseconds. + Weight::from_parts(58_825_000, 19894) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -104,7 +102,7 @@ impl WeightInfo for SubstrateWeight { /// Storage: `RankedCollective::Members` (r:1 w:1) /// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) /// Storage: `CoreFellowship::Params` (r:1 w:0) - /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `RankedCollective::MemberCount` (r:1 w:1) /// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) /// Storage: `RankedCollective::IdToIndex` (r:1 w:1) @@ -115,10 +113,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn bump_demote() -> Weight { // Proof Size summary in bytes: - // Measured: `17384` + // Measured: `17388` // Estimated: `19894` - // Minimum execution time: 59_111_000 picoseconds. - Weight::from_parts(61_394_000, 19894) + // Minimum execution time: 61_387_000 picoseconds. + Weight::from_parts(63_408_000, 19894) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -130,8 +128,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `388` // Estimated: `3514` - // Minimum execution time: 16_166_000 picoseconds. - Weight::from_parts(16_773_000, 3514) + // Minimum execution time: 15_941_000 picoseconds. + Weight::from_parts(16_547_000, 3514) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -149,8 +147,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `146` // Estimated: `3514` - // Minimum execution time: 25_508_000 picoseconds. - Weight::from_parts(25_952_000, 3514) + // Minimum execution time: 24_963_000 picoseconds. + Weight::from_parts(25_873_000, 3514) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -159,7 +157,7 @@ impl WeightInfo for SubstrateWeight { /// Storage: `CoreFellowship::Member` (r:1 w:1) /// Proof: `CoreFellowship::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) /// Storage: `CoreFellowship::Params` (r:1 w:0) - /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `RankedCollective::MemberCount` (r:1 w:1) /// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) /// Storage: `CoreFellowship::MemberEvidence` (r:1 w:1) @@ -170,10 +168,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn promote() -> Weight { // Proof Size summary in bytes: - // Measured: `17252` + // Measured: `16931` // Estimated: `19894` - // Minimum execution time: 51_102_000 picoseconds. - Weight::from_parts(53_302_000, 19894) + // Minimum execution time: 55_062_000 picoseconds. + Weight::from_parts(58_422_000, 19894) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -187,8 +185,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `293` // Estimated: `3514` - // Minimum execution time: 16_035_000 picoseconds. - Weight::from_parts(16_529_000, 3514) + // Minimum execution time: 15_901_000 picoseconds. + Weight::from_parts(16_746_000, 3514) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -200,8 +198,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `313` // Estimated: `3514` - // Minimum execution time: 14_966_000 picoseconds. - Weight::from_parts(15_340_000, 3514) + // Minimum execution time: 14_768_000 picoseconds. + Weight::from_parts(15_421_000, 3514) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -215,8 +213,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `16843` // Estimated: `19894` - // Minimum execution time: 35_137_000 picoseconds. - Weight::from_parts(36_285_000, 19894) + // Minimum execution time: 36_925_000 picoseconds. + Weight::from_parts(38_330_000, 19894) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -228,8 +226,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `79` // Estimated: `19894` - // Minimum execution time: 24_307_000 picoseconds. - Weight::from_parts(25_426_000, 19894) + // Minimum execution time: 25_210_000 picoseconds. + Weight::from_parts(26_247_000, 19894) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -238,13 +236,13 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests. impl WeightInfo for () { /// Storage: `CoreFellowship::Params` (r:0 w:1) - /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) fn set_params() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 6_836_000 picoseconds. - Weight::from_parts(7_057_000, 0) + // Minimum execution time: 7_633_000 picoseconds. + Weight::from_parts(8_018_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `CoreFellowship::Member` (r:1 w:1) @@ -252,7 +250,7 @@ impl WeightInfo for () { /// Storage: `RankedCollective::Members` (r:1 w:1) /// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) /// Storage: `CoreFellowship::Params` (r:1 w:0) - /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `RankedCollective::MemberCount` (r:1 w:1) /// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) /// Storage: `RankedCollective::IdToIndex` (r:1 w:1) @@ -263,10 +261,10 @@ impl WeightInfo for () { /// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn bump_offboard() -> Weight { // Proof Size summary in bytes: - // Measured: `17274` + // Measured: `17278` // Estimated: `19894` - // Minimum execution time: 55_535_000 picoseconds. - Weight::from_parts(57_104_000, 19894) + // Minimum execution time: 57_597_000 picoseconds. + Weight::from_parts(58_825_000, 19894) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } @@ -275,7 +273,7 @@ impl WeightInfo for () { /// Storage: `RankedCollective::Members` (r:1 w:1) /// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) /// Storage: `CoreFellowship::Params` (r:1 w:0) - /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `RankedCollective::MemberCount` (r:1 w:1) /// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) /// Storage: `RankedCollective::IdToIndex` (r:1 w:1) @@ -286,10 +284,10 @@ impl WeightInfo for () { /// Proof: `RankedCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn bump_demote() -> Weight { // Proof Size summary in bytes: - // Measured: `17384` + // Measured: `17388` // Estimated: `19894` - // Minimum execution time: 59_111_000 picoseconds. - Weight::from_parts(61_394_000, 19894) + // Minimum execution time: 61_387_000 picoseconds. + Weight::from_parts(63_408_000, 19894) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } @@ -301,8 +299,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `388` // Estimated: `3514` - // Minimum execution time: 16_166_000 picoseconds. - Weight::from_parts(16_773_000, 3514) + // Minimum execution time: 15_941_000 picoseconds. + Weight::from_parts(16_547_000, 3514) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -320,8 +318,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `146` // Estimated: `3514` - // Minimum execution time: 25_508_000 picoseconds. - Weight::from_parts(25_952_000, 3514) + // Minimum execution time: 24_963_000 picoseconds. + Weight::from_parts(25_873_000, 3514) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -330,7 +328,7 @@ impl WeightInfo for () { /// Storage: `CoreFellowship::Member` (r:1 w:1) /// Proof: `CoreFellowship::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) /// Storage: `CoreFellowship::Params` (r:1 w:0) - /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `RankedCollective::MemberCount` (r:1 w:1) /// Proof: `RankedCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) /// Storage: `CoreFellowship::MemberEvidence` (r:1 w:1) @@ -341,10 +339,10 @@ impl WeightInfo for () { /// Proof: `RankedCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn promote() -> Weight { // Proof Size summary in bytes: - // Measured: `17252` + // Measured: `16931` // Estimated: `19894` - // Minimum execution time: 51_102_000 picoseconds. - Weight::from_parts(53_302_000, 19894) + // Minimum execution time: 55_062_000 picoseconds. + Weight::from_parts(58_422_000, 19894) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } @@ -358,8 +356,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `293` // Estimated: `3514` - // Minimum execution time: 16_035_000 picoseconds. - Weight::from_parts(16_529_000, 3514) + // Minimum execution time: 15_901_000 picoseconds. + Weight::from_parts(16_746_000, 3514) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -371,8 +369,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `313` // Estimated: `3514` - // Minimum execution time: 14_966_000 picoseconds. - Weight::from_parts(15_340_000, 3514) + // Minimum execution time: 14_768_000 picoseconds. + Weight::from_parts(15_421_000, 3514) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -386,8 +384,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `16843` // Estimated: `19894` - // Minimum execution time: 35_137_000 picoseconds. - Weight::from_parts(36_285_000, 19894) + // Minimum execution time: 36_925_000 picoseconds. + Weight::from_parts(38_330_000, 19894) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -399,8 +397,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `79` // Estimated: `19894` - // Minimum execution time: 24_307_000 picoseconds. - Weight::from_parts(25_426_000, 19894) + // Minimum execution time: 25_210_000 picoseconds. + Weight::from_parts(26_247_000, 19894) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } From afe16a50b0668e64867805b6e8afe8a027efc09a Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 15 Apr 2024 17:22:13 +0100 Subject: [PATCH 13/31] init migration --- .../frame/core-fellowship/src/benchmarking.rs | 1 - substrate/frame/core-fellowship/src/lib.rs | 16 ++- .../frame/core-fellowship/src/migration.rs | 123 ++++++++++++++++++ 3 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 substrate/frame/core-fellowship/src/migration.rs diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index 504a158274fe..55fe4b23482a 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -69,7 +69,6 @@ mod benchmarks { #[benchmark] fn set_params() -> Result<(), BenchmarkError> { - make_member::(9)?; let max_rank: usize = T::Members::max_rank().into(); let params = ParamsType { active_salary: BoundedVec::try_from(vec![100u32.into(); max_rank]).unwrap(), diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index b1ad3099a357..19334438b817 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -79,10 +79,11 @@ 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)] @@ -117,15 +118,15 @@ pub struct ParamsType< Ranks: Get, > { /// The amounts to be paid when a member of a given rank (-1) is active. - active_salary: BoundedVec, + pub active_salary: BoundedVec, /// The amounts to be paid when a member of a given rank (-1) is passive. - passive_salary: BoundedVec, + pub passive_salary: BoundedVec, /// The period between which unproven members become demoted. - demotion_period: BoundedVec, + pub demotion_period: BoundedVec, /// The period between which members must wait before they may proceed to this rank. - min_promotion_period: BoundedVec, + pub min_promotion_period: BoundedVec, /// Amount by which an account can remain at rank 0 (candidate before being offboard entirely). - offboard_timeout: BlockNumber, + pub offboard_timeout: BlockNumber, } impl< @@ -165,8 +166,11 @@ pub mod pallet { traits::{tokens::GetSalary, EnsureOrigin}, }; use frame_system::{ensure_root, pallet_prelude::*}; + /// The in-code storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(PhantomData<(T, I)>); #[pallet::config] diff --git a/substrate/frame/core-fellowship/src/migration.rs b/substrate/frame/core-fellowship/src/migration.rs new file mode 100644 index 000000000000..86d9330c749b --- /dev/null +++ b/substrate/frame/core-fellowship/src/migration.rs @@ -0,0 +1,123 @@ +use super::*; +use frame_support::{ + pallet_prelude::*, storage_alias, traits::UncheckedOnRuntimeUpgrade, BoundedVec, +}; +/// The log target of this pallet. +pub const LOG_TARGET: &str = "runtime::core_fellowship"; + +mod v0 { + use frame_system::pallet_prelude::BlockNumberFor; + + use super::*; + + #[derive(Encode, Decode, Eq, PartialEq, Clone, TypeInfo, MaxEncodedLen, RuntimeDebug)] + pub struct ParamsType { + pub active_salary: [Balance; RANKS], + pub passive_salary: [Balance; RANKS], + pub demotion_period: [BlockNumber; RANKS], + pub min_promotion_period: [BlockNumber; RANKS], + pub offboard_timeout: BlockNumber, + } + + impl Default + for ParamsType + { + 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], + offboard_timeout: BlockNumber::default(), + } + } + } + + /// Number of available ranks from old version. + pub(crate) const RANK_COUNT: usize = 9; + + pub type ParamsOf = ParamsType<>::Balance, BlockNumberFor, RANK_COUNT>; + + /// V0 type for [`crate::Params`]. + #[storage_alias] + pub type Params, I: 'static> = + StorageValue, ParamsOf, ValueQuery>; +} + +mod v1 { + use super::*; + + pub struct Migration(PhantomData<(T, I)>); + impl, I: 'static> UncheckedOnRuntimeUpgrade for Migration { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + log::info!( + target: LOG_TARGET, + "Running migration from v0 to v1", + ); + // Read the old value from storage + let old_value = v0::Params::::take(); + // Write the new value to storage + let new = crate::ParamsType { + active_salary: BoundedVec::try_from(old_value.active_salary.to_vec()).unwrap(), + passive_salary: BoundedVec::try_from(old_value.passive_salary.to_vec()).unwrap(), + demotion_period: BoundedVec::try_from(old_value.demotion_period.to_vec()).unwrap(), + min_promotion_period: BoundedVec::try_from(old_value.min_promotion_period.to_vec()) + .unwrap(), + offboard_timeout: old_value.offboard_timeout, + }; + crate::Params::::put(new); + T::DbWeight::get().reads_writes(1, 1) + } + } +} + +/// [`UncheckedOnRuntimeUpgrade`] implementation [`Migration`] wrapped in a +/// [`VersionedMigration`](frame_support::migrations::VersionedMigration), which ensures that: +/// - The migration only runs once when the on-chain storage version is 0 +/// - The on-chain storage version is updated to `1` after the migration executes +/// - Reads/Writes from checking/settings the on-chain storage version are accounted for +pub type Migrate = frame_support::migrations::VersionedMigration< + 0, // The migration will only execute when the on-chain storage version is 0 + 1, // The on-chain storage version will be set to 1 after the migration is complete + v1::Migration, + crate::pallet::Pallet, + ::DbWeight, +>; + +#[cfg(any(all(feature = "try-runtime", test), doc))] +mod test { + use super::*; + use crate::tests::unit::{new_test_ext, Test}; + + #[test] + fn migration_v0_to_v1_works() { + new_test_ext().execute_with(|| { + let params = v0::ParamsType { + active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90], + passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9], + demotion_period: [2, 4, 6, 8, 10, 12, 14, 16, 18], + min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27], + offboard_timeout: 1, + }; + + v0::Params::::put(params); + + // Execute the migration + v1::Migration::::on_runtime_upgrade(); + + let migrated_params = crate::ParamsType { + active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]) + .unwrap(), + passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(), + demotion_period: BoundedVec::try_from(vec![2, 4, 6, 8, 10, 12, 14, 16, 18]) + .unwrap(), + min_promotion_period: BoundedVec::try_from(vec![3, 6, 9, 12, 15, 18, 21, 24, 27]) + .unwrap(), + offboard_timeout: 1, + }; + + // After the migration, the type should be Bounedvec<> + assert_eq!(crate::Params::::get(), migrated_params); + }) + } +} From a746913a055e57cb77bf96dd0551380367675747 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 15 Apr 2024 17:52:51 +0100 Subject: [PATCH 14/31] remove migration test --- .../frame/core-fellowship/src/migration.rs | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/substrate/frame/core-fellowship/src/migration.rs b/substrate/frame/core-fellowship/src/migration.rs index 86d9330c749b..647d67ec08c1 100644 --- a/substrate/frame/core-fellowship/src/migration.rs +++ b/substrate/frame/core-fellowship/src/migration.rs @@ -83,41 +83,3 @@ pub type Migrate = frame_support::migrations::VersionedMigration< crate::pallet::Pallet, ::DbWeight, >; - -#[cfg(any(all(feature = "try-runtime", test), doc))] -mod test { - use super::*; - use crate::tests::unit::{new_test_ext, Test}; - - #[test] - fn migration_v0_to_v1_works() { - new_test_ext().execute_with(|| { - let params = v0::ParamsType { - active_salary: [10, 20, 30, 40, 50, 60, 70, 80, 90], - passive_salary: [1, 2, 3, 4, 5, 6, 7, 8, 9], - demotion_period: [2, 4, 6, 8, 10, 12, 14, 16, 18], - min_promotion_period: [3, 6, 9, 12, 15, 18, 21, 24, 27], - offboard_timeout: 1, - }; - - v0::Params::::put(params); - - // Execute the migration - v1::Migration::::on_runtime_upgrade(); - - let migrated_params = crate::ParamsType { - active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]) - .unwrap(), - passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(), - demotion_period: BoundedVec::try_from(vec![2, 4, 6, 8, 10, 12, 14, 16, 18]) - .unwrap(), - min_promotion_period: BoundedVec::try_from(vec![3, 6, 9, 12, 15, 18, 21, 24, 27]) - .unwrap(), - offboard_timeout: 1, - }; - - // After the migration, the type should be Bounedvec<> - assert_eq!(crate::Params::::get(), migrated_params); - }) - } -} From 23a0d06daae5e477bc0f9381662b19c1a95dd1cc Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 15 Apr 2024 22:23:46 +0100 Subject: [PATCH 15/31] no truncate --- .../frame/core-fellowship/src/migration.rs | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/substrate/frame/core-fellowship/src/migration.rs b/substrate/frame/core-fellowship/src/migration.rs index 647d67ec08c1..548b3e00a859 100644 --- a/substrate/frame/core-fellowship/src/migration.rs +++ b/substrate/frame/core-fellowship/src/migration.rs @@ -1,9 +1,10 @@ use super::*; use frame_support::{ - pallet_prelude::*, storage_alias, traits::UncheckedOnRuntimeUpgrade, BoundedVec, + pallet_prelude::*, storage_alias, traits::{UncheckedOnRuntimeUpgrade, DefensiveTruncateFrom}, BoundedVec, }; -/// The log target of this pallet. -pub const LOG_TARGET: &str = "runtime::core_fellowship"; + +#[cfg(feature = "try-runtime")] +use sp_runtime::TryRuntimeError; mod v0 { use frame_system::pallet_prelude::BlockNumberFor; @@ -49,20 +50,21 @@ mod v1 { pub struct Migration(PhantomData<(T, I)>); impl, I: 'static> UncheckedOnRuntimeUpgrade for Migration { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, TryRuntimeError> { + ensure!(T::MaxRank::get() >= v0::RANK_COUNT as u32, "pallet-core-fellowship: new bound should not truncate"); + Ok(Default::default()) + } + fn on_runtime_upgrade() -> frame_support::weights::Weight { - log::info!( - target: LOG_TARGET, - "Running migration from v0 to v1", - ); // Read the old value from storage let old_value = v0::Params::::take(); // Write the new value to storage let new = crate::ParamsType { - active_salary: BoundedVec::try_from(old_value.active_salary.to_vec()).unwrap(), - passive_salary: BoundedVec::try_from(old_value.passive_salary.to_vec()).unwrap(), - demotion_period: BoundedVec::try_from(old_value.demotion_period.to_vec()).unwrap(), - min_promotion_period: BoundedVec::try_from(old_value.min_promotion_period.to_vec()) - .unwrap(), + active_salary: BoundedVec::defensive_truncate_from(old_value.active_salary.to_vec()), + passive_salary: BoundedVec::defensive_truncate_from(old_value.passive_salary.to_vec()), + demotion_period: BoundedVec::defensive_truncate_from(old_value.demotion_period.to_vec()), + min_promotion_period: BoundedVec::defensive_truncate_from(old_value.min_promotion_period.to_vec()), offboard_timeout: old_value.offboard_timeout, }; crate::Params::::put(new); @@ -71,7 +73,7 @@ mod v1 { } } -/// [`UncheckedOnRuntimeUpgrade`] implementation [`Migration`] wrapped in a +/// [`UncheckedOnRuntimeUpgrade`] implementation [`v1::Migration`] wrapped in a /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), which ensures that: /// - The migration only runs once when the on-chain storage version is 0 /// - The on-chain storage version is updated to `1` after the migration executes From e4fc2a11446f71a515c241a71f723bd7b78c17ce Mon Sep 17 00:00:00 2001 From: doordashcon Date: Thu, 18 Apr 2024 17:29:16 +0100 Subject: [PATCH 16/31] remove nesting --- substrate/frame/core-fellowship/src/lib.rs | 2 +- .../frame/core-fellowship/src/migration.rs | 64 ++++++++++--------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index 19334438b817..9b34e5cbf78d 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -167,7 +167,7 @@ pub mod pallet { }; use frame_system::{ensure_root, pallet_prelude::*}; /// The in-code storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] diff --git a/substrate/frame/core-fellowship/src/migration.rs b/substrate/frame/core-fellowship/src/migration.rs index 548b3e00a859..02433794d45c 100644 --- a/substrate/frame/core-fellowship/src/migration.rs +++ b/substrate/frame/core-fellowship/src/migration.rs @@ -1,6 +1,9 @@ use super::*; use frame_support::{ - pallet_prelude::*, storage_alias, traits::{UncheckedOnRuntimeUpgrade, DefensiveTruncateFrom}, BoundedVec, + pallet_prelude::*, + storage_alias, + traits::{DefensiveTruncateFrom, UncheckedOnRuntimeUpgrade}, + BoundedVec, }; #[cfg(feature = "try-runtime")] @@ -45,43 +48,46 @@ mod v0 { StorageValue, ParamsOf, ValueQuery>; } -mod v1 { - use super::*; - - pub struct Migration(PhantomData<(T, I)>); - impl, I: 'static> UncheckedOnRuntimeUpgrade for Migration { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, TryRuntimeError> { - ensure!(T::MaxRank::get() >= v0::RANK_COUNT as u32, "pallet-core-fellowship: new bound should not truncate"); - Ok(Default::default()) - } +pub struct Migration(PhantomData<(T, I)>); +impl, I: 'static> UncheckedOnRuntimeUpgrade for Migration { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, TryRuntimeError> { + ensure!( + T::MaxRank::get() >= v0::RANK_COUNT as u32, + "pallet-core-fellowship: new bound should not truncate" + ); + Ok(Default::default()) + } - fn on_runtime_upgrade() -> frame_support::weights::Weight { - // Read the old value from storage - let old_value = v0::Params::::take(); - // Write the new value to storage - let new = crate::ParamsType { - active_salary: BoundedVec::defensive_truncate_from(old_value.active_salary.to_vec()), - passive_salary: BoundedVec::defensive_truncate_from(old_value.passive_salary.to_vec()), - demotion_period: BoundedVec::defensive_truncate_from(old_value.demotion_period.to_vec()), - min_promotion_period: BoundedVec::defensive_truncate_from(old_value.min_promotion_period.to_vec()), - offboard_timeout: old_value.offboard_timeout, - }; - crate::Params::::put(new); - T::DbWeight::get().reads_writes(1, 1) - } + fn on_runtime_upgrade() -> frame_support::weights::Weight { + // Read the old value from storage + let old_value = v0::Params::::take(); + // Write the new value to storage + let new = crate::ParamsType { + active_salary: BoundedVec::defensive_truncate_from(old_value.active_salary.to_vec()), + passive_salary: BoundedVec::defensive_truncate_from(old_value.passive_salary.to_vec()), + demotion_period: BoundedVec::defensive_truncate_from( + old_value.demotion_period.to_vec(), + ), + min_promotion_period: BoundedVec::defensive_truncate_from( + old_value.min_promotion_period.to_vec(), + ), + offboard_timeout: old_value.offboard_timeout, + }; + crate::Params::::put(new); + T::DbWeight::get().reads_writes(1, 1) } } -/// [`UncheckedOnRuntimeUpgrade`] implementation [`v1::Migration`] wrapped in a +/// [`UncheckedOnRuntimeUpgrade`] implementation [`Migration`] wrapped in a /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), which ensures that: /// - The migration only runs once when the on-chain storage version is 0 -/// - The on-chain storage version is updated to `1` after the migration executes +/// - The on-chain storage version is updated to `2` after the migration executes /// - Reads/Writes from checking/settings the on-chain storage version are accounted for pub type Migrate = frame_support::migrations::VersionedMigration< 0, // The migration will only execute when the on-chain storage version is 0 - 1, // The on-chain storage version will be set to 1 after the migration is complete - v1::Migration, + 2, // The on-chain storage version will be set to 2 after the migration is complete + Migration, crate::pallet::Pallet, ::DbWeight, >; From 11c73be89222096bf5c6804c3b89ec16319da2d0 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Fri, 19 Apr 2024 19:36:10 +0100 Subject: [PATCH 17/31] adds header --- .../frame/core-fellowship/src/migration.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/substrate/frame/core-fellowship/src/migration.rs b/substrate/frame/core-fellowship/src/migration.rs index 02433794d45c..07c0f433fd0e 100644 --- a/substrate/frame/core-fellowship/src/migration.rs +++ b/substrate/frame/core-fellowship/src/migration.rs @@ -1,3 +1,21 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Storage migrations for the core-fellowship pallet. use super::*; use frame_support::{ pallet_prelude::*, From a93fdcafce39484fd6d9bc29a0fa4f89bbedd17f Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 22 Apr 2024 17:14:04 +0100 Subject: [PATCH 18/31] MigrateToV1>>> --- substrate/frame/core-fellowship/src/lib.rs | 2 +- substrate/frame/core-fellowship/src/migration.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index 9b34e5cbf78d..19334438b817 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -167,7 +167,7 @@ pub mod pallet { }; use frame_system::{ensure_root, pallet_prelude::*}; /// The in-code storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] diff --git a/substrate/frame/core-fellowship/src/migration.rs b/substrate/frame/core-fellowship/src/migration.rs index 07c0f433fd0e..854235d60dfa 100644 --- a/substrate/frame/core-fellowship/src/migration.rs +++ b/substrate/frame/core-fellowship/src/migration.rs @@ -66,8 +66,8 @@ mod v0 { StorageValue, ParamsOf, ValueQuery>; } -pub struct Migration(PhantomData<(T, I)>); -impl, I: 'static> UncheckedOnRuntimeUpgrade for Migration { +pub struct MigrateToV1(PhantomData<(T, I)>); +impl, I: 'static> UncheckedOnRuntimeUpgrade for MigrateToV1 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, TryRuntimeError> { ensure!( @@ -100,12 +100,12 @@ impl, I: 'static> UncheckedOnRuntimeUpgrade for Migration { /// [`UncheckedOnRuntimeUpgrade`] implementation [`Migration`] wrapped in a /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), which ensures that: /// - The migration only runs once when the on-chain storage version is 0 -/// - The on-chain storage version is updated to `2` after the migration executes +/// - The on-chain storage version is updated to `1` after the migration executes /// - Reads/Writes from checking/settings the on-chain storage version are accounted for -pub type Migrate = frame_support::migrations::VersionedMigration< +pub type MigrateV0ToV1 = frame_support::migrations::VersionedMigration< 0, // The migration will only execute when the on-chain storage version is 0 - 2, // The on-chain storage version will be set to 2 after the migration is complete - Migration, + 1, // The on-chain storage version will be set to 1 after the migration is complete + MigrateToV1, crate::pallet::Pallet, ::DbWeight, >; From 7da28ff434634bebfe7f51eafcad5670ab98598f Mon Sep 17 00:00:00 2001 From: doordashcon Date: Mon, 22 Apr 2024 17:21:59 +0100 Subject: [PATCH 19/31] doc update Migration to MigrateToV1 --- substrate/frame/core-fellowship/src/migration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/core-fellowship/src/migration.rs b/substrate/frame/core-fellowship/src/migration.rs index 854235d60dfa..b8b5540a4b47 100644 --- a/substrate/frame/core-fellowship/src/migration.rs +++ b/substrate/frame/core-fellowship/src/migration.rs @@ -97,7 +97,7 @@ impl, I: 'static> UncheckedOnRuntimeUpgrade for MigrateToV1 { } } -/// [`UncheckedOnRuntimeUpgrade`] implementation [`Migration`] wrapped in a +/// [`UncheckedOnRuntimeUpgrade`] implementation [`MigrateToV1`] wrapped in a /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), which ensures that: /// - The migration only runs once when the on-chain storage version is 0 /// - The on-chain storage version is updated to `1` after the migration executes From 252d152479593d8c0c18f85bfa9110bc19bd9cb4 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Fri, 26 Apr 2024 15:08:32 +0100 Subject: [PATCH 20/31] westend core pallet migration --- .../runtimes/collectives/collectives-westend/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index c599ba37f128..eb02f5e01948 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -44,8 +44,9 @@ pub mod xcm_config; pub mod fellowship; pub use ambassador::pallet_ambassador_origins; +use ambassador::AmbassadorCoreInstance; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use fellowship::{pallet_fellowship_origins, Fellows}; +use fellowship::{pallet_fellowship_origins, Fellows, FellowshipCoreInstance}; use impls::{AllianceProposalProvider, EqualOrGreatestRootCmp}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; @@ -727,6 +728,9 @@ type Migrations = ( cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, // permanent pallet_xcm::migration::MigrateToLatestXcmVersion, + // unreleased + pallet_core_fellowship::migration::MigrateV0ToV1, + pallet_core_fellowship::migration::MigrateV0ToV1, ); /// Executive: handles dispatch to the various modules. From 2aca81aec33773791aefb126c4d0ff57e39fb3b0 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Fri, 26 Apr 2024 17:49:21 +0100 Subject: [PATCH 21/31] doc add westend-collective --- .../runtimes/collectives/collectives-westend/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 32d31c927092..31f9c1a64d7c 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -730,6 +730,7 @@ type Migrations = ( pallet_xcm::migration::MigrateToLatestXcmVersion, // unreleased pallet_core_fellowship::migration::MigrateV0ToV1, + // unreleased pallet_core_fellowship::migration::MigrateV0ToV1, ); From 4d798a41b4c976e0106a1bee4fc34315ba27f108 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Sat, 27 Apr 2024 18:54:38 +0100 Subject: [PATCH 22/31] nit --- polkadot/runtime/rococo/src/governance/fellowship.rs | 2 +- prdoc/pr_3393.prdoc | 3 ++- substrate/frame/core-fellowship/src/lib.rs | 10 +++++----- substrate/frame/ranked-collective/src/lib.rs | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/polkadot/runtime/rococo/src/governance/fellowship.rs b/polkadot/runtime/rococo/src/governance/fellowship.rs index 79f7012d2648..9acb40fb9437 100644 --- a/polkadot/runtime/rococo/src/governance/fellowship.rs +++ b/polkadot/runtime/rococo/src/governance/fellowship.rs @@ -266,7 +266,7 @@ impl pallet_referenda::TracksInfo 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) } } diff --git a/prdoc/pr_3393.prdoc b/prdoc/pr_3393.prdoc index 815250f26d06..7de3f054113d 100644 --- a/prdoc/pr_3393.prdoc +++ b/prdoc/pr_3393.prdoc @@ -11,4 +11,5 @@ doc: crates: - name: pallet-core-fellowship - name: pallet-ranked-collective - - name: pallet-salary \ No newline at end of file + - name: pallet-salary + \ No newline at end of file diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index 19334438b817..616715a8fb85 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -326,7 +326,7 @@ pub mod pallet { }; if demotion_period.is_zero() { - return Err(Error::::NothingDoing.into()); + return Err(Error::::NothingDoing.into()) } let demotion_block = member.last_proof.saturating_add(demotion_period); @@ -346,7 +346,7 @@ pub mod pallet { Event::::Offboarded { who } }; Self::deposit_event(event); - return Ok(Pays::No.into()); + return Ok(Pays::No.into()) } Err(Error::::NothingDoing.into()) @@ -636,15 +636,15 @@ impl, I: 'static> RankedMembersSwapHandler 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::::contains_key(old) { defensive!("Should not try to swap non-member"); - return; + return } if Member::::contains_key(new) { defensive!("Should not try to overwrite existing member"); - return; + return } if let Some(member) = Member::::take(old) { diff --git a/substrate/frame/ranked-collective/src/lib.rs b/substrate/frame/ranked-collective/src/lib.rs index 7065e86b33f8..0ff14b879f07 100644 --- a/substrate/frame/ranked-collective/src/lib.rs +++ b/substrate/frame/ranked-collective/src/lib.rs @@ -675,7 +675,7 @@ pub mod pallet { ); if r.unique == 0 { // return Err(Error::::NoneRemaining) - return Ok(Pays::Yes.into()); + return Ok(Pays::Yes.into()) } if let Some(cursor) = r.maybe_cursor { VotingCleanup::::insert(poll_index, BoundedVec::truncate_from(cursor)); From fc72258139ab2e980c0fb8548e24a2751263584d Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 30 Apr 2024 04:23:47 +0100 Subject: [PATCH 23/31] max_rank in Ranked Member not needed --- .../collectives-westend/src/ambassador/mod.rs | 4 +-- .../collectives-westend/src/fellowship/mod.rs | 3 +- .../rococo/src/governance/fellowship.rs | 1 - .../xcm/xcm-builder/src/tests/pay/salary.rs | 3 -- prdoc/pr_3393.prdoc | 7 ++-- substrate/bin/node/runtime/src/lib.rs | 3 +- .../frame/core-fellowship/src/benchmarking.rs | 27 ++++++++-------- substrate/frame/core-fellowship/src/lib.rs | 4 ++- .../core-fellowship/src/tests/integration.rs | 13 ++++---- .../frame/core-fellowship/src/tests/unit.rs | 32 ++++++++----------- substrate/frame/ranked-collective/src/lib.rs | 8 ----- substrate/frame/salary/src/tests/unit.rs | 3 -- substrate/frame/support/src/traits/members.rs | 3 -- 13 files changed, 41 insertions(+), 70 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 dbeea6ba7487..ceef6de6b743 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs @@ -119,7 +119,6 @@ impl pallet_ranked_collective::Config for Runtime type VoteWeight = pallet_ranked_collective::Linear; #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = (crate::AmbassadorCore, crate::AmbassadorSalary); - type MaxRank = ConstU32<9>; } parameter_types! { @@ -221,8 +220,7 @@ impl pallet_core_fellowship::Config for Runtime { type ApproveOrigin = PromoteOrigin; type PromoteOrigin = PromoteOrigin; type EvidenceSize = ConstU32<65536>; - type MaxRank = - >::MaxRank; + type MaxRank = ConstU32<9>; } pub type AmbassadorSalaryInstance = pallet_salary::Instance2; diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs index ac4669be2c18..6a4a18207967 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs @@ -154,7 +154,6 @@ impl pallet_ranked_collective::Config 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; @@ -211,7 +210,7 @@ impl pallet_core_fellowship::Config for Runtime { EnsureCanPromoteTo, >; type EvidenceSize = ConstU32<65536>; - type MaxRank = >::MaxRank; + type MaxRank = ConstU32<9>; } pub type FellowshipSalaryInstance = pallet_salary::Instance1; diff --git a/polkadot/runtime/rococo/src/governance/fellowship.rs b/polkadot/runtime/rococo/src/governance/fellowship.rs index 9acb40fb9437..a589b768afde 100644 --- a/polkadot/runtime/rococo/src/governance/fellowship.rs +++ b/polkadot/runtime/rococo/src/governance/fellowship.rs @@ -358,5 +358,4 @@ impl pallet_ranked_collective::Config for Runtime type VoteWeight = pallet_ranked_collective::Geometric; #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = (); - type MaxRank = ConstU32<9>; } diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs index d40db26b4f90..6a2945c6a9b9 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs @@ -84,9 +84,6 @@ 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) { diff --git a/prdoc/pr_3393.prdoc b/prdoc/pr_3393.prdoc index 7de3f054113d..27ebb3859303 100644 --- a/prdoc/pr_3393.prdoc +++ b/prdoc/pr_3393.prdoc @@ -1,15 +1,12 @@ # 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` +title: Add `MaxRank` Config to `pallet-core-fellowship` 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. + This PR adds a new Config `MaxRank` to the core fellowship pallet. 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 - \ No newline at end of file diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index fedb6c371673..f4618cea52b8 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1038,7 +1038,6 @@ 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 { @@ -1870,7 +1869,7 @@ impl pallet_core_fellowship::Config for Runtime { type ApproveOrigin = EnsureRootWithSuccess>; type PromoteOrigin = EnsureRootWithSuccess>; type EvidenceSize = ConstU32<16_384>; - type MaxRank = ::MaxRank; + type MaxRank = ConstU32<9>; } parameter_types! { diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index 55fe4b23482a..e7e5368bed91 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -25,6 +25,7 @@ use crate::Pallet as CoreFellowship; use frame_benchmarking::v2::*; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; use sp_arithmetic::traits::Bounded; +use sp_runtime::bounded_vec; const SEED: u32 = 0; @@ -35,7 +36,7 @@ mod benchmarks { use super::*; fn ensure_evidence, I: 'static>(who: &T::AccountId) -> BenchResult { - let evidence = BoundedVec::try_from(vec![0; Evidence::::bound()]).unwrap(); + let evidence = bounded_vec![0; Evidence::::bound()]; let wish = Wish::Retention; let origin = RawOrigin::Signed(who.clone()).into(); CoreFellowship::::submit_evidence(origin, wish, evidence)?; @@ -54,12 +55,12 @@ mod benchmarks { } fn set_benchmark_params, I: 'static>() -> Result<(), BenchmarkError> { - let max_rank: usize = T::Members::max_rank().into(); + let max_rank = T::MaxRank::get().try_into().unwrap(); let params = ParamsType { - 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(), + active_salary: bounded_vec![100u32.into(); max_rank], + passive_salary: bounded_vec![10u32.into(); max_rank], + demotion_period: bounded_vec![100u32.into(); max_rank], + min_promotion_period: bounded_vec![100u32.into(); max_rank], offboard_timeout: 1u32.into(), }; @@ -69,12 +70,12 @@ mod benchmarks { #[benchmark] fn set_params() -> Result<(), BenchmarkError> { - let max_rank: usize = T::Members::max_rank().into(); + let max_rank = T::MaxRank::get().try_into().unwrap(); let params = ParamsType { - 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(), + active_salary: bounded_vec![100u32.into(); max_rank], + passive_salary: bounded_vec![10u32.into(); max_rank], + demotion_period: bounded_vec![100u32.into(); max_rank], + min_promotion_period: bounded_vec![100u32.into(); max_rank], offboard_timeout: 1u32.into(), }; @@ -153,8 +154,8 @@ mod benchmarks { fn promote() -> Result<(), BenchmarkError> { // Ensure that the `min_promotion_period` wont get in our way. let mut params = Params::::get(); - let max_rank: usize = T::Members::max_rank().into(); - params.min_promotion_period = BoundedVec::try_from(vec![Zero::zero(); max_rank]).unwrap(); + let max_rank = T::MaxRank::get().try_into().unwrap(); + params.min_promotion_period = bounded_vec![Zero::zero(); max_rank]; Params::::put(¶ms); let member = make_member::(1)?; diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index 616715a8fb85..4af445df69ea 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -213,6 +213,8 @@ pub mod pallet { #[pallet::constant] type EvidenceSize: Get; + /// Represents the highest possible rank in this pallet. + /// Increasing this value is supported, but decreasing it may lead to a broken state. #[pallet::constant] type MaxRank: Get; } @@ -564,7 +566,7 @@ pub mod pallet { /// in the range `1..=RANK_COUNT` is `None`. pub(crate) fn rank_to_index(rank: RankOf) -> Option { match TryInto::::try_into(rank) { - Ok(r) if r <= T::Members::max_rank().into() && r > 0 => Some(r - 1), + Ok(r) if r as u32 <= >::MaxRank::get() && r > 0 => Some(r - 1), _ => return None, } } diff --git a/substrate/frame/core-fellowship/src/tests/integration.rs b/substrate/frame/core-fellowship/src/tests/integration.rs index bd18355e9186..f31373166585 100644 --- a/substrate/frame/core-fellowship/src/tests/integration.rs +++ b/substrate/frame/core-fellowship/src/tests/integration.rs @@ -27,6 +27,7 @@ use frame_system::EnsureSignedBy; use pallet_ranked_collective::{EnsureRanked, Geometric, Rank, TallyOf, Votes}; use sp_core::{ConstU32, Get}; use sp_runtime::{ + bounded_vec, traits::{Convert, ReduceBy, ReplaceWithDefault, TryMorphInto}, BuildStorage, DispatchError, }; @@ -78,7 +79,7 @@ impl Config for Test { type ApproveOrigin = TryMapSuccess, u64>, TryMorphInto>; type PromoteOrigin = TryMapSuccess, u64>, TryMorphInto>; type EvidenceSize = EvidenceSize; - type MaxRank = ::MaxRank; + type MaxRank = ConstU32<9>; } pub struct TestPolls; @@ -158,7 +159,6 @@ impl pallet_ranked_collective::Config for Test { type VoteWeight = Geometric; #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = CoreFellowship; - type MaxRank = ConstU32<9>; } pub fn new_test_ext() -> sp_io::TestExternalities { @@ -168,11 +168,10 @@ pub fn new_test_ext() -> sp_io::TestExternalities { assert_ok!(Club::add_member(RuntimeOrigin::root(), 100)); promote_n_times(100, 9); let params = ParamsType { - active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]).unwrap(), - passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(), - demotion_period: BoundedVec::try_from(vec![2, 4, 6, 8, 10, 12, 14, 16, 18]).unwrap(), - min_promotion_period: BoundedVec::try_from(vec![3, 6, 9, 12, 15, 18, 21, 24, 27]) - .unwrap(), + active_salary: bounded_vec![10, 20, 30, 40, 50, 60, 70, 80, 90], + passive_salary: bounded_vec![1, 2, 3, 4, 5, 6, 7, 8, 9], + demotion_period: bounded_vec![2, 4, 6, 8, 10, 12, 14, 16, 18], + min_promotion_period: bounded_vec![3, 6, 9, 12, 15, 18, 21, 24, 27], offboard_timeout: 1, }; assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); diff --git a/substrate/frame/core-fellowship/src/tests/unit.rs b/substrate/frame/core-fellowship/src/tests/unit.rs index 8695b118616c..9245e5159a90 100644 --- a/substrate/frame/core-fellowship/src/tests/unit.rs +++ b/substrate/frame/core-fellowship/src/tests/unit.rs @@ -27,7 +27,7 @@ use frame_support::{ traits::{tokens::GetSalary, ConstU32, IsInVec, TryMapSuccess}, }; use frame_system::EnsureSignedBy; -use sp_runtime::{traits::TryMorphInto, BuildStorage, DispatchError, DispatchResult}; +use sp_runtime::{bounded_vec, traits::TryMorphInto, BuildStorage, DispatchError, DispatchResult}; use crate as pallet_core_fellowship; use crate::*; @@ -89,9 +89,6 @@ 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: u64, rank: u16) { @@ -128,11 +125,10 @@ pub fn new_test_ext() -> sp_io::TestExternalities { ext.execute_with(|| { set_rank(100, 9); let params = ParamsType { - active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]).unwrap(), - passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(), - demotion_period: BoundedVec::try_from(vec![2, 4, 6, 8, 10, 12, 14, 16, 18]).unwrap(), - min_promotion_period: BoundedVec::try_from(vec![3, 6, 9, 12, 15, 18, 21, 24, 27]) - .unwrap(), + active_salary: bounded_vec![10, 20, 30, 40, 50, 60, 70, 80, 90], + passive_salary: bounded_vec![1, 2, 3, 4, 5, 6, 7, 8, 9], + demotion_period: bounded_vec![2, 4, 6, 8, 10, 12, 14, 16, 18], + min_promotion_period: bounded_vec![3, 6, 9, 12, 15, 18, 21, 24, 27], offboard_timeout: 1, }; @@ -177,11 +173,10 @@ fn basic_stuff() { fn set_params_works() { new_test_ext().execute_with(|| { let params = ParamsType { - active_salary: BoundedVec::try_from(vec![10, 20, 30, 40, 50, 60, 70, 80, 90]).unwrap(), - passive_salary: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(), - demotion_period: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(), - min_promotion_period: BoundedVec::try_from(vec![1, 2, 3, 4, 5, 10, 15, 20, 30]) - .unwrap(), + active_salary: bounded_vec![10, 20, 30, 40, 50, 60, 70, 80, 90], + passive_salary: bounded_vec![1, 2, 3, 4, 5, 6, 7, 8, 9], + demotion_period: bounded_vec![1, 2, 3, 4, 5, 6, 7, 8, 9], + min_promotion_period: bounded_vec![1, 2, 3, 4, 5, 10, 15, 20, 30], offboard_timeout: 1, }; assert_noop!( @@ -292,11 +287,10 @@ fn offboard_works() { fn infinite_demotion_period_works() { new_test_ext().execute_with(|| { let params = ParamsType { - active_salary: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]).unwrap(), - passive_salary: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]).unwrap(), - min_promotion_period: BoundedVec::try_from(vec![10, 10, 10, 10, 10, 10, 10, 10, 10]) - .unwrap(), - demotion_period: BoundedVec::try_from(vec![0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(), + active_salary: bounded_vec![10, 10, 10, 10, 10, 10, 10, 10, 10], + passive_salary: bounded_vec![10, 10, 10, 10, 10, 10, 10, 10, 10], + min_promotion_period: bounded_vec![10, 10, 10, 10, 10, 10, 10, 10, 10], + demotion_period: bounded_vec![0, 0, 0, 0, 0, 0, 0, 0, 0], offboard_timeout: 0, }; assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params))); diff --git a/substrate/frame/ranked-collective/src/lib.rs b/substrate/frame/ranked-collective/src/lib.rs index 0ff14b879f07..ceaf03de2110 100644 --- a/substrate/frame/ranked-collective/src/lib.rs +++ b/substrate/frame/ranked-collective/src/lib.rs @@ -434,10 +434,6 @@ pub mod pallet { /// Setup a member for benchmarking. #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup: BenchmarkSetup; - - /// The maximum number of members. - #[pallet::constant] - type MaxRank: Get; } /// The number of members in the collective who have at least the rank according to the index @@ -1007,9 +1003,5 @@ pub mod pallet { fn demote(who: &Self::AccountId) -> DispatchResult { Self::do_demote_member(who.clone(), None) } - - fn max_rank() -> Self::Rank { - T::MaxRank::get() as Rank - } } } diff --git a/substrate/frame/salary/src/tests/unit.rs b/substrate/frame/salary/src/tests/unit.rs index 10c133aa0a8a..db1c8b947ef5 100644 --- a/substrate/frame/salary/src/tests/unit.rs +++ b/substrate/frame/salary/src/tests/unit.rs @@ -135,9 +135,6 @@ 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: u64, rank: u64) { diff --git a/substrate/frame/support/src/traits/members.rs b/substrate/frame/support/src/traits/members.rs index 1c48b585becc..53de84ab2245 100644 --- a/substrate/frame/support/src/traits/members.rs +++ b/substrate/frame/support/src/traits/members.rs @@ -304,9 +304,6 @@ pub trait RankedMembers { /// Demote a member to the next lower rank; demoting beyond the `min_rank` removes the /// member entirely. fn demote(who: &Self::AccountId) -> DispatchResult; - - /// The maximum rank possible in this membership organisation. - fn max_rank() -> Self::Rank; } /// Handler that can deal with the swap of two members. From 093232f966fae12e2ff64b6ea66993fd54bed9b9 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 30 Apr 2024 04:56:48 +0100 Subject: [PATCH 24/31] remove Config salary pallet test --- substrate/frame/salary/src/tests/integration.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/frame/salary/src/tests/integration.rs b/substrate/frame/salary/src/tests/integration.rs index df7ad4eeb32d..4fbdd2458de4 100644 --- a/substrate/frame/salary/src/tests/integration.rs +++ b/substrate/frame/salary/src/tests/integration.rs @@ -182,7 +182,6 @@ impl pallet_ranked_collective::Config for Test { type VoteWeight = Geometric; #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = Salary; - type MaxRank = ConstU32<9>; } pub fn new_test_ext() -> sp_io::TestExternalities { From 3f21602656c6a76cc577440e9e4bd64137a55860 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 30 Apr 2024 06:05:07 +0100 Subject: [PATCH 25/31] ranked remove MaxRank in test --- substrate/frame/ranked-collective/src/tests.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/substrate/frame/ranked-collective/src/tests.rs b/substrate/frame/ranked-collective/src/tests.rs index a3609f14c0d8..ad8b7d2a8018 100644 --- a/substrate/frame/ranked-collective/src/tests.rs +++ b/substrate/frame/ranked-collective/src/tests.rs @@ -23,7 +23,7 @@ use frame_support::{ assert_noop, assert_ok, derive_impl, error::BadOrigin, parameter_types, - traits::{ConstU16, ConstU32, EitherOf, MapSuccess, Polling}, + traits::{ConstU16, EitherOf, MapSuccess, Polling}, }; use sp_core::Get; use sp_runtime::{ @@ -181,7 +181,6 @@ impl Config for Test { type VoteWeight = Geometric; #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = (); - type MaxRank = ConstU32<9>; } pub struct ExtBuilder {} From f9724a2b54ec4df1d447c578eeab1a0251bf2937 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 30 Apr 2024 06:22:33 +0100 Subject: [PATCH 26/31] clippy --- substrate/frame/salary/src/tests/integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/salary/src/tests/integration.rs b/substrate/frame/salary/src/tests/integration.rs index 4fbdd2458de4..124ab38c5651 100644 --- a/substrate/frame/salary/src/tests/integration.rs +++ b/substrate/frame/salary/src/tests/integration.rs @@ -24,7 +24,7 @@ use frame_support::{ traits::{ConstU64, EitherOf, MapSuccess, PollStatus, Polling}, }; use pallet_ranked_collective::{EnsureRanked, Geometric, TallyOf, Votes}; -use sp_core::{ConstU16, ConstU32, Get}; +use sp_core::{ConstU16, Get}; use sp_runtime::{ traits::{Convert, ReduceBy, ReplaceWithDefault}, BuildStorage, DispatchError, From 25f0d06e5b89ef92ddd91eb650cd2b1cc0f62f8b Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 30 Apr 2024 10:15:37 +0100 Subject: [PATCH 27/31] similar import for benchmarks --- substrate/frame/core-fellowship/src/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index e7e5368bed91..575a06a21c18 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -23,9 +23,9 @@ use super::*; use crate::Pallet as CoreFellowship; use frame_benchmarking::v2::*; +use frame_support::testing_prelude::bounded_vec; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; use sp_arithmetic::traits::Bounded; -use sp_runtime::bounded_vec; const SEED: u32 = 0; From 2afaa8f12b367807e2650e2acfe2029aec7966b9 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 30 Apr 2024 18:14:49 +0100 Subject: [PATCH 28/31] sp_runtime::bounded_vec --- substrate/frame/core-fellowship/src/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index 575a06a21c18..e7e5368bed91 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -23,9 +23,9 @@ use super::*; use crate::Pallet as CoreFellowship; use frame_benchmarking::v2::*; -use frame_support::testing_prelude::bounded_vec; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; use sp_arithmetic::traits::Bounded; +use sp_runtime::bounded_vec; const SEED: u32 = 0; From ee9f04768dbee8928769b905615df082ff03ee5e Mon Sep 17 00:00:00 2001 From: doordashcon Date: Wed, 1 May 2024 08:35:37 +0100 Subject: [PATCH 29/31] sp_core --- substrate/frame/core-fellowship/src/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index e7e5368bed91..c450c5cc89dd 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -25,7 +25,7 @@ use crate::Pallet as CoreFellowship; use frame_benchmarking::v2::*; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; use sp_arithmetic::traits::Bounded; -use sp_runtime::bounded_vec; +use sp_core::bounded_vec; const SEED: u32 = 0; From 4a31d0af69d3529e9a9ad3dff44d05f8aeb296c8 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Fri, 3 May 2024 14:20:48 +0100 Subject: [PATCH 30/31] back to BoundedVec::try_from.. --- .../frame/core-fellowship/src/benchmarking.rs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index c450c5cc89dd..b3ee3ab7d165 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -25,7 +25,6 @@ use crate::Pallet as CoreFellowship; use frame_benchmarking::v2::*; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; use sp_arithmetic::traits::Bounded; -use sp_core::bounded_vec; const SEED: u32 = 0; @@ -36,7 +35,7 @@ mod benchmarks { use super::*; fn ensure_evidence, I: 'static>(who: &T::AccountId) -> BenchResult { - let evidence = bounded_vec![0; Evidence::::bound()]; + let evidence = BoundedVec::try_from(vec![0; Evidence::::bound()]).unwrap(); let wish = Wish::Retention; let origin = RawOrigin::Signed(who.clone()).into(); CoreFellowship::::submit_evidence(origin, wish, evidence)?; @@ -57,10 +56,10 @@ mod benchmarks { fn set_benchmark_params, I: 'static>() -> Result<(), BenchmarkError> { let max_rank = T::MaxRank::get().try_into().unwrap(); let params = ParamsType { - active_salary: bounded_vec![100u32.into(); max_rank], - passive_salary: bounded_vec![10u32.into(); max_rank], - demotion_period: bounded_vec![100u32.into(); max_rank], - min_promotion_period: bounded_vec![100u32.into(); max_rank], + 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(), }; @@ -72,10 +71,10 @@ mod benchmarks { fn set_params() -> Result<(), BenchmarkError> { let max_rank = T::MaxRank::get().try_into().unwrap(); let params = ParamsType { - active_salary: bounded_vec![100u32.into(); max_rank], - passive_salary: bounded_vec![10u32.into(); max_rank], - demotion_period: bounded_vec![100u32.into(); max_rank], - min_promotion_period: bounded_vec![100u32.into(); max_rank], + 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(), }; @@ -155,7 +154,7 @@ mod benchmarks { // Ensure that the `min_promotion_period` wont get in our way. let mut params = Params::::get(); let max_rank = T::MaxRank::get().try_into().unwrap(); - params.min_promotion_period = bounded_vec![Zero::zero(); max_rank]; + params.min_promotion_period = BoundedVec::try_from(vec![Zero::zero(); max_rank]).unwrap(); Params::::put(¶ms); let member = make_member::(1)?; From 5071cb93c9f5b4dd4a918bb2aace0329c96ad0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 16 May 2024 17:36:20 +0200 Subject: [PATCH 31/31] Update substrate/frame/core-fellowship/src/lib.rs --- substrate/frame/core-fellowship/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index 4af445df69ea..94339b85d052 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -214,6 +214,7 @@ pub mod pallet { type EvidenceSize: Get; /// Represents the highest possible rank in this pallet. + /// /// Increasing this value is supported, but decreasing it may lead to a broken state. #[pallet::constant] type MaxRank: Get;