diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index 5feb1692d955d..69a73c51fdc7e 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -842,7 +842,7 @@ benchmarks! { assert_eq!(targets.len() as u32, v); } - set_staking_limits { + set_staking_configs { // This function always does the same thing... just write to 4 storage items. }: _( RawOrigin::Root, @@ -850,13 +850,15 @@ benchmarks! { BalanceOf::::max_value(), Some(u32::MAX), Some(u32::MAX), - Some(Percent::max_value()) + Some(Percent::max_value()), + Perbill::max_value() ) verify { assert_eq!(MinNominatorBond::::get(), BalanceOf::::max_value()); assert_eq!(MinValidatorBond::::get(), BalanceOf::::max_value()); assert_eq!(MaxNominatorsCount::::get(), Some(u32::MAX)); assert_eq!(MaxValidatorsCount::::get(), Some(u32::MAX)); assert_eq!(ChillThreshold::::get(), Some(Percent::from_percent(100))); + assert_eq!(MinCommission::::get(), Perbill::from_percent(100)); } chill_other { @@ -872,13 +874,14 @@ benchmarks! { let stash = scenario.origin_stash1.clone(); assert!(T::SortedListProvider::contains(&stash)); - Staking::::set_staking_limits( + Staking::::set_staking_configs( RawOrigin::Root.into(), BalanceOf::::max_value(), BalanceOf::::max_value(), Some(0), Some(0), - Some(Percent::from_percent(0)) + Some(Percent::from_percent(0)), + Zero::zero(), )?; let caller = whitelisted_caller(); diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index f8f9c8c794dc7..f7e96ce0cf765 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -215,6 +215,12 @@ pub mod pallet { #[pallet::storage] pub type MinValidatorBond = StorageValue<_, BalanceOf, ValueQuery>; + /// The minimum amount of commission that validators can set. + /// + /// If set to `0`, no limit exists. + #[pallet::storage] + pub type MinCommission = StorageValue<_, Perbill, ValueQuery>; + /// Map from all (unlocked) "controller" accounts to the info regarding the staking. #[pallet::storage] #[pallet::getter(fn ledger)] @@ -486,6 +492,8 @@ pub mod pallet { Vec<(T::AccountId, T::AccountId, BalanceOf, crate::StakerStatus)>, pub min_nominator_bond: BalanceOf, pub min_validator_bond: BalanceOf, + pub max_validator_count: Option, + pub max_nominator_count: Option, } #[cfg(feature = "std")] @@ -502,6 +510,8 @@ pub mod pallet { stakers: Default::default(), min_nominator_bond: Default::default(), min_validator_bond: Default::default(), + max_validator_count: None, + max_nominator_count: None, } } } @@ -519,6 +529,12 @@ pub mod pallet { StorageVersion::::put(Releases::V7_0_0); MinNominatorBond::::put(self.min_nominator_bond); MinValidatorBond::::put(self.min_validator_bond); + if let Some(x) = self.max_validator_count { + MaxValidatorsCount::::put(x); + } + if let Some(x) = self.max_nominator_count { + MaxNominatorsCount::::put(x); + } for &(ref stash, ref controller, balance, ref status) in &self.stakers { log!( @@ -650,6 +666,8 @@ pub mod pallet { /// There are too many validators in the system. Governance needs to adjust the staking /// settings to keep things safe for the runtime. TooManyValidators, + /// Commission is too low. Must be at least `MinCommission`. + CommissionTooLow, } #[pallet::hooks] @@ -955,9 +973,13 @@ pub mod pallet { let controller = ensure_signed(origin)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + ensure!(ledger.active >= MinValidatorBond::::get(), Error::::InsufficientBond); let stash = &ledger.stash; + // ensure their commission is correct. + ensure!(prefs.commission >= MinCommission::::get(), Error::::CommissionTooLow); + // Only check limits if they are not already a validator. if !Validators::::contains_key(stash) { // If this error is reached, we need to adjust the `MinValidatorBond` and start @@ -1508,7 +1530,7 @@ pub mod pallet { Ok(()) } - /// Update the various staking limits this pallet. + /// Update the various staking configurations . /// /// * `min_nominator_bond`: The minimum active bond needed to be a nominator. /// * `min_validator_bond`: The minimum active bond needed to be a validator. @@ -1516,26 +1538,32 @@ pub mod pallet { /// set to `None`, no limit is enforced. /// * `max_validator_count`: The max number of users who can be a validator at once. When /// set to `None`, no limit is enforced. + /// * `chill_threshold`: The ratio of `max_nominator_count` or `max_validator_count` which + /// should be filled in order for the `chill_other` transaction to work. + /// * `min_commission`: The minimum amount of commission that each validators must maintain. + /// This is checked only upon calling `validate`. Existing validators are not affected. /// /// Origin must be Root to call this function. /// /// NOTE: Existing nominators and validators will not be affected by this update. /// to kick people under the new limits, `chill_other` should be called. - #[pallet::weight(T::WeightInfo::set_staking_limits())] - pub fn set_staking_limits( + #[pallet::weight(T::WeightInfo::set_staking_configs())] + pub fn set_staking_configs( origin: OriginFor, min_nominator_bond: BalanceOf, min_validator_bond: BalanceOf, max_nominator_count: Option, max_validator_count: Option, - threshold: Option, + chill_threshold: Option, + min_commission: Perbill, ) -> DispatchResult { ensure_root(origin)?; MinNominatorBond::::set(min_nominator_bond); MinValidatorBond::::set(min_validator_bond); MaxNominatorsCount::::set(max_nominator_count); MaxValidatorsCount::::set(max_validator_count); - ChillThreshold::::set(threshold); + ChillThreshold::::set(chill_threshold); + MinCommission::::set(min_commission); Ok(()) } diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index f8f37bed0066c..4604351b52305 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4350,7 +4350,15 @@ fn chill_other_works() { ); // Change the minimum bond... but no limits. - assert_ok!(Staking::set_staking_limits(Origin::root(), 1_500, 2_000, None, None, None)); + assert_ok!(Staking::set_staking_configs( + Origin::root(), + 1_500, + 2_000, + None, + None, + None, + Zero::zero() + )); // Still can't chill these users assert_noop!( @@ -4363,13 +4371,14 @@ fn chill_other_works() { ); // Add limits, but no threshold - assert_ok!(Staking::set_staking_limits( + assert_ok!(Staking::set_staking_configs( Origin::root(), 1_500, 2_000, Some(10), Some(10), - None + None, + Zero::zero() )); // Still can't chill these users @@ -4383,13 +4392,14 @@ fn chill_other_works() { ); // Add threshold, but no limits - assert_ok!(Staking::set_staking_limits( + assert_ok!(Staking::set_staking_configs( Origin::root(), 1_500, 2_000, None, None, - Some(Percent::from_percent(0)) + Some(Percent::from_percent(0)), + Zero::zero() )); // Still can't chill these users @@ -4403,13 +4413,14 @@ fn chill_other_works() { ); // Add threshold and limits - assert_ok!(Staking::set_staking_limits( + assert_ok!(Staking::set_staking_configs( Origin::root(), 1_500, 2_000, Some(10), Some(10), - Some(Percent::from_percent(75)) + Some(Percent::from_percent(75)), + Zero::zero() )); // 16 people total because tests start with 2 active one @@ -4447,13 +4458,14 @@ fn capped_stakers_works() { // Change the maximums let max = 10; - assert_ok!(Staking::set_staking_limits( + assert_ok!(Staking::set_staking_configs( Origin::root(), 10, 10, Some(max), Some(max), - Some(Percent::from_percent(0)) + Some(Percent::from_percent(0)), + Zero::zero(), )); // can create `max - validator_count` validators @@ -4516,12 +4528,60 @@ fn capped_stakers_works() { )); // No problem when we set to `None` again - assert_ok!(Staking::set_staking_limits(Origin::root(), 10, 10, None, None, None)); + assert_ok!(Staking::set_staking_configs( + Origin::root(), + 10, + 10, + None, + None, + None, + Zero::zero(), + )); assert_ok!(Staking::nominate(Origin::signed(last_nominator), vec![1])); assert_ok!(Staking::validate(Origin::signed(last_validator), ValidatorPrefs::default())); }) } +#[test] +fn min_commission_works() { + ExtBuilder::default().build_and_execute(|| { + assert_ok!(Staking::validate( + Origin::signed(10), + ValidatorPrefs { commission: Perbill::from_percent(5), blocked: false } + )); + + assert_ok!(Staking::set_staking_configs( + Origin::root(), + 0, + 0, + None, + None, + None, + Perbill::from_percent(10), + )); + + // can't make it less than 10 now + assert_noop!( + Staking::validate( + Origin::signed(10), + ValidatorPrefs { commission: Perbill::from_percent(5), blocked: false } + ), + Error::::CommissionTooLow + ); + + // can only change to higher. + assert_ok!(Staking::validate( + Origin::signed(10), + ValidatorPrefs { commission: Perbill::from_percent(10), blocked: false } + )); + + assert_ok!(Staking::validate( + Origin::signed(10), + ValidatorPrefs { commission: Perbill::from_percent(15), blocked: false } + )); + }) +} + mod sorted_list_provider { use super::*; use frame_election_provider_support::SortedListProvider; diff --git a/frame/staking/src/weights.rs b/frame/staking/src/weights.rs index 32c8dc80da158..0ca819898fbb0 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: 2021-09-04, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-11-29, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: @@ -35,7 +35,6 @@ // --output=./frame/staking/src/weights.rs // --template=./.maintain/frame-weight-template.hbs - #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] @@ -71,7 +70,7 @@ pub trait WeightInfo { fn new_era(v: u32, n: u32, ) -> Weight; fn get_npos_voters(v: u32, n: u32, s: u32, ) -> Weight; fn get_npos_targets(v: u32, ) -> Weight; - fn set_staking_limits() -> Weight; + fn set_staking_configs() -> Weight; fn chill_other() -> Weight; } @@ -85,7 +84,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (73_865_000 as Weight) + (63_660_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -95,7 +94,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (114_296_000 as Weight) + (103_672_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } @@ -109,7 +108,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (121_737_000 as Weight) + (110_884_000 as Weight) .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -118,7 +117,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded_update(s: u32, ) -> Weight { - (51_631_000 as Weight) + (46_379_000 as Weight) // Standard Error: 0 .saturating_add((55_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) @@ -138,12 +137,13 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (101_870_000 as Weight) + (91_303_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(11 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking MinValidatorBond (r:1 w:0) + // Storage: Staking MinCommission (r:1 w:0) // Storage: Staking Validators (r:1 w:1) // Storage: Staking MaxValidatorsCount (r:1 w:0) // Storage: Staking Nominators (r:1 w:1) @@ -153,16 +153,16 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (69_092_000 as Weight) - .saturating_add(T::DbWeight::get().reads(11 as Weight)) + (66_587_000 as Weight) + .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking Nominators (r:1 w:1) fn kick(k: u32, ) -> Weight { - (21_468_000 as Weight) - // Standard Error: 19_000 - .saturating_add((16_415_000 as Weight).saturating_mul(k as Weight)) + (21_153_000 as Weight) + // Standard Error: 16_000 + .saturating_add((13_502_000 as Weight).saturating_mul(k as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(k as Weight))) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(k as Weight))) @@ -179,9 +179,9 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (82_389_000 as Weight) - // Standard Error: 14_000 - .saturating_add((5_597_000 as Weight).saturating_mul(n as Weight)) + (75_456_000 as Weight) + // Standard Error: 12_000 + .saturating_add((5_051_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) .saturating_add(T::DbWeight::get().writes(6 as Weight)) @@ -194,47 +194,47 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (69_655_000 as Weight) + (65_332_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking Payee (r:0 w:1) fn set_payee() -> Weight { - (12_770_000 as Weight) + (11_757_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking Bonded (r:1 w:1) // Storage: Staking Ledger (r:2 w:2) fn set_controller() -> Weight { - (27_756_000 as Weight) + (24_252_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } // Storage: Staking ValidatorCount (r:0 w:1) fn set_validator_count() -> Weight { - (2_446_000 as Weight) + (2_252_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (2_720_000 as Weight) + (2_431_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (2_711_000 as Weight) + (2_397_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era_always() -> Weight { - (2_796_000 as Weight) + (2_423_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking Invulnerables (r:0 w:1) fn set_invulnerables(v: u32, ) -> Weight { - (3_141_000 as Weight) + (2_876_000 as Weight) // Standard Error: 0 .saturating_add((53_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -253,18 +253,18 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:2) fn force_unstake(s: u32, ) -> Weight { - (97_394_000 as Weight) - // Standard Error: 2_000 - .saturating_add((2_370_000 as Weight).saturating_mul(s as Weight)) + (87_540_000 as Weight) + // Standard Error: 1_000 + .saturating_add((1_791_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().writes(12 as Weight)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } // Storage: Staking UnappliedSlashes (r:1 w:1) fn cancel_deferred_slash(s: u32, ) -> Weight { - (2_783_746_000 as Weight) - // Standard Error: 182_000 - .saturating_add((16_223_000 as Weight).saturating_mul(s as Weight)) + (2_769_801_000 as Weight) + // Standard Error: 181_000 + .saturating_add((16_225_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -279,9 +279,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Payee (r:2 w:0) // Storage: System Account (r:2 w:2) fn payout_stakers_dead_controller(n: u32, ) -> Weight { - (109_233_000 as Weight) - // Standard Error: 17_000 - .saturating_add((47_612_000 as Weight).saturating_mul(n as Weight)) + (103_452_000 as Weight) + // Standard Error: 19_000 + .saturating_add((42_909_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) .saturating_add(T::DbWeight::get().writes(2 as Weight)) @@ -299,9 +299,9 @@ impl WeightInfo for SubstrateWeight { // Storage: System Account (r:2 w:2) // Storage: Balances Locks (r:2 w:2) fn payout_stakers_alive_staked(n: u32, ) -> Weight { - (177_392_000 as Weight) - // Standard Error: 20_000 - .saturating_add((60_771_000 as Weight).saturating_mul(n as Weight)) + (145_995_000 as Weight) + // Standard Error: 27_000 + .saturating_add((55_974_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().reads((5 as Weight).saturating_mul(n as Weight))) .saturating_add(T::DbWeight::get().writes(3 as Weight)) @@ -314,9 +314,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (111_858_000 as Weight) - // Standard Error: 4_000 - .saturating_add((36_000 as Weight).saturating_mul(l as Weight)) + (101_568_000 as Weight) + // Standard Error: 2_000 + .saturating_add((66_000 as Weight).saturating_mul(l as Weight)) .saturating_add(T::DbWeight::get().reads(9 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -331,14 +331,15 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 68_000 - .saturating_add((33_495_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 69_000 + .saturating_add((29_939_000 as Weight).saturating_mul(e as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) .saturating_add(T::DbWeight::get().writes((7 as Weight).saturating_mul(e as Weight))) } // Storage: System Account (r:1 w:1) // Storage: Staking Bonded (r:1 w:1) + // Storage: Staking Ledger (r:1 w:1) // Storage: Staking SlashingSpans (r:1 w:1) // Storage: Staking Validators (r:1 w:0) // Storage: Staking Nominators (r:1 w:1) @@ -347,14 +348,13 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) - // Storage: Staking Ledger (r:0 w:1) // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (100_178_000 as Weight) + (96_886_000 as Weight) // Standard Error: 1_000 - .saturating_add((2_358_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(T::DbWeight::get().reads(11 as Weight)) + .saturating_add((1_790_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().writes(12 as Weight)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } @@ -378,10 +378,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn new_era(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 860_000 - .saturating_add((298_721_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 873_000 + .saturating_add((286_141_000 as Weight).saturating_mul(v as Weight)) // Standard Error: 43_000 - .saturating_add((49_427_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((44_712_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(208 as Weight)) .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(v as Weight))) .saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(n as Weight))) @@ -399,12 +399,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Nominators (r:1000 w:0) fn get_npos_voters(v: u32, n: u32, s: u32, ) -> Weight { (0 as Weight) - // Standard Error: 91_000 - .saturating_add((26_605_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 91_000 - .saturating_add((31_481_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 3_122_000 - .saturating_add((16_672_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 87_000 + .saturating_add((24_049_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 87_000 + .saturating_add((27_514_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(204 as Weight)) .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(v as Weight))) .saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(n as Weight))) @@ -413,19 +411,20 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Validators (r:501 w:0) fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 34_000 - .saturating_add((10_558_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 32_000 + .saturating_add((10_128_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(v as Weight))) } + // Storage: Staking MinCommission (r:0 w:1) // Storage: Staking MinValidatorBond (r:0 w:1) // Storage: Staking MaxValidatorsCount (r:0 w:1) // Storage: Staking ChillThreshold (r:0 w:1) // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) - fn set_staking_limits() -> Weight { - (6_353_000 as Weight) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) + fn set_staking_configs() -> Weight { + (6_187_000 as Weight) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking ChillThreshold (r:1 w:0) @@ -438,7 +437,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (83_389_000 as Weight) + (78_282_000 as Weight) .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } @@ -453,7 +452,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (73_865_000 as Weight) + (63_660_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -463,7 +462,7 @@ impl WeightInfo for () { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (114_296_000 as Weight) + (103_672_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } @@ -477,7 +476,7 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (121_737_000 as Weight) + (110_884_000 as Weight) .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -486,7 +485,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded_update(s: u32, ) -> Weight { - (51_631_000 as Weight) + (46_379_000 as Weight) // Standard Error: 0 .saturating_add((55_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) @@ -506,12 +505,13 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (101_870_000 as Weight) + (91_303_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(11 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking MinValidatorBond (r:1 w:0) + // Storage: Staking MinCommission (r:1 w:0) // Storage: Staking Validators (r:1 w:1) // Storage: Staking MaxValidatorsCount (r:1 w:0) // Storage: Staking Nominators (r:1 w:1) @@ -521,16 +521,16 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (69_092_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(11 as Weight)) + (66_587_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking Nominators (r:1 w:1) fn kick(k: u32, ) -> Weight { - (21_468_000 as Weight) - // Standard Error: 19_000 - .saturating_add((16_415_000 as Weight).saturating_mul(k as Weight)) + (21_153_000 as Weight) + // Standard Error: 16_000 + .saturating_add((13_502_000 as Weight).saturating_mul(k as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(k as Weight))) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(k as Weight))) @@ -547,9 +547,9 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (82_389_000 as Weight) - // Standard Error: 14_000 - .saturating_add((5_597_000 as Weight).saturating_mul(n as Weight)) + (75_456_000 as Weight) + // Standard Error: 12_000 + .saturating_add((5_051_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) @@ -562,47 +562,47 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (69_655_000 as Weight) + (65_332_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking Payee (r:0 w:1) fn set_payee() -> Weight { - (12_770_000 as Weight) + (11_757_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking Bonded (r:1 w:1) // Storage: Staking Ledger (r:2 w:2) fn set_controller() -> Weight { - (27_756_000 as Weight) + (24_252_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } // Storage: Staking ValidatorCount (r:0 w:1) fn set_validator_count() -> Weight { - (2_446_000 as Weight) + (2_252_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (2_720_000 as Weight) + (2_431_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (2_711_000 as Weight) + (2_397_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era_always() -> Weight { - (2_796_000 as Weight) + (2_423_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking Invulnerables (r:0 w:1) fn set_invulnerables(v: u32, ) -> Weight { - (3_141_000 as Weight) + (2_876_000 as Weight) // Standard Error: 0 .saturating_add((53_000 as Weight).saturating_mul(v as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) @@ -621,18 +621,18 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:2) fn force_unstake(s: u32, ) -> Weight { - (97_394_000 as Weight) - // Standard Error: 2_000 - .saturating_add((2_370_000 as Weight).saturating_mul(s as Weight)) + (87_540_000 as Weight) + // Standard Error: 1_000 + .saturating_add((1_791_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().writes(12 as Weight)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } // Storage: Staking UnappliedSlashes (r:1 w:1) fn cancel_deferred_slash(s: u32, ) -> Weight { - (2_783_746_000 as Weight) - // Standard Error: 182_000 - .saturating_add((16_223_000 as Weight).saturating_mul(s as Weight)) + (2_769_801_000 as Weight) + // Standard Error: 181_000 + .saturating_add((16_225_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -647,9 +647,9 @@ impl WeightInfo for () { // Storage: Staking Payee (r:2 w:0) // Storage: System Account (r:2 w:2) fn payout_stakers_dead_controller(n: u32, ) -> Weight { - (109_233_000 as Weight) - // Standard Error: 17_000 - .saturating_add((47_612_000 as Weight).saturating_mul(n as Weight)) + (103_452_000 as Weight) + // Standard Error: 19_000 + .saturating_add((42_909_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) @@ -667,9 +667,9 @@ impl WeightInfo for () { // Storage: System Account (r:2 w:2) // Storage: Balances Locks (r:2 w:2) fn payout_stakers_alive_staked(n: u32, ) -> Weight { - (177_392_000 as Weight) - // Standard Error: 20_000 - .saturating_add((60_771_000 as Weight).saturating_mul(n as Weight)) + (145_995_000 as Weight) + // Standard Error: 27_000 + .saturating_add((55_974_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().reads((5 as Weight).saturating_mul(n as Weight))) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) @@ -682,9 +682,9 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (111_858_000 as Weight) - // Standard Error: 4_000 - .saturating_add((36_000 as Weight).saturating_mul(l as Weight)) + (101_568_000 as Weight) + // Standard Error: 2_000 + .saturating_add((66_000 as Weight).saturating_mul(l as Weight)) .saturating_add(RocksDbWeight::get().reads(9 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -699,14 +699,15 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 68_000 - .saturating_add((33_495_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 69_000 + .saturating_add((29_939_000 as Weight).saturating_mul(e as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) .saturating_add(RocksDbWeight::get().writes((7 as Weight).saturating_mul(e as Weight))) } // Storage: System Account (r:1 w:1) // Storage: Staking Bonded (r:1 w:1) + // Storage: Staking Ledger (r:1 w:1) // Storage: Staking SlashingSpans (r:1 w:1) // Storage: Staking Validators (r:1 w:0) // Storage: Staking Nominators (r:1 w:1) @@ -715,14 +716,13 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) - // Storage: Staking Ledger (r:0 w:1) // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (100_178_000 as Weight) + (96_886_000 as Weight) // Standard Error: 1_000 - .saturating_add((2_358_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(RocksDbWeight::get().reads(11 as Weight)) + .saturating_add((1_790_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().writes(12 as Weight)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } @@ -746,10 +746,10 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn new_era(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 860_000 - .saturating_add((298_721_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 873_000 + .saturating_add((286_141_000 as Weight).saturating_mul(v as Weight)) // Standard Error: 43_000 - .saturating_add((49_427_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((44_712_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(208 as Weight)) .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(v as Weight))) .saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(n as Weight))) @@ -767,12 +767,10 @@ impl WeightInfo for () { // Storage: Staking Nominators (r:1000 w:0) fn get_npos_voters(v: u32, n: u32, s: u32, ) -> Weight { (0 as Weight) - // Standard Error: 91_000 - .saturating_add((26_605_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 91_000 - .saturating_add((31_481_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 3_122_000 - .saturating_add((16_672_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 87_000 + .saturating_add((24_049_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 87_000 + .saturating_add((27_514_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(204 as Weight)) .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(v as Weight))) .saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(n as Weight))) @@ -781,19 +779,20 @@ impl WeightInfo for () { // Storage: Staking Validators (r:501 w:0) fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 34_000 - .saturating_add((10_558_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 32_000 + .saturating_add((10_128_000 as Weight).saturating_mul(v as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(v as Weight))) } + // Storage: Staking MinCommission (r:0 w:1) // Storage: Staking MinValidatorBond (r:0 w:1) // Storage: Staking MaxValidatorsCount (r:0 w:1) // Storage: Staking ChillThreshold (r:0 w:1) // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) - fn set_staking_limits() -> Weight { - (6_353_000 as Weight) - .saturating_add(RocksDbWeight::get().writes(5 as Weight)) + fn set_staking_configs() -> Weight { + (6_187_000 as Weight) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) // Storage: Staking ChillThreshold (r:1 w:0) @@ -806,7 +805,7 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (83_389_000 as Weight) + (78_282_000 as Weight) .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } diff --git a/primitives/arithmetic/src/per_things.rs b/primitives/arithmetic/src/per_things.rs index f388c19de6b43..783b331b33532 100644 --- a/primitives/arithmetic/src/per_things.rs +++ b/primitives/arithmetic/src/per_things.rs @@ -833,6 +833,16 @@ macro_rules! implement_per_thing { } } + impl $crate::traits::Zero for $name { + fn zero() -> Self { + Self::zero() + } + + fn is_zero(&self) -> bool { + self == &Self::zero() + } + } + #[cfg(test)] mod $test_mod {