Skip to content

Commit

Permalink
new_session weight
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Aug 20, 2024
1 parent d5efccd commit 157b888
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 45 deletions.
24 changes: 18 additions & 6 deletions pallets/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -233,7 +234,7 @@ benchmarks! {
Signers::<T>::put(vec![validator_id_res.clone(), validator_id_res.clone()]);

}: {
Staking::<T>::new_session_handler(&vec![validator_id_res])
let _ = Staking::<T>::new_session_handler(&vec![validator_id_res]);
}
verify {
assert!(NextSigners::<T>::get().is_none());
Expand All @@ -252,27 +253,38 @@ benchmarks! {


}: {
Staking::<T>::new_session_handler(&signers)
let _ = Staking::<T>::new_session_handler(&signers);
}
verify {
assert_eq!(NextSigners::<T>::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 = <T as pallet_session::Config>::ValidatorId::try_from(caller.clone()).or(Err(Error::<T>::InvalidValidatorId)).unwrap();

let second_signer: T::AccountId = account("second_signer", 0, SEED);
let second_signer_id = <T as pallet_session::Config>::ValidatorId::try_from(second_signer.clone()).or(Err(Error::<T>::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::<T>::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::<T>::put(SignersSize {
total_signers: MAX_SIGNERS,
threshold: 3,
last_session_change: 0
});


}: {
Staking::<T>::new_session_handler(&signers)
let _ = Staking::<T>::new_session_handler(&signers);
}
verify {
assert!(NextSigners::<T>::get().is_some());
Expand Down
2 changes: 1 addition & 1 deletion pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T as Config>::WeightInfo::new_session(current_signers.len() as u32, count)
}

// removes first signer and pushes new signer to back if total signers not increased
Expand Down
52 changes: 37 additions & 15 deletions pallets/staking/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -208,21 +208,32 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// 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`)
Expand Down Expand Up @@ -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`)
Expand Down
55 changes: 32 additions & 23 deletions runtime/src/weights/pallet_staking_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024
Expand Down Expand Up @@ -55,8 +55,8 @@ impl<T: frame_system::Config> 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))
Expand All @@ -73,8 +73,8 @@ impl<T: frame_system::Config> 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))
Expand All @@ -95,8 +95,8 @@ impl<T: frame_system::Config> 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))
Expand Down Expand Up @@ -131,8 +131,8 @@ impl<T: frame_system::Config> 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))
Expand All @@ -145,7 +145,7 @@ impl<T: frame_system::Config> 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))
Expand All @@ -161,10 +161,8 @@ impl<T: frame_system::Config> 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()))
Expand All @@ -179,8 +177,8 @@ impl<T: frame_system::Config> 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))
Expand Down Expand Up @@ -211,7 +209,7 @@ impl<T: frame_system::Config> 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))
Expand All @@ -220,20 +218,31 @@ impl<T: frame_system::Config> 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()))
}
}

0 comments on commit 157b888

Please sign in to comment.