From 157b8887abbc04548ce108f6a12e2b809be850c0 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Tue, 20 Aug 2024 11:21:58 -0400 Subject: [PATCH] new_session weight --- pallets/staking/src/benchmarking.rs | 24 ++++++-- pallets/staking/src/lib.rs | 2 +- pallets/staking/src/weights.rs | 52 +++++++++++++----- .../src/weights/pallet_staking_extension.rs | 55 +++++++++++-------- 4 files changed, 88 insertions(+), 45 deletions(-) diff --git a/pallets/staking/src/benchmarking.rs b/pallets/staking/src/benchmarking.rs index 389eac99b..e9bb5fea7 100644 --- a/pallets/staking/src/benchmarking.rs +++ b/pallets/staking/src/benchmarking.rs @@ -23,6 +23,7 @@ use frame_support::{ traits::{Currency, Get}, }; use frame_system::{EventRecord, RawOrigin}; +use pallet_parameters::{SignersInfo, SignersSize}; use pallet_staking::{Pallet as FrameStaking, RewardDestination, ValidatorPrefs}; use sp_std::{vec, vec::Vec}; @@ -233,7 +234,7 @@ benchmarks! { Signers::::put(vec![validator_id_res.clone(), validator_id_res.clone()]); }: { - Staking::::new_session_handler(&vec![validator_id_res]) + let _ = Staking::::new_session_handler(&vec![validator_id_res]); } verify { assert!(NextSigners::::get().is_none()); @@ -252,14 +253,15 @@ benchmarks! { }: { - Staking::::new_session_handler(&signers) + let _ = Staking::::new_session_handler(&signers); } verify { assert_eq!(NextSigners::::get().unwrap().next_signers.len(), signers.len() - 2); } new_session { - let confirmation_num = MAX_SIGNERS as usize - 1; + let c in 1 .. MAX_SIGNERS as u32 - 1; + let l in 0 .. MAX_SIGNERS as u32; let caller: T::AccountId = whitelisted_caller(); let validator_id_res = ::ValidatorId::try_from(caller.clone()).or(Err(Error::::InvalidValidatorId)).unwrap(); @@ -267,12 +269,22 @@ benchmarks! { let second_signer: T::AccountId = account("second_signer", 0, SEED); let second_signer_id = ::ValidatorId::try_from(second_signer.clone()).or(Err(Error::::InvalidValidatorId)).unwrap(); // full signer list leaving room for one extra validator - let mut signers = vec![second_signer_id.clone(); confirmation_num as usize]; + let mut signers = vec![second_signer_id.clone(); c as usize]; + Signers::::put(signers.clone()); - signers.push(validator_id_res.clone()); + signers.push(second_signer_id.clone()); + // place new signer in the signers struct in different locations to calculate random selection re-run + signers[l as usize % c as usize] = validator_id_res.clone(); + + SignersInfo::::put(SignersSize { + total_signers: MAX_SIGNERS, + threshold: 3, + last_session_change: 0 + }); + }: { - Staking::::new_session_handler(&signers) + let _ = Staking::::new_session_handler(&signers); } verify { assert!(NextSigners::::get().is_some()); diff --git a/pallets/staking/src/lib.rs b/pallets/staking/src/lib.rs index a6da5ed84..7e3a5619f 100644 --- a/pallets/staking/src/lib.rs +++ b/pallets/staking/src/lib.rs @@ -565,7 +565,7 @@ pub mod pallet { } current_signers.push(next_signer_up.clone()); new_signer = next_signer_up.encode(); - // TODO add last weight here + weight = ::WeightInfo::new_session(current_signers.len() as u32, count) } // removes first signer and pushes new signer to back if total signers not increased diff --git a/pallets/staking/src/weights.rs b/pallets/staking/src/weights.rs index 4b32de2fc..ba51fd542 100644 --- a/pallets/staking/src/weights.rs +++ b/pallets/staking/src/weights.rs @@ -61,7 +61,7 @@ pub trait WeightInfo { fn confirm_key_reshare_completed() -> Weight; fn new_session_validators_less_then_signers() -> Weight; fn new_session_not_adding_new_signer() -> Weight; - fn new_session() -> Weight; + fn new_session(c: u32, l: u32) -> Weight; } /// Weights for pallet_staking_extension using the Substrate node and recommended hardware. @@ -208,21 +208,32 @@ impl WeightInfo for SubstrateWeight { /// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Parameters::SignersInfo` (r:1 w:0) /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Babe::NextRandomness` (r:1 w:0) + /// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Babe::EpochStart` (r:1 w:0) + /// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `StakingExtension::ReshareData` (r:0 w:1) /// Proof: `StakingExtension::ReshareData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `StakingExtension::NextSigners` (r:0 w:1) /// Proof: `StakingExtension::NextSigners` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - fn new_session() -> Weight { + /// The range of component `c` is `[1, 14]`. + /// The range of component `l` is `[0, 15]`. + fn new_session(c: u32, l: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `727` - // Estimated: `2212` - // Minimum execution time: 10_000_000 picoseconds. - Weight::from_parts(10_000_000, 0) - .saturating_add(Weight::from_parts(0, 2212)) - .saturating_add(T::DbWeight::get().reads(3)) + // Measured: `482 + c * (32 ±0)` + // Estimated: `1966 + c * (32 ±0)` + // Minimum execution time: 13_000_000 picoseconds. + Weight::from_parts(12_791_889, 0) + .saturating_add(Weight::from_parts(0, 1966)) + // Standard Error: 22_917 + .saturating_add(Weight::from_parts(65_067, 0).saturating_mul(c.into())) + // Standard Error: 19_636 + .saturating_add(Weight::from_parts(30_071, 0).saturating_mul(l.into())) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 32).saturating_mul(c.into())) } /// Storage: `StakingExtension::Signers` (r:1 w:0) /// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -389,21 +400,32 @@ impl WeightInfo for () { /// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Parameters::SignersInfo` (r:1 w:0) /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Babe::NextRandomness` (r:1 w:0) + /// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Babe::EpochStart` (r:1 w:0) + /// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `StakingExtension::ReshareData` (r:0 w:1) /// Proof: `StakingExtension::ReshareData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `StakingExtension::NextSigners` (r:0 w:1) /// Proof: `StakingExtension::NextSigners` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - fn new_session() -> Weight { + /// The range of component `c` is `[1, 14]`. + /// The range of component `l` is `[0, 15]`. + fn new_session(c: u32, l: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `727` - // Estimated: `2212` - // Minimum execution time: 10_000_000 picoseconds. - Weight::from_parts(10_000_000, 0) - .saturating_add(Weight::from_parts(0, 2212)) - .saturating_add(RocksDbWeight::get().reads(3)) + // Measured: `482 + c * (32 ±0)` + // Estimated: `1966 + c * (32 ±0)` + // Minimum execution time: 13_000_000 picoseconds. + Weight::from_parts(12_791_889, 0) + .saturating_add(Weight::from_parts(0, 1966)) + // Standard Error: 22_917 + .saturating_add(Weight::from_parts(65_067, 0).saturating_mul(c.into())) + // Standard Error: 19_636 + .saturating_add(Weight::from_parts(30_071, 0).saturating_mul(l.into())) + .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 32).saturating_mul(c.into())) } /// Storage: `StakingExtension::Signers` (r:1 w:0) /// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) diff --git a/runtime/src/weights/pallet_staking_extension.rs b/runtime/src/weights/pallet_staking_extension.rs index 2016ff379..4029ab5c6 100644 --- a/runtime/src/weights/pallet_staking_extension.rs +++ b/runtime/src/weights/pallet_staking_extension.rs @@ -16,7 +16,7 @@ //! Autogenerated weights for `pallet_staking_extension` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0 -//! DATE: 2024-08-19, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-08-20, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `Jesses-MacBook-Pro.local`, CPU: `` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -55,8 +55,8 @@ impl pallet_staking_extension::WeightInfo for WeightInf // Proof Size summary in bytes: // Measured: `1309` // Estimated: `4774` - // Minimum execution time: 25_000_000 picoseconds. - Weight::from_parts(25_000_000, 0) + // Minimum execution time: 23_000_000 picoseconds. + Weight::from_parts(24_000_000, 0) .saturating_add(Weight::from_parts(0, 4774)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -73,8 +73,8 @@ impl pallet_staking_extension::WeightInfo for WeightInf // Proof Size summary in bytes: // Measured: `1430` // Estimated: `4895` - // Minimum execution time: 29_000_000 picoseconds. - Weight::from_parts(32_000_000, 0) + // Minimum execution time: 26_000_000 picoseconds. + Weight::from_parts(26_000_000, 0) .saturating_add(Weight::from_parts(0, 4895)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) @@ -95,8 +95,8 @@ impl pallet_staking_extension::WeightInfo for WeightInf // Proof Size summary in bytes: // Measured: `1262` // Estimated: `4764` - // Minimum execution time: 42_000_000 picoseconds. - Weight::from_parts(49_000_000, 0) + // Minimum execution time: 38_000_000 picoseconds. + Weight::from_parts(39_000_000, 0) .saturating_add(Weight::from_parts(0, 4764)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) @@ -131,8 +131,8 @@ impl pallet_staking_extension::WeightInfo for WeightInf // Proof Size summary in bytes: // Measured: `1918` // Estimated: `6248` - // Minimum execution time: 65_000_000 picoseconds. - Weight::from_parts(66_000_000, 0) + // Minimum execution time: 59_000_000 picoseconds. + Weight::from_parts(62_000_000, 0) .saturating_add(Weight::from_parts(0, 6248)) .saturating_add(T::DbWeight::get().reads(13)) .saturating_add(T::DbWeight::get().writes(8)) @@ -145,7 +145,7 @@ impl pallet_staking_extension::WeightInfo for WeightInf // Proof Size summary in bytes: // Measured: `320` // Estimated: `3785` - // Minimum execution time: 10_000_000 picoseconds. + // Minimum execution time: 9_000_000 picoseconds. Weight::from_parts(10_000_000, 0) .saturating_add(Weight::from_parts(0, 3785)) .saturating_add(T::DbWeight::get().reads(1)) @@ -161,10 +161,8 @@ impl pallet_staking_extension::WeightInfo for WeightInf // Measured: `797 + c * (32 ±0)` // Estimated: `4298 + c * (29 ±1)` // Minimum execution time: 11_000_000 picoseconds. - Weight::from_parts(12_143_646, 0) + Weight::from_parts(11_500_000, 0) .saturating_add(Weight::from_parts(0, 4298)) - // Standard Error: 177_742 - .saturating_add(Weight::from_parts(91_160, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(Weight::from_parts(0, 29).saturating_mul(c.into())) @@ -179,8 +177,8 @@ impl pallet_staking_extension::WeightInfo for WeightInf // Proof Size summary in bytes: // Measured: `1309` // Estimated: `4774` - // Minimum execution time: 12_000_000 picoseconds. - Weight::from_parts(13_000_000, 0) + // Minimum execution time: 11_000_000 picoseconds. + Weight::from_parts(12_000_000, 0) .saturating_add(Weight::from_parts(0, 4774)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) @@ -211,7 +209,7 @@ impl pallet_staking_extension::WeightInfo for WeightInf // Measured: `439` // Estimated: `1924` // Minimum execution time: 9_000_000 picoseconds. - Weight::from_parts(10_000_000, 0) + Weight::from_parts(9_000_000, 0) .saturating_add(Weight::from_parts(0, 1924)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) @@ -220,20 +218,31 @@ impl pallet_staking_extension::WeightInfo for WeightInf /// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Parameters::SignersInfo` (r:1 w:0) /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Babe::NextRandomness` (r:1 w:0) + /// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Babe::EpochStart` (r:1 w:0) + /// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `StakingExtension::ReshareData` (r:0 w:1) /// Proof: `StakingExtension::ReshareData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `StakingExtension::NextSigners` (r:0 w:1) /// Proof: `StakingExtension::NextSigners` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - fn new_session() -> Weight { + /// The range of component `c` is `[1, 14]`. + /// The range of component `l` is `[0, 15]`. + fn new_session(c: u32, l: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `727` - // Estimated: `2212` - // Minimum execution time: 10_000_000 picoseconds. - Weight::from_parts(14_000_000, 0) - .saturating_add(Weight::from_parts(0, 2212)) - .saturating_add(T::DbWeight::get().reads(3)) + // Measured: `482 + c * (32 ±0)` + // Estimated: `1966 + c * (32 ±0)` + // Minimum execution time: 13_000_000 picoseconds. + Weight::from_parts(12_683_761, 0) + .saturating_add(Weight::from_parts(0, 1966)) + // Standard Error: 28_030 + .saturating_add(Weight::from_parts(45_131, 0).saturating_mul(c.into())) + // Standard Error: 24_017 + .saturating_add(Weight::from_parts(12_438, 0).saturating_mul(l.into())) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 32).saturating_mul(c.into())) } }