Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
fixes for kitchensink-runtime and pallet grandpa
Browse files Browse the repository at this point in the history
Signed-off-by: muraca <[email protected]>
  • Loading branch information
muraca committed Feb 11, 2023
1 parent 9bad78b commit 5538376
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ fn get_result_weight(result: DispatchResultWithPostInfo) -> Option<Weight> {
}

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Actual proposal for a given hash, if it's current.
pub fn proposal_of(who: T::Hash) -> Option<<T as Config<I>>::Proposal> {
ProposalOf::<T, I>::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
Expand Down
10 changes: 5 additions & 5 deletions frame/elections-phragmen/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,18 @@ fn distribute_voters<T: Config>(
/// members, or members and runners-up.
fn fill_seats_up_to<T: Config>(m: u32) -> Result<Vec<T::AccountId>, &'static str> {
let _ = submit_candidates_with_self_vote::<T>(m, "fill_seats_up_to")?;
assert_eq!(<Elections<T>>::candidates().len() as u32, m, "wrong number of candidates.");
assert_eq!(<Candidates<T>>::get().len() as u32, m, "wrong number of candidates.");
<Elections<T>>::do_phragmen();
assert_eq!(<Elections<T>>::candidates().len(), 0, "some candidates remaining.");
assert_eq!(<Candidates<T>>::get().len(), 0, "some candidates remaining.");
assert_eq!(
<Members<T>>::get().len() + <Elections<T>>::runners_up().len(),
<Members<T>>::get().len() + RunnersUp::<T>::get().len(),
m as usize,
"wrong number of members and runners-up",
);
Ok(<Members<T>>::get()
.into_iter()
.map(|m| m.who)
.chain(<Elections<T>>::runners_up().into_iter().map(|r| r.who))
.chain(RunnersUp::<T>::get().into_iter().map(|r| r.who))
.collect())
}

Expand Down Expand Up @@ -409,7 +409,7 @@ benchmarks! {
verify {
assert_eq!(<Members<T>>::get().len() as u32, T::DesiredMembers::get().min(c));
assert_eq!(
<Elections<T>>::runners_up().len() as u32,
RunnersUp::<T>::get().len() as u32,
T::DesiredRunnersUp::get().min(c.saturating_sub(T::DesiredMembers::get())),
);

Expand Down
6 changes: 6 additions & 0 deletions frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ pub enum StoredState<N> {
}

impl<T: Config> Pallet<T> {
/// 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::<T>::get()
}

/// Get the current set of authorities, along with their respective weights.
pub fn grandpa_authorities() -> AuthorityList {
storage::unhashed::get_or_default::<VersionedAuthorityList>(GRANDPA_AUTHORITIES_KEY).into()
Expand Down
6 changes: 3 additions & 3 deletions frame/grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Test>::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::<Test>::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::<Test>::get(i as u64).is_none());
}
});
}
Expand Down
5 changes: 5 additions & 0 deletions frame/im-online/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@ impl<T: Config + pallet_authorship::Config>
}

impl<T: Config> Pallet<T> {
/// The current set of keys that may issue a heartbeat.
pub fn keys() -> WeakBoundedVec<T::AuthorityId, T::MaxKeys> {
Keys::<T>::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
Expand Down
10 changes: 5 additions & 5 deletions frame/nomination-pools/test-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Runtime>::get(), None);

// create the pool, we know this has id 1.
assert_ok!(Pools::create(RuntimeOrigin::signed(10), 50, 10, 10, 10));
Expand Down Expand Up @@ -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::<Runtime>::get(), None);

// create the pool, we know this has id 1.
assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10));
Expand Down Expand Up @@ -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::<Runtime>::get(), None);

// create the pool, we know this has id 1.
assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10));
Expand Down Expand Up @@ -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::<Runtime>::get(), None);

// create the pool, we know this has id 1.
assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10));
Expand Down Expand Up @@ -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::<Runtime>::get(), None);

