Skip to content

Commit

Permalink
add new_session_not_adding_new_signer
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Aug 20, 2024
1 parent 5fa6a24 commit d5efccd
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 11 deletions.
39 changes: 39 additions & 0 deletions pallets/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,45 @@ benchmarks! {
verify {
assert!(NextSigners::<T>::get().is_none());
}

new_session_not_adding_new_signer {
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(); 5];
Signers::<T>::put(signers.clone());
signers.push(validator_id_res.clone());


}: {
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 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];
Signers::<T>::put(signers.clone());
signers.push(validator_id_res.clone());

}: {
Staking::<T>::new_session_handler(&signers)
}
verify {
assert!(NextSigners::<T>::get().is_some());
}
}

impl_benchmark_test_suite!(Staking, crate::mock::new_test_ext(), crate::mock::Test);
7 changes: 6 additions & 1 deletion pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,19 +549,23 @@ pub mod pallet {

let signers_info = pallet_parameters::Pallet::<T>::signers_info();
let mut new_signer = vec![];
let mut weight: Weight = <T as Config>::WeightInfo::new_session_not_adding_new_signer();

if current_signers_length <= signers_info.total_signers as usize {
let mut randomness = Self::get_randomness();
// grab a current signer to initiate value
let mut next_signer_up = &current_signers[0].clone();
let mut index;
let mut count = 0u32;
// loops to find signer in validator that is not already signer
while current_signers.contains(next_signer_up) {
index = randomness.next_u32() % validators.len() as u32;
next_signer_up = &validators[index as usize];
count += 1;
}
current_signers.push(next_signer_up.clone());
new_signer = next_signer_up.encode();
// TODO add last weight here
}

// removes first signer and pushes new signer to back if total signers not increased
Expand All @@ -583,7 +587,8 @@ pub mod pallet {
JumpStartProgress::<T>::mutate(|jump_start_details| {
jump_start_details.parent_key_threshold = signers_info.threshold
});
Ok(0.into())

Ok(weight)
}
}

Expand Down
82 changes: 82 additions & 0 deletions pallets/staking/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub trait WeightInfo {
fn confirm_key_reshare_confirmed(c: u32) -> Weight;
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;
}

/// Weights for pallet_staking_extension using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -202,6 +204,46 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(Weight::from_parts(0, 1719))
.saturating_add(T::DbWeight::get().reads(1))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// 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: `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 {
// 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))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// 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: `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_not_adding_new_signer() -> Weight {
// Proof Size summary in bytes:
// Measured: `439`
// Estimated: `1924`
// Minimum execution time: 9_000_000 picoseconds.
Weight::from_parts(10_000_000, 0)
.saturating_add(Weight::from_parts(0, 1924))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -343,4 +385,44 @@ impl WeightInfo for () {
.saturating_add(Weight::from_parts(0, 1719))
.saturating_add(RocksDbWeight::get().reads(1))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// 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: `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 {
// 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))
.saturating_add(RocksDbWeight::get().writes(3))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// 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: `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_not_adding_new_signer() -> Weight {
// Proof Size summary in bytes:
// Measured: `439`
// Estimated: `1924`
// Minimum execution time: 9_000_000 picoseconds.
Weight::from_parts(10_000_000, 0)
.saturating_add(Weight::from_parts(0, 1924))
.saturating_add(RocksDbWeight::get().reads(3))
.saturating_add(RocksDbWeight::get().writes(3))
}
}
62 changes: 52 additions & 10 deletions runtime/src/weights/pallet_staking_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Measured: `1309`
// Estimated: `4774`
// Minimum execution time: 25_000_000 picoseconds.
Weight::from_parts(27_000_000, 0)
Weight::from_parts(25_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: 30_000_000 picoseconds.
Weight::from_parts(33_000_000, 0)
// Minimum execution time: 29_000_000 picoseconds.
Weight::from_parts(32_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: 43_000_000 picoseconds.
Weight::from_parts(55_000_000, 0)
// Minimum execution time: 42_000_000 picoseconds.
Weight::from_parts(49_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 @@ -146,7 +146,7 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Measured: `320`
// Estimated: `3785`
// Minimum execution time: 10_000_000 picoseconds.
Weight::from_parts(11_000_000, 0)
Weight::from_parts(10_000_000, 0)
.saturating_add(Weight::from_parts(0, 3785))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -161,8 +161,10 @@ 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_756_906, 0)
Weight::from_parts(12_143_646, 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 @@ -178,7 +180,7 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Measured: `1309`
// Estimated: `4774`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(12_000_000, 0)
Weight::from_parts(13_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 All @@ -189,9 +191,49 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `234`
// Estimated: `1719`
// Minimum execution time: 4_000_000 picoseconds.
Weight::from_parts(4_000_000, 0)
// Minimum execution time: 3_000_000 picoseconds.
Weight::from_parts(3_000_000, 0)
.saturating_add(Weight::from_parts(0, 1719))
.saturating_add(T::DbWeight::get().reads(1))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// 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: `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_not_adding_new_signer() -> Weight {
// Proof Size summary in bytes:
// Measured: `439`
// Estimated: `1924`
// Minimum execution time: 9_000_000 picoseconds.
Weight::from_parts(10_000_000, 0)
.saturating_add(Weight::from_parts(0, 1924))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// 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: `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 {
// 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))
.saturating_add(T::DbWeight::get().writes(3))
}
}

0 comments on commit d5efccd

Please sign in to comment.