diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index b6d02fa2fd30d..ce1f5afc64c1d 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -761,8 +761,8 @@ pub mod migrations { use super::*; pub fn pre_migrate() -> Result<(), &'static str> { - assert!(CurrentValidatorsCount::::get().is_zero(), "CurrentValidatorsCount already set."); - assert!(CurrentNominatorsCount::::get().is_zero(), "CurrentNominatorsCount already set."); + assert!(CounterForValidators::::get().is_zero(), "CounterForValidators already set."); + assert!(CounterForNominators::::get().is_zero(), "CounterForNominators already set."); assert!(StorageVersion::::get() == Releases::V6_0_0); Ok(()) } @@ -772,8 +772,8 @@ pub mod migrations { let validator_count = Validators::::iter().count() as u32; let nominator_count = Nominators::::iter().count() as u32; - CurrentValidatorsCount::::put(validator_count); - CurrentNominatorsCount::::put(nominator_count); + CounterForValidators::::put(validator_count); + CounterForNominators::::put(nominator_count); StorageVersion::::put(Releases::V7_0_0); log!(info, "Completed staking migration to Releases::V7_0_0"); @@ -998,14 +998,14 @@ pub mod pallet { /// The map from (wannabe) validator stash key to the preferences of that validator. /// - /// When updating this storage item, you must also update the `CurrentValidatorsCount`. + /// When updating this storage item, you must also update the `CounterForValidators`. #[pallet::storage] #[pallet::getter(fn validators)] pub type Validators = StorageMap<_, Twox64Concat, T::AccountId, ValidatorPrefs, ValueQuery>; /// A tracker to keep count of the number of items in the `Validators` map. #[pallet::storage] - pub type CurrentValidatorsCount = StorageValue<_, u32, ValueQuery>; + pub type CounterForValidators = StorageValue<_, u32, ValueQuery>; /// The maximum validator count before we stop allowing new validators to join. /// @@ -1015,14 +1015,14 @@ pub mod pallet { /// The map from nominator stash key to the set of stash keys of all validators to nominate. /// - /// When updating this storage item, you must also update the `CurrentNominatorsCount`. + /// When updating this storage item, you must also update the `CounterForNominators`. #[pallet::storage] #[pallet::getter(fn nominators)] pub type Nominators = StorageMap<_, Twox64Concat, T::AccountId, Nominations>; /// A tracker to keep count of the number of items in the `Nominators` map. #[pallet::storage] - pub type CurrentNominatorsCount = StorageValue<_, u32, ValueQuery>; + pub type CounterForNominators = StorageValue<_, u32, ValueQuery>; /// The maximum nominator count before we stop allowing new validators to join. /// @@ -1717,7 +1717,7 @@ pub mod pallet { // If this error is reached, we need to adjust the `MinValidatorBond` and start calling `chill_other`. // Until then, we explicitly block new validators to protect the runtime. if let Some(max_validators) = MaxValidatorsCount::::get() { - ensure!(CurrentValidatorsCount::::get() < max_validators, Error::::TooManyValidators); + ensure!(CounterForValidators::::get() < max_validators, Error::::TooManyValidators); } let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; @@ -1758,7 +1758,7 @@ pub mod pallet { // If this error is reached, we need to adjust the `MinNominatorBond` and start calling `chill_other`. // Until then, we explicitly block new nominators to protect the runtime. if let Some(max_nominators) = MaxNominatorsCount::::get() { - ensure!(CurrentNominatorsCount::::get() < max_nominators, Error::::TooManyNominators); + ensure!(CounterForNominators::::get() < max_nominators, Error::::TooManyNominators); } let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; @@ -2966,42 +2966,42 @@ impl Pallet { } /// This function will add a nominator to the `Nominators` storage map, - /// and keep track of the `CurrentNominatorsCount`. + /// and keep track of the `CounterForNominators`. /// /// If the nominator already exists, their nominations will be updated. pub fn do_add_nominator(who: &T::AccountId, nominations: Nominations) { if !Nominators::::contains_key(who) { - CurrentNominatorsCount::::mutate(|x| x.saturating_inc()) + CounterForNominators::::mutate(|x| x.saturating_inc()) } Nominators::::insert(who, nominations); } /// This function will remove a nominator from the `Nominators` storage map, - /// and keep track of the `CurrentNominatorsCount`. + /// and keep track of the `CounterForNominators`. pub fn do_remove_nominator(who: &T::AccountId) { if Nominators::::contains_key(who) { Nominators::::remove(who); - CurrentNominatorsCount::::mutate(|x| x.saturating_dec()); + CounterForNominators::::mutate(|x| x.saturating_dec()); } } /// This function will add a validator to the `Validators` storage map, - /// and keep track of the `CurrentValidatorsCount`. + /// and keep track of the `CounterForValidators`. /// /// If the validator already exists, their preferences will be updated. pub fn do_add_validator(who: &T::AccountId, prefs: ValidatorPrefs) { if !Validators::::contains_key(who) { - CurrentValidatorsCount::::mutate(|x| x.saturating_inc()) + CounterForValidators::::mutate(|x| x.saturating_inc()) } Validators::::insert(who, prefs); } /// This function will remove a validator from the `Validators` storage map, - /// and keep track of the `CurrentValidatorsCount`. + /// and keep track of the `CounterForValidators`. pub fn do_remove_validator(who: &T::AccountId) { if Validators::::contains_key(who) { Validators::::remove(who); - CurrentValidatorsCount::::mutate(|x| x.saturating_dec()); + CounterForValidators::::mutate(|x| x.saturating_dec()); } } } @@ -3017,11 +3017,11 @@ impl frame_election_provider_support::ElectionDataProvider, ) -> data_provider::Result<(Vec<(T::AccountId, VoteWeight, Vec)>, Weight)> { - let nominator_count = CurrentNominatorsCount::::get(); - let validator_count = CurrentValidatorsCount::::get(); + let nominator_count = CounterForNominators::::get(); + let validator_count = CounterForValidators::::get(); let voter_count = nominator_count.saturating_add(validator_count) as usize; - debug_assert!(>::iter().count() as u32 == CurrentNominatorsCount::::get()); - debug_assert!(>::iter().count() as u32 == CurrentValidatorsCount::::get()); + debug_assert!(>::iter().count() as u32 == CounterForNominators::::get()); + debug_assert!(>::iter().count() as u32 == CounterForValidators::::get()); if maybe_max_len.map_or(false, |max_len| voter_count > max_len) { return Err("Voter snapshot too big"); @@ -3037,7 +3037,7 @@ impl frame_election_provider_support::ElectionDataProvider) -> data_provider::Result<(Vec, Weight)> { - let target_count = CurrentValidatorsCount::::get() as usize; + let target_count = CounterForValidators::::get() as usize; if maybe_max_len.map_or(false, |max_len| target_count > max_len) { return Err("Target snapshot too big"); diff --git a/frame/staking/src/mock.rs b/frame/staking/src/mock.rs index 35a1fa45284da..e0079cc3f375a 100644 --- a/frame/staking/src/mock.rs +++ b/frame/staking/src/mock.rs @@ -498,8 +498,8 @@ fn post_conditions() { fn check_count() { let nominator_count = Nominators::::iter().count() as u32; let validator_count = Validators::::iter().count() as u32; - assert_eq!(nominator_count, CurrentNominatorsCount::::get()); - assert_eq!(validator_count, CurrentValidatorsCount::::get()); + assert_eq!(nominator_count, CounterForNominators::::get()); + assert_eq!(validator_count, CounterForValidators::::get()); } fn check_ledgers() { diff --git a/frame/staking/src/testing_utils.rs b/frame/staking/src/testing_utils.rs index 8a4392edfed25..c643cb283373b 100644 --- a/frame/staking/src/testing_utils.rs +++ b/frame/staking/src/testing_utils.rs @@ -30,9 +30,9 @@ const SEED: u32 = 0; /// This function removes all validators and nominators from storage. pub fn clear_validators_and_nominators() { Validators::::remove_all(None); - CurrentValidatorsCount::::kill(); + CounterForValidators::::kill(); Nominators::::remove_all(None); - CurrentNominatorsCount::::kill(); + CounterForNominators::::kill(); } /// Grab a funded user. diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index 976ee34d9b8eb..5d42d866b1336 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4107,9 +4107,9 @@ mod election_data_provider { #[test] fn capped_stakers_works() { ExtBuilder::default().build_and_execute(|| { - let validator_count = CurrentValidatorsCount::::get(); + let validator_count = CounterForValidators::::get(); assert_eq!(validator_count, 3); - let nominator_count = CurrentNominatorsCount::::get(); + let nominator_count = CounterForNominators::::get(); assert_eq!(nominator_count, 1); // Change the maximums