From 5538376041e14c33652973886e604719950a4fa5 Mon Sep 17 00:00:00 2001 From: muraca Date: Sat, 11 Feb 2023 19:44:11 +0100 Subject: [PATCH] fixes for kitchensink-runtime and pallet grandpa Signed-off-by: muraca --- bin/node/runtime/src/impls.rs | 2 +- frame/collective/src/lib.rs | 5 +++++ frame/elections-phragmen/src/benchmarking.rs | 10 +++++----- frame/grandpa/src/lib.rs | 6 ++++++ frame/grandpa/src/tests.rs | 6 +++--- frame/im-online/src/lib.rs | 5 +++++ frame/nomination-pools/test-staking/src/lib.rs | 10 +++++----- frame/offences/benchmarking/src/lib.rs | 4 ++-- frame/session/benchmarking/src/lib.rs | 6 +++--- frame/staking/src/benchmarking.rs | 4 ++-- frame/staking/src/testing_utils.rs | 2 +- frame/state-trie-migration/src/lib.rs | 4 ++-- 12 files changed, 40 insertions(+), 24 deletions(-) diff --git a/bin/node/runtime/src/impls.rs b/bin/node/runtime/src/impls.rs index 4fadbc9d076bd..d2e35be701cfb 100644 --- a/bin/node/runtime/src/impls.rs +++ b/bin/node/runtime/src/impls.rs @@ -123,7 +123,7 @@ mod multiplier_tests { use crate::{ constants::{currency::*, time::*}, AdjustmentVariable, MaximumMultiplier, MinimumMultiplier, Runtime, - RuntimeBlockWeights as BlockWeights, System, TargetBlockFullness, TransactionPayment, + RuntimeBlockWeights as BlockWeights, System, TargetBlockFullness, }; use frame_support::{ dispatch::DispatchClass, diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index 578e78786d80c..daf0143c97dac 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -737,6 +737,11 @@ fn get_result_weight(result: DispatchResultWithPostInfo) -> Option { } impl, I: 'static> Pallet { + /// Actual proposal for a given hash, if it's current. + pub fn proposal_of(who: T::Hash) -> Option<>::Proposal> { + ProposalOf::::get(who) + } + /// Check whether `who` is a member of the collective. pub fn is_member(who: &T::AccountId) -> bool { // Note: The dispatchables *do not* use this to check membership so make sure diff --git a/frame/elections-phragmen/src/benchmarking.rs b/frame/elections-phragmen/src/benchmarking.rs index d87cc21b92751..f8c3ce3c74a47 100644 --- a/frame/elections-phragmen/src/benchmarking.rs +++ b/frame/elections-phragmen/src/benchmarking.rs @@ -121,18 +121,18 @@ fn distribute_voters( /// members, or members and runners-up. fn fill_seats_up_to(m: u32) -> Result, &'static str> { let _ = submit_candidates_with_self_vote::(m, "fill_seats_up_to")?; - assert_eq!(>::candidates().len() as u32, m, "wrong number of candidates."); + assert_eq!(>::get().len() as u32, m, "wrong number of candidates."); >::do_phragmen(); - assert_eq!(>::candidates().len(), 0, "some candidates remaining."); + assert_eq!(>::get().len(), 0, "some candidates remaining."); assert_eq!( - >::get().len() + >::runners_up().len(), + >::get().len() + RunnersUp::::get().len(), m as usize, "wrong number of members and runners-up", ); Ok(>::get() .into_iter() .map(|m| m.who) - .chain(>::runners_up().into_iter().map(|r| r.who)) + .chain(RunnersUp::::get().into_iter().map(|r| r.who)) .collect()) } @@ -409,7 +409,7 @@ benchmarks! { verify { assert_eq!(>::get().len() as u32, T::DesiredMembers::get().min(c)); assert_eq!( - >::runners_up().len() as u32, + RunnersUp::::get().len() as u32, T::DesiredRunnersUp::get().min(c.saturating_sub(T::DesiredMembers::get())), ); diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 1aadd6caae1dc..8650ce07f4c9a 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -418,6 +418,12 @@ pub enum StoredState { } impl Pallet { + /// The number of changes (both in terms of keys and underlying economic responsibilities) + /// in the "set" of Grandpa validators from genesis. + pub fn current_set_id() -> SetId { + CurrentSetId::::get() + } + /// Get the current set of authorities, along with their respective weights. pub fn grandpa_authorities() -> AuthorityList { storage::unhashed::get_or_default::(GRANDPA_AUTHORITIES_KEY).into() diff --git a/frame/grandpa/src/tests.rs b/frame/grandpa/src/tests.rs index ab3b51e7fd183..766317b34602f 100644 --- a/frame/grandpa/src/tests.rs +++ b/frame/grandpa/src/tests.rs @@ -794,19 +794,19 @@ fn cleans_up_old_set_id_session_mappings() { // we should have a session id mapping for all the set ids from // `max_set_id_session_entries` eras we have observed for i in 1..=max_set_id_session_entries { - assert!(Grandpa::session_for_set(i as u64).is_some()); + assert!(SetIdSession::::get(i as u64).is_some()); } start_era(max_set_id_session_entries * 2); // we should keep tracking the new mappings for new eras for i in max_set_id_session_entries + 1..=max_set_id_session_entries * 2 { - assert!(Grandpa::session_for_set(i as u64).is_some()); + assert!(SetIdSession::::get(i as u64).is_some()); } // but the old ones should have been pruned by now for i in 1..=max_set_id_session_entries { - assert!(Grandpa::session_for_set(i as u64).is_none()); + assert!(SetIdSession::::get(i as u64).is_none()); } }); } diff --git a/frame/im-online/src/lib.rs b/frame/im-online/src/lib.rs index 409d564397301..ad02c2f843fd1 100644 --- a/frame/im-online/src/lib.rs +++ b/frame/im-online/src/lib.rs @@ -606,6 +606,11 @@ impl } impl Pallet { + /// The current set of keys that may issue a heartbeat. + pub fn keys() -> WeakBoundedVec { + Keys::::get() + } + /// Returns `true` if a heartbeat has been received for the authority at /// `authority_index` in the authorities series or if the authority has /// authored at least one block, during the current session. Otherwise diff --git a/frame/nomination-pools/test-staking/src/lib.rs b/frame/nomination-pools/test-staking/src/lib.rs index 933e42578d1a6..7e90cfb5d6786 100644 --- a/frame/nomination-pools/test-staking/src/lib.rs +++ b/frame/nomination-pools/test-staking/src/lib.rs @@ -32,7 +32,7 @@ use sp_runtime::traits::Zero; fn pool_lifecycle_e2e() { new_test_ext().execute_with(|| { assert_eq!(Balances::minimum_balance(), 5); - assert_eq!(Staking::current_era(), None); + assert_eq!(CurrentEra::::get(), None); // create the pool, we know this has id 1. assert_ok!(Pools::create(RuntimeOrigin::signed(10), 50, 10, 10, 10)); @@ -196,7 +196,7 @@ fn pool_slash_e2e() { new_test_ext().execute_with(|| { ExistentialDeposit::set(1); assert_eq!(Balances::minimum_balance(), 1); - assert_eq!(Staking::current_era(), None); + assert_eq!(CurrentEra::::get(), None); // create the pool, we know this has id 1. assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10)); @@ -403,7 +403,7 @@ fn pool_slash_proportional() { ExistentialDeposit::set(1); BondingDuration::set(28); assert_eq!(Balances::minimum_balance(), 1); - assert_eq!(Staking::current_era(), None); + assert_eq!(CurrentEra::::get(), None); // create the pool, we know this has id 1. assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10)); @@ -540,7 +540,7 @@ fn pool_slash_non_proportional_only_bonded_pool() { ExistentialDeposit::set(1); BondingDuration::set(28); assert_eq!(Balances::minimum_balance(), 1); - assert_eq!(Staking::current_era(), None); + assert_eq!(CurrentEra::::get(), None); // create the pool, we know this has id 1. assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10)); @@ -619,7 +619,7 @@ fn pool_slash_non_proportional_bonded_pool_and_chunks() { ExistentialDeposit::set(1); BondingDuration::set(28); assert_eq!(Balances::minimum_balance(), 1); - assert_eq!(Staking::current_era(), None); + assert_eq!(CurrentEra::::get(), None); // create the pool, we know this has id 1. assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10)); diff --git a/frame/offences/benchmarking/src/lib.rs b/frame/offences/benchmarking/src/lib.rs index b71321906cbdd..e7c048d0af841 100644 --- a/frame/offences/benchmarking/src/lib.rs +++ b/frame/offences/benchmarking/src/lib.rs @@ -301,7 +301,7 @@ benchmarks! { Staking::::set_slash_reward_fraction(Perbill::one()); let (offenders, raw_offenders) = make_offenders_im_online::(o, n)?; - let keys = ImOnline::::keys(); + let keys = ImOnline::::keys(); let validator_set_count = keys.len() as u32; let offenders_count = offenders.len() as u32; let offence = UnresponsivenessOffence { @@ -442,7 +442,7 @@ benchmarks! { Staking::::set_slash_reward_fraction(Perbill::one()); let (mut offenders, raw_offenders) = make_offenders::(1, n)?; - let keys = ImOnline::::keys(); + let keys = ImOnline::::keys(); let offence = BabeEquivocationOffence { slot: 0u64.into(), diff --git a/frame/session/benchmarking/src/lib.rs b/frame/session/benchmarking/src/lib.rs index c222272153fc9..d32af7be2171f 100644 --- a/frame/session/benchmarking/src/lib.rs +++ b/frame/session/benchmarking/src/lib.rs @@ -61,7 +61,7 @@ benchmarks! { false, RewardDestination::Staked, )?; - let v_controller = pallet_staking::Pallet::::bonded(&v_stash).ok_or("not stash")?; + let v_controller = pallet_staking::Bonded::::get(&v_stash).ok_or("not stash")?; let keys = T::Keys::decode(&mut TrailingZeroInput::zeroes()).unwrap(); let proof: Vec = vec![0,1,2,3]; @@ -78,7 +78,7 @@ benchmarks! { false, RewardDestination::Staked )?; - let v_controller = pallet_staking::Pallet::::bonded(&v_stash).ok_or("not stash")?; + let v_controller = pallet_staking::Bonded::::get(&v_stash).ok_or("not stash")?; let keys = T::Keys::decode(&mut TrailingZeroInput::zeroes()).unwrap(); let proof: Vec = vec![0,1,2,3]; Session::::set_keys(RawOrigin::Signed(v_controller.clone()).into(), keys, proof)?; @@ -134,7 +134,7 @@ fn check_membership_proof_setup( use rand::{RngCore, SeedableRng}; let validator = T::Lookup::lookup(who).unwrap(); - let controller = pallet_staking::Pallet::::bonded(validator).unwrap(); + let controller = pallet_staking::Bonded::::get(validator).unwrap(); let keys = { let mut keys = [0u8; 128]; diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index a4366bbd8aa9a..838269e414736 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -556,7 +556,7 @@ benchmarks! { let current_era = CurrentEra::::get().unwrap(); // set the commission for this particular era as well. - >::insert(current_era, validator.clone(), >::validators(&validator)); + >::insert(current_era, validator.clone(), Validators::::get(&validator)); let caller = whitelisted_caller(); let validator_controller = >::get(&validator).unwrap(); @@ -589,7 +589,7 @@ benchmarks! { let current_era = CurrentEra::::get().unwrap(); // set the commission for this particular era as well. - >::insert(current_era, validator.clone(), >::validators(&validator)); + >::insert(current_era, validator.clone(), Validators::::get(&validator)); let caller = whitelisted_caller(); let balance_before = T::Currency::free_balance(&validator); diff --git a/frame/staking/src/testing_utils.rs b/frame/staking/src/testing_utils.rs index 4a63937b4a517..ae00ec671cd01 100644 --- a/frame/staking/src/testing_utils.rs +++ b/frame/staking/src/testing_utils.rs @@ -227,5 +227,5 @@ pub fn create_validators_with_nominators_for_era( /// get the current era. pub fn current_era() -> EraIndex { - CurrentEra::::get().unwrap_or(0) + CurrentEra::::get().unwrap_or(0) } diff --git a/frame/state-trie-migration/src/lib.rs b/frame/state-trie-migration/src/lib.rs index 9d1cf0f46eefc..6638b30ba1a13 100644 --- a/frame/state-trie-migration/src/lib.rs +++ b/frame/state-trie-migration/src/lib.rs @@ -1685,7 +1685,7 @@ pub(crate) mod remote_tests { let last_state_root = ext.backend.root().clone(); let ((finished, weight), proof) = ext.execute_and_prove(|| { let weight = run_to_block::(now + One::one()).1; - if StateTrieMigration::::migration_process().finished() { + if MigrationProcess::::get().finished() { return (true, weight) } duration += One::one(); @@ -1722,7 +1722,7 @@ pub(crate) mod remote_tests { target: LOG_TARGET, "finished on_initialize migration in {} block, final state of the task: {:?}", duration, - StateTrieMigration::::migration_process(), + MigrationProcess::::get(), ) });