From 84e029e4c6e7edb565e2ddbf11ad1acf5c5a183b Mon Sep 17 00:00:00 2001 From: Ankan Date: Mon, 26 Dec 2022 22:29:57 +0100 Subject: [PATCH 01/12] test passes --- frame/staking/src/lib.rs | 13 ++- frame/staking/src/pallet/impls.rs | 66 ++++++++----- frame/staking/src/pallet/mod.rs | 2 +- frame/staking/src/tests.rs | 157 +++++++++++------------------- 4 files changed, 105 insertions(+), 133 deletions(-) diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 0f5b8e0123ab6..f3cb054692a99 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -366,12 +366,19 @@ pub struct ActiveEraInfo { /// Reward points of an era. Used to split era total payout between validators. /// -/// This points will be used to reward validators and their respective nominators. +/// This points will be used to reward validators and their respective nominators. As the rewards +/// for `individual` validators are paid out, they are removed from the map to prevent a validator +/// to collect reward for same era twice. #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct EraRewardPoints { - /// Total number of points. Equals the sum of reward points for each validator. + /// Total number of points in an era. + /// + /// At insert, this equals the sum of reward points for each validator. As validator cashes out + /// their individual reward points, sum of validator reward points reduces but total for an era + /// will always remain same. This is important, since we rely on `total` to calculate reward + /// payouts for the validator correctly. pub total: RewardPoint, - /// The reward points earned by a given validator. + /// The reward points earned by a given validator. Deducted as reward points get cashed. pub individual: BTreeMap, } diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index db9aeba6fb58e..621091d54b66e 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -25,7 +25,7 @@ use frame_support::{ dispatch::WithPostDispatchInfo, pallet_prelude::*, traits::{ - Currency, CurrencyToVote, Defensive, DefensiveResult, EstimateNextNewSession, Get, + Currency, CurrencyToVote, Defensive, EstimateNextNewSession, Get, Imbalance, LockableCurrency, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons, }, weights::Weight, @@ -43,9 +43,10 @@ use sp_staking::{ use sp_std::prelude::*; use crate::{ - log, slashing, weights::WeightInfo, ActiveEraInfo, BalanceOf, EraPayout, Exposure, ExposureOf, - Forcing, IndividualExposure, MaxWinnersOf, Nominations, PositiveImbalanceOf, RewardDestination, - SessionInterface, StakingLedger, ValidatorPrefs, + log, slashing, weights::WeightInfo, ActiveEraInfo, BalanceOf, EraPayout, EraRewardPoints, + Exposure, ExposureOf, Forcing, IndividualExposure, MaxWinnersOf, Nominations, + PositiveImbalanceOf, RewardDestination, SessionInterface, StakingLedger, + ValidatorPrefs, }; use super::{pallet::*, STAKING_ID}; @@ -147,8 +148,6 @@ impl Pallet { .with_weight(T::WeightInfo::payout_stakers_alive_staked(0)) ); - // Note: if era has no reward to be claimed, era may be future. better not to update - // `ledger.claimed_rewards` in this case. let era_payout = >::get(&era).ok_or_else(|| { Error::::InvalidEraToReward .with_weight(T::WeightInfo::payout_stakers_alive_staked(0)) @@ -160,28 +159,14 @@ impl Pallet { let mut ledger = >::get(&controller).ok_or(Error::::NotController)?; ledger - .claimed_rewards - .retain(|&x| x >= current_era.saturating_sub(history_depth)); - - match ledger.claimed_rewards.binary_search(&era) { - Ok(_) => - return Err(Error::::AlreadyClaimed - .with_weight(T::WeightInfo::payout_stakers_alive_staked(0))), - Err(pos) => ledger - .claimed_rewards - .try_insert(pos, era) - // Since we retain era entries in `claimed_rewards` only upto - // `HistoryDepth`, following bound is always expected to be - // satisfied. - .defensive_map_err(|_| Error::::BoundNotMet)?, - } - - let exposure = >::get(&era, &ledger.stash); + .claimed_rewards + .retain(|&x| x >= current_era.saturating_sub(history_depth)); // Input data seems good, no errors allowed after this point - >::insert(&controller, &ledger); + let exposure = >::get(&era, &ledger.stash); + // Get Era reward points. It has TOTAL and INDIVIDUAL // Find the fraction of the era reward that belongs to the validator // Take that fraction of the eras rewards to split to nominator and validator @@ -189,7 +174,7 @@ impl Pallet { // Then look at the validator, figure out the proportion of their reward // which goes to them and each of their nominators. - let era_reward_points = >::get(&era); + let era_reward_points = Self::get_era_reward_points(&era, &ledger); let total_reward_points = era_reward_points.total; let validator_reward_points = era_reward_points .individual @@ -197,11 +182,17 @@ impl Pallet { .copied() .unwrap_or_else(Zero::zero); - // Nothing to do if they have no reward points. + // No reward points to claim. This can also happen if rewards have already been claimed. if validator_reward_points.is_zero() { - return Ok(Some(T::WeightInfo::payout_stakers_alive_staked(0)).into()) + return Err(Error::::NothingToClaim + .with_weight(T::WeightInfo::payout_stakers_alive_staked(0))) } + // drop reward points for the validator so it cannot be claimed again. + >::mutate(&era, |era_rewards| { + era_rewards.individual.remove(&ledger.stash); + }); + // This is the fraction of the total reward that the validator and the // nominators will get. let validator_total_reward_part = @@ -273,6 +264,27 @@ impl Pallet { >::insert(controller, ledger); } + fn get_era_reward_points( + era: &EraIndex, + ledger: &StakingLedger, + ) -> EraRewardPoints { + let mut era_reward_points = >::get(&era); + + // In the older version of code, ledger maintained the record of `claimed_rewards`. + // Going forward, we don't keep them in the ledger but drop them from + // `EraRewardPoints` as they are claimed. Since we maintain `$HistoryDepth` eras in the + // `ledger.claimed_rewards`, once `$HistoryDepth` number of eras have passed, this code is + // redundant and can be cleaned up, relying solely on `EraRewardPoints` to prevent double + // claim. + // TODO: Clean up `ledger.claimed_rewards` after 84 eras. + if ledger.claimed_rewards.binary_search(&era).is_ok() { + // since rewards are already claimed for this era, drop them. + era_reward_points.individual.remove(&ledger.stash); + } + + era_reward_points + } + /// Chill a stash account. pub(crate) fn chill_stash(stash: &T::AccountId) { let chilled_as_validator = Self::do_remove_validator(stash); diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 8e8a8d9c7f600..ccc2491c79c07 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -745,7 +745,7 @@ pub mod pallet { /// Items are not sorted and unique. NotSortedAndUnique, /// Rewards for this era have already been claimed for this validator. - AlreadyClaimed, + NothingToClaim, /// Incorrect previous history depth input provided. IncorrectHistoryDepth, /// Incorrect number of slashing spans provided. diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index 46c3c97441938..460ff0c1ba283 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -19,12 +19,7 @@ use super::{ConfigOp, Event, *}; use frame_election_provider_support::{ElectionProvider, SortedListProvider, Support}; -use frame_support::{ - assert_noop, assert_ok, assert_storage_noop, bounded_vec, - dispatch::{extract_actual_weight, GetDispatchInfo, WithPostDispatchInfo}, - pallet_prelude::*, - traits::{Currency, Get, ReservableCurrency}, -}; +use frame_support::{assert_err, assert_noop, assert_ok, assert_storage_noop, bounded_vec, dispatch::{extract_actual_weight, GetDispatchInfo, WithPostDispatchInfo}, pallet_prelude::*, traits::{Currency, Get, ReservableCurrency}}; use mock::*; use pallet_balances::Error as BalancesError; use sp_runtime::{ @@ -1039,6 +1034,13 @@ fn reward_destination_works() { Pallet::::reward_by_ids(vec![(11, 1)]); mock::start_active_era(1); + + // validator has available reward points to claim + assert_eq!( + Staking::eras_reward_points(&0).individual.get(&10), + None + ); + mock::make_all_reward_payment(0); // Check that RewardDestination is Staked (default) @@ -1053,10 +1055,17 @@ fn reward_destination_works() { total: 1000 + total_payout_0, active: 1000 + total_payout_0, unlocking: Default::default(), - claimed_rewards: bounded_vec![0], + // claimed_rewards are not added to ledger anymore + claimed_rewards: Default::default(), }) ); + // claimed reward points dropped + assert_eq!( + Staking::eras_reward_points(&0).individual.get(&10), + None + ); + // Change RewardDestination to Stash >::insert(&11, RewardDestination::Stash); @@ -1081,10 +1090,16 @@ fn reward_destination_works() { total: 1000 + total_payout_0, active: 1000 + total_payout_0, unlocking: Default::default(), - claimed_rewards: bounded_vec![0, 1], + claimed_rewards: Default::default(), }) ); + // claimed reward points dropped + assert_eq!( + Staking::eras_reward_points(&1).individual.get(&10), + None + ); + // Change RewardDestination to Controller >::insert(&11, RewardDestination::Controller); @@ -1110,9 +1125,14 @@ fn reward_destination_works() { total: 1000 + total_payout_0, active: 1000 + total_payout_0, unlocking: Default::default(), - claimed_rewards: bounded_vec![0, 1, 2], + claimed_rewards: Default::default(), }) ); + // claimed reward points dropped + assert_eq!( + Staking::eras_reward_points(&2).individual.get(&10), + None + ); // Check that amount in staked account is NOT increased. assert_eq!(Balances::free_balance(11), recorded_stash_balance); }); @@ -3569,7 +3589,7 @@ fn claim_reward_at_the_last_era_and_no_double_claim_and_invalid_claim() { assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(1337), 11, 2), // Fail: Double claim - Error::::AlreadyClaimed.with_weight(err_weight) + Error::::NothingToClaim.with_weight(err_weight) ); assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(1337), 11, active_era), @@ -3750,7 +3770,21 @@ fn test_payout_stakers() { let pre_payout_total_issuance = Balances::total_issuance(); RewardOnUnbalanceWasCalled::set(false); + // validator has era points not claimed yet + assert_eq!( + Staking::eras_reward_points(&1).individual.get(&11), + Some(&1) + ); + + // claim rewards assert_ok!(Staking::payout_stakers(RuntimeOrigin::signed(1337), 11, 1)); + + // claimed reward points dropped + assert_eq!( + Staking::eras_reward_points(&1).individual.get(&11), + None + ); + assert_eq_error_rate!( Balances::total_issuance(), pre_payout_total_issuance + actual_paid_out, @@ -3769,18 +3803,6 @@ fn test_payout_stakers() { assert_eq!(Balances::free_balance(&(100 + i)), balance + i as Balance); } - // We track rewards in `claimed_rewards` vec - assert_eq!( - Staking::ledger(&10), - Some(StakingLedger { - stash: 11, - total: 1000, - active: 1000, - unlocking: Default::default(), - claimed_rewards: bounded_vec![1] - }) - ); - for i in 3..16 { Staking::reward_by_ids(vec![(11, 1)]); @@ -3800,7 +3822,7 @@ fn test_payout_stakers() { assert!(RewardOnUnbalanceWasCalled::get()); } - // We track rewards in `claimed_rewards` vec + // claimed_rewards not used assert_eq!( Staking::ledger(&10), Some(StakingLedger { @@ -3808,7 +3830,7 @@ fn test_payout_stakers() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: (1..=14).collect::>().try_into().unwrap() + claimed_rewards: Default::default(), }) ); @@ -3841,7 +3863,7 @@ fn test_payout_stakers() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![expected_start_reward_era, expected_last_reward_era] + claimed_rewards: Default::default(), }) ); @@ -3856,13 +3878,7 @@ fn test_payout_stakers() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![ - expected_start_reward_era, - 23, - 42, - 69, - expected_last_reward_era - ] + claimed_rewards: Default::default(), }) ); }); @@ -3940,11 +3956,11 @@ fn payout_stakers_handles_basic_errors() { // Can't claim again assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(1337), 11, expected_start_reward_era), - Error::::AlreadyClaimed.with_weight(err_weight) + Error::::NothingToClaim.with_weight(err_weight) ); assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(1337), 11, expected_last_reward_era), - Error::::AlreadyClaimed.with_weight(err_weight) + Error::::NothingToClaim.with_weight(err_weight) ); }); } @@ -4005,10 +4021,8 @@ fn payout_stakers_handles_weight_refund() { // Collect payouts for an era where the validator did not receive any points. let call = TestCall::Staking(StakingCall::payout_stakers { validator_stash: 11, era: 2 }); - let info = call.get_dispatch_info(); let result = call.dispatch(RuntimeOrigin::signed(20)); - assert_ok!(result); - assert_eq!(extract_actual_weight(&result, &info), zero_nom_payouts_weight); + assert_err!(result, Error::::NothingToClaim.with_weight(zero_nom_payouts_weight)); // Reward the validator and its nominators. Staking::reward_by_ids(vec![(11, 1)]); @@ -5477,70 +5491,6 @@ fn proportional_ledger_slash_works() { ); } -#[test] -fn pre_bonding_era_cannot_be_claimed() { - // Verifies initial conditions of mock - ExtBuilder::default().nominate(false).build_and_execute(|| { - let history_depth = HistoryDepth::get(); - // jump to some era above history_depth - let mut current_era = history_depth + 10; - let last_reward_era = current_era - 1; - let start_reward_era = current_era - history_depth; - - // put some money in stash=3 and controller=4. - for i in 3..5 { - let _ = Balances::make_free_balance_be(&i, 2000); - } - - mock::start_active_era(current_era); - - // add a new candidate for being a validator. account 3 controlled by 4. - assert_ok!(Staking::bond(RuntimeOrigin::signed(3), 4, 1500, RewardDestination::Controller)); - - let claimed_rewards: BoundedVec<_, _> = - (start_reward_era..=last_reward_era).collect::>().try_into().unwrap(); - assert_eq!( - Staking::ledger(&4).unwrap(), - StakingLedger { - stash: 3, - total: 1500, - active: 1500, - unlocking: Default::default(), - claimed_rewards, - } - ); - - // start next era - current_era = current_era + 1; - mock::start_active_era(current_era); - - // claiming reward for last era in which validator was active works - assert_ok!(Staking::payout_stakers(RuntimeOrigin::signed(4), 3, current_era - 1)); - - // consumed weight for all payout_stakers dispatches that fail - let err_weight = ::WeightInfo::payout_stakers_alive_staked(0); - // cannot claim rewards for an era before bonding occured as it is - // already marked as claimed. - assert_noop!( - Staking::payout_stakers(RuntimeOrigin::signed(4), 3, current_era - 2), - Error::::AlreadyClaimed.with_weight(err_weight) - ); - - // decoding will fail now since Staking Ledger is in corrupt state - HistoryDepth::set(history_depth - 1); - assert_eq!(Staking::ledger(&4), None); - - // make sure stakers still cannot claim rewards that they are not meant to - assert_noop!( - Staking::payout_stakers(RuntimeOrigin::signed(4), 3, current_era - 2), - Error::::NotController - ); - - // fix the corrupted state for post conditions check - HistoryDepth::set(history_depth); - }); -} - #[test] fn reducing_history_depth_abrupt() { // Verifies initial conditions of mock @@ -5576,6 +5526,9 @@ fn reducing_history_depth_abrupt() { } ); + // reward validator + Pallet::::reward_by_ids(vec![(3, 1)]); + // next era current_era = current_era + 1; mock::start_active_era(current_era); @@ -5593,7 +5546,7 @@ fn reducing_history_depth_abrupt() { // claiming reward does not work anymore assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(4), 3, current_era - 1), - Error::::NotController + Error::::NothingToClaim.with_weight(::WeightInfo::payout_stakers_alive_staked(0)) ); // new stakers can still bond From b0136e827a1e89043a00c55d606fe7f1bd2f05a9 Mon Sep 17 00:00:00 2001 From: Ankan Date: Mon, 26 Dec 2022 22:48:25 +0100 Subject: [PATCH 02/12] minor fixes --- frame/staking/src/lib.rs | 12 ++++++------ frame/staking/src/pallet/impls.rs | 2 +- frame/staking/src/pallet/mod.rs | 3 ++- frame/staking/src/tests.rs | 8 ++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index f3cb054692a99..7aacfeb5f6fff 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -366,17 +366,17 @@ pub struct ActiveEraInfo { /// Reward points of an era. Used to split era total payout between validators. /// -/// This points will be used to reward validators and their respective nominators. As the rewards +/// These points will be used to reward validators and their respective nominators. As the rewards /// for `individual` validators are paid out, they are removed from the map to prevent a validator -/// to collect reward for same era twice. +/// to claim reward for a same era twice. #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct EraRewardPoints { /// Total number of points in an era. /// - /// At insert, this equals the sum of reward points for each validator. As validator cashes out - /// their individual reward points, sum of validator reward points reduces but total for an era - /// will always remain same. This is important, since we rely on `total` to calculate reward - /// payouts for the validator correctly. + /// At insert, this equals the sum of reward points for each validator. As a validator claims + /// their era reward, individual points are dropped hence sum of individual validator reward + /// points reduces but `total` for an era will always remain same. This is important, since we + /// rely on `total` to calculate reward payouts for the remaining set of validators correctly. pub total: RewardPoint, /// The reward points earned by a given validator. Deducted as reward points get cashed. pub individual: BTreeMap, diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index 621091d54b66e..2d71bbad1d374 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -182,7 +182,7 @@ impl Pallet { .copied() .unwrap_or_else(Zero::zero); - // No reward points to claim. This can also happen if rewards have already been claimed. + // No reward points to claim. This can also happen if reward has already been claimed. if validator_reward_points.is_zero() { return Err(Error::::NothingToClaim .with_weight(T::WeightInfo::payout_stakers_alive_staked(0))) diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index ccc2491c79c07..eee4d9a3e19ca 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -744,7 +744,8 @@ pub mod pallet { InvalidNumberOfNominations, /// Items are not sorted and unique. NotSortedAndUnique, - /// Rewards for this era have already been claimed for this validator. + /// No rewards available to claim for this era. Either validator did not earn any reward or + /// has already claimed it previously. NothingToClaim, /// Incorrect previous history depth input provided. IncorrectHistoryDepth, diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index 460ff0c1ba283..7f250711864dc 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -1035,10 +1035,10 @@ fn reward_destination_works() { mock::start_active_era(1); - // validator has available reward points to claim + // validator has unclaimed reward points at era 0. assert_eq!( - Staking::eras_reward_points(&0).individual.get(&10), - None + Staking::eras_reward_points(&0).individual.get(&11), + Some(&1) ); mock::make_all_reward_payment(0); @@ -3770,7 +3770,7 @@ fn test_payout_stakers() { let pre_payout_total_issuance = Balances::total_issuance(); RewardOnUnbalanceWasCalled::set(false); - // validator has era points not claimed yet + // validator has unclaimed reward points at era 1. assert_eq!( Staking::eras_reward_points(&1).individual.get(&11), Some(&1) From 16a536cae10fee007f850bdd3b026ff0cf1d3387 Mon Sep 17 00:00:00 2001 From: Ankan Date: Tue, 27 Dec 2022 04:31:28 +0100 Subject: [PATCH 03/12] not init claimed rewards on first bond --- frame/staking/src/lib.rs | 6 ++++-- frame/staking/src/pallet/mod.rs | 7 +------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 7aacfeb5f6fff..e1aed815bb7a4 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -472,8 +472,10 @@ pub struct StakingLedger { /// (assuming it doesn't get slashed first). It is assumed that this will be treated as a first /// in, first out queue where the new (higher value) eras get pushed on the back. pub unlocking: BoundedVec>, T::MaxUnlockingChunks>, - /// List of eras for which the stakers behind a validator have claimed rewards. Only updated - /// for validators. + /// Earlier used as a list of eras for which the stakers behind a validator have claimed + /// rewards. Since v14, it should only be used to read historic `claimed_rewards` and never for + /// newer data. After `$HistoryDepth` eras have passed since v14, this can be cleaned up in a + /// migration. pub claimed_rewards: BoundedVec, } diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index eee4d9a3e19ca..1f507f6772f8d 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -888,12 +888,7 @@ pub mod pallet { total: value, active: value, unlocking: Default::default(), - claimed_rewards: (last_reward_era..current_era) - .try_collect() - // Since last_reward_era is calculated as `current_era - - // HistoryDepth`, following bound is always expected to be - // satisfied. - .defensive_map_err(|_| Error::::BoundNotMet)?, + claimed_rewards: Default::default(), }; Self::update_ledger(&controller, &item); Ok(()) From 398b3ac051830647f70839a2618dbb0286686511 Mon Sep 17 00:00:00 2001 From: Ankan Date: Tue, 27 Dec 2022 04:32:02 +0100 Subject: [PATCH 04/12] fmt --- frame/staking/src/pallet/impls.rs | 11 ++++----- frame/staking/src/tests.rs | 40 +++++++++++-------------------- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index 2d71bbad1d374..6524cb99c1f0c 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -25,8 +25,8 @@ use frame_support::{ dispatch::WithPostDispatchInfo, pallet_prelude::*, traits::{ - Currency, CurrencyToVote, Defensive, EstimateNextNewSession, Get, - Imbalance, LockableCurrency, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons, + Currency, CurrencyToVote, Defensive, EstimateNextNewSession, Get, Imbalance, + LockableCurrency, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons, }, weights::Weight, }; @@ -45,8 +45,7 @@ use sp_std::prelude::*; use crate::{ log, slashing, weights::WeightInfo, ActiveEraInfo, BalanceOf, EraPayout, EraRewardPoints, Exposure, ExposureOf, Forcing, IndividualExposure, MaxWinnersOf, Nominations, - PositiveImbalanceOf, RewardDestination, SessionInterface, StakingLedger, - ValidatorPrefs, + PositiveImbalanceOf, RewardDestination, SessionInterface, StakingLedger, ValidatorPrefs, }; use super::{pallet::*, STAKING_ID}; @@ -159,8 +158,8 @@ impl Pallet { let mut ledger = >::get(&controller).ok_or(Error::::NotController)?; ledger - .claimed_rewards - .retain(|&x| x >= current_era.saturating_sub(history_depth)); + .claimed_rewards + .retain(|&x| x >= current_era.saturating_sub(history_depth)); // Input data seems good, no errors allowed after this point >::insert(&controller, &ledger); diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index 7f250711864dc..e47243685dee8 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -19,7 +19,12 @@ use super::{ConfigOp, Event, *}; use frame_election_provider_support::{ElectionProvider, SortedListProvider, Support}; -use frame_support::{assert_err, assert_noop, assert_ok, assert_storage_noop, bounded_vec, dispatch::{extract_actual_weight, GetDispatchInfo, WithPostDispatchInfo}, pallet_prelude::*, traits::{Currency, Get, ReservableCurrency}}; +use frame_support::{ + assert_err, assert_noop, assert_ok, assert_storage_noop, bounded_vec, + dispatch::{extract_actual_weight, GetDispatchInfo, WithPostDispatchInfo}, + pallet_prelude::*, + traits::{Currency, Get, ReservableCurrency}, +}; use mock::*; use pallet_balances::Error as BalancesError; use sp_runtime::{ @@ -1036,10 +1041,7 @@ fn reward_destination_works() { mock::start_active_era(1); // validator has unclaimed reward points at era 0. - assert_eq!( - Staking::eras_reward_points(&0).individual.get(&11), - Some(&1) - ); + assert_eq!(Staking::eras_reward_points(&0).individual.get(&11), Some(&1)); mock::make_all_reward_payment(0); @@ -1061,10 +1063,7 @@ fn reward_destination_works() { ); // claimed reward points dropped - assert_eq!( - Staking::eras_reward_points(&0).individual.get(&10), - None - ); + assert_eq!(Staking::eras_reward_points(&0).individual.get(&10), None); // Change RewardDestination to Stash >::insert(&11, RewardDestination::Stash); @@ -1095,10 +1094,7 @@ fn reward_destination_works() { ); // claimed reward points dropped - assert_eq!( - Staking::eras_reward_points(&1).individual.get(&10), - None - ); + assert_eq!(Staking::eras_reward_points(&1).individual.get(&10), None); // Change RewardDestination to Controller >::insert(&11, RewardDestination::Controller); @@ -1129,10 +1125,7 @@ fn reward_destination_works() { }) ); // claimed reward points dropped - assert_eq!( - Staking::eras_reward_points(&2).individual.get(&10), - None - ); + assert_eq!(Staking::eras_reward_points(&2).individual.get(&10), None); // Check that amount in staked account is NOT increased. assert_eq!(Balances::free_balance(11), recorded_stash_balance); }); @@ -3771,19 +3764,13 @@ fn test_payout_stakers() { let pre_payout_total_issuance = Balances::total_issuance(); RewardOnUnbalanceWasCalled::set(false); // validator has unclaimed reward points at era 1. - assert_eq!( - Staking::eras_reward_points(&1).individual.get(&11), - Some(&1) - ); + assert_eq!(Staking::eras_reward_points(&1).individual.get(&11), Some(&1)); // claim rewards assert_ok!(Staking::payout_stakers(RuntimeOrigin::signed(1337), 11, 1)); // claimed reward points dropped - assert_eq!( - Staking::eras_reward_points(&1).individual.get(&11), - None - ); + assert_eq!(Staking::eras_reward_points(&1).individual.get(&11), None); assert_eq_error_rate!( Balances::total_issuance(), @@ -5546,7 +5533,8 @@ fn reducing_history_depth_abrupt() { // claiming reward does not work anymore assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(4), 3, current_era - 1), - Error::::NothingToClaim.with_weight(::WeightInfo::payout_stakers_alive_staked(0)) + Error::::NothingToClaim + .with_weight(::WeightInfo::payout_stakers_alive_staked(0)) ); // new stakers can still bond From 0a9dded7722ab81f943b28b2f26a6ec5c23767c9 Mon Sep 17 00:00:00 2001 From: Ankan Date: Tue, 27 Dec 2022 04:39:46 +0100 Subject: [PATCH 05/12] fix test --- frame/staking/src/pallet/mod.rs | 9 ++------- frame/staking/src/tests.rs | 28 +++++++--------------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 1f507f6772f8d..06c8bda8b69b5 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -24,9 +24,8 @@ use frame_support::{ dispatch::Codec, pallet_prelude::*, traits::{ - Currency, CurrencyToVote, Defensive, DefensiveResult, DefensiveSaturating, EnsureOrigin, - EstimateNextNewSession, Get, LockIdentifier, LockableCurrency, OnUnbalanced, TryCollect, - UnixTime, + Currency, CurrencyToVote, Defensive, DefensiveSaturating, EnsureOrigin, + EstimateNextNewSession, Get, LockIdentifier, LockableCurrency, OnUnbalanced, UnixTime, }, weights::Weight, BoundedVec, @@ -876,10 +875,6 @@ pub mod pallet { >::insert(&stash, &controller); >::insert(&stash, payee); - let current_era = CurrentEra::::get().unwrap_or(0); - let history_depth = T::HistoryDepth::get(); - let last_reward_era = current_era.saturating_sub(history_depth); - let stash_balance = T::Currency::free_balance(&stash); let value = value.min(stash_balance); Self::deposit_event(Event::::Bonded { stash: stash.clone(), amount: value }); diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index e47243685dee8..5880db15b2d5b 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -441,7 +441,7 @@ fn staking_should_work() { total: 1500, active: 1500, unlocking: Default::default(), - claimed_rewards: bounded_vec![0], + claimed_rewards: Default::default(), }) ); // e.g. it cannot reserve more than 500 that it has free from the total 2000 @@ -4058,7 +4058,7 @@ fn payout_stakers_handles_weight_refund() { } #[test] -fn bond_during_era_correctly_populates_claimed_rewards() { +fn bond_does_not_populate_claimed_rewards() { ExtBuilder::default().has_stakers(false).build_and_execute(|| { // Era = None bond_validator(9, 8, 1000); @@ -4069,7 +4069,7 @@ fn bond_during_era_correctly_populates_claimed_rewards() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + claimed_rewards: Default::default(), }) ); mock::start_active_era(5); @@ -4081,13 +4081,12 @@ fn bond_during_era_correctly_populates_claimed_rewards() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: (0..5).collect::>().try_into().unwrap(), + claimed_rewards: Default::default(), }) ); // make sure only era upto history depth is stored let current_era = 99; - let last_reward_era = 99 - HistoryDepth::get(); mock::start_active_era(current_era); bond_validator(13, 12, 1000); assert_eq!( @@ -4097,10 +4096,7 @@ fn bond_during_era_correctly_populates_claimed_rewards() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: (last_reward_era..current_era) - .collect::>() - .try_into() - .unwrap(), + claimed_rewards: Default::default(), }) ); }); @@ -5484,8 +5480,6 @@ fn reducing_history_depth_abrupt() { ExtBuilder::default().nominate(false).build_and_execute(|| { let original_history_depth = HistoryDepth::get(); let mut current_era = original_history_depth + 10; - let last_reward_era = current_era - 1; - let start_reward_era = current_era - original_history_depth; // put some money in (stash, controller)=(3,4),(5,6). for i in 3..7 { @@ -5498,10 +5492,6 @@ fn reducing_history_depth_abrupt() { // add a new candidate for being a staker. account 3 controlled by 4. assert_ok!(Staking::bond(RuntimeOrigin::signed(3), 4, 1500, RewardDestination::Controller)); - // all previous era before the bonding action should be marked as - // claimed. - let claimed_rewards: BoundedVec<_, _> = - (start_reward_era..=last_reward_era).collect::>().try_into().unwrap(); assert_eq!( Staking::ledger(&4).unwrap(), StakingLedger { @@ -5509,7 +5499,7 @@ fn reducing_history_depth_abrupt() { total: 1500, active: 1500, unlocking: Default::default(), - claimed_rewards, + claimed_rewards: Default::default(), } ); @@ -5541,10 +5531,6 @@ fn reducing_history_depth_abrupt() { assert_ok!(Staking::bond(RuntimeOrigin::signed(5), 6, 1200, RewardDestination::Controller)); // new staking ledgers created will be bounded by the current history depth - let last_reward_era = current_era - 1; - let start_reward_era = current_era - history_depth; - let claimed_rewards: BoundedVec<_, _> = - (start_reward_era..=last_reward_era).collect::>().try_into().unwrap(); assert_eq!( Staking::ledger(&6).unwrap(), StakingLedger { @@ -5552,7 +5538,7 @@ fn reducing_history_depth_abrupt() { total: 1200, active: 1200, unlocking: Default::default(), - claimed_rewards, + claimed_rewards: Default::default(), } ); From 15a81fc23af837ff236cac96f5c93d27a4057fb4 Mon Sep 17 00:00:00 2001 From: Ankan Date: Thu, 29 Dec 2022 22:39:02 +0100 Subject: [PATCH 06/12] add test to verify ledger is read before reward claim --- frame/staking/src/tests.rs | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index 5880db15b2d5b..cca78bbc52325 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -5474,6 +5474,65 @@ fn proportional_ledger_slash_works() { ); } +#[test] +fn legacy_claimed_reward_checked_before_claim() { + // Verifies initial conditions of mock + ExtBuilder::default().nominate(false).build_and_execute(|| { + // put some money in stash=3 and controller=4. + for i in 3..5 { + let _ = Balances::make_free_balance_be(&i, 2000); + } + mock::start_active_era(2); + // add a new candidate for being a validator. account 3 controlled by 4. + assert_ok!(Staking::bond(RuntimeOrigin::signed(3), 4, 1500, RewardDestination::Controller)); + assert_eq!( + Staking::ledger(&4).unwrap(), + StakingLedger { + stash: 3, + total: 1500, + active: 1500, + unlocking: Default::default(), + claimed_rewards: Default::default(), + } + ); + // go forward few eras rewarding the validator for each era + for e in 3..10 { + mock::start_active_era(e); + Pallet::::reward_by_ids(vec![(3, 1)]); + } + let zero_weight = ::WeightInfo::payout_stakers_alive_staked(0); + // fake that validator has already claimed rewards for even eras (4, 6, 8) that is recorded + // in the staking leger (legacy way). + Ledger::::insert( + 4, + StakingLedger { + stash: 3, + total: 1500, + active: 1500, + unlocking: Default::default(), + claimed_rewards: bounded_vec![4, 6, 8], + }, + ); + + // moving to next era + mock::start_active_era(10); + + // then verify validators can claim only unclaimed eras + for e in 3..10 { + if e % 2 != 0 { + // validator can claim rewards for odd eras + assert_ok!(Staking::payout_stakers(RuntimeOrigin::signed(4), 3, e)); + } else { + // cannot claim rewards for even eras. + assert_noop!( + Staking::payout_stakers(RuntimeOrigin::signed(4), 3, e), + Error::::NothingToClaim.with_weight(zero_weight) + ); + } + } + }); +} + #[test] fn reducing_history_depth_abrupt() { // Verifies initial conditions of mock From ae8bc8c0188dfcb0ba096cea4042915ca86079b8 Mon Sep 17 00:00:00 2001 From: Ankan Date: Thu, 29 Dec 2022 23:15:04 +0100 Subject: [PATCH 07/12] claimed_rewards is now legacy --- frame/staking/src/lib.rs | 28 ++++---- frame/staking/src/pallet/impls.rs | 12 ++-- frame/staking/src/pallet/mod.rs | 2 +- frame/staking/src/tests.rs | 112 +++++++++++++++--------------- 4 files changed, 78 insertions(+), 76 deletions(-) diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index e1aed815bb7a4..801e8bbe50d89 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -368,17 +368,18 @@ pub struct ActiveEraInfo { /// /// These points will be used to reward validators and their respective nominators. As the rewards /// for `individual` validators are paid out, they are removed from the map to prevent a validator -/// to claim reward for a same era twice. +/// to claim reward for the same era twice. #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct EraRewardPoints { /// Total number of points in an era. /// - /// At insert, this equals the sum of reward points for each validator. As a validator claims - /// their era reward, individual points are dropped hence sum of individual validator reward - /// points reduces but `total` for an era will always remain same. This is important, since we - /// rely on `total` to calculate reward payouts for the remaining set of validators correctly. + /// For an active era, this always equals the sum of reward points for each validator. As a + /// validator claims their era reward in the succeeding eras, individual points are dropped + /// hence sum of individual validator reward points reduces but `total` for an era will always + /// remain same. This is important, since we rely on `total` to calculate reward payouts for + /// the remaining set of validators correctly. pub total: RewardPoint, - /// The reward points earned by a given validator. Deducted as reward points get cashed. + /// The reward points earned by a given validator. Dropped as reward points get claimed. pub individual: BTreeMap, } @@ -472,11 +473,12 @@ pub struct StakingLedger { /// (assuming it doesn't get slashed first). It is assumed that this will be treated as a first /// in, first out queue where the new (higher value) eras get pushed on the back. pub unlocking: BoundedVec>, T::MaxUnlockingChunks>, - /// Earlier used as a list of eras for which the stakers behind a validator have claimed - /// rewards. Since v14, it should only be used to read historic `claimed_rewards` and never for - /// newer data. After `$HistoryDepth` eras have passed since v14, this can be cleaned up in a - /// migration. - pub claimed_rewards: BoundedVec, + /// Legacy field. Used as a list of eras for which the stakers behind a validator have claimed + /// rewards. It should only be used to read old `claimed_rewards` and a new entry should not be + /// added to it. + /// FIXME: Clean up after `T::HistoryDepth` eras. + /// Tracker: + pub legacy_claimed_rewards: BoundedVec, } impl StakingLedger { @@ -487,7 +489,7 @@ impl StakingLedger { total: Zero::zero(), active: Zero::zero(), unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), } } @@ -517,7 +519,7 @@ impl StakingLedger { total, active: self.active, unlocking, - claimed_rewards: self.claimed_rewards, + legacy_claimed_rewards: self.legacy_claimed_rewards, } } diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index 6524cb99c1f0c..ef3f83c5f0e7a 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -158,7 +158,7 @@ impl Pallet { let mut ledger = >::get(&controller).ok_or(Error::::NotController)?; ledger - .claimed_rewards + .legacy_claimed_rewards .retain(|&x| x >= current_era.saturating_sub(history_depth)); // Input data seems good, no errors allowed after this point @@ -276,7 +276,7 @@ impl Pallet { // redundant and can be cleaned up, relying solely on `EraRewardPoints` to prevent double // claim. // TODO: Clean up `ledger.claimed_rewards` after 84 eras. - if ledger.claimed_rewards.binary_search(&era).is_ok() { + if ledger.legacy_claimed_rewards.binary_search(&era).is_ok() { // since rewards are already claimed for this era, drop them. era_reward_points.individual.remove(&ledger.stash); } @@ -1055,7 +1055,7 @@ impl ElectionDataProvider for Pallet { active: stake, total: stake, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }, ); @@ -1073,7 +1073,7 @@ impl ElectionDataProvider for Pallet { active: stake, total: stake, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }, ); Self::do_add_validator( @@ -1114,7 +1114,7 @@ impl ElectionDataProvider for Pallet { active: stake, total: stake, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }, ); Self::do_add_validator( @@ -1135,7 +1135,7 @@ impl ElectionDataProvider for Pallet { active: stake, total: stake, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }, ); Self::do_add_nominator( diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 06c8bda8b69b5..6810d74610355 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -883,7 +883,7 @@ pub mod pallet { total: value, active: value, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }; Self::update_ledger(&controller, &item); Ok(()) diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index cca78bbc52325..b54053e4e09aa 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -154,7 +154,7 @@ fn basic_setup_works() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], } ); // Account 20 controls the stash from account 21, which is 200 * balance_factor units @@ -165,7 +165,7 @@ fn basic_setup_works() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); // Account 1 does not control any stash @@ -188,7 +188,7 @@ fn basic_setup_works() { total: 500, active: 500, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); assert_eq!(Staking::nominators(101).unwrap().targets, vec![11, 21]); @@ -441,7 +441,7 @@ fn staking_should_work() { total: 1500, active: 1500, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }) ); // e.g. it cannot reserve more than 500 that it has free from the total 2000 @@ -1030,7 +1030,7 @@ fn reward_destination_works() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1058,7 +1058,7 @@ fn reward_destination_works() { active: 1000 + total_payout_0, unlocking: Default::default(), // claimed_rewards are not added to ledger anymore - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }) ); @@ -1089,7 +1089,7 @@ fn reward_destination_works() { total: 1000 + total_payout_0, active: 1000 + total_payout_0, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }) ); @@ -1121,7 +1121,7 @@ fn reward_destination_works() { total: 1000 + total_payout_0, active: 1000 + total_payout_0, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }) ); // claimed reward points dropped @@ -1185,7 +1185,7 @@ fn bond_extra_works() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1202,7 +1202,7 @@ fn bond_extra_works() { total: 1000 + 100, active: 1000 + 100, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1216,7 +1216,7 @@ fn bond_extra_works() { total: 1000000, active: 1000000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); }); @@ -1254,7 +1254,7 @@ fn bond_extra_and_withdraw_unbonded_works() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); assert_eq!( @@ -1272,7 +1272,7 @@ fn bond_extra_and_withdraw_unbonded_works() { total: 1000 + 100, active: 1000 + 100, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); // Exposure is a snapshot! only updated after the next era update. @@ -1293,7 +1293,7 @@ fn bond_extra_and_withdraw_unbonded_works() { total: 1000 + 100, active: 1000 + 100, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); // Exposure is now updated. @@ -1311,7 +1311,7 @@ fn bond_extra_and_withdraw_unbonded_works() { total: 1000 + 100, active: 100, unlocking: bounded_vec![UnlockChunk { value: 1000, era: 2 + 3 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }), ); @@ -1324,7 +1324,7 @@ fn bond_extra_and_withdraw_unbonded_works() { total: 1000 + 100, active: 100, unlocking: bounded_vec![UnlockChunk { value: 1000, era: 2 + 3 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }), ); @@ -1340,7 +1340,7 @@ fn bond_extra_and_withdraw_unbonded_works() { total: 1000 + 100, active: 100, unlocking: bounded_vec![UnlockChunk { value: 1000, era: 2 + 3 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }), ); @@ -1356,7 +1356,7 @@ fn bond_extra_and_withdraw_unbonded_works() { total: 100, active: 100, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }), ); }) @@ -1459,7 +1459,7 @@ fn rebond_works() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1478,7 +1478,7 @@ fn rebond_works() { total: 1000, active: 100, unlocking: bounded_vec![UnlockChunk { value: 900, era: 2 + 3 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1491,7 +1491,7 @@ fn rebond_works() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1504,7 +1504,7 @@ fn rebond_works() { total: 1000, active: 100, unlocking: bounded_vec![UnlockChunk { value: 900, era: 5 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1517,7 +1517,7 @@ fn rebond_works() { total: 1000, active: 600, unlocking: bounded_vec![UnlockChunk { value: 400, era: 5 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1530,7 +1530,7 @@ fn rebond_works() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1545,7 +1545,7 @@ fn rebond_works() { total: 1000, active: 100, unlocking: bounded_vec![UnlockChunk { value: 900, era: 5 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1558,7 +1558,7 @@ fn rebond_works() { total: 1000, active: 600, unlocking: bounded_vec![UnlockChunk { value: 400, era: 5 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); }) @@ -1585,7 +1585,7 @@ fn rebond_is_fifo() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1600,7 +1600,7 @@ fn rebond_is_fifo() { total: 1000, active: 600, unlocking: bounded_vec![UnlockChunk { value: 400, era: 2 + 3 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1618,7 +1618,7 @@ fn rebond_is_fifo() { UnlockChunk { value: 400, era: 2 + 3 }, UnlockChunk { value: 300, era: 3 + 3 }, ], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1637,7 +1637,7 @@ fn rebond_is_fifo() { UnlockChunk { value: 300, era: 3 + 3 }, UnlockChunk { value: 200, era: 4 + 3 }, ], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1653,7 +1653,7 @@ fn rebond_is_fifo() { UnlockChunk { value: 400, era: 2 + 3 }, UnlockChunk { value: 100, era: 3 + 3 }, ], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); }) @@ -1682,7 +1682,7 @@ fn rebond_emits_right_value_in_event() { total: 1000, active: 100, unlocking: bounded_vec![UnlockChunk { value: 900, era: 1 + 3 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -1695,7 +1695,7 @@ fn rebond_emits_right_value_in_event() { total: 1000, active: 200, unlocking: bounded_vec![UnlockChunk { value: 800, era: 1 + 3 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); // Event emitted should be correct @@ -1710,7 +1710,7 @@ fn rebond_emits_right_value_in_event() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); // Event emitted should be correct, only 800 @@ -1746,7 +1746,7 @@ fn reward_to_stake_works() { total: 69, active: 69, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }, ); @@ -1810,7 +1810,7 @@ fn reap_stash_works() { total: 5, active: 5, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }, ); @@ -1945,7 +1945,7 @@ fn bond_with_no_staked_value() { active: 0, total: 5, unlocking: bounded_vec![UnlockChunk { value: 5, era: 3 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }) ); @@ -3049,7 +3049,7 @@ fn staker_cannot_bail_deferred_slash() { active: 0, total: 500, stash: 101, - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], unlocking: bounded_vec![UnlockChunk { era: 4u32, value: 500 }], } ); @@ -3817,7 +3817,7 @@ fn test_payout_stakers() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }) ); @@ -3850,7 +3850,7 @@ fn test_payout_stakers() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }) ); @@ -3865,7 +3865,7 @@ fn test_payout_stakers() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }) ); }); @@ -4069,7 +4069,7 @@ fn bond_does_not_populate_claimed_rewards() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }) ); mock::start_active_era(5); @@ -4081,7 +4081,7 @@ fn bond_does_not_populate_claimed_rewards() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }) ); @@ -4096,7 +4096,7 @@ fn bond_does_not_populate_claimed_rewards() { total: 1000, active: 1000, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }) ); }); @@ -4341,7 +4341,7 @@ fn cannot_rebond_to_lower_than_ed() { total: 10 * 1000, active: 10 * 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], } ); @@ -4355,7 +4355,7 @@ fn cannot_rebond_to_lower_than_ed() { total: 10 * 1000, active: 0, unlocking: bounded_vec![UnlockChunk { value: 10 * 1000, era: 3 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], } ); @@ -4381,7 +4381,7 @@ fn cannot_bond_extra_to_lower_than_ed() { total: 10 * 1000, active: 10 * 1000, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], } ); @@ -4395,7 +4395,7 @@ fn cannot_bond_extra_to_lower_than_ed() { total: 10 * 1000, active: 0, unlocking: bounded_vec![UnlockChunk { value: 10 * 1000, era: 3 }], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], } ); @@ -4422,7 +4422,7 @@ fn do_not_die_when_active_is_ed() { total: 1000 * ed, active: 1000 * ed, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], } ); @@ -4439,7 +4439,7 @@ fn do_not_die_when_active_is_ed() { total: ed, active: ed, unlocking: Default::default(), - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], } ); }) @@ -5239,7 +5239,7 @@ fn proportional_slash_stop_slashing_if_remaining_zero() { active: 20, // we have some chunks, but they are not affected. unlocking: bounded_vec![c(1, 10), c(2, 10)], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }; assert_eq!(BondingDuration::get(), 3); @@ -5257,7 +5257,7 @@ fn proportional_ledger_slash_works() { total: 10, active: 10, unlocking: bounded_vec![], - claimed_rewards: bounded_vec![], + legacy_claimed_rewards: bounded_vec![], }; assert_eq!(BondingDuration::get(), 3); @@ -5492,7 +5492,7 @@ fn legacy_claimed_reward_checked_before_claim() { total: 1500, active: 1500, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), } ); // go forward few eras rewarding the validator for each era @@ -5510,7 +5510,7 @@ fn legacy_claimed_reward_checked_before_claim() { total: 1500, active: 1500, unlocking: Default::default(), - claimed_rewards: bounded_vec![4, 6, 8], + legacy_claimed_rewards: bounded_vec![4, 6, 8], }, ); @@ -5558,7 +5558,7 @@ fn reducing_history_depth_abrupt() { total: 1500, active: 1500, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), } ); @@ -5597,7 +5597,7 @@ fn reducing_history_depth_abrupt() { total: 1200, active: 1200, unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), } ); From aa63fecd14be6a85dd4c5963e8ad86dd6785e8d1 Mon Sep 17 00:00:00 2001 From: Ankan Date: Thu, 29 Dec 2022 23:22:26 +0100 Subject: [PATCH 08/12] rename claimed_rewards everywhere --- frame/staking/src/benchmarking.rs | 2 +- frame/staking/src/lib.rs | 5 ++--- frame/staking/src/pallet/impls.rs | 5 ++--- frame/staking/src/pallet/mod.rs | 4 ++-- frame/staking/src/tests.rs | 1 - 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index b3d32b26ec1f7..d8005c043288a 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -681,7 +681,7 @@ benchmarks! { active: T::Currency::minimum_balance() - One::one(), total: T::Currency::minimum_balance() - One::one(), unlocking: Default::default(), - claimed_rewards: Default::default(), + legacy_claimed_rewards: Default::default(), }; Ledger::::insert(&controller, l); diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 801e8bbe50d89..70425afdc9cd4 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -474,9 +474,8 @@ pub struct StakingLedger { /// in, first out queue where the new (higher value) eras get pushed on the back. pub unlocking: BoundedVec>, T::MaxUnlockingChunks>, /// Legacy field. Used as a list of eras for which the stakers behind a validator have claimed - /// rewards. It should only be used to read old `claimed_rewards` and a new entry should not be - /// added to it. - /// FIXME: Clean up after `T::HistoryDepth` eras. + /// rewards. It should only be used for reading old state. + /// TODO: Clean up after `T::HistoryDepth` eras. /// Tracker: pub legacy_claimed_rewards: BoundedVec, } diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index ef3f83c5f0e7a..3916b01b070b7 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -269,13 +269,12 @@ impl Pallet { ) -> EraRewardPoints { let mut era_reward_points = >::get(&era); - // In the older version of code, ledger maintained the record of `claimed_rewards`. + // In the older version of code, ledger maintained the record of `legacy_claimed_rewards`. // Going forward, we don't keep them in the ledger but drop them from // `EraRewardPoints` as they are claimed. Since we maintain `$HistoryDepth` eras in the - // `ledger.claimed_rewards`, once `$HistoryDepth` number of eras have passed, this code is + // `ledger.legacy_claimed_rewards`, once `$HistoryDepth` number of eras have passed, this code is // redundant and can be cleaned up, relying solely on `EraRewardPoints` to prevent double // claim. - // TODO: Clean up `ledger.claimed_rewards` after 84 eras. if ledger.legacy_claimed_rewards.binary_search(&era).is_ok() { // since rewards are already claimed for this era, drop them. era_reward_points.individual.remove(&ledger.stash); diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 6810d74610355..524486137c16a 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -135,7 +135,7 @@ pub mod pallet { /// HistoryDepth, current_era]`: `ErasStakers`, `ErasStakersClipped`, /// `ErasValidatorPrefs`, `ErasValidatorReward`, `ErasRewardPoints`, /// `ErasTotalStake`, `ErasStartSessionIndex`, - /// `StakingLedger.claimed_rewards`. + /// `StakingLedger.legacy_claimed_rewards`. /// /// Must be more than the number of eras delayed by session. /// I.e. active era must always be in history. I.e. `active_era > @@ -145,7 +145,7 @@ pub mod pallet { /// this should be set to same value or greater as in storage. /// /// Note: `HistoryDepth` is used as the upper bound for the `BoundedVec` - /// item `StakingLedger.claimed_rewards`. Setting this value lower than + /// item `StakingLedger.legacy_claimed_rewards`. Setting this value lower than /// the existing value can lead to inconsistencies in the /// `StakingLedger` and will need to be handled properly in a migration. /// The test `reducing_history_depth_abrupt` shows this effect. diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index b54053e4e09aa..c23df62093bd0 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -3809,7 +3809,6 @@ fn test_payout_stakers() { assert!(RewardOnUnbalanceWasCalled::get()); } - // claimed_rewards not used assert_eq!( Staking::ledger(&10), Some(StakingLedger { From ea4569c3c5290c57498d56a60e4ea528f802040e Mon Sep 17 00:00:00 2001 From: Ankan Date: Mon, 2 Jan 2023 13:09:45 +0100 Subject: [PATCH 09/12] small doc --- frame/staking/src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 70425afdc9cd4..08a24a76052aa 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -373,11 +373,12 @@ pub struct ActiveEraInfo { pub struct EraRewardPoints { /// Total number of points in an era. /// - /// For an active era, this always equals the sum of reward points for each validator. As a - /// validator claims their era reward in the succeeding eras, individual points are dropped - /// hence sum of individual validator reward points reduces but `total` for an era will always - /// remain same. This is important, since we rely on `total` to calculate reward payouts for - /// the remaining set of validators correctly. + /// For an active era, `total` is strictly equal to the sum of reward points for each + /// validator. For any `era < active_era`, `total >= sum(individual)`. As a validator claims + /// their era reward in the succeeding eras, individual points are dropped hence sum of + /// individual validator reward points reduces but `total` for an era will always remain same. + /// This is important, since we rely on `total` to calculate reward payouts for the remaining + /// set of validators correctly. pub total: RewardPoint, /// The reward points earned by a given validator. Dropped as reward points get claimed. pub individual: BTreeMap, From 49b42b39dcbd980ea0a85cf61548ca940ab9c03d Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 2 Jan 2023 13:11:02 +0000 Subject: [PATCH 10/12] ".git/.scripts/bench-bot.sh" pallet dev pallet_staking --- frame/staking/src/weights.rs | 392 +++++++++++++++++------------------ 1 file changed, 195 insertions(+), 197 deletions(-) diff --git a/frame/staking/src/weights.rs b/frame/staking/src/weights.rs index 9c283f5a065e3..e9f320f0be22c 100644 --- a/frame/staking/src/weights.rs +++ b/frame/staking/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_staking //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-12-25, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-01-02, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 @@ -85,13 +85,12 @@ pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:1) // Storage: Staking Ledger (r:1 w:1) - // Storage: Staking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - // Minimum execution time: 54_884 nanoseconds. - Weight::from_ref_time(55_487_000) - .saturating_add(T::DbWeight::get().reads(4)) + // Minimum execution time: 51_711 nanoseconds. + Weight::from_ref_time(52_132_000) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(4)) } // Storage: Staking Bonded (r:1 w:0) @@ -100,8 +99,8 @@ impl WeightInfo for SubstrateWeight { // Storage: VoterList ListNodes (r:3 w:3) // Storage: VoterList ListBags (r:2 w:2) fn bond_extra() -> Weight { - // Minimum execution time: 95_115 nanoseconds. - Weight::from_ref_time(96_213_000) + // Minimum execution time: 93_380 nanoseconds. + Weight::from_ref_time(93_946_000) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -115,8 +114,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: VoterList ListBags (r:2 w:2) fn unbond() -> Weight { - // Minimum execution time: 102_031 nanoseconds. - Weight::from_ref_time(102_842_000) + // Minimum execution time: 100_147 nanoseconds. + Weight::from_ref_time(100_812_000) .saturating_add(T::DbWeight::get().reads(12)) .saturating_add(T::DbWeight::get().writes(8)) } @@ -126,10 +125,10 @@ impl WeightInfo for SubstrateWeight { // Storage: System Account (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_update(s: u32, ) -> Weight { - // Minimum execution time: 46_569 nanoseconds. - Weight::from_ref_time(48_034_493) - // Standard Error: 654 - .saturating_add(Weight::from_ref_time(63_628).saturating_mul(s.into())) + // Minimum execution time: 45_364 nanoseconds. + Weight::from_ref_time(46_911_629) + // Standard Error: 1_407 + .saturating_add(Weight::from_ref_time(69_968).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -149,10 +148,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking SpanSlash (r:0 w:2) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_kill(s: u32, ) -> Weight { - // Minimum execution time: 90_154 nanoseconds. - Weight::from_ref_time(95_725_631) - // Standard Error: 2_491 - .saturating_add(Weight::from_ref_time(1_110_795).saturating_mul(s.into())) + // Minimum execution time: 88_213 nanoseconds. + Weight::from_ref_time(93_463_720) + // Standard Error: 2_636 + .saturating_add(Weight::from_ref_time(1_085_185).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(13)) .saturating_add(T::DbWeight::get().writes(12)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -169,8 +168,8 @@ impl WeightInfo for SubstrateWeight { // Storage: VoterList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - // Minimum execution time: 67_978 nanoseconds. - Weight::from_ref_time(69_153_000) + // Minimum execution time: 67_099 nanoseconds. + Weight::from_ref_time(68_191_000) .saturating_add(T::DbWeight::get().reads(11)) .saturating_add(T::DbWeight::get().writes(5)) } @@ -178,10 +177,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Nominators (r:1 w:1) /// The range of component `k` is `[1, 128]`. fn kick(k: u32, ) -> Weight { - // Minimum execution time: 45_328 nanoseconds. - Weight::from_ref_time(47_719_103) - // Standard Error: 14_458 - .saturating_add(Weight::from_ref_time(6_999_252).saturating_mul(k.into())) + // Minimum execution time: 41_445 nanoseconds. + Weight::from_ref_time(44_962_870) + // Standard Error: 10_928 + .saturating_add(Weight::from_ref_time(6_883_493).saturating_mul(k.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(k.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(k.into()))) @@ -199,10 +198,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking CounterForNominators (r:1 w:1) /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { - // Minimum execution time: 74_650 nanoseconds. - Weight::from_ref_time(74_350_075) - // Standard Error: 10_527 - .saturating_add(Weight::from_ref_time(2_878_737).saturating_mul(n.into())) + // Minimum execution time: 73_453 nanoseconds. + Weight::from_ref_time(73_189_687) + // Standard Error: 7_022 + .saturating_add(Weight::from_ref_time(2_786_394).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(12)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(T::DbWeight::get().writes(6)) @@ -215,58 +214,58 @@ impl WeightInfo for SubstrateWeight { // Storage: VoterList ListBags (r:1 w:1) // Storage: VoterList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - // Minimum execution time: 67_790 nanoseconds. - Weight::from_ref_time(68_738_000) + // Minimum execution time: 66_871 nanoseconds. + Weight::from_ref_time(67_339_000) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking Payee (r:0 w:1) fn set_payee() -> Weight { - // Minimum execution time: 19_237 nanoseconds. - Weight::from_ref_time(19_534_000) + // Minimum execution time: 18_498 nanoseconds. + Weight::from_ref_time(19_102_000) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Staking Bonded (r:1 w:1) // Storage: Staking Ledger (r:2 w:2) fn set_controller() -> Weight { - // Minimum execution time: 27_288 nanoseconds. - Weight::from_ref_time(27_667_000) + // Minimum execution time: 26_291 nanoseconds. + Weight::from_ref_time(26_773_000) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) } // Storage: Staking ValidatorCount (r:0 w:1) fn set_validator_count() -> Weight { - // Minimum execution time: 5_155 nanoseconds. - Weight::from_ref_time(5_464_000) + // Minimum execution time: 5_041 nanoseconds. + Weight::from_ref_time(5_180_000) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - // Minimum execution time: 5_405 nanoseconds. - Weight::from_ref_time(5_670_000) + // Minimum execution time: 5_181 nanoseconds. + Weight::from_ref_time(5_376_000) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - // Minimum execution time: 5_459 nanoseconds. - Weight::from_ref_time(5_616_000) + // Minimum execution time: 5_147 nanoseconds. + Weight::from_ref_time(5_367_000) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era_always() -> Weight { - // Minimum execution time: 5_476 nanoseconds. - Weight::from_ref_time(5_692_000) + // Minimum execution time: 5_092 nanoseconds. + Weight::from_ref_time(5_386_000) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Staking Invulnerables (r:0 w:1) /// The range of component `v` is `[0, 1000]`. fn set_invulnerables(v: u32, ) -> Weight { - // Minimum execution time: 5_544 nanoseconds. - Weight::from_ref_time(6_513_190) - // Standard Error: 76 - .saturating_add(Weight::from_ref_time(9_975).saturating_mul(v.into())) + // Minimum execution time: 5_092 nanoseconds. + Weight::from_ref_time(6_128_507) + // Standard Error: 35 + .saturating_add(Weight::from_ref_time(10_214).saturating_mul(v.into())) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Staking Bonded (r:1 w:1) @@ -284,10 +283,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking SpanSlash (r:0 w:2) /// The range of component `s` is `[0, 100]`. fn force_unstake(s: u32, ) -> Weight { - // Minimum execution time: 82_414 nanoseconds. - Weight::from_ref_time(88_511_246) - // Standard Error: 2_622 - .saturating_add(Weight::from_ref_time(1_131_814).saturating_mul(s.into())) + // Minimum execution time: 80_032 nanoseconds. + Weight::from_ref_time(86_217_712) + // Standard Error: 3_099 + .saturating_add(Weight::from_ref_time(1_087_141).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(11)) .saturating_add(T::DbWeight::get().writes(12)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -295,10 +294,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking UnappliedSlashes (r:1 w:1) /// The range of component `s` is `[1, 1000]`. fn cancel_deferred_slash(s: u32, ) -> Weight { - // Minimum execution time: 94_197 nanoseconds. - Weight::from_ref_time(903_418_326) - // Standard Error: 59_354 - .saturating_add(Weight::from_ref_time(4_948_354).saturating_mul(s.into())) + // Minimum execution time: 92_566 nanoseconds. + Weight::from_ref_time(896_598_086) + // Standard Error: 58_641 + .saturating_add(Weight::from_ref_time(4_947_854).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -307,19 +306,19 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: Staking Ledger (r:1 w:1) // Storage: Staking ErasStakersClipped (r:1 w:0) - // Storage: Staking ErasRewardPoints (r:1 w:0) + // Storage: Staking ErasRewardPoints (r:1 w:1) // Storage: Staking ErasValidatorPrefs (r:1 w:0) // Storage: Staking Payee (r:1 w:0) // Storage: System Account (r:1 w:1) /// The range of component `n` is `[0, 256]`. fn payout_stakers_dead_controller(n: u32, ) -> Weight { - // Minimum execution time: 133_065 nanoseconds. - Weight::from_ref_time(197_555_906) - // Standard Error: 19_561 - .saturating_add(Weight::from_ref_time(22_683_426).saturating_mul(n.into())) + // Minimum execution time: 129_612 nanoseconds. + Weight::from_ref_time(190_241_064) + // Standard Error: 16_367 + .saturating_add(Weight::from_ref_time(21_803_742).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(9)) .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(n.into()))) - .saturating_add(T::DbWeight::get().writes(2)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) } // Storage: Staking CurrentEra (r:1 w:0) @@ -327,20 +326,20 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: Staking Ledger (r:1 w:1) // Storage: Staking ErasStakersClipped (r:1 w:0) - // Storage: Staking ErasRewardPoints (r:1 w:0) + // Storage: Staking ErasRewardPoints (r:1 w:1) // Storage: Staking ErasValidatorPrefs (r:1 w:0) // Storage: Staking Payee (r:1 w:0) // Storage: System Account (r:1 w:1) // Storage: Balances Locks (r:1 w:1) /// The range of component `n` is `[0, 256]`. fn payout_stakers_alive_staked(n: u32, ) -> Weight { - // Minimum execution time: 164_719 nanoseconds. - Weight::from_ref_time(226_304_276) - // Standard Error: 31_675 - .saturating_add(Weight::from_ref_time(32_622_427).saturating_mul(n.into())) + // Minimum execution time: 163_449 nanoseconds. + Weight::from_ref_time(226_561_152) + // Standard Error: 31_806 + .saturating_add(Weight::from_ref_time(30_833_324).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().reads((5_u64).saturating_mul(n.into()))) - .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(n.into()))) } // Storage: Staking Ledger (r:1 w:1) @@ -351,10 +350,10 @@ impl WeightInfo for SubstrateWeight { // Storage: VoterList ListBags (r:2 w:2) /// The range of component `l` is `[1, 32]`. fn rebond(l: u32, ) -> Weight { - // Minimum execution time: 95_631 nanoseconds. - Weight::from_ref_time(96_861_556) - // Standard Error: 2_114 - .saturating_add(Weight::from_ref_time(37_543).saturating_mul(l.into())) + // Minimum execution time: 93_246 nanoseconds. + Weight::from_ref_time(94_821_054) + // Standard Error: 3_650 + .saturating_add(Weight::from_ref_time(36_330).saturating_mul(l.into())) .saturating_add(T::DbWeight::get().reads(9)) .saturating_add(T::DbWeight::get().writes(8)) } @@ -373,10 +372,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking SpanSlash (r:0 w:1) /// The range of component `s` is `[1, 100]`. fn reap_stash(s: u32, ) -> Weight { - // Minimum execution time: 95_251 nanoseconds. - Weight::from_ref_time(97_818_954) - // Standard Error: 2_356 - .saturating_add(Weight::from_ref_time(1_104_695).saturating_mul(s.into())) + // Minimum execution time: 92_720 nanoseconds. + Weight::from_ref_time(94_789_924) + // Standard Error: 2_078 + .saturating_add(Weight::from_ref_time(1_079_803).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(12)) .saturating_add(T::DbWeight::get().writes(12)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -401,12 +400,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `v` is `[1, 10]`. /// The range of component `n` is `[0, 100]`. fn new_era(v: u32, n: u32, ) -> Weight { - // Minimum execution time: 512_923 nanoseconds. - Weight::from_ref_time(514_740_000) - // Standard Error: 1_790_238 - .saturating_add(Weight::from_ref_time(59_320_539).saturating_mul(v.into())) - // Standard Error: 178_387 - .saturating_add(Weight::from_ref_time(13_902_705).saturating_mul(n.into())) + // Minimum execution time: 503_914 nanoseconds. + Weight::from_ref_time(505_646_000) + // Standard Error: 1_794_658 + .saturating_add(Weight::from_ref_time(59_521_614).saturating_mul(v.into())) + // Standard Error: 178_827 + .saturating_add(Weight::from_ref_time(13_592_655).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(206)) .saturating_add(T::DbWeight::get().reads((5_u64).saturating_mul(v.into()))) .saturating_add(T::DbWeight::get().reads((4_u64).saturating_mul(n.into()))) @@ -424,12 +423,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `v` is `[500, 1000]`. /// The range of component `n` is `[500, 1000]`. fn get_npos_voters(v: u32, n: u32, ) -> Weight { - // Minimum execution time: 24_913_316 nanoseconds. - Weight::from_ref_time(25_053_596_000) - // Standard Error: 324_610 - .saturating_add(Weight::from_ref_time(3_454_859).saturating_mul(v.into())) - // Standard Error: 324_610 - .saturating_add(Weight::from_ref_time(3_020_267).saturating_mul(n.into())) + // Minimum execution time: 24_525_194 nanoseconds. + Weight::from_ref_time(24_790_684_000) + // Standard Error: 324_084 + .saturating_add(Weight::from_ref_time(3_440_622).saturating_mul(v.into())) + // Standard Error: 324_084 + .saturating_add(Weight::from_ref_time(2_826_495).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(201)) .saturating_add(T::DbWeight::get().reads((5_u64).saturating_mul(v.into()))) .saturating_add(T::DbWeight::get().reads((4_u64).saturating_mul(n.into()))) @@ -439,10 +438,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Validators (r:501 w:0) /// The range of component `v` is `[500, 1000]`. fn get_npos_targets(v: u32, ) -> Weight { - // Minimum execution time: 4_916_401 nanoseconds. - Weight::from_ref_time(81_160_966) - // Standard Error: 23_829 - .saturating_add(Weight::from_ref_time(9_883_413).saturating_mul(v.into())) + // Minimum execution time: 4_835_231 nanoseconds. + Weight::from_ref_time(17_096_800) + // Standard Error: 22_273 + .saturating_add(Weight::from_ref_time(9_749_555).saturating_mul(v.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(v.into()))) } @@ -453,8 +452,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs_all_set() -> Weight { - // Minimum execution time: 10_937 nanoseconds. - Weight::from_ref_time(11_324_000) + // Minimum execution time: 10_517 nanoseconds. + Weight::from_ref_time(11_027_000) .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Staking MinCommission (r:0 w:1) @@ -464,8 +463,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs_all_remove() -> Weight { - // Minimum execution time: 9_424 nanoseconds. - Weight::from_ref_time(10_021_000) + // Minimum execution time: 9_548 nanoseconds. + Weight::from_ref_time(9_817_000) .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Staking Ledger (r:1 w:0) @@ -479,23 +478,23 @@ impl WeightInfo for SubstrateWeight { // Storage: VoterList ListBags (r:1 w:1) // Storage: VoterList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - // Minimum execution time: 84_495 nanoseconds. - Weight::from_ref_time(85_559_000) + // Minimum execution time: 82_497 nanoseconds. + Weight::from_ref_time(83_406_000) .saturating_add(T::DbWeight::get().reads(11)) .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Staking MinCommission (r:1 w:0) // Storage: Staking Validators (r:1 w:1) fn force_apply_min_commission() -> Weight { - // Minimum execution time: 20_385 nanoseconds. - Weight::from_ref_time(20_824_000) + // Minimum execution time: 19_250 nanoseconds. + Weight::from_ref_time(19_710_000) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Staking MinCommission (r:0 w:1) fn set_min_commission() -> Weight { - // Minimum execution time: 6_995 nanoseconds. - Weight::from_ref_time(7_213_000) + // Minimum execution time: 6_074 nanoseconds. + Weight::from_ref_time(6_385_000) .saturating_add(T::DbWeight::get().writes(1)) } } @@ -504,13 +503,12 @@ impl WeightInfo for SubstrateWeight { impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:1) // Storage: Staking Ledger (r:1 w:1) - // Storage: Staking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - // Minimum execution time: 54_884 nanoseconds. - Weight::from_ref_time(55_487_000) - .saturating_add(RocksDbWeight::get().reads(4)) + // Minimum execution time: 51_711 nanoseconds. + Weight::from_ref_time(52_132_000) + .saturating_add(RocksDbWeight::get().reads(3)) .saturating_add(RocksDbWeight::get().writes(4)) } // Storage: Staking Bonded (r:1 w:0) @@ -519,8 +517,8 @@ impl WeightInfo for () { // Storage: VoterList ListNodes (r:3 w:3) // Storage: VoterList ListBags (r:2 w:2) fn bond_extra() -> Weight { - // Minimum execution time: 95_115 nanoseconds. - Weight::from_ref_time(96_213_000) + // Minimum execution time: 93_380 nanoseconds. + Weight::from_ref_time(93_946_000) .saturating_add(RocksDbWeight::get().reads(8)) .saturating_add(RocksDbWeight::get().writes(7)) } @@ -534,8 +532,8 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: VoterList ListBags (r:2 w:2) fn unbond() -> Weight { - // Minimum execution time: 102_031 nanoseconds. - Weight::from_ref_time(102_842_000) + // Minimum execution time: 100_147 nanoseconds. + Weight::from_ref_time(100_812_000) .saturating_add(RocksDbWeight::get().reads(12)) .saturating_add(RocksDbWeight::get().writes(8)) } @@ -545,10 +543,10 @@ impl WeightInfo for () { // Storage: System Account (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_update(s: u32, ) -> Weight { - // Minimum execution time: 46_569 nanoseconds. - Weight::from_ref_time(48_034_493) - // Standard Error: 654 - .saturating_add(Weight::from_ref_time(63_628).saturating_mul(s.into())) + // Minimum execution time: 45_364 nanoseconds. + Weight::from_ref_time(46_911_629) + // Standard Error: 1_407 + .saturating_add(Weight::from_ref_time(69_968).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(3)) } @@ -568,10 +566,10 @@ impl WeightInfo for () { // Storage: Staking SpanSlash (r:0 w:2) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_kill(s: u32, ) -> Weight { - // Minimum execution time: 90_154 nanoseconds. - Weight::from_ref_time(95_725_631) - // Standard Error: 2_491 - .saturating_add(Weight::from_ref_time(1_110_795).saturating_mul(s.into())) + // Minimum execution time: 88_213 nanoseconds. + Weight::from_ref_time(93_463_720) + // Standard Error: 2_636 + .saturating_add(Weight::from_ref_time(1_085_185).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(13)) .saturating_add(RocksDbWeight::get().writes(12)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -588,8 +586,8 @@ impl WeightInfo for () { // Storage: VoterList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - // Minimum execution time: 67_978 nanoseconds. - Weight::from_ref_time(69_153_000) + // Minimum execution time: 67_099 nanoseconds. + Weight::from_ref_time(68_191_000) .saturating_add(RocksDbWeight::get().reads(11)) .saturating_add(RocksDbWeight::get().writes(5)) } @@ -597,10 +595,10 @@ impl WeightInfo for () { // Storage: Staking Nominators (r:1 w:1) /// The range of component `k` is `[1, 128]`. fn kick(k: u32, ) -> Weight { - // Minimum execution time: 45_328 nanoseconds. - Weight::from_ref_time(47_719_103) - // Standard Error: 14_458 - .saturating_add(Weight::from_ref_time(6_999_252).saturating_mul(k.into())) + // Minimum execution time: 41_445 nanoseconds. + Weight::from_ref_time(44_962_870) + // Standard Error: 10_928 + .saturating_add(Weight::from_ref_time(6_883_493).saturating_mul(k.into())) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(k.into()))) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(k.into()))) @@ -618,10 +616,10 @@ impl WeightInfo for () { // Storage: Staking CounterForNominators (r:1 w:1) /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { - // Minimum execution time: 74_650 nanoseconds. - Weight::from_ref_time(74_350_075) - // Standard Error: 10_527 - .saturating_add(Weight::from_ref_time(2_878_737).saturating_mul(n.into())) + // Minimum execution time: 73_453 nanoseconds. + Weight::from_ref_time(73_189_687) + // Standard Error: 7_022 + .saturating_add(Weight::from_ref_time(2_786_394).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(12)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(RocksDbWeight::get().writes(6)) @@ -634,58 +632,58 @@ impl WeightInfo for () { // Storage: VoterList ListBags (r:1 w:1) // Storage: VoterList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - // Minimum execution time: 67_790 nanoseconds. - Weight::from_ref_time(68_738_000) + // Minimum execution time: 66_871 nanoseconds. + Weight::from_ref_time(67_339_000) .saturating_add(RocksDbWeight::get().reads(8)) .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking Payee (r:0 w:1) fn set_payee() -> Weight { - // Minimum execution time: 19_237 nanoseconds. - Weight::from_ref_time(19_534_000) + // Minimum execution time: 18_498 nanoseconds. + Weight::from_ref_time(19_102_000) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Staking Bonded (r:1 w:1) // Storage: Staking Ledger (r:2 w:2) fn set_controller() -> Weight { - // Minimum execution time: 27_288 nanoseconds. - Weight::from_ref_time(27_667_000) + // Minimum execution time: 26_291 nanoseconds. + Weight::from_ref_time(26_773_000) .saturating_add(RocksDbWeight::get().reads(3)) .saturating_add(RocksDbWeight::get().writes(3)) } // Storage: Staking ValidatorCount (r:0 w:1) fn set_validator_count() -> Weight { - // Minimum execution time: 5_155 nanoseconds. - Weight::from_ref_time(5_464_000) + // Minimum execution time: 5_041 nanoseconds. + Weight::from_ref_time(5_180_000) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - // Minimum execution time: 5_405 nanoseconds. - Weight::from_ref_time(5_670_000) + // Minimum execution time: 5_181 nanoseconds. + Weight::from_ref_time(5_376_000) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - // Minimum execution time: 5_459 nanoseconds. - Weight::from_ref_time(5_616_000) + // Minimum execution time: 5_147 nanoseconds. + Weight::from_ref_time(5_367_000) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era_always() -> Weight { - // Minimum execution time: 5_476 nanoseconds. - Weight::from_ref_time(5_692_000) + // Minimum execution time: 5_092 nanoseconds. + Weight::from_ref_time(5_386_000) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Staking Invulnerables (r:0 w:1) /// The range of component `v` is `[0, 1000]`. fn set_invulnerables(v: u32, ) -> Weight { - // Minimum execution time: 5_544 nanoseconds. - Weight::from_ref_time(6_513_190) - // Standard Error: 76 - .saturating_add(Weight::from_ref_time(9_975).saturating_mul(v.into())) + // Minimum execution time: 5_092 nanoseconds. + Weight::from_ref_time(6_128_507) + // Standard Error: 35 + .saturating_add(Weight::from_ref_time(10_214).saturating_mul(v.into())) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Staking Bonded (r:1 w:1) @@ -703,10 +701,10 @@ impl WeightInfo for () { // Storage: Staking SpanSlash (r:0 w:2) /// The range of component `s` is `[0, 100]`. fn force_unstake(s: u32, ) -> Weight { - // Minimum execution time: 82_414 nanoseconds. - Weight::from_ref_time(88_511_246) - // Standard Error: 2_622 - .saturating_add(Weight::from_ref_time(1_131_814).saturating_mul(s.into())) + // Minimum execution time: 80_032 nanoseconds. + Weight::from_ref_time(86_217_712) + // Standard Error: 3_099 + .saturating_add(Weight::from_ref_time(1_087_141).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(11)) .saturating_add(RocksDbWeight::get().writes(12)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -714,10 +712,10 @@ impl WeightInfo for () { // Storage: Staking UnappliedSlashes (r:1 w:1) /// The range of component `s` is `[1, 1000]`. fn cancel_deferred_slash(s: u32, ) -> Weight { - // Minimum execution time: 94_197 nanoseconds. - Weight::from_ref_time(903_418_326) - // Standard Error: 59_354 - .saturating_add(Weight::from_ref_time(4_948_354).saturating_mul(s.into())) + // Minimum execution time: 92_566 nanoseconds. + Weight::from_ref_time(896_598_086) + // Standard Error: 58_641 + .saturating_add(Weight::from_ref_time(4_947_854).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -726,19 +724,19 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: Staking Ledger (r:1 w:1) // Storage: Staking ErasStakersClipped (r:1 w:0) - // Storage: Staking ErasRewardPoints (r:1 w:0) + // Storage: Staking ErasRewardPoints (r:1 w:1) // Storage: Staking ErasValidatorPrefs (r:1 w:0) // Storage: Staking Payee (r:1 w:0) // Storage: System Account (r:1 w:1) /// The range of component `n` is `[0, 256]`. fn payout_stakers_dead_controller(n: u32, ) -> Weight { - // Minimum execution time: 133_065 nanoseconds. - Weight::from_ref_time(197_555_906) - // Standard Error: 19_561 - .saturating_add(Weight::from_ref_time(22_683_426).saturating_mul(n.into())) + // Minimum execution time: 129_612 nanoseconds. + Weight::from_ref_time(190_241_064) + // Standard Error: 16_367 + .saturating_add(Weight::from_ref_time(21_803_742).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(9)) .saturating_add(RocksDbWeight::get().reads((3_u64).saturating_mul(n.into()))) - .saturating_add(RocksDbWeight::get().writes(2)) + .saturating_add(RocksDbWeight::get().writes(3)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(n.into()))) } // Storage: Staking CurrentEra (r:1 w:0) @@ -746,20 +744,20 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: Staking Ledger (r:1 w:1) // Storage: Staking ErasStakersClipped (r:1 w:0) - // Storage: Staking ErasRewardPoints (r:1 w:0) + // Storage: Staking ErasRewardPoints (r:1 w:1) // Storage: Staking ErasValidatorPrefs (r:1 w:0) // Storage: Staking Payee (r:1 w:0) // Storage: System Account (r:1 w:1) // Storage: Balances Locks (r:1 w:1) /// The range of component `n` is `[0, 256]`. fn payout_stakers_alive_staked(n: u32, ) -> Weight { - // Minimum execution time: 164_719 nanoseconds. - Weight::from_ref_time(226_304_276) - // Standard Error: 31_675 - .saturating_add(Weight::from_ref_time(32_622_427).saturating_mul(n.into())) + // Minimum execution time: 163_449 nanoseconds. + Weight::from_ref_time(226_561_152) + // Standard Error: 31_806 + .saturating_add(Weight::from_ref_time(30_833_324).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(10)) .saturating_add(RocksDbWeight::get().reads((5_u64).saturating_mul(n.into()))) - .saturating_add(RocksDbWeight::get().writes(3)) + .saturating_add(RocksDbWeight::get().writes(4)) .saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(n.into()))) } // Storage: Staking Ledger (r:1 w:1) @@ -770,10 +768,10 @@ impl WeightInfo for () { // Storage: VoterList ListBags (r:2 w:2) /// The range of component `l` is `[1, 32]`. fn rebond(l: u32, ) -> Weight { - // Minimum execution time: 95_631 nanoseconds. - Weight::from_ref_time(96_861_556) - // Standard Error: 2_114 - .saturating_add(Weight::from_ref_time(37_543).saturating_mul(l.into())) + // Minimum execution time: 93_246 nanoseconds. + Weight::from_ref_time(94_821_054) + // Standard Error: 3_650 + .saturating_add(Weight::from_ref_time(36_330).saturating_mul(l.into())) .saturating_add(RocksDbWeight::get().reads(9)) .saturating_add(RocksDbWeight::get().writes(8)) } @@ -792,10 +790,10 @@ impl WeightInfo for () { // Storage: Staking SpanSlash (r:0 w:1) /// The range of component `s` is `[1, 100]`. fn reap_stash(s: u32, ) -> Weight { - // Minimum execution time: 95_251 nanoseconds. - Weight::from_ref_time(97_818_954) - // Standard Error: 2_356 - .saturating_add(Weight::from_ref_time(1_104_695).saturating_mul(s.into())) + // Minimum execution time: 92_720 nanoseconds. + Weight::from_ref_time(94_789_924) + // Standard Error: 2_078 + .saturating_add(Weight::from_ref_time(1_079_803).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(12)) .saturating_add(RocksDbWeight::get().writes(12)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -820,12 +818,12 @@ impl WeightInfo for () { /// The range of component `v` is `[1, 10]`. /// The range of component `n` is `[0, 100]`. fn new_era(v: u32, n: u32, ) -> Weight { - // Minimum execution time: 512_923 nanoseconds. - Weight::from_ref_time(514_740_000) - // Standard Error: 1_790_238 - .saturating_add(Weight::from_ref_time(59_320_539).saturating_mul(v.into())) - // Standard Error: 178_387 - .saturating_add(Weight::from_ref_time(13_902_705).saturating_mul(n.into())) + // Minimum execution time: 503_914 nanoseconds. + Weight::from_ref_time(505_646_000) + // Standard Error: 1_794_658 + .saturating_add(Weight::from_ref_time(59_521_614).saturating_mul(v.into())) + // Standard Error: 178_827 + .saturating_add(Weight::from_ref_time(13_592_655).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(206)) .saturating_add(RocksDbWeight::get().reads((5_u64).saturating_mul(v.into()))) .saturating_add(RocksDbWeight::get().reads((4_u64).saturating_mul(n.into()))) @@ -843,12 +841,12 @@ impl WeightInfo for () { /// The range of component `v` is `[500, 1000]`. /// The range of component `n` is `[500, 1000]`. fn get_npos_voters(v: u32, n: u32, ) -> Weight { - // Minimum execution time: 24_913_316 nanoseconds. - Weight::from_ref_time(25_053_596_000) - // Standard Error: 324_610 - .saturating_add(Weight::from_ref_time(3_454_859).saturating_mul(v.into())) - // Standard Error: 324_610 - .saturating_add(Weight::from_ref_time(3_020_267).saturating_mul(n.into())) + // Minimum execution time: 24_525_194 nanoseconds. + Weight::from_ref_time(24_790_684_000) + // Standard Error: 324_084 + .saturating_add(Weight::from_ref_time(3_440_622).saturating_mul(v.into())) + // Standard Error: 324_084 + .saturating_add(Weight::from_ref_time(2_826_495).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(201)) .saturating_add(RocksDbWeight::get().reads((5_u64).saturating_mul(v.into()))) .saturating_add(RocksDbWeight::get().reads((4_u64).saturating_mul(n.into()))) @@ -858,10 +856,10 @@ impl WeightInfo for () { // Storage: Staking Validators (r:501 w:0) /// The range of component `v` is `[500, 1000]`. fn get_npos_targets(v: u32, ) -> Weight { - // Minimum execution time: 4_916_401 nanoseconds. - Weight::from_ref_time(81_160_966) - // Standard Error: 23_829 - .saturating_add(Weight::from_ref_time(9_883_413).saturating_mul(v.into())) + // Minimum execution time: 4_835_231 nanoseconds. + Weight::from_ref_time(17_096_800) + // Standard Error: 22_273 + .saturating_add(Weight::from_ref_time(9_749_555).saturating_mul(v.into())) .saturating_add(RocksDbWeight::get().reads(2)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(v.into()))) } @@ -872,8 +870,8 @@ impl WeightInfo for () { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs_all_set() -> Weight { - // Minimum execution time: 10_937 nanoseconds. - Weight::from_ref_time(11_324_000) + // Minimum execution time: 10_517 nanoseconds. + Weight::from_ref_time(11_027_000) .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Staking MinCommission (r:0 w:1) @@ -883,8 +881,8 @@ impl WeightInfo for () { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs_all_remove() -> Weight { - // Minimum execution time: 9_424 nanoseconds. - Weight::from_ref_time(10_021_000) + // Minimum execution time: 9_548 nanoseconds. + Weight::from_ref_time(9_817_000) .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Staking Ledger (r:1 w:0) @@ -898,23 +896,23 @@ impl WeightInfo for () { // Storage: VoterList ListBags (r:1 w:1) // Storage: VoterList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - // Minimum execution time: 84_495 nanoseconds. - Weight::from_ref_time(85_559_000) + // Minimum execution time: 82_497 nanoseconds. + Weight::from_ref_time(83_406_000) .saturating_add(RocksDbWeight::get().reads(11)) .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Staking MinCommission (r:1 w:0) // Storage: Staking Validators (r:1 w:1) fn force_apply_min_commission() -> Weight { - // Minimum execution time: 20_385 nanoseconds. - Weight::from_ref_time(20_824_000) + // Minimum execution time: 19_250 nanoseconds. + Weight::from_ref_time(19_710_000) .saturating_add(RocksDbWeight::get().reads(2)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Staking MinCommission (r:0 w:1) fn set_min_commission() -> Weight { - // Minimum execution time: 6_995 nanoseconds. - Weight::from_ref_time(7_213_000) + // Minimum execution time: 6_074 nanoseconds. + Weight::from_ref_time(6_385_000) .saturating_add(RocksDbWeight::get().writes(1)) } } From 0d556578defcb043de48b9e71a99ed291cee0ae9 Mon Sep 17 00:00:00 2001 From: Ankan Date: Fri, 6 Jan 2023 15:15:43 +0100 Subject: [PATCH 11/12] don't break any ui --- frame/staking/src/pallet/impls.rs | 2 +- frame/staking/src/pallet/mod.rs | 5 ++--- frame/staking/src/tests.rs | 12 ++++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index 3916b01b070b7..58f91337c9442 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -183,7 +183,7 @@ impl Pallet { // No reward points to claim. This can also happen if reward has already been claimed. if validator_reward_points.is_zero() { - return Err(Error::::NothingToClaim + return Err(Error::::AlreadyClaimed .with_weight(T::WeightInfo::payout_stakers_alive_staked(0))) } diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 524486137c16a..a14518419dee8 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -743,9 +743,8 @@ pub mod pallet { InvalidNumberOfNominations, /// Items are not sorted and unique. NotSortedAndUnique, - /// No rewards available to claim for this era. Either validator did not earn any reward or - /// has already claimed it previously. - NothingToClaim, + /// No rewards to claim. Either no reward is earned or is already claimed. + AlreadyClaimed, /// Incorrect previous history depth input provided. IncorrectHistoryDepth, /// Incorrect number of slashing spans provided. diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index c23df62093bd0..3567032d4d002 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -3582,7 +3582,7 @@ fn claim_reward_at_the_last_era_and_no_double_claim_and_invalid_claim() { assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(1337), 11, 2), // Fail: Double claim - Error::::NothingToClaim.with_weight(err_weight) + Error::::AlreadyClaimed.with_weight(err_weight) ); assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(1337), 11, active_era), @@ -3942,11 +3942,11 @@ fn payout_stakers_handles_basic_errors() { // Can't claim again assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(1337), 11, expected_start_reward_era), - Error::::NothingToClaim.with_weight(err_weight) + Error::::AlreadyClaimed.with_weight(err_weight) ); assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(1337), 11, expected_last_reward_era), - Error::::NothingToClaim.with_weight(err_weight) + Error::::AlreadyClaimed.with_weight(err_weight) ); }); } @@ -4008,7 +4008,7 @@ fn payout_stakers_handles_weight_refund() { // Collect payouts for an era where the validator did not receive any points. let call = TestCall::Staking(StakingCall::payout_stakers { validator_stash: 11, era: 2 }); let result = call.dispatch(RuntimeOrigin::signed(20)); - assert_err!(result, Error::::NothingToClaim.with_weight(zero_nom_payouts_weight)); + assert_err!(result, Error::::AlreadyClaimed.with_weight(zero_nom_payouts_weight)); // Reward the validator and its nominators. Staking::reward_by_ids(vec![(11, 1)]); @@ -5525,7 +5525,7 @@ fn legacy_claimed_reward_checked_before_claim() { // cannot claim rewards for even eras. assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(4), 3, e), - Error::::NothingToClaim.with_weight(zero_weight) + Error::::AlreadyClaimed.with_weight(zero_weight) ); } } @@ -5581,7 +5581,7 @@ fn reducing_history_depth_abrupt() { // claiming reward does not work anymore assert_noop!( Staking::payout_stakers(RuntimeOrigin::signed(4), 3, current_era - 1), - Error::::NothingToClaim + Error::::AlreadyClaimed .with_weight(::WeightInfo::payout_stakers_alive_staked(0)) ); From b4ac591f233906e4d49bd1c7691fbf7c19e47f79 Mon Sep 17 00:00:00 2001 From: Ankan Date: Fri, 6 Jan 2023 15:16:18 +0100 Subject: [PATCH 12/12] cargo fmt --- frame/staking/src/pallet/impls.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index 58f91337c9442..0355888c801db 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -272,9 +272,9 @@ impl Pallet { // In the older version of code, ledger maintained the record of `legacy_claimed_rewards`. // Going forward, we don't keep them in the ledger but drop them from // `EraRewardPoints` as they are claimed. Since we maintain `$HistoryDepth` eras in the - // `ledger.legacy_claimed_rewards`, once `$HistoryDepth` number of eras have passed, this code is - // redundant and can be cleaned up, relying solely on `EraRewardPoints` to prevent double - // claim. + // `ledger.legacy_claimed_rewards`, once `$HistoryDepth` number of eras have passed, this + // code is redundant and can be cleaned up, relying solely on `EraRewardPoints` to prevent + // double claim. if ledger.legacy_claimed_rewards.binary_search(&era).is_ok() { // since rewards are already claimed for this era, drop them. era_reward_points.individual.remove(&ledger.stash);