diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index ff4a8ba986b00..66d2a9e5ce8fc 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -18,7 +18,10 @@ //! Staking pallet benchmarking. use super::*; -use crate::Pallet as Staking; +use crate::{ + voter_bags::{Bag, Node}, + Pallet as Staking, +}; use testing_utils::*; use frame_support::{ @@ -26,7 +29,7 @@ use frame_support::{ traits::{Currency, Get, Imbalance}, }; use sp_runtime::{ - traits::{CheckedSub, StaticLookup, Zero}, + traits::{StaticLookup, Zero}, Perbill, Percent, }; use sp_staking::SessionIndex; @@ -36,6 +39,7 @@ use crate::voter_bags::VoterList; pub use frame_benchmarking::{ account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller, }; +use frame_support::traits::CurrencyToVote; use frame_system::RawOrigin; use sp_runtime::traits::{Bounded, One}; @@ -137,6 +141,132 @@ pub fn create_validator_with_nominators( Ok((v_stash, nominators)) } +/// Data for a rebag scenario. +struct RebagScenario { + dest1_stash: T::AccountId, + src1_stash: T::AccountId, + /// Stash that is expected to be rebagged. + src2_stash: T::AccountId, + /// Controller of the Stash that is expected to be rebagged. + src2_controller: T::AccountId, + src3_stash: T::AccountId, + src_bag_thresh: BalanceOf, + dest_bag_thresh: BalanceOf, +} + +impl RebagScenario { + /// Verify that the rebag worked. + fn verify_post_rebag(&self) -> Result<(), &'static str> { + let RebagScenario { + dest1_stash, + src1_stash, + src2_stash, + src3_stash, + src_bag_thresh, + dest_bag_thresh, + .. + } = self; + + let src2_node = Node::::from_id(&src2_stash).ok_or("node not found for src stash")?; + let weight_of = Staking::::weight_of_fn(); + ensure!( + !src2_node.is_misplaced(&weight_of), + "src2_node must be in proper place after rebag" + ); + + let total_issuance = T::Currency::total_issuance(); + + let dest_bag_thresh = T::CurrencyToVote::to_vote(*dest_bag_thresh, total_issuance); + let dest_bag_ids = Bag::::get(dest_bag_thresh) + .ok_or("destination bag not found")? + .iter() + .map(|n| n.voter().id.clone()) + .collect::>(); + ensure!( + dest_bag_ids == vec![dest1_stash.clone(), src2_stash.clone()], + "destination bag is not in expected state after rebag" + ); + + let src_bag_thresh = T::CurrencyToVote::to_vote(*src_bag_thresh, total_issuance); + let src_bag_ids = Bag::::get(src_bag_thresh) + .ok_or("source bag not found")? + .iter() + .map(|n| n.voter().id.clone()) + .collect::>(); + ensure!( + src_bag_ids == vec![src1_stash.clone(), src3_stash.clone()], + "source bag not in expected state after rebag" + ); + + Ok(()) + } +} + +// Build `RebagScenario`. +fn build_rebag_scenario( + src_bag_thresh: BalanceOf, + dest_bag_thresh: BalanceOf, +) -> Result, &'static str> { + // The most expensive case for this rebag-ing: + // + // - The node to be rebagged should exist as a non-terminal node in a bag with at least + // 2 other nodes so both its prev and next are nodes that will need be updated + // when it is removed. + // - The destination bag is not empty, because then we need to update the `next` pointer + // of the previous node in addition to the work we do otherwise. + + // create_stash_controller takes a factor, so we compute it. + let src_factor: BalanceOf = + BalanceOf::::from(src_bag_thresh) * 10u32.into() / T::Currency::minimum_balance(); + let dest_factor: BalanceOf = + BalanceOf::::from(dest_bag_thresh) * 10u32.into() / T::Currency::minimum_balance(); + + let (dest1_stash, dest1_controller) = + create_stash_controller_b::(USER_SEED, dest_factor, Default::default())?; + Staking::::validate(RawOrigin::Signed(dest1_controller).into(), Default::default())?; + + let (src1_stash, src1_controller) = + create_stash_controller_b::(USER_SEED + 1, src_factor, Default::default())?; + Staking::::validate(RawOrigin::Signed(src1_controller.clone()).into(), Default::default())?; + + let (src2_stash, src2_controller) = + create_stash_controller_b::(USER_SEED + 2, src_factor, Default::default())?; + Staking::::validate(RawOrigin::Signed(src2_controller.clone()).into(), Default::default())?; + + let (src3_stash, src3_controller) = + create_stash_controller_b::(USER_SEED + 3, src_factor, Default::default())?; + Staking::::validate(RawOrigin::Signed(src3_controller.clone()).into(), Default::default())?; + + let src2_node = Node::::from_id(&src2_stash).ok_or("node not found for src2_stash")?; + let src_bag_ids = Bag::::get(src2_node.bag_upper) + .ok_or("source bag not found")? + .iter() + .map(|n| n.voter().id.clone()) + .collect::>(); + ensure!( + src_bag_ids == vec![src1_stash.clone(), src2_stash.clone(), src3_stash.clone()], + "src2_stash should be the middle node of 3", + ); + + let dest1_node = Node::::from_id(&dest1_stash).ok_or("node not found for dest1_stash")?; + let dest_bag_ids = Bag::::get(dest1_node.proper_bag_for()) + .ok_or("destination bag not found")? + .iter() + .map(|n| n.voter().id.clone()) + .collect::>(); + ensure!(dest_bag_ids == vec![dest1_stash.clone()], "destination bag should have 1 node",); + + Ok(RebagScenario { + dest1_stash, + src1_stash, + src2_stash, + src2_controller, + src3_stash, + src_bag_thresh, + dest_bag_thresh, + }) +} + const USER_SEED: u32 = 999666; benchmarks! { @@ -154,21 +284,55 @@ benchmarks! { } bond_extra { - let (stash, controller) = create_stash_controller::(USER_SEED, 100, Default::default())?; - let max_additional = T::Currency::minimum_balance() * 10u32.into(); - let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; - let original_bonded: BalanceOf = ledger.active; + // Clean up any existing state. + clear_validators_and_nominators::(); + + // The worst case scenario includes the voter changing bags. + let thresholds = T::VoterBagThresholds::get(); + let total_issuance = T::Currency::total_issuance(); + // the bag the voter will start at + let src_bag_thresh = + T::CurrencyToVote::to_currency(thresholds[0] as u128, total_issuance); + // the bag we will move the voter to + let dest_bag_thresh = + T::CurrencyToVote::to_currency(thresholds[1] as u128, total_issuance); + let rebag_scenario + = build_rebag_scenario::(src_bag_thresh, dest_bag_thresh)?; + + let max_additional = dest_bag_thresh - src_bag_thresh; + + let stash = rebag_scenario.src2_stash.clone(); + let ledger = Ledger::::get(&rebag_scenario.src2_controller).ok_or("ledger not created after")?; + let old_bonded: BalanceOf = ledger.active; whitelist_account!(stash); }: _(RawOrigin::Signed(stash), max_additional) verify { - let ledger = Ledger::::get(&controller).ok_or("ledger not created after")?; + let ledger = Ledger::::get(&rebag_scenario.src2_controller).ok_or("ledger not created after")?; let new_bonded: BalanceOf = ledger.active; - assert!(original_bonded < new_bonded); + assert!(old_bonded < new_bonded); + + rebag_scenario.verify_post_rebag()?; } unbond { - let (_, controller) = create_stash_controller::(USER_SEED, 100, Default::default())?; - let amount = T::Currency::minimum_balance() * 10u32.into(); + // Clean up any existing state. + clear_validators_and_nominators::(); + + // The worst case scenario includes the voter changing bags. + let thresholds = T::VoterBagThresholds::get(); + let total_issuance = T::Currency::total_issuance(); + // the bag the voter will start at + let src_bag_thresh = + T::CurrencyToVote::to_currency(thresholds[1] as u128, total_issuance); + // the bag we will move the voter to + let dest_bag_thresh = + T::CurrencyToVote::to_currency(thresholds[0] as u128, total_issuance); + let rebag_scenario + = build_rebag_scenario::(src_bag_thresh, dest_bag_thresh)?; + + let amount = src_bag_thresh - dest_bag_thresh; + + let controller = rebag_scenario.src2_controller.clone(); let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; let original_bonded: BalanceOf = ledger.active; whitelist_account!(controller); @@ -177,6 +341,8 @@ benchmarks! { let ledger = Ledger::::get(&controller).ok_or("ledger not created after")?; let new_bonded: BalanceOf = ledger.active; assert!(original_bonded > new_bonded); + + rebag_scenario.verify_post_rebag()?; } // Withdraw only updates the ledger @@ -446,23 +612,53 @@ benchmarks! { rebond { let l in 1 .. MAX_UNLOCKING_CHUNKS as u32; - let (_, controller) = create_stash_controller::(USER_SEED, 100, Default::default())?; - let mut staking_ledger = Ledger::::get(controller.clone()).unwrap(); + + // Clean up any existing state. + clear_validators_and_nominators::(); + + // The worst case scenario includes the voter changing bags. + let thresholds = T::VoterBagThresholds::get(); + let total_issuance = T::Currency::total_issuance(); + // the bag the voter will start at + let src_bag_thresh = + T::CurrencyToVote::to_currency(thresholds[0] as u128, total_issuance); + // the bag we will move the voter to + let dest_bag_thresh = + T::CurrencyToVote::to_currency(thresholds[1] as u128, total_issuance); + let rebag_scenario + = build_rebag_scenario::(src_bag_thresh, dest_bag_thresh)?; + + // rebond an amount that will put the user into the destination bag + let rebond_amount = dest_bag_thresh - src_bag_thresh; + + // spread that amount to rebond across `l` unlocking chunks, + let value = rebond_amount / l.into(); + // so the sum of unlocking chunks puts voter into the dest bag + assert!(value * l.into() + src_bag_thresh > src_bag_thresh); + assert!(value * l.into() + src_bag_thresh <= dest_bag_thresh); + let unlock_chunk = UnlockChunk::> { - value: 1u32.into(), + value, era: EraIndex::zero(), }; + + let controller = rebag_scenario.src2_controller.clone(); + let mut staking_ledger = Ledger::::get(controller.clone()).unwrap(); for _ in 0 .. l { staking_ledger.unlocking.push(unlock_chunk.clone()) } - Ledger::::insert(controller.clone(), staking_ledger.clone()); + let original_bonded: BalanceOf = staking_ledger.active; + Ledger::::insert(controller.clone(), staking_ledger); whitelist_account!(controller); - }: _(RawOrigin::Signed(controller.clone()), (l + 100).into()) + }: _(RawOrigin::Signed(controller.clone()), rebond_amount) verify { let ledger = Ledger::::get(&controller).ok_or("ledger not created after")?; let new_bonded: BalanceOf = ledger.active; assert!(original_bonded < new_bonded); + assert!(src_bag_thresh < new_bonded); + + rebag_scenario.verify_post_rebag()?; } set_history_depth { @@ -660,90 +856,42 @@ benchmarks! { } rebag { - // The most expensive case for this call: - // - // - It doesn't matter where in the origin bag the stash lies; the number of reads and - // writes is constant. We can use the case that the stash is the only one in the origin - // bag, for simplicity. - // - The destination bag is not empty, because then we need to update the `next` pointer - // of the previous node in addition to the work we do otherwise. - - use crate::voter_bags::{Bag, Node}; - - let make_validator = |n: u32, balance_factor: u32| -> Result<(T::AccountId, T::AccountId), &'static str> { - let (stash, controller) = create_stash_controller::(n, balance_factor, Default::default())?; - whitelist_account!(controller); - - let prefs = ValidatorPrefs::default(); - // bond the full value of the stash - let free_balance = T::Currency::free_balance(&stash); - Staking::::bond_extra(RawOrigin::Signed(stash.clone()).into(), free_balance)?; - Staking::::validate(RawOrigin::Signed(controller.clone()).into(), prefs)?; - - Ok((stash, controller)) - }; - // Clean up any existing state. clear_validators_and_nominators::(); let thresholds = T::VoterBagThresholds::get(); - - // stash controls the node account - let bag0_thresh = thresholds[0]; - let (stash, controller) = make_validator(USER_SEED, bag0_thresh as u32)?; - - // create another validator with more stake - let bag2_thresh = thresholds[2]; - let (other_stash, _) = make_validator(USER_SEED + 1, bag2_thresh as u32)?; + let total_issuance = T::Currency::total_issuance(); + // the bag the voter will start at + let src_bag_thresh = + T::CurrencyToVote::to_currency(thresholds[0] as u128, total_issuance); + // the bag we will move the voter to + let dest_bag_thresh = + T::CurrencyToVote::to_currency(thresholds[1] as u128, total_issuance); + let rebag_scenario + = build_rebag_scenario::(src_bag_thresh, dest_bag_thresh)?; // update the stash account's value/weight // // note that we have to manually update the ledger; if we were to just call // `Staking::::bond_extra`, then it would implicitly rebag. We want to separate that step // so we can measure it in isolation. - let other_free_balance = T::Currency::free_balance(&other_stash); - T::Currency::make_free_balance_be(&stash, other_free_balance); - let controller = Staking::::bonded(&stash).ok_or("stash had no controller")?; - let mut ledger = Staking::::ledger(&controller).ok_or("controller had no ledger")?; - let extra = other_free_balance.checked_sub(&ledger.total).ok_or("balance did not increase")?; - ledger.total += extra; - ledger.active += extra; - Staking::::update_ledger(&controller, &ledger); - - // verify preconditions + T::Currency::make_free_balance_be(&rebag_scenario.src2_stash, dest_bag_thresh); + let mut ledger = Staking::::ledger(&rebag_scenario.src2_controller).ok_or("controller had no ledger")?; + ledger.total = dest_bag_thresh; + ledger.active = dest_bag_thresh; + Staking::::update_ledger(&rebag_scenario.src2_controller, &ledger); + let weight_of = Staking::::weight_of_fn(); - let node = Node::::from_id(&stash).ok_or("node not found for stash")?; + let src2_node = Node::::from_id(&rebag_scenario.src2_stash).ok_or("node not found for stash")?; ensure!( - node.is_misplaced(&weight_of), + src2_node.is_misplaced(&weight_of), "rebagging only makes sense when a node is misplaced", ); - ensure!( - { - let origin_bag = Bag::::get(node.bag_upper).ok_or("origin bag not found")?; - origin_bag.iter().count() == 1 - }, - "stash should be the only node in origin bag", - ); - let other_node = Node::::from_id(&other_stash).ok_or("node not found for other_stash")?; - ensure!(!other_node.is_misplaced(&weight_of), "other stash balance never changed"); - ensure!( - { - let destination_bag = Bag::::get(node.proper_bag_for()).ok_or("destination bag not found")?; - destination_bag.iter().count() != 0 - }, - "destination bag should not be empty", - ); - drop(node); - // caller will call rebag let caller = whitelisted_caller(); - // ensure it's distinct from the other accounts - ensure!(caller != stash, "caller must not be the same as the stash"); - ensure!(caller != controller, "caller must not be the same as the controller"); - }: _(RawOrigin::Signed(caller), stash.clone()) + }: _(RawOrigin::Signed(caller), rebag_scenario.src2_stash.clone()) verify { - let node = Node::::from_id(&stash).ok_or("node not found for stash")?; - ensure!(!node.is_misplaced(&weight_of), "node must be in proper place after rebag"); + rebag_scenario.verify_post_rebag()?; } regenerate { diff --git a/frame/staking/src/testing_utils.rs b/frame/staking/src/testing_utils.rs index 44bd84b9a167f..d01ed8d1fec2d 100644 --- a/frame/staking/src/testing_utils.rs +++ b/frame/staking/src/testing_utils.rs @@ -49,11 +49,23 @@ pub fn create_funded_user( n: u32, balance_factor: u32, ) -> T::AccountId { + create_funded_user_b::(string, n, balance_factor.into()) +} + +/// Grab a funded user. +pub fn create_funded_user_b( + string: &'static str, + n: u32, + balance_factor: crate::BalanceOf, +) -> T::AccountId { + let initial_issuance = T::Currency::total_issuance(); let user = account(string, n, SEED); - let balance = T::Currency::minimum_balance() * balance_factor.into(); - T::Currency::make_free_balance_be(&user, balance); - // ensure T::CurrencyToVote will work correctly. - T::Currency::issue(balance); + let balance = T::Currency::minimum_balance() * balance_factor; + let positive_imbalance = T::Currency::make_free_balance_be(&user, balance); + drop(positive_imbalance); + // make sure the issuance increases to account for the positive imbalance + assert_eq!(initial_issuance + balance, T::Currency::total_issuance()); + user } @@ -63,18 +75,27 @@ pub fn create_stash_controller( balance_factor: u32, destination: RewardDestination, ) -> Result<(T::AccountId, T::AccountId), &'static str> { - let stash = create_funded_user::("stash", n, balance_factor); - let controller = create_funded_user::("controller", n, balance_factor); + create_stash_controller_b::(n, balance_factor.into(), destination) +} + +/// Create a stash and controller pair. +pub fn create_stash_controller_b( + n: u32, + balance_factor: crate::BalanceOf, + destination: RewardDestination, +) -> Result<(T::AccountId, T::AccountId), &'static str> { + let stash = create_funded_user_b::("stash", n, balance_factor); + let controller = create_funded_user_b::("controller", n, balance_factor); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); - let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into(); + let amount = T::Currency::minimum_balance() * (balance_factor / 10u32.into()).max(1u32.into()); Staking::::bond( RawOrigin::Signed(stash.clone()).into(), controller_lookup, amount, destination, )?; - return Ok((stash, controller)) + Ok((stash, controller)) } /// Create a stash and controller pair, where the controller is dead, and payouts go to controller. diff --git a/frame/staking/src/weights.rs b/frame/staking/src/weights.rs index ef88087db8f04..20360f5878a71 100644 --- a/frame/staking/src/weights.rs +++ b/frame/staking/src/weights.rs @@ -17,8 +17,8 @@ //! Autogenerated weights for pallet_staking //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-06-30, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-07-30, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: @@ -81,156 +81,155 @@ pub trait WeightInfo { pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { fn bond() -> Weight { - (70_861_000 as Weight) + (75_618_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn bond_extra() -> Weight { - (54_634_000 as Weight) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + (147_539_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(9 as Weight)) } fn unbond() -> Weight { - (58_152_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + (156_029_000 as Weight) + .saturating_add(T::DbWeight::get().reads(15 as Weight)) + .saturating_add(T::DbWeight::get().writes(10 as Weight)) } fn withdraw_unbonded_update(s: u32, ) -> Weight { - (53_561_000 as Weight) + (53_353_000 as Weight) // Standard Error: 0 - .saturating_add((38_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((23_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)) } fn withdraw_unbonded_kill(s: u32, ) -> Weight { - (93_297_000 as Weight) - // Standard Error: 1_000 - .saturating_add((2_349_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) + (88_676_000 as Weight) + // Standard Error: 2_000 + .saturating_add((2_404_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } fn validate() -> Weight { - (67_912_000 as Weight) + (72_505_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn kick(k: u32, ) -> Weight { - (44_238_000 as Weight) - // Standard Error: 20_000 - .saturating_add((15_852_000 as Weight).saturating_mul(k as Weight)) + (16_746_000 as Weight) + // Standard Error: 13_000 + .saturating_add((17_014_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))) } fn nominate(n: u32, ) -> Weight { - (91_375_000 as Weight) - // Standard Error: 48_000 - .saturating_add((5_002_000 as Weight).saturating_mul(n as Weight)) + (90_347_000 as Weight) + // Standard Error: 19_000 + .saturating_add((5_699_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(7 as Weight)) } fn chill() -> Weight { - (27_150_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + (18_852_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) } fn set_payee() -> Weight { - (11_982_000 as Weight) + (13_275_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn set_controller() -> Weight { - (26_858_000 as Weight) + (27_988_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn set_validator_count() -> Weight { - (2_000_000 as Weight) + (2_520_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn force_no_eras() -> Weight { - (2_232_000 as Weight) + (2_787_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn force_new_era() -> Weight { - (2_256_000 as Weight) + (2_726_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn force_new_era_always() -> Weight { - (2_224_000 as Weight) + (2_819_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn set_invulnerables(v: u32, ) -> Weight { - (2_344_000 as Weight) + (3_009_000 as Weight) // Standard Error: 0 - .saturating_add((5_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((56_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn force_unstake(s: u32, ) -> Weight { - (70_433_000 as Weight) - // Standard Error: 1_000 - .saturating_add((2_352_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(T::DbWeight::get().reads(8 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) + (63_697_000 as Weight) + // Standard Error: 2_000 + .saturating_add((2_458_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } fn cancel_deferred_slash(s: u32, ) -> Weight { - (3_208_783_000 as Weight) - // Standard Error: 220_000 - .saturating_add((18_751_000 as Weight).saturating_mul(s as Weight)) + (3_384_988_000 as Weight) + // Standard Error: 223_000 + .saturating_add((19_957_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)) } fn payout_stakers_dead_controller(n: u32, ) -> Weight { - (136_667_000 as Weight) - // Standard Error: 31_000 - .saturating_add((47_790_000 as Weight).saturating_mul(n as Weight)) + (122_159_000 as Weight) + // Standard Error: 21_000 + .saturating_add((48_664_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)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(n as Weight))) } fn payout_stakers_alive_staked(n: u32, ) -> Weight { - (157_202_000 as Weight) - // Standard Error: 36_000 - .saturating_add((61_104_000 as Weight).saturating_mul(n as Weight)) + (160_650_000 as Weight) + // Standard Error: 24_000 + .saturating_add((63_021_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)) .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) } fn rebond(l: u32, ) -> Weight { - (48_267_000 as Weight) + (139_997_000 as Weight) // Standard Error: 2_000 - .saturating_add((28_000 as Weight).saturating_mul(l as Weight)) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + .saturating_add((83_000 as Weight).saturating_mul(l as Weight)) + .saturating_add(T::DbWeight::get().reads(11 as Weight)) + .saturating_add(T::DbWeight::get().writes(10 as Weight)) } fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 71_000 - .saturating_add((34_769_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 72_000 + .saturating_add((35_288_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))) } fn reap_stash(s: u32, ) -> Weight { - (108_325_000 as Weight) - // Standard Error: 2_000 - .saturating_add((2_365_000 as Weight).saturating_mul(s as Weight)) + (104_464_000 as Weight) + // Standard Error: 1_000 + .saturating_add((2_399_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))) } fn new_era(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 1_084_000 - .saturating_add((307_737_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 54_000 - .saturating_add((51_644_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(83 as Weight)) + // Standard Error: 950_000 + .saturating_add((304_562_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 47_000 + .saturating_add((51_442_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(T::DbWeight::get().reads(209 as Weight)) .saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(v as Weight))) .saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(n as Weight))) .saturating_add(T::DbWeight::get().writes(4 as Weight)) @@ -238,48 +237,46 @@ impl WeightInfo for SubstrateWeight { } fn get_npos_voters(v: u32, n: u32, s: u32, ) -> Weight { (0 as Weight) - // Standard Error: 118_000 - .saturating_add((21_454_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 118_000 - .saturating_add((31_494_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 4_041_000 - .saturating_add((52_930_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(T::DbWeight::get().reads(75 as Weight)) + // Standard Error: 94_000 + .saturating_add((25_271_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 94_000 + .saturating_add((34_128_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(T::DbWeight::get().reads(201 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))) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) } fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 29_000 - .saturating_add((10_880_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 31_000 + .saturating_add((11_726_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))) } fn set_staking_limits() -> Weight { - (5_902_000 as Weight) + (6_560_000 as Weight) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } fn chill_other() -> Weight { - (73_685_000 as Weight) + (91_746_000 as Weight) .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn rebag() -> Weight { - (84_501_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) + (106_035_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn regenerate(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 128_000 - .saturating_add((40_328_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 128_000 - .saturating_add((42_763_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 115_000 + .saturating_add((42_247_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 115_000 + .saturating_add((44_439_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(v as Weight))) .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(14 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(v as Weight))) .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(n as Weight))) } @@ -288,156 +285,155 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { fn bond() -> Weight { - (70_861_000 as Weight) + (75_618_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn bond_extra() -> Weight { - (54_634_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(3 as Weight)) - .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + (147_539_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(10 as Weight)) + .saturating_add(RocksDbWeight::get().writes(9 as Weight)) } fn unbond() -> Weight { - (58_152_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(6 as Weight)) - .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + (156_029_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(15 as Weight)) + .saturating_add(RocksDbWeight::get().writes(10 as Weight)) } fn withdraw_unbonded_update(s: u32, ) -> Weight { - (53_561_000 as Weight) + (53_353_000 as Weight) // Standard Error: 0 - .saturating_add((38_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((23_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn withdraw_unbonded_kill(s: u32, ) -> Weight { - (93_297_000 as Weight) - // Standard Error: 1_000 - .saturating_add((2_349_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(RocksDbWeight::get().reads(10 as Weight)) - .saturating_add(RocksDbWeight::get().writes(7 as Weight)) + (88_676_000 as Weight) + // Standard Error: 2_000 + .saturating_add((2_404_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(RocksDbWeight::get().reads(8 as Weight)) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } fn validate() -> Weight { - (67_912_000 as Weight) + (72_505_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } fn kick(k: u32, ) -> Weight { - (44_238_000 as Weight) - // Standard Error: 20_000 - .saturating_add((15_852_000 as Weight).saturating_mul(k as Weight)) + (16_746_000 as Weight) + // Standard Error: 13_000 + .saturating_add((17_014_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))) } fn nominate(n: u32, ) -> Weight { - (91_375_000 as Weight) - // Standard Error: 48_000 - .saturating_add((5_002_000 as Weight).saturating_mul(n as Weight)) + (90_347_000 as Weight) + // Standard Error: 19_000 + .saturating_add((5_699_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(7 as Weight)) } fn chill() -> Weight { - (27_150_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + (18_852_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) } fn set_payee() -> Weight { - (11_982_000 as Weight) + (13_275_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn set_controller() -> Weight { - (26_858_000 as Weight) + (27_988_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn set_validator_count() -> Weight { - (2_000_000 as Weight) + (2_520_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn force_no_eras() -> Weight { - (2_232_000 as Weight) + (2_787_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn force_new_era() -> Weight { - (2_256_000 as Weight) + (2_726_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn force_new_era_always() -> Weight { - (2_224_000 as Weight) + (2_819_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn set_invulnerables(v: u32, ) -> Weight { - (2_344_000 as Weight) + (3_009_000 as Weight) // Standard Error: 0 - .saturating_add((5_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((56_000 as Weight).saturating_mul(v as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn force_unstake(s: u32, ) -> Weight { - (70_433_000 as Weight) - // Standard Error: 1_000 - .saturating_add((2_352_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(RocksDbWeight::get().reads(8 as Weight)) - .saturating_add(RocksDbWeight::get().writes(7 as Weight)) + (63_697_000 as Weight) + // Standard Error: 2_000 + .saturating_add((2_458_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } fn cancel_deferred_slash(s: u32, ) -> Weight { - (3_208_783_000 as Weight) - // Standard Error: 220_000 - .saturating_add((18_751_000 as Weight).saturating_mul(s as Weight)) + (3_384_988_000 as Weight) + // Standard Error: 223_000 + .saturating_add((19_957_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn payout_stakers_dead_controller(n: u32, ) -> Weight { - (136_667_000 as Weight) - // Standard Error: 31_000 - .saturating_add((47_790_000 as Weight).saturating_mul(n as Weight)) + (122_159_000 as Weight) + // Standard Error: 21_000 + .saturating_add((48_664_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)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(n as Weight))) } fn payout_stakers_alive_staked(n: u32, ) -> Weight { - (157_202_000 as Weight) - // Standard Error: 36_000 - .saturating_add((61_104_000 as Weight).saturating_mul(n as Weight)) + (160_650_000 as Weight) + // Standard Error: 24_000 + .saturating_add((63_021_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)) .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) } fn rebond(l: u32, ) -> Weight { - (48_267_000 as Weight) + (139_997_000 as Weight) // Standard Error: 2_000 - .saturating_add((28_000 as Weight).saturating_mul(l as Weight)) - .saturating_add(RocksDbWeight::get().reads(3 as Weight)) - .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + .saturating_add((83_000 as Weight).saturating_mul(l as Weight)) + .saturating_add(RocksDbWeight::get().reads(11 as Weight)) + .saturating_add(RocksDbWeight::get().writes(10 as Weight)) } fn set_history_depth(e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 71_000 - .saturating_add((34_769_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 72_000 + .saturating_add((35_288_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))) } fn reap_stash(s: u32, ) -> Weight { - (108_325_000 as Weight) - // Standard Error: 2_000 - .saturating_add((2_365_000 as Weight).saturating_mul(s as Weight)) + (104_464_000 as Weight) + // Standard Error: 1_000 + .saturating_add((2_399_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))) } fn new_era(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 1_084_000 - .saturating_add((307_737_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 54_000 - .saturating_add((51_644_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(RocksDbWeight::get().reads(83 as Weight)) + // Standard Error: 950_000 + .saturating_add((304_562_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 47_000 + .saturating_add((51_442_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(RocksDbWeight::get().reads(209 as Weight)) .saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(v as Weight))) .saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(n as Weight))) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) @@ -445,48 +441,46 @@ impl WeightInfo for () { } fn get_npos_voters(v: u32, n: u32, s: u32, ) -> Weight { (0 as Weight) - // Standard Error: 118_000 - .saturating_add((21_454_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 118_000 - .saturating_add((31_494_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 4_041_000 - .saturating_add((52_930_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(RocksDbWeight::get().reads(75 as Weight)) + // Standard Error: 94_000 + .saturating_add((25_271_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 94_000 + .saturating_add((34_128_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(RocksDbWeight::get().reads(201 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))) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) } fn get_npos_targets(v: u32, ) -> Weight { (0 as Weight) - // Standard Error: 29_000 - .saturating_add((10_880_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 31_000 + .saturating_add((11_726_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))) } fn set_staking_limits() -> Weight { - (5_902_000 as Weight) + (6_560_000 as Weight) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } fn chill_other() -> Weight { - (73_685_000 as Weight) + (91_746_000 as Weight) .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } fn rebag() -> Weight { - (84_501_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(7 as Weight)) - .saturating_add(RocksDbWeight::get().writes(5 as Weight)) + (106_035_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(9 as Weight)) + .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } fn regenerate(v: u32, n: u32, ) -> Weight { (0 as Weight) - // Standard Error: 128_000 - .saturating_add((40_328_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 128_000 - .saturating_add((42_763_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 115_000 + .saturating_add((42_247_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 115_000 + .saturating_add((44_439_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(v as Weight))) .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) - .saturating_add(RocksDbWeight::get().writes(14 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(v as Weight))) .saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(n as Weight))) }