From 79e68ba6aef282981e0c708bc7111e7ff8258ae4 Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Wed, 2 Feb 2022 19:45:05 -0800 Subject: [PATCH 01/21] pallet-staking: Add extrinsic `force_apply_min_commission` --- frame/staking/src/pallet/mod.rs | 16 ++++++++++++++ frame/staking/src/tests.rs | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 2a870fda063d3..5334effbdc623 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -1616,6 +1616,22 @@ pub mod pallet { Self::chill_stash(&stash); Ok(()) } + + /// Force all validators to have at least the minimum commission. This will not affect + /// validators who already have a commission greater than or equal to the min. + #[pallet::weight(666)] + pub fn force_apply_min_commission(origin: OriginFor) -> DispatchResult { + ensure_root(origin)?; + let min_commission = MinCommission::::get(); + Validators::::translate(|_, mut prefs: ValidatorPrefs| { + if prefs.commission < min_commission { + prefs.commission = min_commission + } + + Some(prefs) + }); + Ok(()) + } } } diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index 538b75ead340b..8366c1b6e66f8 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4711,3 +4711,40 @@ mod sorted_list_provider { }); } } + +#[test] +fn force_apply_min_commission_works() { + let prefs = |c| ValidatorPrefs { commission: Perbill::from_percent(c), blocked: false }; + let validators = || Validators::::iter().collect::>(); + ExtBuilder::default().build_and_execute(|| { + + // Given all validators have a commission of 0 + assert_eq!(validators(), vec![(31, prefs(0)), (21, prefs(0)), (11, prefs(0))]); + // and the min commission is 0 + assert_eq!(MinCommission::::get(), Perbill::from_percent(0)); + + // When + assert_ok!(Staking::force_apply_min_commission(Origin::root())); + + // Then + assert_eq!(validators(), vec![(31, prefs(0)), (21, prefs(0)), (11, prefs(0))]); + + // Given + assert_ok!(Staking::validate(Origin::signed(30), prefs(10))); + + // When + assert_ok!(Staking::force_apply_min_commission(Origin::root())); + + // Then + assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(0)), (11, prefs(0))]); + + // Given + MinCommission::::set(Perbill::from_percent(5)); + + // When + assert_ok!(Staking::force_apply_min_commission(Origin::root())); + + // Then + assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); + }); +} \ No newline at end of file From 62f35786a05fe720fd307b4f68432f31b612a8b3 Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Wed, 2 Feb 2022 20:12:38 -0800 Subject: [PATCH 02/21] Add benchmarks --- frame/staking/src/benchmarking.rs | 21 +++++++++++++++++++++ frame/staking/src/pallet/mod.rs | 12 +++++++++--- frame/staking/src/tests.rs | 9 ++++----- frame/staking/src/weights.rs | 11 +++++++++++ 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index 564172d912413..d881f16010e3e 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -900,6 +900,27 @@ benchmarks! { assert!(!T::SortedListProvider::contains(&stash)); } + force_apply_min_commission { + let i in 1..MaxValidators::::get(); + // Clean up any existing state + clear_validators_and_nominators::(); + + // Create `i` validators with a commission of 50% + frame_support::assert_ok!(create_validators::(i, 1)); + + // Sanity check that all the generated validators have the expected commission + for (_, prefs) in Validators::::iter() { + assert_eq!(prefs.commission, Perbill::from_percent(50)); + } + // Set the min commission to 75% + MinCommission::::set(Perbill::from_percent(75)); + }: _(RawOrigin::Root, 0) + verify { + for (_, prefs) in Validators::::iter() { + assert_eq!(prefs.commission, Perbill::from_percent(75)); + } + } + impl_benchmark_test_suite!( Staking, crate::mock::ExtBuilder::default().has_stakers(true), diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 5334effbdc623..1ea82563d573a 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -1618,9 +1618,15 @@ pub mod pallet { } /// Force all validators to have at least the minimum commission. This will not affect - /// validators who already have a commission greater than or equal to the min. - #[pallet::weight(666)] - pub fn force_apply_min_commission(origin: OriginFor) -> DispatchResult { + /// validators who already have a commission greater than or equal to the minimum. + /// + /// Note that parameter `_validator_count` should be the upper bound of the number of + /// validators stored and is only used for weights. + #[pallet::weight(T::WeightInfo::force_apply_min_commission(*_validator_count))] + pub fn force_apply_min_commission( + origin: OriginFor, + _validator_count: u32, + ) -> DispatchResult { ensure_root(origin)?; let min_commission = MinCommission::::get(); Validators::::translate(|_, mut prefs: ValidatorPrefs| { diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index 8366c1b6e66f8..2af6650ceb8b4 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4717,14 +4717,13 @@ fn force_apply_min_commission_works() { let prefs = |c| ValidatorPrefs { commission: Perbill::from_percent(c), blocked: false }; let validators = || Validators::::iter().collect::>(); ExtBuilder::default().build_and_execute(|| { - // Given all validators have a commission of 0 assert_eq!(validators(), vec![(31, prefs(0)), (21, prefs(0)), (11, prefs(0))]); // and the min commission is 0 assert_eq!(MinCommission::::get(), Perbill::from_percent(0)); // When - assert_ok!(Staking::force_apply_min_commission(Origin::root())); + assert_ok!(Staking::force_apply_min_commission(Origin::root(), 0)); // Then assert_eq!(validators(), vec![(31, prefs(0)), (21, prefs(0)), (11, prefs(0))]); @@ -4733,7 +4732,7 @@ fn force_apply_min_commission_works() { assert_ok!(Staking::validate(Origin::signed(30), prefs(10))); // When - assert_ok!(Staking::force_apply_min_commission(Origin::root())); + assert_ok!(Staking::force_apply_min_commission(Origin::root(), 0)); // Then assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(0)), (11, prefs(0))]); @@ -4742,9 +4741,9 @@ fn force_apply_min_commission_works() { MinCommission::::set(Perbill::from_percent(5)); // When - assert_ok!(Staking::force_apply_min_commission(Origin::root())); + assert_ok!(Staking::force_apply_min_commission(Origin::root(), 0)); // Then assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); }); -} \ No newline at end of file +} diff --git a/frame/staking/src/weights.rs b/frame/staking/src/weights.rs index 42f762c721e4c..1614c362c6cca 100644 --- a/frame/staking/src/weights.rs +++ b/frame/staking/src/weights.rs @@ -74,6 +74,7 @@ pub trait WeightInfo { fn get_npos_targets(v: u32, ) -> Weight; fn set_staking_configs() -> Weight; fn chill_other() -> Weight; + fn force_apply_min_commission(n: u32) -> Weight; } /// Weights for pallet_staking using the Substrate node and recommended hardware. @@ -445,6 +446,11 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } + fn force_apply_min_commission(_n: u32) -> Weight { + (54_681_000 as Weight) + .saturating_add(T::DbWeight::get().reads(11 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) + } } // For backwards compatibility and tests @@ -815,4 +821,9 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } + fn force_apply_min_commission(_n: u32) -> Weight { + (54_681_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(11 as Weight)) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + } } From ada4198b0922536a04bbbd6837d9f362cffbb213 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Thu, 3 Feb 2022 05:13:26 +0000 Subject: [PATCH 03/21] cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/staking/src/weights.rs | 244 ++++++++++++++++++----------------- 1 file changed, 124 insertions(+), 120 deletions(-) diff --git a/frame/staking/src/weights.rs b/frame/staking/src/weights.rs index 1614c362c6cca..b355c0e8cfb95 100644 --- a/frame/staking/src/weights.rs +++ b/frame/staking/src/weights.rs @@ -18,11 +18,11 @@ //! Autogenerated weights for pallet_staking //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-01-31, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-02-03, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: -// ./target/production/substrate +// target/production/substrate // benchmark // --chain=dev // --steps=50 @@ -33,9 +33,7 @@ // --wasm-execution=compiled // --heap-pages=4096 // --output=./frame/staking/src/weights.rs -// --template=.maintain/frame-weight-template.hbs -// --header=HEADER-APACHE2 -// --raw +// --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -74,7 +72,7 @@ pub trait WeightInfo { fn get_npos_targets(v: u32, ) -> Weight; fn set_staking_configs() -> Weight; fn chill_other() -> Weight; - fn force_apply_min_commission(n: u32) -> Weight; + fn force_apply_min_commission(i: u32, ) -> Weight; } /// Weights for pallet_staking using the Substrate node and recommended hardware. @@ -87,7 +85,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (37_688_000 as Weight) + (37_595_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -97,7 +95,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (63_507_000 as Weight) + (65_492_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } @@ -111,7 +109,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (70_634_000 as Weight) + (71_995_000 as Weight) .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -120,9 +118,9 @@ 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 { - (30_002_000 as Weight) + (30_409_000 as Weight) // Standard Error: 0 - .saturating_add((55_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((54_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -140,7 +138,7 @@ 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 { - (58_077_000 as Weight) + (59_308_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(11 as Weight)) } @@ -156,16 +154,16 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (44_603_000 as Weight) + (45_843_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 { - (14_580_000 as Weight) - // Standard Error: 13_000 - .saturating_add((8_076_000 as Weight).saturating_mul(k as Weight)) + (18_827_000 as Weight) + // Standard Error: 12_000 + .saturating_add((8_180_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))) @@ -182,9 +180,9 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (49_856_000 as Weight) - // Standard Error: 8_000 - .saturating_add((3_430_000 as Weight).saturating_mul(n as Weight)) + (51_330_000 as Weight) + // Standard Error: 11_000 + .saturating_add((3_429_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)) @@ -197,37 +195,37 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (43_815_000 as Weight) + (45_106_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 { - (7_553_000 as Weight) + (7_825_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 { - (15_177_000 as Weight) + (15_965_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 { - (1_090_000 as Weight) + (1_159_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (1_169_000 as Weight) + (1_116_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (1_089_000 as Weight) + (1_136_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) @@ -237,9 +235,9 @@ impl WeightInfo for SubstrateWeight { } // Storage: Staking Invulnerables (r:0 w:1) fn set_invulnerables(v: u32, ) -> Weight { - (1_612_000 as Weight) + (1_540_000 as Weight) // Standard Error: 0 - .saturating_add((50_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((54_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking Bonded (r:1 w:1) @@ -256,18 +254,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 { - (56_103_000 as Weight) + (57_524_000 as Weight) // Standard Error: 1_000 - .saturating_add((798_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((796_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 { - (942_911_000 as Weight) - // Standard Error: 55_000 - .saturating_add((4_973_000 as Weight).saturating_mul(s as Weight)) + (949_701_000 as Weight) + // Standard Error: 56_000 + .saturating_add((4_990_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)) } @@ -282,9 +280,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 { - (77_948_000 as Weight) - // Standard Error: 13_000 - .saturating_add((23_507_000 as Weight).saturating_mul(n as Weight)) + (83_857_000 as Weight) + // Standard Error: 17_000 + .saturating_add((23_927_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)) @@ -302,9 +300,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 { - (94_386_000 as Weight) - // Standard Error: 19_000 - .saturating_add((32_763_000 as Weight).saturating_mul(n as Weight)) + (107_020_000 as Weight) + // Standard Error: 22_000 + .saturating_add((33_246_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)) @@ -317,9 +315,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (63_577_000 as Weight) - // Standard Error: 2_000 - .saturating_add((47_000 as Weight).saturating_mul(l as Weight)) + (66_178_000 as Weight) + // Standard Error: 4_000 + .saturating_add((7_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)) } @@ -334,8 +332,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 57_000 - .saturating_add((19_691_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 64_000 + .saturating_add((20_566_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))) @@ -354,9 +352,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (61_871_000 as Weight) - // Standard Error: 0 - .saturating_add((796_000 as Weight).saturating_mul(s as Weight)) + (62_752_000 as Weight) + // Standard Error: 1_000 + .saturating_add((807_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))) @@ -381,10 +379,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: 823_000 - .saturating_add((218_725_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 41_000 - .saturating_add((31_349_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 914_000 + .saturating_add((220_871_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 45_000 + .saturating_add((31_496_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))) @@ -402,12 +400,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: 86_000 - .saturating_add((18_168_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 86_000 - .saturating_add((21_061_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 2_951_000 - .saturating_add((8_164_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 98_000 + .saturating_add((18_340_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 98_000 + .saturating_add((21_225_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))) @@ -417,7 +413,7 @@ impl WeightInfo for SubstrateWeight { fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) // Standard Error: 29_000 - .saturating_add((7_761_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((7_785_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))) } @@ -428,7 +424,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs() -> Weight { - (3_586_000 as Weight) + (3_421_000 as Weight) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -442,14 +438,19 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (54_681_000 as Weight) + (55_521_000 as Weight) .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } - fn force_apply_min_commission(_n: u32) -> Weight { - (54_681_000 as Weight) - .saturating_add(T::DbWeight::get().reads(11 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) + // Storage: Staking MinCommission (r:1 w:0) + // Storage: Staking Validators (r:2 w:1) + fn force_apply_min_commission(i: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 13_000 + .saturating_add((8_050_000 as Weight).saturating_mul(i as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight))) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } } @@ -462,7 +463,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (37_688_000 as Weight) + (37_595_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -472,7 +473,7 @@ impl WeightInfo for () { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (63_507_000 as Weight) + (65_492_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } @@ -486,7 +487,7 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (70_634_000 as Weight) + (71_995_000 as Weight) .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -495,9 +496,9 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded_update(s: u32, ) -> Weight { - (30_002_000 as Weight) + (30_409_000 as Weight) // Standard Error: 0 - .saturating_add((55_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((54_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -515,7 +516,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (58_077_000 as Weight) + (59_308_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(11 as Weight)) } @@ -531,16 +532,16 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (44_603_000 as Weight) + (45_843_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 { - (14_580_000 as Weight) - // Standard Error: 13_000 - .saturating_add((8_076_000 as Weight).saturating_mul(k as Weight)) + (18_827_000 as Weight) + // Standard Error: 12_000 + .saturating_add((8_180_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))) @@ -557,9 +558,9 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (49_856_000 as Weight) - // Standard Error: 8_000 - .saturating_add((3_430_000 as Weight).saturating_mul(n as Weight)) + (51_330_000 as Weight) + // Standard Error: 11_000 + .saturating_add((3_429_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)) @@ -572,37 +573,37 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (43_815_000 as Weight) + (45_106_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 { - (7_553_000 as Weight) + (7_825_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 { - (15_177_000 as Weight) + (15_965_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 { - (1_090_000 as Weight) + (1_159_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (1_169_000 as Weight) + (1_116_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (1_089_000 as Weight) + (1_136_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) @@ -612,9 +613,9 @@ impl WeightInfo for () { } // Storage: Staking Invulnerables (r:0 w:1) fn set_invulnerables(v: u32, ) -> Weight { - (1_612_000 as Weight) + (1_540_000 as Weight) // Standard Error: 0 - .saturating_add((50_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((54_000 as Weight).saturating_mul(v as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking Bonded (r:1 w:1) @@ -631,18 +632,18 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:2) fn force_unstake(s: u32, ) -> Weight { - (56_103_000 as Weight) + (57_524_000 as Weight) // Standard Error: 1_000 - .saturating_add((798_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((796_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 { - (942_911_000 as Weight) - // Standard Error: 55_000 - .saturating_add((4_973_000 as Weight).saturating_mul(s as Weight)) + (949_701_000 as Weight) + // Standard Error: 56_000 + .saturating_add((4_990_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -657,9 +658,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 { - (77_948_000 as Weight) - // Standard Error: 13_000 - .saturating_add((23_507_000 as Weight).saturating_mul(n as Weight)) + (83_857_000 as Weight) + // Standard Error: 17_000 + .saturating_add((23_927_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)) @@ -677,9 +678,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 { - (94_386_000 as Weight) - // Standard Error: 19_000 - .saturating_add((32_763_000 as Weight).saturating_mul(n as Weight)) + (107_020_000 as Weight) + // Standard Error: 22_000 + .saturating_add((33_246_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)) @@ -692,9 +693,9 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (63_577_000 as Weight) - // Standard Error: 2_000 - .saturating_add((47_000 as Weight).saturating_mul(l as Weight)) + (66_178_000 as Weight) + // Standard Error: 4_000 + .saturating_add((7_000 as Weight).saturating_mul(l as Weight)) .saturating_add(RocksDbWeight::get().reads(9 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -709,8 +710,8 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 57_000 - .saturating_add((19_691_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 64_000 + .saturating_add((20_566_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))) @@ -729,9 +730,9 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (61_871_000 as Weight) - // Standard Error: 0 - .saturating_add((796_000 as Weight).saturating_mul(s as Weight)) + (62_752_000 as Weight) + // Standard Error: 1_000 + .saturating_add((807_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))) @@ -756,10 +757,10 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn new_era(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 823_000 - .saturating_add((218_725_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 41_000 - .saturating_add((31_349_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 914_000 + .saturating_add((220_871_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 45_000 + .saturating_add((31_496_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))) @@ -777,12 +778,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: 86_000 - .saturating_add((18_168_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 86_000 - .saturating_add((21_061_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 2_951_000 - .saturating_add((8_164_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 98_000 + .saturating_add((18_340_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 98_000 + .saturating_add((21_225_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))) @@ -792,7 +791,7 @@ impl WeightInfo for () { fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) // Standard Error: 29_000 - .saturating_add((7_761_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((7_785_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))) } @@ -803,7 +802,7 @@ impl WeightInfo for () { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs() -> Weight { - (3_586_000 as Weight) + (3_421_000 as Weight) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -817,13 +816,18 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (54_681_000 as Weight) + (55_521_000 as Weight) .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } - fn force_apply_min_commission(_n: u32) -> Weight { - (54_681_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(11 as Weight)) - .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + // Storage: Staking MinCommission (r:1 w:0) + // Storage: Staking Validators (r:2 w:1) + fn force_apply_min_commission(i: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 13_000 + .saturating_add((8_050_000 as Weight).saturating_mul(i as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(i as Weight))) + .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } } From 2cd137dc1e0f47ef7a46cea88bf5eaf9d2b4d1ce Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Thu, 3 Feb 2022 09:25:47 -0800 Subject: [PATCH 04/21] Bound iteration by max_validator_count --- frame/staking/src/benchmarking.rs | 2 +- frame/staking/src/pallet/mod.rs | 23 +++++++++++++++++------ frame/staking/src/tests.rs | 15 ++++++++++++--- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index d881f16010e3e..5076fee5d30b7 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -914,7 +914,7 @@ benchmarks! { } // Set the min commission to 75% MinCommission::::set(Perbill::from_percent(75)); - }: _(RawOrigin::Root, 0) + }: _(RawOrigin::Root, i) verify { for (_, prefs) in Validators::::iter() { assert_eq!(prefs.commission, Perbill::from_percent(75)); diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 1ea82563d573a..b8bc7252dd0b0 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -1622,20 +1622,31 @@ pub mod pallet { /// /// Note that parameter `_validator_count` should be the upper bound of the number of /// validators stored and is only used for weights. - #[pallet::weight(T::WeightInfo::force_apply_min_commission(*_validator_count))] + #[pallet::weight(T::WeightInfo::force_apply_min_commission(*max_validator_count))] pub fn force_apply_min_commission( origin: OriginFor, - _validator_count: u32, + max_validator_count: u32, ) -> DispatchResult { ensure_root(origin)?; let min_commission = MinCommission::::get(); - Validators::::translate(|_, mut prefs: ValidatorPrefs| { + let mut validators_to_update = Vec::with_capacity(max_validator_count as usize); + + for (index, (validator_id, mut prefs)) in Validators::::iter().enumerate() { + if index as u32 >= max_validator_count { + log!(trace, "max_validator_count is less than the number of validators"); + break + } + if prefs.commission < min_commission { - prefs.commission = min_commission + prefs.commission = min_commission; + validators_to_update.push((validator_id, prefs)); } + } + + for (validator_id, prefs) in validators_to_update { + Validators::::insert(validator_id, prefs) + } - Some(prefs) - }); Ok(()) } } diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index 2af6650ceb8b4..c20989ca3f3e0 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4723,7 +4723,7 @@ fn force_apply_min_commission_works() { assert_eq!(MinCommission::::get(), Perbill::from_percent(0)); // When - assert_ok!(Staking::force_apply_min_commission(Origin::root(), 0)); + assert_ok!(Staking::force_apply_min_commission(Origin::root(), 3)); // Then assert_eq!(validators(), vec![(31, prefs(0)), (21, prefs(0)), (11, prefs(0))]); @@ -4732,7 +4732,7 @@ fn force_apply_min_commission_works() { assert_ok!(Staking::validate(Origin::signed(30), prefs(10))); // When - assert_ok!(Staking::force_apply_min_commission(Origin::root(), 0)); + assert_ok!(Staking::force_apply_min_commission(Origin::root(), 3)); // Then assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(0)), (11, prefs(0))]); @@ -4741,9 +4741,18 @@ fn force_apply_min_commission_works() { MinCommission::::set(Perbill::from_percent(5)); // When - assert_ok!(Staking::force_apply_min_commission(Origin::root(), 0)); + assert_ok!(Staking::force_apply_min_commission(Origin::root(), 3)); // Then assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); + + // Given + MinCommission::::set(Perbill::from_percent(6)); + + // When we call with a `max_validator_count` of 2 + assert_ok!(Staking::force_apply_min_commission(Origin::root(), 2)); + + // Then only the first two validators are affected + assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(6)), (11, prefs(5))]); }); } From 89119d2273b05c98ee28c0df10691bbfd8f4f661 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Thu, 3 Feb 2022 18:17:47 +0000 Subject: [PATCH 05/21] cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/staking/src/weights.rs | 200 ++++++++++++++++++----------------- 1 file changed, 102 insertions(+), 98 deletions(-) diff --git a/frame/staking/src/weights.rs b/frame/staking/src/weights.rs index b355c0e8cfb95..9e2c2750154e7 100644 --- a/frame/staking/src/weights.rs +++ b/frame/staking/src/weights.rs @@ -85,7 +85,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (37_595_000 as Weight) + (37_187_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -95,7 +95,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (65_492_000 as Weight) + (64_679_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } @@ -109,7 +109,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (71_995_000 as Weight) + (70_369_000 as Weight) .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -118,9 +118,9 @@ 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 { - (30_409_000 as Weight) + (30_513_000 as Weight) // Standard Error: 0 - .saturating_add((54_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((52_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -138,7 +138,7 @@ 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 { - (59_308_000 as Weight) + (58_352_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(11 as Weight)) } @@ -154,16 +154,16 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (45_843_000 as Weight) + (44_402_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 { - (18_827_000 as Weight) + (14_702_000 as Weight) // Standard Error: 12_000 - .saturating_add((8_180_000 as Weight).saturating_mul(k as Weight)) + .saturating_add((8_131_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))) @@ -180,9 +180,9 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (51_330_000 as Weight) - // Standard Error: 11_000 - .saturating_add((3_429_000 as Weight).saturating_mul(n as Weight)) + (50_113_000 as Weight) + // Standard Error: 15_000 + .saturating_add((3_456_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)) @@ -195,49 +195,49 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (45_106_000 as Weight) + (44_751_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 { - (7_825_000 as Weight) + (7_991_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 { - (15_965_000 as Weight) + (15_882_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 { - (1_159_000 as Weight) + (1_154_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (1_116_000 as Weight) + (1_202_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (1_136_000 as Weight) + (1_217_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 { - (1_144_000 as Weight) + (1_232_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 { - (1_540_000 as Weight) + (1_734_000 as Weight) // Standard Error: 0 - .saturating_add((54_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((51_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking Bonded (r:1 w:1) @@ -254,18 +254,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 { - (57_524_000 as Weight) + (56_723_000 as Weight) // Standard Error: 1_000 - .saturating_add((796_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((804_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 { - (949_701_000 as Weight) + (944_999_000 as Weight) // Standard Error: 56_000 - .saturating_add((4_990_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((4_996_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)) } @@ -280,9 +280,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 { - (83_857_000 as Weight) - // Standard Error: 17_000 - .saturating_add((23_927_000 as Weight).saturating_mul(n as Weight)) + (79_959_000 as Weight) + // Standard Error: 14_000 + .saturating_add((23_431_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)) @@ -300,9 +300,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 { - (107_020_000 as Weight) + (113_794_000 as Weight) // Standard Error: 22_000 - .saturating_add((33_246_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((32_859_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)) @@ -315,9 +315,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (66_178_000 as Weight) + (64_211_000 as Weight) // Standard Error: 4_000 - .saturating_add((7_000 as Weight).saturating_mul(l as Weight)) + .saturating_add((45_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)) } @@ -332,8 +332,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 64_000 - .saturating_add((20_566_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 60_000 + .saturating_add((20_811_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))) @@ -352,9 +352,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (62_752_000 as Weight) - // Standard Error: 1_000 - .saturating_add((807_000 as Weight).saturating_mul(s as Weight)) + (62_434_000 as Weight) + // Standard Error: 0 + .saturating_add((804_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))) @@ -379,10 +379,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: 914_000 - .saturating_add((220_871_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 896_000 + .saturating_add((227_004_000 as Weight).saturating_mul(v as Weight)) // Standard Error: 45_000 - .saturating_add((31_496_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((31_665_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))) @@ -400,10 +400,12 @@ 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: 98_000 - .saturating_add((18_340_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 98_000 - .saturating_add((21_225_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 89_000 + .saturating_add((19_105_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 89_000 + .saturating_add((21_888_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 3_054_000 + .saturating_add((6_771_000 as Weight).saturating_mul(s 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))) @@ -412,8 +414,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Validators (r:501 w:0) fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 29_000 - .saturating_add((7_785_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 26_000 + .saturating_add((7_719_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))) } @@ -424,7 +426,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs() -> Weight { - (3_421_000 as Weight) + (3_536_000 as Weight) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -438,7 +440,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (55_521_000 as Weight) + (55_532_000 as Weight) .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } @@ -447,7 +449,7 @@ impl WeightInfo for SubstrateWeight { fn force_apply_min_commission(i: u32, ) -> Weight { (0 as Weight) // Standard Error: 13_000 - .saturating_add((8_050_000 as Weight).saturating_mul(i as Weight)) + .saturating_add((9_070_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight))) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) @@ -463,7 +465,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (37_595_000 as Weight) + (37_187_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -473,7 +475,7 @@ impl WeightInfo for () { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (65_492_000 as Weight) + (64_679_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } @@ -487,7 +489,7 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (71_995_000 as Weight) + (70_369_000 as Weight) .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -496,9 +498,9 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded_update(s: u32, ) -> Weight { - (30_409_000 as Weight) + (30_513_000 as Weight) // Standard Error: 0 - .saturating_add((54_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((52_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -516,7 +518,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (59_308_000 as Weight) + (58_352_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(11 as Weight)) } @@ -532,16 +534,16 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (45_843_000 as Weight) + (44_402_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 { - (18_827_000 as Weight) + (14_702_000 as Weight) // Standard Error: 12_000 - .saturating_add((8_180_000 as Weight).saturating_mul(k as Weight)) + .saturating_add((8_131_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))) @@ -558,9 +560,9 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (51_330_000 as Weight) - // Standard Error: 11_000 - .saturating_add((3_429_000 as Weight).saturating_mul(n as Weight)) + (50_113_000 as Weight) + // Standard Error: 15_000 + .saturating_add((3_456_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)) @@ -573,49 +575,49 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (45_106_000 as Weight) + (44_751_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 { - (7_825_000 as Weight) + (7_991_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 { - (15_965_000 as Weight) + (15_882_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 { - (1_159_000 as Weight) + (1_154_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (1_116_000 as Weight) + (1_202_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (1_136_000 as Weight) + (1_217_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era_always() -> Weight { - (1_144_000 as Weight) + (1_232_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking Invulnerables (r:0 w:1) fn set_invulnerables(v: u32, ) -> Weight { - (1_540_000 as Weight) + (1_734_000 as Weight) // Standard Error: 0 - .saturating_add((54_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((51_000 as Weight).saturating_mul(v as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking Bonded (r:1 w:1) @@ -632,18 +634,18 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:2) fn force_unstake(s: u32, ) -> Weight { - (57_524_000 as Weight) + (56_723_000 as Weight) // Standard Error: 1_000 - .saturating_add((796_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((804_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 { - (949_701_000 as Weight) + (944_999_000 as Weight) // Standard Error: 56_000 - .saturating_add((4_990_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((4_996_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -658,9 +660,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 { - (83_857_000 as Weight) - // Standard Error: 17_000 - .saturating_add((23_927_000 as Weight).saturating_mul(n as Weight)) + (79_959_000 as Weight) + // Standard Error: 14_000 + .saturating_add((23_431_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)) @@ -678,9 +680,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 { - (107_020_000 as Weight) + (113_794_000 as Weight) // Standard Error: 22_000 - .saturating_add((33_246_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((32_859_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)) @@ -693,9 +695,9 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (66_178_000 as Weight) + (64_211_000 as Weight) // Standard Error: 4_000 - .saturating_add((7_000 as Weight).saturating_mul(l as Weight)) + .saturating_add((45_000 as Weight).saturating_mul(l as Weight)) .saturating_add(RocksDbWeight::get().reads(9 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -710,8 +712,8 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 64_000 - .saturating_add((20_566_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 60_000 + .saturating_add((20_811_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))) @@ -730,9 +732,9 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (62_752_000 as Weight) - // Standard Error: 1_000 - .saturating_add((807_000 as Weight).saturating_mul(s as Weight)) + (62_434_000 as Weight) + // Standard Error: 0 + .saturating_add((804_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))) @@ -757,10 +759,10 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn new_era(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 914_000 - .saturating_add((220_871_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 896_000 + .saturating_add((227_004_000 as Weight).saturating_mul(v as Weight)) // Standard Error: 45_000 - .saturating_add((31_496_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((31_665_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))) @@ -778,10 +780,12 @@ 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: 98_000 - .saturating_add((18_340_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 98_000 - .saturating_add((21_225_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 89_000 + .saturating_add((19_105_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 89_000 + .saturating_add((21_888_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 3_054_000 + .saturating_add((6_771_000 as Weight).saturating_mul(s 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))) @@ -790,8 +794,8 @@ impl WeightInfo for () { // Storage: Staking Validators (r:501 w:0) fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 29_000 - .saturating_add((7_785_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 26_000 + .saturating_add((7_719_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))) } @@ -802,7 +806,7 @@ impl WeightInfo for () { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs() -> Weight { - (3_421_000 as Weight) + (3_536_000 as Weight) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -816,7 +820,7 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (55_521_000 as Weight) + (55_532_000 as Weight) .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } @@ -825,7 +829,7 @@ impl WeightInfo for () { fn force_apply_min_commission(i: u32, ) -> Weight { (0 as Weight) // Standard Error: 13_000 - .saturating_add((8_050_000 as Weight).saturating_mul(i as Weight)) + .saturating_add((9_070_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(i as Weight))) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) From 407760601d4692630e661a618813d43d6ab11c58 Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Mon, 7 Feb 2022 20:18:11 -0800 Subject: [PATCH 06/21] Only apply to 1 validator --- frame/staking/src/benchmarking.rs | 29 ++++++++++------ frame/staking/src/pallet/mod.rs | 27 +++++--------- frame/staking/src/tests.rs | 58 +++++++++++-------------------- frame/staking/src/weights.rs | 12 ++----- 4 files changed, 51 insertions(+), 75 deletions(-) diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index 5076fee5d30b7..a2735295e404b 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -901,24 +901,31 @@ benchmarks! { } force_apply_min_commission { - let i in 1..MaxValidators::::get(); // Clean up any existing state clear_validators_and_nominators::(); - // Create `i` validators with a commission of 50% - frame_support::assert_ok!(create_validators::(i, 1)); + // Create a validator with a commission of 50% + let (stash, controller) = + create_stash_controller::(1, 1, RewardDestination::Staked)?; + let validator_prefs = + ValidatorPrefs { commission: Perbill::from_percent(50), ..Default::default() }; + Staking::::validate(RawOrigin::Signed(controller).into(), validator_prefs)?; + + // Sanity check + assert_eq!( + Validators::::get(&stash), + ValidatorPrefs { commission: Perbill::from_percent(50), ..Default::default() } + ); - // Sanity check that all the generated validators have the expected commission - for (_, prefs) in Validators::::iter() { - assert_eq!(prefs.commission, Perbill::from_percent(50)); - } // Set the min commission to 75% MinCommission::::set(Perbill::from_percent(75)); - }: _(RawOrigin::Root, i) + }: _(RawOrigin::Root, stash.clone()) verify { - for (_, prefs) in Validators::::iter() { - assert_eq!(prefs.commission, Perbill::from_percent(75)); - } + // The validators commission has been bumped to 75% + assert_eq!( + Validators::::get(&stash), + ValidatorPrefs { commission: Perbill::from_percent(75), ..Default::default() } + ); } impl_benchmark_test_suite!( diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index b8bc7252dd0b0..8328efbc33cf1 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -1622,30 +1622,21 @@ pub mod pallet { /// /// Note that parameter `_validator_count` should be the upper bound of the number of /// validators stored and is only used for weights. - #[pallet::weight(T::WeightInfo::force_apply_min_commission(*max_validator_count))] + #[pallet::weight(T::WeightInfo::force_apply_min_commission())] pub fn force_apply_min_commission( origin: OriginFor, - max_validator_count: u32, + validator_stash: T::AccountId, ) -> DispatchResult { ensure_root(origin)?; let min_commission = MinCommission::::get(); - let mut validators_to_update = Vec::with_capacity(max_validator_count as usize); - - for (index, (validator_id, mut prefs)) in Validators::::iter().enumerate() { - if index as u32 >= max_validator_count { - log!(trace, "max_validator_count is less than the number of validators"); - break - } - if prefs.commission < min_commission { - prefs.commission = min_commission; - validators_to_update.push((validator_id, prefs)); - } - } - - for (validator_id, prefs) in validators_to_update { - Validators::::insert(validator_id, prefs) - } + if Validators::::contains_key(&validator_stash) { + let _ = Validators::::try_mutate(validator_stash, |prefs| { + (prefs.commission < min_commission) + .then(|| prefs.commission = min_commission) + .ok_or(()) + }); + }; Ok(()) } diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index c20989ca3f3e0..b6b33475b78dc 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4715,44 +4715,28 @@ mod sorted_list_provider { #[test] fn force_apply_min_commission_works() { let prefs = |c| ValidatorPrefs { commission: Perbill::from_percent(c), blocked: false }; - let validators = || Validators::::iter().collect::>(); + // let validators = || Validators::::iter().collect::>(); ExtBuilder::default().build_and_execute(|| { - // Given all validators have a commission of 0 - assert_eq!(validators(), vec![(31, prefs(0)), (21, prefs(0)), (11, prefs(0))]); - // and the min commission is 0 - assert_eq!(MinCommission::::get(), Perbill::from_percent(0)); - - // When - assert_ok!(Staking::force_apply_min_commission(Origin::root(), 3)); - - // Then - assert_eq!(validators(), vec![(31, prefs(0)), (21, prefs(0)), (11, prefs(0))]); - - // Given assert_ok!(Staking::validate(Origin::signed(30), prefs(10))); - - // When - assert_ok!(Staking::force_apply_min_commission(Origin::root(), 3)); - - // Then - assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(0)), (11, prefs(0))]); - - // Given - MinCommission::::set(Perbill::from_percent(5)); - - // When - assert_ok!(Staking::force_apply_min_commission(Origin::root(), 3)); - - // Then - assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); - - // Given - MinCommission::::set(Perbill::from_percent(6)); - - // When we call with a `max_validator_count` of 2 - assert_ok!(Staking::force_apply_min_commission(Origin::root(), 2)); - - // Then only the first two validators are affected - assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(6)), (11, prefs(5))]); + assert_ok!(Staking::validate(Origin::signed(20), prefs(5))); + + // // Given + // assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); + // assert_eq!(MinCommission::::set(Perbill::from_percent(5)); + + // // When applying to a commission greater than min + // assert_ok!(Staking::force_apply_min_commission(Origin::root(), 30)); + // // Then the commission is not changed + // assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); + + // // When applying to a commission that is equal to min + // assert_ok!(Staking::force_apply_min_commission(Origin::root(), 21)); + // // Then the commission is not changed + // assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); + + // // When applying to a commission that is less than the min + // assert_ok!(Staking::force_apply_min_commission(Origin::root(), 11)); + // // Then the commission is bumped to the min + // assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); }); } diff --git a/frame/staking/src/weights.rs b/frame/staking/src/weights.rs index 9e2c2750154e7..3667a498d2ebd 100644 --- a/frame/staking/src/weights.rs +++ b/frame/staking/src/weights.rs @@ -72,7 +72,7 @@ pub trait WeightInfo { fn get_npos_targets(v: u32, ) -> Weight; fn set_staking_configs() -> Weight; fn chill_other() -> Weight; - fn force_apply_min_commission(i: u32, ) -> Weight; + fn force_apply_min_commission() -> Weight; } /// Weights for pallet_staking using the Substrate node and recommended hardware. @@ -446,13 +446,10 @@ impl WeightInfo for SubstrateWeight { } // Storage: Staking MinCommission (r:1 w:0) // Storage: Staking Validators (r:2 w:1) - fn force_apply_min_commission(i: u32, ) -> Weight { + fn force_apply_min_commission() -> Weight { (0 as Weight) // Standard Error: 13_000 - .saturating_add((9_070_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight))) - .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } } @@ -826,12 +823,9 @@ impl WeightInfo for () { } // Storage: Staking MinCommission (r:1 w:0) // Storage: Staking Validators (r:2 w:1) - fn force_apply_min_commission(i: u32, ) -> Weight { + fn force_apply_min_commission() -> Weight { (0 as Weight) // Standard Error: 13_000 - .saturating_add((9_070_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) - .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(i as Weight))) - .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } } From abea07b011fbb1741a6e86a1757ed2aab28b9cd8 Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Mon, 7 Feb 2022 20:48:01 -0800 Subject: [PATCH 07/21] Update doc comments --- frame/staking/src/pallet/mod.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 8328efbc33cf1..51635c964fe3c 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -1617,11 +1617,8 @@ pub mod pallet { Ok(()) } - /// Force all validators to have at least the minimum commission. This will not affect - /// validators who already have a commission greater than or equal to the minimum. - /// - /// Note that parameter `_validator_count` should be the upper bound of the number of - /// validators stored and is only used for weights. + /// Force a validator to have at least the minimum commission. This will not affect a + /// validator who already has a commission greater than or equal to the minimum. #[pallet::weight(T::WeightInfo::force_apply_min_commission())] pub fn force_apply_min_commission( origin: OriginFor, From 18c00897d5e1aa17667f536f8fc5459a88699adf Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Tue, 8 Feb 2022 11:15:54 -0800 Subject: [PATCH 08/21] Uncomment tests --- frame/staking/src/tests.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index b6b33475b78dc..e16452c78e16a 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4715,28 +4715,28 @@ mod sorted_list_provider { #[test] fn force_apply_min_commission_works() { let prefs = |c| ValidatorPrefs { commission: Perbill::from_percent(c), blocked: false }; - // let validators = || Validators::::iter().collect::>(); + let validators = || Validators::::iter().collect::>(); ExtBuilder::default().build_and_execute(|| { assert_ok!(Staking::validate(Origin::signed(30), prefs(10))); assert_ok!(Staking::validate(Origin::signed(20), prefs(5))); - // // Given - // assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); - // assert_eq!(MinCommission::::set(Perbill::from_percent(5)); + // Given + assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); + MinCommission::::set(Perbill::from_percent(5)); - // // When applying to a commission greater than min - // assert_ok!(Staking::force_apply_min_commission(Origin::root(), 30)); - // // Then the commission is not changed - // assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); + // When applying to a commission greater than min + assert_ok!(Staking::force_apply_min_commission(Origin::root(), 30)); + // Then the commission is not changed + assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); - // // When applying to a commission that is equal to min - // assert_ok!(Staking::force_apply_min_commission(Origin::root(), 21)); - // // Then the commission is not changed - // assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); + // When applying to a commission that is equal to min + assert_ok!(Staking::force_apply_min_commission(Origin::root(), 21)); + // Then the commission is not changed + assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); - // // When applying to a commission that is less than the min - // assert_ok!(Staking::force_apply_min_commission(Origin::root(), 11)); - // // Then the commission is bumped to the min - // assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); + // When applying to a commission that is less than the min + assert_ok!(Staking::force_apply_min_commission(Origin::root(), 11)); + // Then the commission is bumped to the min + assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); }); } From ef68c2598092782499fa5aa2176d0460c0dfd07e Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Tue, 8 Feb 2022 20:08:25 +0000 Subject: [PATCH 09/21] cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/staking/src/weights.rs | 226 +++++++++++++++++------------------ 1 file changed, 113 insertions(+), 113 deletions(-) diff --git a/frame/staking/src/weights.rs b/frame/staking/src/weights.rs index 3667a498d2ebd..e640dd896cc42 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-02-03, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-02-08, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -85,7 +85,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (37_187_000 as Weight) + (37_629_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -95,7 +95,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (64_679_000 as Weight) + (65_380_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } @@ -109,7 +109,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (70_369_000 as Weight) + (70_652_000 as Weight) .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -118,9 +118,9 @@ 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 { - (30_513_000 as Weight) + (30_701_000 as Weight) // Standard Error: 0 - .saturating_add((52_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((51_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -138,7 +138,7 @@ 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 { - (58_352_000 as Weight) + (57_869_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(11 as Weight)) } @@ -154,16 +154,16 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (44_402_000 as Weight) + (44_284_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 { - (14_702_000 as Weight) - // Standard Error: 12_000 - .saturating_add((8_131_000 as Weight).saturating_mul(k as Weight)) + (15_359_000 as Weight) + // Standard Error: 13_000 + .saturating_add((8_267_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))) @@ -180,9 +180,9 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (50_113_000 as Weight) - // Standard Error: 15_000 - .saturating_add((3_456_000 as Weight).saturating_mul(n as Weight)) + (51_182_000 as Weight) + // Standard Error: 13_000 + .saturating_add((3_408_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)) @@ -195,47 +195,47 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (44_751_000 as Weight) + (44_238_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 { - (7_991_000 as Weight) + (7_635_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 { - (15_882_000 as Weight) + (15_707_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 { - (1_154_000 as Weight) + (1_142_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (1_202_000 as Weight) + (1_220_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (1_217_000 as Weight) + (1_255_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 { - (1_232_000 as Weight) + (1_218_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 { - (1_734_000 as Weight) + (1_735_000 as Weight) // Standard Error: 0 .saturating_add((51_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -254,18 +254,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 { - (56_723_000 as Weight) - // Standard Error: 1_000 - .saturating_add((804_000 as Weight).saturating_mul(s as Weight)) + (56_603_000 as Weight) + // Standard Error: 2_000 + .saturating_add((805_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 { - (944_999_000 as Weight) + (950_623_000 as Weight) // Standard Error: 56_000 - .saturating_add((4_996_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((4_993_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)) } @@ -280,9 +280,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 { - (79_959_000 as Weight) - // Standard Error: 14_000 - .saturating_add((23_431_000 as Weight).saturating_mul(n as Weight)) + (85_025_000 as Weight) + // Standard Error: 15_000 + .saturating_add((23_801_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)) @@ -300,9 +300,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 { - (113_794_000 as Weight) - // Standard Error: 22_000 - .saturating_add((32_859_000 as Weight).saturating_mul(n as Weight)) + (102_215_000 as Weight) + // Standard Error: 17_000 + .saturating_add((33_516_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)) @@ -315,9 +315,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (64_211_000 as Weight) - // Standard Error: 4_000 - .saturating_add((45_000 as Weight).saturating_mul(l as Weight)) + (64_243_000 as Weight) + // Standard Error: 3_000 + .saturating_add((60_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)) } @@ -332,8 +332,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 60_000 - .saturating_add((20_811_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 61_000 + .saturating_add((20_422_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))) @@ -352,9 +352,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (62_434_000 as Weight) + (62_305_000 as Weight) // Standard Error: 0 - .saturating_add((804_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((797_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))) @@ -379,10 +379,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: 896_000 - .saturating_add((227_004_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 45_000 - .saturating_add((31_665_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 916_000 + .saturating_add((219_827_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 46_000 + .saturating_add((31_499_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))) @@ -400,12 +400,12 @@ 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: 89_000 - .saturating_add((19_105_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 89_000 - .saturating_add((21_888_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 3_054_000 - .saturating_add((6_771_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 87_000 + .saturating_add((18_348_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 87_000 + .saturating_add((21_273_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 2_982_000 + .saturating_add((1_676_000 as Weight).saturating_mul(s 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))) @@ -414,8 +414,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Validators (r:501 w:0) fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 26_000 - .saturating_add((7_719_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 30_000 + .saturating_add((7_665_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))) } @@ -426,7 +426,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs() -> Weight { - (3_536_000 as Weight) + (3_490_000 as Weight) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -440,16 +440,16 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (55_532_000 as Weight) + (56_176_000 as Weight) .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Staking MinCommission (r:1 w:0) - // Storage: Staking Validators (r:2 w:1) + // Storage: Staking Validators (r:1 w:1) fn force_apply_min_commission() -> Weight { - (0 as Weight) - // Standard Error: 13_000 + (9_652_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } @@ -462,7 +462,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (37_187_000 as Weight) + (37_629_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -472,7 +472,7 @@ impl WeightInfo for () { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (64_679_000 as Weight) + (65_380_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } @@ -486,7 +486,7 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (70_369_000 as Weight) + (70_652_000 as Weight) .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -495,9 +495,9 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded_update(s: u32, ) -> Weight { - (30_513_000 as Weight) + (30_701_000 as Weight) // Standard Error: 0 - .saturating_add((52_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((51_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -515,7 +515,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (58_352_000 as Weight) + (57_869_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(11 as Weight)) } @@ -531,16 +531,16 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (44_402_000 as Weight) + (44_284_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 { - (14_702_000 as Weight) - // Standard Error: 12_000 - .saturating_add((8_131_000 as Weight).saturating_mul(k as Weight)) + (15_359_000 as Weight) + // Standard Error: 13_000 + .saturating_add((8_267_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))) @@ -557,9 +557,9 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (50_113_000 as Weight) - // Standard Error: 15_000 - .saturating_add((3_456_000 as Weight).saturating_mul(n as Weight)) + (51_182_000 as Weight) + // Standard Error: 13_000 + .saturating_add((3_408_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)) @@ -572,47 +572,47 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (44_751_000 as Weight) + (44_238_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 { - (7_991_000 as Weight) + (7_635_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 { - (15_882_000 as Weight) + (15_707_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 { - (1_154_000 as Weight) + (1_142_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (1_202_000 as Weight) + (1_220_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (1_217_000 as Weight) + (1_255_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era_always() -> Weight { - (1_232_000 as Weight) + (1_218_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking Invulnerables (r:0 w:1) fn set_invulnerables(v: u32, ) -> Weight { - (1_734_000 as Weight) + (1_735_000 as Weight) // Standard Error: 0 .saturating_add((51_000 as Weight).saturating_mul(v as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) @@ -631,18 +631,18 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:2) fn force_unstake(s: u32, ) -> Weight { - (56_723_000 as Weight) - // Standard Error: 1_000 - .saturating_add((804_000 as Weight).saturating_mul(s as Weight)) + (56_603_000 as Weight) + // Standard Error: 2_000 + .saturating_add((805_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 { - (944_999_000 as Weight) + (950_623_000 as Weight) // Standard Error: 56_000 - .saturating_add((4_996_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((4_993_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -657,9 +657,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 { - (79_959_000 as Weight) - // Standard Error: 14_000 - .saturating_add((23_431_000 as Weight).saturating_mul(n as Weight)) + (85_025_000 as Weight) + // Standard Error: 15_000 + .saturating_add((23_801_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)) @@ -677,9 +677,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 { - (113_794_000 as Weight) - // Standard Error: 22_000 - .saturating_add((32_859_000 as Weight).saturating_mul(n as Weight)) + (102_215_000 as Weight) + // Standard Error: 17_000 + .saturating_add((33_516_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)) @@ -692,9 +692,9 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (64_211_000 as Weight) - // Standard Error: 4_000 - .saturating_add((45_000 as Weight).saturating_mul(l as Weight)) + (64_243_000 as Weight) + // Standard Error: 3_000 + .saturating_add((60_000 as Weight).saturating_mul(l as Weight)) .saturating_add(RocksDbWeight::get().reads(9 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -709,8 +709,8 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 60_000 - .saturating_add((20_811_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 61_000 + .saturating_add((20_422_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))) @@ -729,9 +729,9 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (62_434_000 as Weight) + (62_305_000 as Weight) // Standard Error: 0 - .saturating_add((804_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((797_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))) @@ -756,10 +756,10 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn new_era(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 896_000 - .saturating_add((227_004_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 45_000 - .saturating_add((31_665_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 916_000 + .saturating_add((219_827_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 46_000 + .saturating_add((31_499_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))) @@ -777,12 +777,12 @@ 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: 89_000 - .saturating_add((19_105_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 89_000 - .saturating_add((21_888_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 3_054_000 - .saturating_add((6_771_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 87_000 + .saturating_add((18_348_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 87_000 + .saturating_add((21_273_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 2_982_000 + .saturating_add((1_676_000 as Weight).saturating_mul(s 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))) @@ -791,8 +791,8 @@ impl WeightInfo for () { // Storage: Staking Validators (r:501 w:0) fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 26_000 - .saturating_add((7_719_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 30_000 + .saturating_add((7_665_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))) } @@ -803,7 +803,7 @@ impl WeightInfo for () { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs() -> Weight { - (3_536_000 as Weight) + (3_490_000 as Weight) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -817,15 +817,15 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (55_532_000 as Weight) + (56_176_000 as Weight) .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Staking MinCommission (r:1 w:0) - // Storage: Staking Validators (r:2 w:1) + // Storage: Staking Validators (r:1 w:1) fn force_apply_min_commission() -> Weight { - (0 as Weight) - // Standard Error: 13_000 + (9_652_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } } From 5ec80f20623f8c9507dfd455b0db77bda26e3109 Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Wed, 9 Feb 2022 10:12:56 -0800 Subject: [PATCH 10/21] Accept signed origins --- frame/staking/src/benchmarking.rs | 3 ++- frame/staking/src/pallet/mod.rs | 5 +++-- frame/staking/src/tests.rs | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index a2735295e404b..65a1ee92e2eab 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -919,7 +919,8 @@ benchmarks! { // Set the min commission to 75% MinCommission::::set(Perbill::from_percent(75)); - }: _(RawOrigin::Root, stash.clone()) + let caller = whitelisted_caller(); + }: _(RawOrigin::Signed(caller), stash.clone()) verify { // The validators commission has been bumped to 75% assert_eq!( diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 51635c964fe3c..b6eb79b9f08c4 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -1618,13 +1618,14 @@ pub mod pallet { } /// Force a validator to have at least the minimum commission. This will not affect a - /// validator who already has a commission greater than or equal to the minimum. + /// validator who already has a commission greater than or equal to the minimum. Any account + /// can call this. #[pallet::weight(T::WeightInfo::force_apply_min_commission())] pub fn force_apply_min_commission( origin: OriginFor, validator_stash: T::AccountId, ) -> DispatchResult { - ensure_root(origin)?; + ensure_signed(origin)?; let min_commission = MinCommission::::get(); if Validators::::contains_key(&validator_stash) { diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index e16452c78e16a..ee2c7551d9fa4 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4725,17 +4725,17 @@ fn force_apply_min_commission_works() { MinCommission::::set(Perbill::from_percent(5)); // When applying to a commission greater than min - assert_ok!(Staking::force_apply_min_commission(Origin::root(), 30)); + assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 30)); // Then the commission is not changed assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); // When applying to a commission that is equal to min - assert_ok!(Staking::force_apply_min_commission(Origin::root(), 21)); + assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 21)); // Then the commission is not changed assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); // When applying to a commission that is less than the min - assert_ok!(Staking::force_apply_min_commission(Origin::root(), 11)); + assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 11)); // Then the commission is bumped to the min assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); }); From 66c740af2843ae11e904ef6d075d47bd021389c6 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Wed, 9 Feb 2022 19:03:53 +0000 Subject: [PATCH 11/21] cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/staking/src/weights.rs | 218 +++++++++++++++++------------------ 1 file changed, 109 insertions(+), 109 deletions(-) diff --git a/frame/staking/src/weights.rs b/frame/staking/src/weights.rs index e640dd896cc42..65b0c3fa707ae 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-02-08, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-02-09, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -85,7 +85,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (37_629_000 as Weight) + (38_773_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -95,7 +95,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (65_380_000 as Weight) + (65_086_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } @@ -109,7 +109,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (70_652_000 as Weight) + (71_199_000 as Weight) .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -118,9 +118,9 @@ 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 { - (30_701_000 as Weight) + (30_705_000 as Weight) // Standard Error: 0 - .saturating_add((51_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((53_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -138,7 +138,7 @@ 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 { - (57_869_000 as Weight) + (59_094_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(11 as Weight)) } @@ -154,16 +154,16 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (44_284_000 as Weight) + (45_065_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 { - (15_359_000 as Weight) - // Standard Error: 13_000 - .saturating_add((8_267_000 as Weight).saturating_mul(k as Weight)) + (16_344_000 as Weight) + // Standard Error: 14_000 + .saturating_add((8_309_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))) @@ -180,9 +180,9 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (51_182_000 as Weight) - // Standard Error: 13_000 - .saturating_add((3_408_000 as Weight).saturating_mul(n as Weight)) + (50_829_000 as Weight) + // Standard Error: 11_000 + .saturating_add((3_428_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)) @@ -195,47 +195,47 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (44_238_000 as Weight) + (44_535_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 { - (7_635_000 as Weight) + (7_899_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 { - (15_707_000 as Weight) + (15_591_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 { - (1_142_000 as Weight) + (1_060_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (1_220_000 as Weight) + (1_101_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (1_255_000 as Weight) + (1_089_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 { - (1_218_000 as Weight) + (1_190_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 { - (1_735_000 as Weight) + (1_740_000 as Weight) // Standard Error: 0 .saturating_add((51_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -254,18 +254,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 { - (56_603_000 as Weight) - // Standard Error: 2_000 - .saturating_add((805_000 as Weight).saturating_mul(s as Weight)) + (56_793_000 as Weight) + // Standard Error: 1_000 + .saturating_add((796_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 { - (950_623_000 as Weight) + (947_950_000 as Weight) // Standard Error: 56_000 - .saturating_add((4_993_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((4_989_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)) } @@ -280,9 +280,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 { - (85_025_000 as Weight) - // Standard Error: 15_000 - .saturating_add((23_801_000 as Weight).saturating_mul(n as Weight)) + (67_367_000 as Weight) + // Standard Error: 25_000 + .saturating_add((23_827_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)) @@ -300,9 +300,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 { - (102_215_000 as Weight) - // Standard Error: 17_000 - .saturating_add((33_516_000 as Weight).saturating_mul(n as Weight)) + (109_799_000 as Weight) + // Standard Error: 19_000 + .saturating_add((32_909_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)) @@ -315,9 +315,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (64_243_000 as Weight) - // Standard Error: 3_000 - .saturating_add((60_000 as Weight).saturating_mul(l as Weight)) + (64_163_000 as Weight) + // Standard Error: 2_000 + .saturating_add((64_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)) } @@ -332,8 +332,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 61_000 - .saturating_add((20_422_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 59_000 + .saturating_add((20_350_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))) @@ -352,9 +352,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (62_305_000 as Weight) + (62_478_000 as Weight) // Standard Error: 0 - .saturating_add((797_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((794_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))) @@ -379,10 +379,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: 916_000 - .saturating_add((219_827_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 46_000 - .saturating_add((31_499_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 899_000 + .saturating_add((219_129_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 45_000 + .saturating_add((31_393_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))) @@ -400,12 +400,12 @@ 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: 87_000 - .saturating_add((18_348_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 87_000 - .saturating_add((21_273_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 2_982_000 - .saturating_add((1_676_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 81_000 + .saturating_add((18_858_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 81_000 + .saturating_add((21_714_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 2_777_000 + .saturating_add((25_797_000 as Weight).saturating_mul(s 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))) @@ -414,8 +414,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Validators (r:501 w:0) fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 30_000 - .saturating_add((7_665_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 27_000 + .saturating_add((7_846_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))) } @@ -426,7 +426,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs() -> Weight { - (3_490_000 as Weight) + (3_472_000 as Weight) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -440,14 +440,14 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (56_176_000 as Weight) + (55_643_000 as Weight) .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Staking MinCommission (r:1 w:0) // Storage: Staking Validators (r:1 w:1) fn force_apply_min_commission() -> Weight { - (9_652_000 as Weight) + (9_485_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -462,7 +462,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (37_629_000 as Weight) + (38_773_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -472,7 +472,7 @@ impl WeightInfo for () { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (65_380_000 as Weight) + (65_086_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } @@ -486,7 +486,7 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (70_652_000 as Weight) + (71_199_000 as Weight) .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -495,9 +495,9 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded_update(s: u32, ) -> Weight { - (30_701_000 as Weight) + (30_705_000 as Weight) // Standard Error: 0 - .saturating_add((51_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((53_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -515,7 +515,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (57_869_000 as Weight) + (59_094_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(11 as Weight)) } @@ -531,16 +531,16 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (44_284_000 as Weight) + (45_065_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 { - (15_359_000 as Weight) - // Standard Error: 13_000 - .saturating_add((8_267_000 as Weight).saturating_mul(k as Weight)) + (16_344_000 as Weight) + // Standard Error: 14_000 + .saturating_add((8_309_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))) @@ -557,9 +557,9 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (51_182_000 as Weight) - // Standard Error: 13_000 - .saturating_add((3_408_000 as Weight).saturating_mul(n as Weight)) + (50_829_000 as Weight) + // Standard Error: 11_000 + .saturating_add((3_428_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)) @@ -572,47 +572,47 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (44_238_000 as Weight) + (44_535_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 { - (7_635_000 as Weight) + (7_899_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 { - (15_707_000 as Weight) + (15_591_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 { - (1_142_000 as Weight) + (1_060_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (1_220_000 as Weight) + (1_101_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (1_255_000 as Weight) + (1_089_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era_always() -> Weight { - (1_218_000 as Weight) + (1_190_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking Invulnerables (r:0 w:1) fn set_invulnerables(v: u32, ) -> Weight { - (1_735_000 as Weight) + (1_740_000 as Weight) // Standard Error: 0 .saturating_add((51_000 as Weight).saturating_mul(v as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) @@ -631,18 +631,18 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:2) fn force_unstake(s: u32, ) -> Weight { - (56_603_000 as Weight) - // Standard Error: 2_000 - .saturating_add((805_000 as Weight).saturating_mul(s as Weight)) + (56_793_000 as Weight) + // Standard Error: 1_000 + .saturating_add((796_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 { - (950_623_000 as Weight) + (947_950_000 as Weight) // Standard Error: 56_000 - .saturating_add((4_993_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((4_989_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -657,9 +657,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 { - (85_025_000 as Weight) - // Standard Error: 15_000 - .saturating_add((23_801_000 as Weight).saturating_mul(n as Weight)) + (67_367_000 as Weight) + // Standard Error: 25_000 + .saturating_add((23_827_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)) @@ -677,9 +677,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 { - (102_215_000 as Weight) - // Standard Error: 17_000 - .saturating_add((33_516_000 as Weight).saturating_mul(n as Weight)) + (109_799_000 as Weight) + // Standard Error: 19_000 + .saturating_add((32_909_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)) @@ -692,9 +692,9 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (64_243_000 as Weight) - // Standard Error: 3_000 - .saturating_add((60_000 as Weight).saturating_mul(l as Weight)) + (64_163_000 as Weight) + // Standard Error: 2_000 + .saturating_add((64_000 as Weight).saturating_mul(l as Weight)) .saturating_add(RocksDbWeight::get().reads(9 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -709,8 +709,8 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 61_000 - .saturating_add((20_422_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 59_000 + .saturating_add((20_350_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))) @@ -729,9 +729,9 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (62_305_000 as Weight) + (62_478_000 as Weight) // Standard Error: 0 - .saturating_add((797_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((794_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))) @@ -756,10 +756,10 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn new_era(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 916_000 - .saturating_add((219_827_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 46_000 - .saturating_add((31_499_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 899_000 + .saturating_add((219_129_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 45_000 + .saturating_add((31_393_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))) @@ -777,12 +777,12 @@ 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: 87_000 - .saturating_add((18_348_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 87_000 - .saturating_add((21_273_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 2_982_000 - .saturating_add((1_676_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 81_000 + .saturating_add((18_858_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 81_000 + .saturating_add((21_714_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 2_777_000 + .saturating_add((25_797_000 as Weight).saturating_mul(s 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))) @@ -791,8 +791,8 @@ impl WeightInfo for () { // Storage: Staking Validators (r:501 w:0) fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 30_000 - .saturating_add((7_665_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 27_000 + .saturating_add((7_846_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))) } @@ -803,7 +803,7 @@ impl WeightInfo for () { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs() -> Weight { - (3_490_000 as Weight) + (3_472_000 as Weight) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -817,14 +817,14 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (56_176_000 as Weight) + (55_643_000 as Weight) .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Staking MinCommission (r:1 w:0) // Storage: Staking Validators (r:1 w:1) fn force_apply_min_commission() -> Weight { - (9_652_000 as Weight) + (9_485_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } From 68ed575b8a73bf71cee475b97db216fae7455daa Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Wed, 9 Feb 2022 12:12:44 -0800 Subject: [PATCH 12/21] Remove contains_key check --- frame/staking/src/pallet/mod.rs | 16 +++++++++------- frame/staking/src/tests.rs | 5 +++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index b6eb79b9f08c4..2425e5c11048c 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -1628,13 +1628,15 @@ pub mod pallet { ensure_signed(origin)?; let min_commission = MinCommission::::get(); - if Validators::::contains_key(&validator_stash) { - let _ = Validators::::try_mutate(validator_stash, |prefs| { - (prefs.commission < min_commission) - .then(|| prefs.commission = min_commission) - .ok_or(()) - }); - }; + let _ = Validators::::try_mutate_exists(validator_stash, |maybe_prefs| { + maybe_prefs + .as_mut() + .map(|prefs| { + (prefs.commission < min_commission) + .then(|| prefs.commission = min_commission) + }) + .ok_or(()) + }); Ok(()) } diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index ee2c7551d9fa4..b223fb44006b6 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4738,5 +4738,10 @@ fn force_apply_min_commission_works() { assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 11)); // Then the commission is bumped to the min assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); + + // When applying commission to a validator that doesn't exist + assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 420)); + // Then the validator map is not altered + assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); }); } From 701b745868cc67b47adba86d13cf2902732331e0 Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Wed, 9 Feb 2022 13:01:50 -0800 Subject: [PATCH 13/21] Add test for try_mutate_exists --- frame/support/src/storage/generator/mod.rs | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/frame/support/src/storage/generator/mod.rs b/frame/support/src/storage/generator/mod.rs index ca893f44b3cb0..2f15ef010d819 100644 --- a/frame/support/src/storage/generator/mod.rs +++ b/frame/support/src/storage/generator/mod.rs @@ -69,6 +69,7 @@ mod tests { Value get(fn value) config(): (u64, u64); NumberMap: map hasher(identity) u32 => u64; DoubleMap: double_map hasher(identity) u32, hasher(identity) u32 => u64; + NMap: nmap hasher(blake2_128_concat) u16, hasher(twox_64_concat) u32 => u64; } } @@ -179,4 +180,92 @@ mod tests { assert_eq!(DoubleMap::get(0, 0), 6); }); } + + #[test] + fn try_mutate_exists_works() { + let t = GenesisConfig::default().build_storage().unwrap(); + TestExternalities::new(t).execute_with(|| { + NumberMap::insert(0, 22); + DoubleMap::insert(0, 0, 22); + NMap::insert((0, 0), 22); + + // Storage is not changed if an error is returned + assert_noop!( + NumberMap::try_mutate_exists(0, |maybe_value| -> Result<(), &'static str> { + maybe_value.as_mut().map(|value| *value = 4); + Err("don't change value") + }), + "don't change value" + ); + + assert_noop!( + DoubleMap::try_mutate_exists(0, 0, |maybe_value| -> Result<(), &'static str> { + maybe_value.as_mut().map(|value| *value = 6); + Err("don't change value") + }), + "don't change value" + ); + + assert_noop!( + NMap::try_mutate_exists((0, 0), |maybe_value| -> Result<(), &'static str> { + maybe_value.as_mut().map(|value| *value = 8); + Err("don't change value") + }), + "don't change value" + ); + + + // Values that exist can be mutated + assert_ok!(NumberMap::try_mutate_exists(0, |maybe_value| -> Result<(), &'static str> { + maybe_value.as_mut().map(|value| *value = 4); + Ok(()) + })); + + assert_ok!(DoubleMap::try_mutate_exists(0, 0, |maybe_value| -> Result<(), &'static str> { + maybe_value.as_mut().map(|value| *value = 6); + Ok(()) + })); + + assert_ok!(NMap::try_mutate_exists((0, 0), |maybe_value| -> Result<(), &'static str> { + maybe_value.as_mut().map(|value| *value = 8); + Ok(()) + })); + + // Mutation was successful + assert_eq!(NumberMap::get(0), 4); + assert_eq!(DoubleMap::get(0, 0), 6); + assert_eq!(NMap::get((0, 0)), 8); + + // Keys that don't exist will lead to the callback getting called with `None` + + // The following keys don't exist, + assert!(!NumberMap::contains_key(1)); + assert!(!DoubleMap::contains_key(1, 1)); + assert!(!NMap::contains_key((1, 1))); + // but a normal `get` returns a default value since the map apis here use value query + assert_eq!(NumberMap::get(1), 0); + assert_eq!(DoubleMap::get(1, 1), 0); + assert_eq!(NMap::get((1, 1)), 0); + + assert_ok!(NumberMap::try_mutate_exists(1, |maybe_value| -> Result<(), &'static str> { + assert!(maybe_value.is_none()); + Ok(()) + })); + + assert_ok!(DoubleMap::try_mutate_exists(1, 1, |maybe_value| -> Result<(), &'static str> { + assert!(maybe_value.is_none()); + Ok(()) + })); + + assert_ok!(NMap::try_mutate_exists((1, 1), |maybe_value| -> Result<(), &'static str> { + assert!(maybe_value.is_none()); + Ok(()) + })); + + // The previously non-existent keys are still non-existent + assert!(!NumberMap::contains_key(1)); + assert!(!DoubleMap::contains_key(1, 1)); + assert!(!NMap::contains_key((1, 1))); + }); + } } From 7508b4458864b99caca3bb400892f3ff45daed31 Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Wed, 9 Feb 2022 13:11:14 -0800 Subject: [PATCH 14/21] Impove try_mutate_exists docs --- frame/support/src/storage/generator/mod.rs | 75 ++++++++++++------- frame/support/src/storage/mod.rs | 1 + .../support/src/storage/types/counted_map.rs | 1 + frame/support/src/storage/types/double_map.rs | 1 + frame/support/src/storage/types/nmap.rs | 1 + frame/support/src/traits/stored_map.rs | 3 +- 6 files changed, 53 insertions(+), 29 deletions(-) diff --git a/frame/support/src/storage/generator/mod.rs b/frame/support/src/storage/generator/mod.rs index 2f15ef010d819..1dad6b9b4e178 100644 --- a/frame/support/src/storage/generator/mod.rs +++ b/frame/support/src/storage/generator/mod.rs @@ -214,22 +214,31 @@ mod tests { "don't change value" ); - // Values that exist can be mutated - assert_ok!(NumberMap::try_mutate_exists(0, |maybe_value| -> Result<(), &'static str> { - maybe_value.as_mut().map(|value| *value = 4); - Ok(()) - })); - - assert_ok!(DoubleMap::try_mutate_exists(0, 0, |maybe_value| -> Result<(), &'static str> { - maybe_value.as_mut().map(|value| *value = 6); - Ok(()) - })); + assert_ok!(NumberMap::try_mutate_exists( + 0, + |maybe_value| -> Result<(), &'static str> { + maybe_value.as_mut().map(|value| *value = 4); + Ok(()) + } + )); + + assert_ok!(DoubleMap::try_mutate_exists( + 0, + 0, + |maybe_value| -> Result<(), &'static str> { + maybe_value.as_mut().map(|value| *value = 6); + Ok(()) + } + )); - assert_ok!(NMap::try_mutate_exists((0, 0), |maybe_value| -> Result<(), &'static str> { - maybe_value.as_mut().map(|value| *value = 8); - Ok(()) - })); + assert_ok!(NMap::try_mutate_exists( + (0, 0), + |maybe_value| -> Result<(), &'static str> { + maybe_value.as_mut().map(|value| *value = 8); + Ok(()) + } + )); // Mutation was successful assert_eq!(NumberMap::get(0), 4); @@ -247,20 +256,30 @@ mod tests { assert_eq!(DoubleMap::get(1, 1), 0); assert_eq!(NMap::get((1, 1)), 0); - assert_ok!(NumberMap::try_mutate_exists(1, |maybe_value| -> Result<(), &'static str> { - assert!(maybe_value.is_none()); - Ok(()) - })); - - assert_ok!(DoubleMap::try_mutate_exists(1, 1, |maybe_value| -> Result<(), &'static str> { - assert!(maybe_value.is_none()); - Ok(()) - })); - - assert_ok!(NMap::try_mutate_exists((1, 1), |maybe_value| -> Result<(), &'static str> { - assert!(maybe_value.is_none()); - Ok(()) - })); + assert_ok!(NumberMap::try_mutate_exists( + 1, + |maybe_value| -> Result<(), &'static str> { + assert!(maybe_value.is_none()); + Ok(()) + } + )); + + assert_ok!(DoubleMap::try_mutate_exists( + 1, + 1, + |maybe_value| -> Result<(), &'static str> { + assert!(maybe_value.is_none()); + Ok(()) + } + )); + + assert_ok!(NMap::try_mutate_exists( + (1, 1), + |maybe_value| -> Result<(), &'static str> { + assert!(maybe_value.is_none()); + Ok(()) + } + )); // The previously non-existent keys are still non-existent assert!(!NumberMap::contains_key(1)); diff --git a/frame/support/src/storage/mod.rs b/frame/support/src/storage/mod.rs index e50577697a60a..bb243181d6d73 100644 --- a/frame/support/src/storage/mod.rs +++ b/frame/support/src/storage/mod.rs @@ -266,6 +266,7 @@ pub trait StorageMap { ) -> R; /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. + /// Only calls `f` with `Some` if the key exists in storage. fn try_mutate_exists, R, E, F: FnOnce(&mut Option) -> Result>( key: KeyArg, f: F, diff --git a/frame/support/src/storage/types/counted_map.rs b/frame/support/src/storage/types/counted_map.rs index 7f53b196c8151..9ccf802e0c8b7 100644 --- a/frame/support/src/storage/types/counted_map.rs +++ b/frame/support/src/storage/types/counted_map.rs @@ -190,6 +190,7 @@ where } /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. + /// Only calls `f` with `Some` if the key exists in storage. pub fn try_mutate_exists(key: KeyArg, f: F) -> Result where KeyArg: EncodeLike + Clone, diff --git a/frame/support/src/storage/types/double_map.rs b/frame/support/src/storage/types/double_map.rs index 07da0f2239b3b..70dd4c94a5fe7 100644 --- a/frame/support/src/storage/types/double_map.rs +++ b/frame/support/src/storage/types/double_map.rs @@ -264,6 +264,7 @@ where } /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. + /// Only calls `f` with `Some` if the key exists in storage. pub fn try_mutate_exists(k1: KArg1, k2: KArg2, f: F) -> Result where KArg1: EncodeLike, diff --git a/frame/support/src/storage/types/nmap.rs b/frame/support/src/storage/types/nmap.rs index 03f15e335389b..4898a958bfa9a 100755 --- a/frame/support/src/storage/types/nmap.rs +++ b/frame/support/src/storage/types/nmap.rs @@ -217,6 +217,7 @@ where } /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. + /// Only calls `f` with `Some` if the key exists in storage. pub fn try_mutate_exists(key: KArg, f: F) -> Result where KArg: EncodeLikeTuple + TupleToEncodedIter, diff --git a/frame/support/src/traits/stored_map.rs b/frame/support/src/traits/stored_map.rs index 5173eaeb5def0..2c368294cda82 100644 --- a/frame/support/src/traits/stored_map.rs +++ b/frame/support/src/traits/stored_map.rs @@ -29,7 +29,8 @@ pub trait StoredMap { fn get(k: &K) -> T; /// Maybe mutate the item only if an `Ok` value is returned from `f`. Do nothing if an `Err` is - /// returned. It is removed or reset to default value if it has been mutated to `None` + /// returned. It is removed or reset to default value if it has been mutated to `None`. Only + /// calls `f` with `Some` if the key exists in storage. fn try_mutate_exists>( k: &K, f: impl FnOnce(&mut Option) -> Result, From b85733679c85517b77873b850dca022931921c4f Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Wed, 9 Feb 2022 13:11:42 -0800 Subject: [PATCH 15/21] Delete redundant try_mutate_exists tests; --- frame/support/src/storage/generator/mod.rs | 107 --------------------- 1 file changed, 107 deletions(-) diff --git a/frame/support/src/storage/generator/mod.rs b/frame/support/src/storage/generator/mod.rs index 1dad6b9b4e178..86095938267a1 100644 --- a/frame/support/src/storage/generator/mod.rs +++ b/frame/support/src/storage/generator/mod.rs @@ -180,111 +180,4 @@ mod tests { assert_eq!(DoubleMap::get(0, 0), 6); }); } - - #[test] - fn try_mutate_exists_works() { - let t = GenesisConfig::default().build_storage().unwrap(); - TestExternalities::new(t).execute_with(|| { - NumberMap::insert(0, 22); - DoubleMap::insert(0, 0, 22); - NMap::insert((0, 0), 22); - - // Storage is not changed if an error is returned - assert_noop!( - NumberMap::try_mutate_exists(0, |maybe_value| -> Result<(), &'static str> { - maybe_value.as_mut().map(|value| *value = 4); - Err("don't change value") - }), - "don't change value" - ); - - assert_noop!( - DoubleMap::try_mutate_exists(0, 0, |maybe_value| -> Result<(), &'static str> { - maybe_value.as_mut().map(|value| *value = 6); - Err("don't change value") - }), - "don't change value" - ); - - assert_noop!( - NMap::try_mutate_exists((0, 0), |maybe_value| -> Result<(), &'static str> { - maybe_value.as_mut().map(|value| *value = 8); - Err("don't change value") - }), - "don't change value" - ); - - // Values that exist can be mutated - assert_ok!(NumberMap::try_mutate_exists( - 0, - |maybe_value| -> Result<(), &'static str> { - maybe_value.as_mut().map(|value| *value = 4); - Ok(()) - } - )); - - assert_ok!(DoubleMap::try_mutate_exists( - 0, - 0, - |maybe_value| -> Result<(), &'static str> { - maybe_value.as_mut().map(|value| *value = 6); - Ok(()) - } - )); - - assert_ok!(NMap::try_mutate_exists( - (0, 0), - |maybe_value| -> Result<(), &'static str> { - maybe_value.as_mut().map(|value| *value = 8); - Ok(()) - } - )); - - // Mutation was successful - assert_eq!(NumberMap::get(0), 4); - assert_eq!(DoubleMap::get(0, 0), 6); - assert_eq!(NMap::get((0, 0)), 8); - - // Keys that don't exist will lead to the callback getting called with `None` - - // The following keys don't exist, - assert!(!NumberMap::contains_key(1)); - assert!(!DoubleMap::contains_key(1, 1)); - assert!(!NMap::contains_key((1, 1))); - // but a normal `get` returns a default value since the map apis here use value query - assert_eq!(NumberMap::get(1), 0); - assert_eq!(DoubleMap::get(1, 1), 0); - assert_eq!(NMap::get((1, 1)), 0); - - assert_ok!(NumberMap::try_mutate_exists( - 1, - |maybe_value| -> Result<(), &'static str> { - assert!(maybe_value.is_none()); - Ok(()) - } - )); - - assert_ok!(DoubleMap::try_mutate_exists( - 1, - 1, - |maybe_value| -> Result<(), &'static str> { - assert!(maybe_value.is_none()); - Ok(()) - } - )); - - assert_ok!(NMap::try_mutate_exists( - (1, 1), - |maybe_value| -> Result<(), &'static str> { - assert!(maybe_value.is_none()); - Ok(()) - } - )); - - // The previously non-existent keys are still non-existent - assert!(!NumberMap::contains_key(1)); - assert!(!DoubleMap::contains_key(1, 1)); - assert!(!NMap::contains_key((1, 1))); - }); - } } From 5ec4422868053ddf594db19400744a8b8074acda Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Wed, 9 Feb 2022 13:13:49 -0800 Subject: [PATCH 16/21] Delete residual from removed test --- frame/support/src/storage/generator/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/support/src/storage/generator/mod.rs b/frame/support/src/storage/generator/mod.rs index 86095938267a1..ca893f44b3cb0 100644 --- a/frame/support/src/storage/generator/mod.rs +++ b/frame/support/src/storage/generator/mod.rs @@ -69,7 +69,6 @@ mod tests { Value get(fn value) config(): (u64, u64); NumberMap: map hasher(identity) u32 => u64; DoubleMap: double_map hasher(identity) u32, hasher(identity) u32 => u64; - NMap: nmap hasher(blake2_128_concat) u16, hasher(twox_64_concat) u32 => u64; } } From bf25a87ff1ebc6e3a39637048ff41d11a82882d4 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Wed, 9 Feb 2022 22:02:23 +0000 Subject: [PATCH 17/21] cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/staking/src/weights.rs | 212 +++++++++++++++++------------------ 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/frame/staking/src/weights.rs b/frame/staking/src/weights.rs index 65b0c3fa707ae..dcb544283c225 100644 --- a/frame/staking/src/weights.rs +++ b/frame/staking/src/weights.rs @@ -85,7 +85,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (38_773_000 as Weight) + (37_772_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -95,7 +95,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (65_086_000 as Weight) + (64_816_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } @@ -109,7 +109,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (71_199_000 as Weight) + (71_635_000 as Weight) .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -118,9 +118,9 @@ 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 { - (30_705_000 as Weight) + (30_612_000 as Weight) // Standard Error: 0 - .saturating_add((53_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((59_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -138,7 +138,7 @@ 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 { - (59_094_000 as Weight) + (59_116_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(11 as Weight)) } @@ -154,16 +154,16 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (45_065_000 as Weight) + (45_505_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 { - (16_344_000 as Weight) - // Standard Error: 14_000 - .saturating_add((8_309_000 as Weight).saturating_mul(k as Weight)) + (12_764_000 as Weight) + // Standard Error: 15_000 + .saturating_add((8_301_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))) @@ -180,9 +180,9 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (50_829_000 as Weight) - // Standard Error: 11_000 - .saturating_add((3_428_000 as Weight).saturating_mul(n as Weight)) + (51_439_000 as Weight) + // Standard Error: 10_000 + .saturating_add((3_323_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)) @@ -195,49 +195,49 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (44_535_000 as Weight) + (44_847_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 { - (7_899_000 as Weight) + (7_795_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 { - (15_591_000 as Weight) + (16_051_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 { - (1_060_000 as Weight) + (1_107_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (1_101_000 as Weight) + (1_126_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (1_089_000 as Weight) + (1_183_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 { - (1_190_000 as Weight) + (1_181_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 { - (1_740_000 as Weight) + (1_705_000 as Weight) // Standard Error: 0 - .saturating_add((51_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((50_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Staking Bonded (r:1 w:1) @@ -254,18 +254,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 { - (56_793_000 as Weight) + (57_431_000 as Weight) // Standard Error: 1_000 - .saturating_add((796_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((801_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 { - (947_950_000 as Weight) + (950_258_000 as Weight) // Standard Error: 56_000 - .saturating_add((4_989_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((5_001_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)) } @@ -280,9 +280,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 { - (67_367_000 as Weight) - // Standard Error: 25_000 - .saturating_add((23_827_000 as Weight).saturating_mul(n as Weight)) + (94_238_000 as Weight) + // Standard Error: 15_000 + .saturating_add((23_978_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)) @@ -300,9 +300,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 { - (109_799_000 as Weight) - // Standard Error: 19_000 - .saturating_add((32_909_000 as Weight).saturating_mul(n as Weight)) + (109_323_000 as Weight) + // Standard Error: 22_000 + .saturating_add((33_887_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)) @@ -315,9 +315,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (64_163_000 as Weight) + (64_807_000 as Weight) // Standard Error: 2_000 - .saturating_add((64_000 as Weight).saturating_mul(l as Weight)) + .saturating_add((50_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)) } @@ -332,8 +332,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 59_000 - .saturating_add((20_350_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 61_000 + .saturating_add((20_457_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))) @@ -352,9 +352,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (62_478_000 as Weight) + (62_856_000 as Weight) // Standard Error: 0 - .saturating_add((794_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((802_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))) @@ -379,10 +379,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: 899_000 - .saturating_add((219_129_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 45_000 - .saturating_add((31_393_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 804_000 + .saturating_add((226_855_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 40_000 + .saturating_add((31_928_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))) @@ -400,12 +400,12 @@ 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: 81_000 - .saturating_add((18_858_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 81_000 - .saturating_add((21_714_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 2_777_000 - .saturating_add((25_797_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 87_000 + .saturating_add((18_771_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 87_000 + .saturating_add((21_895_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 2_984_000 + .saturating_add((8_282_000 as Weight).saturating_mul(s 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))) @@ -414,8 +414,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Validators (r:501 w:0) fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 27_000 - .saturating_add((7_846_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 28_000 + .saturating_add((7_801_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))) } @@ -426,7 +426,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs() -> Weight { - (3_472_000 as Weight) + (3_680_000 as Weight) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -440,14 +440,14 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (55_643_000 as Weight) + (55_459_000 as Weight) .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Staking MinCommission (r:1 w:0) // Storage: Staking Validators (r:1 w:1) fn force_apply_min_commission() -> Weight { - (9_485_000 as Weight) + (8_939_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -462,7 +462,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn bond() -> Weight { - (38_773_000 as Weight) + (37_772_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -472,7 +472,7 @@ impl WeightInfo for () { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra() -> Weight { - (65_086_000 as Weight) + (64_816_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } @@ -486,7 +486,7 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn unbond() -> Weight { - (71_199_000 as Weight) + (71_635_000 as Weight) .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -495,9 +495,9 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded_update(s: u32, ) -> Weight { - (30_705_000 as Weight) + (30_612_000 as Weight) // Standard Error: 0 - .saturating_add((53_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((59_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -515,7 +515,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (59_094_000 as Weight) + (59_116_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(11 as Weight)) } @@ -531,16 +531,16 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForValidators (r:1 w:1) fn validate() -> Weight { - (45_065_000 as Weight) + (45_505_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 { - (16_344_000 as Weight) - // Standard Error: 14_000 - .saturating_add((8_309_000 as Weight).saturating_mul(k as Weight)) + (12_764_000 as Weight) + // Standard Error: 15_000 + .saturating_add((8_301_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))) @@ -557,9 +557,9 @@ impl WeightInfo for () { // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) fn nominate(n: u32, ) -> Weight { - (50_829_000 as Weight) - // Standard Error: 11_000 - .saturating_add((3_428_000 as Weight).saturating_mul(n as Weight)) + (51_439_000 as Weight) + // Standard Error: 10_000 + .saturating_add((3_323_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)) @@ -572,49 +572,49 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (44_535_000 as Weight) + (44_847_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 { - (7_899_000 as Weight) + (7_795_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 { - (15_591_000 as Weight) + (16_051_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 { - (1_060_000 as Weight) + (1_107_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_no_eras() -> Weight { - (1_101_000 as Weight) + (1_126_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (1_089_000 as Weight) + (1_183_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking ForceEra (r:0 w:1) fn force_new_era_always() -> Weight { - (1_190_000 as Weight) + (1_181_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking Invulnerables (r:0 w:1) fn set_invulnerables(v: u32, ) -> Weight { - (1_740_000 as Weight) + (1_705_000 as Weight) // Standard Error: 0 - .saturating_add((51_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((50_000 as Weight).saturating_mul(v as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Staking Bonded (r:1 w:1) @@ -631,18 +631,18 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:2) fn force_unstake(s: u32, ) -> Weight { - (56_793_000 as Weight) + (57_431_000 as Weight) // Standard Error: 1_000 - .saturating_add((796_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((801_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 { - (947_950_000 as Weight) + (950_258_000 as Weight) // Standard Error: 56_000 - .saturating_add((4_989_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((5_001_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -657,9 +657,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 { - (67_367_000 as Weight) - // Standard Error: 25_000 - .saturating_add((23_827_000 as Weight).saturating_mul(n as Weight)) + (94_238_000 as Weight) + // Standard Error: 15_000 + .saturating_add((23_978_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)) @@ -677,9 +677,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 { - (109_799_000 as Weight) - // Standard Error: 19_000 - .saturating_add((32_909_000 as Weight).saturating_mul(n as Weight)) + (109_323_000 as Weight) + // Standard Error: 22_000 + .saturating_add((33_887_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)) @@ -692,9 +692,9 @@ impl WeightInfo for () { // Storage: Staking Bonded (r:1 w:0) // Storage: BagsList ListBags (r:2 w:2) fn rebond(l: u32, ) -> Weight { - (64_163_000 as Weight) + (64_807_000 as Weight) // Standard Error: 2_000 - .saturating_add((64_000 as Weight).saturating_mul(l as Weight)) + .saturating_add((50_000 as Weight).saturating_mul(l as Weight)) .saturating_add(RocksDbWeight::get().reads(9 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } @@ -709,8 +709,8 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 59_000 - .saturating_add((20_350_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 61_000 + .saturating_add((20_457_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))) @@ -729,9 +729,9 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) // Storage: Staking SpanSlash (r:0 w:1) fn reap_stash(s: u32, ) -> Weight { - (62_478_000 as Weight) + (62_856_000 as Weight) // Standard Error: 0 - .saturating_add((794_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((802_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))) @@ -756,10 +756,10 @@ impl WeightInfo for () { // Storage: Staking ErasStartSessionIndex (r:0 w:1) fn new_era(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 899_000 - .saturating_add((219_129_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 45_000 - .saturating_add((31_393_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 804_000 + .saturating_add((226_855_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 40_000 + .saturating_add((31_928_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))) @@ -777,12 +777,12 @@ 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: 81_000 - .saturating_add((18_858_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 81_000 - .saturating_add((21_714_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 2_777_000 - .saturating_add((25_797_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 87_000 + .saturating_add((18_771_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 87_000 + .saturating_add((21_895_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 2_984_000 + .saturating_add((8_282_000 as Weight).saturating_mul(s 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))) @@ -791,8 +791,8 @@ impl WeightInfo for () { // Storage: Staking Validators (r:501 w:0) fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 27_000 - .saturating_add((7_846_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 28_000 + .saturating_add((7_801_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))) } @@ -803,7 +803,7 @@ impl WeightInfo for () { // Storage: Staking MaxNominatorsCount (r:0 w:1) // Storage: Staking MinNominatorBond (r:0 w:1) fn set_staking_configs() -> Weight { - (3_472_000 as Weight) + (3_680_000 as Weight) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Staking Ledger (r:1 w:0) @@ -817,14 +817,14 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill_other() -> Weight { - (55_643_000 as Weight) + (55_459_000 as Weight) .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Staking MinCommission (r:1 w:0) // Storage: Staking Validators (r:1 w:1) fn force_apply_min_commission() -> Weight { - (9_485_000 as Weight) + (8_939_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } From 8318f1beb54bce19c27f3da9f9a25b552ce6805b Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Wed, 9 Feb 2022 15:18:06 -0800 Subject: [PATCH 18/21] Return an error when the stash does not exist --- frame/staking/src/pallet/mod.rs | 10 +++++----- frame/staking/src/tests.rs | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 2425e5c11048c..4bd17be364bb4 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -665,6 +665,8 @@ pub mod pallet { TooManyValidators, /// Commission is too low. Must be at least `MinCommission`. CommissionTooLow, + /// Not a validator stash. + NotValidatorStash, } #[pallet::hooks] @@ -1627,17 +1629,15 @@ pub mod pallet { ) -> DispatchResult { ensure_signed(origin)?; let min_commission = MinCommission::::get(); - - let _ = Validators::::try_mutate_exists(validator_stash, |maybe_prefs| { + Validators::::try_mutate_exists(validator_stash, |maybe_prefs| { maybe_prefs .as_mut() .map(|prefs| { (prefs.commission < min_commission) .then(|| prefs.commission = min_commission) }) - .ok_or(()) - }); - + .ok_or(Error::::NotValidatorStash) + })?; Ok(()) } } diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index b223fb44006b6..ec52e9f29de9b 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4725,7 +4725,7 @@ fn force_apply_min_commission_works() { MinCommission::::set(Perbill::from_percent(5)); // When applying to a commission greater than min - assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 30)); + assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 31)); // Then the commission is not changed assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]); @@ -4739,9 +4739,10 @@ fn force_apply_min_commission_works() { // Then the commission is bumped to the min assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); - // When applying commission to a validator that doesn't exist - assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 420)); - // Then the validator map is not altered - assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]); + // When applying commission to a validator that doesn't exist then storage is not altered + assert_noop!( + Staking::force_apply_min_commission(Origin::signed(1), 420), + Error::::NotValidatorStash + ); }); } From 0d90a92a052acbfe69fba0ffcbb0806aeb24e410 Mon Sep 17 00:00:00 2001 From: emostov <32168567+emostov@users.noreply.github.com> Date: Wed, 9 Feb 2022 15:23:48 -0800 Subject: [PATCH 19/21] Update try_mutate_exist doc wording --- frame/support/src/storage/mod.rs | 7 ++++++- frame/support/src/storage/types/counted_map.rs | 3 ++- frame/support/src/storage/types/double_map.rs | 3 ++- frame/support/src/storage/types/map.rs | 2 ++ frame/support/src/storage/types/nmap.rs | 3 ++- frame/support/src/traits/stored_map.rs | 5 +++-- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/frame/support/src/storage/mod.rs b/frame/support/src/storage/mod.rs index bb243181d6d73..3d777fa3ace50 100644 --- a/frame/support/src/storage/mod.rs +++ b/frame/support/src/storage/mod.rs @@ -266,7 +266,8 @@ pub trait StorageMap { ) -> R; /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. - /// Only calls `f` with `Some` if the key exists in storage. + /// `f` will always be called with an option representing if the storage item exists (`Some`) + /// or if the storage item does not exist (`None`), independent of the `QueryType`. fn try_mutate_exists, R, E, F: FnOnce(&mut Option) -> Result>( key: KeyArg, f: F, @@ -609,6 +610,8 @@ pub trait StorageDoubleMap { F: FnOnce(&mut Option) -> R; /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. + /// `f` will always be called with an option representing if the storage item exists (`Some`) + /// or if the storage item does not exist (`None`), independent of the `QueryType`. fn try_mutate_exists(k1: KArg1, k2: KArg2, f: F) -> Result where KArg1: EncodeLike, @@ -736,6 +739,8 @@ pub trait StorageNMap { F: FnOnce(&mut Option) -> R; /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. + /// `f` will always be called with an option representing if the storage item exists (`Some`) + /// or if the storage item does not exist (`None`), independent of the `QueryType`. fn try_mutate_exists(key: KArg, f: F) -> Result where KArg: EncodeLikeTuple + TupleToEncodedIter, diff --git a/frame/support/src/storage/types/counted_map.rs b/frame/support/src/storage/types/counted_map.rs index 9ccf802e0c8b7..9c48267af86e0 100644 --- a/frame/support/src/storage/types/counted_map.rs +++ b/frame/support/src/storage/types/counted_map.rs @@ -190,7 +190,8 @@ where } /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. - /// Only calls `f` with `Some` if the key exists in storage. + /// `f` will always be called with an option representing if the storage item exists (`Some`) + /// or if the storage item does not exist (`None`), independent of the `QueryType`. pub fn try_mutate_exists(key: KeyArg, f: F) -> Result where KeyArg: EncodeLike + Clone, diff --git a/frame/support/src/storage/types/double_map.rs b/frame/support/src/storage/types/double_map.rs index 70dd4c94a5fe7..e864920e488f0 100644 --- a/frame/support/src/storage/types/double_map.rs +++ b/frame/support/src/storage/types/double_map.rs @@ -264,7 +264,8 @@ where } /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. - /// Only calls `f` with `Some` if the key exists in storage. + /// `f` will always be called with an option representing if the storage item exists (`Some`) + /// or if the storage item does not exist (`None`), independent of the `QueryType`. pub fn try_mutate_exists(k1: KArg1, k2: KArg2, f: F) -> Result where KArg1: EncodeLike, diff --git a/frame/support/src/storage/types/map.rs b/frame/support/src/storage/types/map.rs index d0b82e1a84e5b..01aa2f44abe5e 100644 --- a/frame/support/src/storage/types/map.rs +++ b/frame/support/src/storage/types/map.rs @@ -174,6 +174,8 @@ where } /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. + /// `f` will always be called with an option representing if the storage item exists (`Some`) + /// or if the storage item does not exist (`None`), independent of the `QueryType`. pub fn try_mutate_exists(key: KeyArg, f: F) -> Result where KeyArg: EncodeLike, diff --git a/frame/support/src/storage/types/nmap.rs b/frame/support/src/storage/types/nmap.rs index 4898a958bfa9a..5b51ed1ffdf49 100755 --- a/frame/support/src/storage/types/nmap.rs +++ b/frame/support/src/storage/types/nmap.rs @@ -217,7 +217,8 @@ where } /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. - /// Only calls `f` with `Some` if the key exists in storage. + /// `f` will always be called with an option representing if the storage item exists (`Some`) + /// or if the storage item does not exist (`None`), independent of the `QueryType`. pub fn try_mutate_exists(key: KArg, f: F) -> Result where KArg: EncodeLikeTuple + TupleToEncodedIter, diff --git a/frame/support/src/traits/stored_map.rs b/frame/support/src/traits/stored_map.rs index 2c368294cda82..3c3ff2eb0ed98 100644 --- a/frame/support/src/traits/stored_map.rs +++ b/frame/support/src/traits/stored_map.rs @@ -29,8 +29,9 @@ pub trait StoredMap { fn get(k: &K) -> T; /// Maybe mutate the item only if an `Ok` value is returned from `f`. Do nothing if an `Err` is - /// returned. It is removed or reset to default value if it has been mutated to `None`. Only - /// calls `f` with `Some` if the key exists in storage. + /// returned. It is removed or reset to default value if it has been mutated to `None`. + /// `f` will always be called with an option representing if the storage item exists (`Some`) + /// or if the storage item does not exist (`None`), independent of the `QueryType`. fn try_mutate_exists>( k: &K, f: impl FnOnce(&mut Option) -> Result, From 9e142639404d7e1f2b59c3d1c0376ae1edb203ed Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 10 Feb 2022 00:55:09 +0100 Subject: [PATCH 20/21] Update frame/staking/src/pallet/mod.rs --- frame/staking/src/pallet/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 4bd17be364bb4..6351269e38026 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -665,8 +665,6 @@ pub mod pallet { TooManyValidators, /// Commission is too low. Must be at least `MinCommission`. CommissionTooLow, - /// Not a validator stash. - NotValidatorStash, } #[pallet::hooks] From 48f5aa3bf23b3f8146781a3923d41eda7744365f Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 10 Feb 2022 00:55:35 +0100 Subject: [PATCH 21/21] Apply suggestions from code review --- frame/staking/src/pallet/mod.rs | 2 +- frame/staking/src/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 6351269e38026..2be75752f101d 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -1634,7 +1634,7 @@ pub mod pallet { (prefs.commission < min_commission) .then(|| prefs.commission = min_commission) }) - .ok_or(Error::::NotValidatorStash) + .ok_or(Error::::NotStash) })?; Ok(()) } diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index ec52e9f29de9b..4073c069fb6be 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4742,7 +4742,7 @@ fn force_apply_min_commission_works() { // When applying commission to a validator that doesn't exist then storage is not altered assert_noop!( Staking::force_apply_min_commission(Origin::signed(1), 420), - Error::::NotValidatorStash + Error::::NotStash ); }); }