// create the pool, we know this has id 1.
assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10));
Expand Down
4 changes: 2 additions & 2 deletions frame/offences/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ benchmarks! {
Staking::<T>::set_slash_reward_fraction(Perbill::one());

let (offenders, raw_offenders) = make_offenders_im_online::<T>(o, n)?;
let keys = ImOnline::<T>::keys();
let keys = ImOnline::<T>::keys();
let validator_set_count = keys.len() as u32;
let offenders_count = offenders.len() as u32;
let offence = UnresponsivenessOffence {
Expand Down Expand Up @@ -442,7 +442,7 @@ benchmarks! {
Staking::<T>::set_slash_reward_fraction(Perbill::one());

let (mut offenders, raw_offenders) = make_offenders::<T>(1, n)?;
let keys = ImOnline::<T>::keys();
let keys = ImOnline::<T>::keys();

let offence = BabeEquivocationOffence {
slot: 0u64.into(),
Expand Down
6 changes: 3 additions & 3 deletions frame/session/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ benchmarks! {
false,
RewardDestination::Staked,
)?;
let v_controller = pallet_staking::Pallet::<T>::bonded(&v_stash).ok_or("not stash")?;
let v_controller = pallet_staking::Bonded::<T>::get(&v_stash).ok_or("not stash")?;

let keys = T::Keys::decode(&mut TrailingZeroInput::zeroes()).unwrap();
let proof: Vec<u8> = vec![0,1,2,3];
Expand All @@ -78,7 +78,7 @@ benchmarks! {
false,
RewardDestination::Staked
)?;
let v_controller = pallet_staking::Pallet::<T>::bonded(&v_stash).ok_or("not stash")?;
let v_controller = pallet_staking::Bonded::<T>::get(&v_stash).ok_or("not stash")?;
let keys = T::Keys::decode(&mut TrailingZeroInput::zeroes()).unwrap();
let proof: Vec<u8> = vec![0,1,2,3];
Session::<T>::set_keys(RawOrigin::Signed(v_controller.clone()).into(), keys, proof)?;
Expand Down Expand Up @@ -134,7 +134,7 @@ fn check_membership_proof_setup<T: Config>(
use rand::{RngCore, SeedableRng};

let validator = T::Lookup::lookup(who).unwrap();
let controller = pallet_staking::Pallet::<T>::bonded(validator).unwrap();
let controller = pallet_staking::Bonded::<T>::get(validator).unwrap();

let keys = {
let mut keys = [0u8; 128];
Expand Down
4 changes: 2 additions & 2 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ benchmarks! {

let current_era = CurrentEra::<T>::get().unwrap();
// set the commission for this particular era as well.
<ErasValidatorPrefs<T>>::insert(current_era, validator.clone(), <Staking<T>>::validators(&validator));
<ErasValidatorPrefs<T>>::insert(current_era, validator.clone(), Validators::<T>::get(&validator));

let caller = whitelisted_caller();
let validator_controller = <Bonded<T>>::get(&validator).unwrap();
Expand Down Expand Up @@ -589,7 +589,7 @@ benchmarks! {

let current_era = CurrentEra::<T>::get().unwrap();
// set the commission for this particular era as well.
<ErasValidatorPrefs<T>>::insert(current_era, validator.clone(), <Staking<T>>::validators(&validator));
<ErasValidatorPrefs<T>>::insert(current_era, validator.clone(), Validators::<T>::get(&validator));

let caller = whitelisted_caller();
let balance_before = T::Currency::free_balance(&validator);
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/testing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,5 @@ pub fn create_validators_with_nominators_for_era<T: Config>(

/// get the current era.
pub fn current_era<T: Config>() -> EraIndex {
CurrentEra::<T>::get().unwrap_or(0)
CurrentEra::<T>::get().unwrap_or(0)
}
4 changes: 2 additions & 2 deletions frame/state-trie-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Runtime>(now + One::one()).1;
if StateTrieMigration::<Runtime>::migration_process().finished() {
if MigrationProcess::<Runtime>::get().finished() {
return (true, weight)
}
duration += One::one();
Expand Down Expand Up @@ -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::<Runtime>::migration_process(),
MigrationProcess::<Runtime>::get(),
)
});

Expand Down

0 comments on commit 5538376

Please sign in to comment.