Skip to content

Commit

Permalink
benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk committed Sep 27, 2023
1 parent 4e3c94d commit 92dcded
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 67 deletions.
71 changes: 71 additions & 0 deletions pallets/pooled-staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,77 @@ mod benchmarks {
Ok(())
}

#[benchmark]
fn swap_pool() -> Result<(), BenchmarkError> {
const USER_SEED: u32 = 1;

let source_stake = min_candidate_stk::<T>() * 10u32.into();

let (caller, _deposit_amount) = create_funded_user::<T>("caller", USER_SEED, source_stake);

T::EligibleCandidatesFilter::make_candidate_eligible(&caller, true);

PooledStaking::<T>::request_delegate(
RawOrigin::Signed(caller.clone()).into(),
caller.clone(),
TargetPool::AutoCompounding,
source_stake,
)?;

let timer = T::JoiningRequestTimer::now();

T::JoiningRequestTimer::skip_to_elapsed();

PooledStaking::<T>::execute_pending_operations(
RawOrigin::Signed(caller.clone()).into(),
vec![PendingOperationQuery {
delegator: caller.clone(),
operation: JoiningAutoCompounding {
candidate: caller.clone(),
at: timer.clone(),
},
}],
)?;

#[extrinsic_call]
_(
RawOrigin::Signed(caller.clone()),
caller.clone(),
TargetPool::AutoCompounding,
SharesOrStake::Stake(source_stake),
);

let target_stake = source_stake;
let source_shares = crate::pools::AutoCompounding::<T>::stake_to_shares_or_init(
&caller,
Stake(source_stake),
)
.unwrap()
.0;

let target_shares =
crate::pools::ManualRewards::<T>::stake_to_shares_or_init(&caller, Stake(target_stake))
.unwrap()
.0;

assert_last_event::<T>(
Event::SwappedPool {
candidate: caller.clone(),
delegator: caller,
source_pool: TargetPool::AutoCompounding,
source_shares,
source_stake,
target_shares,
target_stake,
pending_leaving: 0u32.into(),
released: 0u32.into(),
}
.into(),
);

Ok(())
}

impl_benchmark_test_suite!(
PooledStaking,
crate::mock::ExtBuilder::default().build(),
Expand Down
1 change: 0 additions & 1 deletion pallets/pooled-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ pub mod pallet {
source_pool: TargetPool,
amount: SharesOrStake<T::Balance>,
) -> DispatchResultWithPostInfo {
// We don't care about the sender.
let delegator = ensure_signed(origin)?;

Calls::<T>::swap_pool(candidate, delegator, source_pool, amount)
Expand Down
149 changes: 88 additions & 61 deletions pallets/pooled-staking/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! Autogenerated weights for pallet_pooled_staking
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-09-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-09-27, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `girazoki-XPS-15-9500`, CPU: `Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz`
//! HOSTNAME: `pop-os`, CPU: `12th Gen Intel(R) Core(TM) i7-1260P`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024
// Executed Command:
Expand All @@ -30,7 +30,7 @@
// --execution=wasm
// --wasm-execution=compiled
// --pallet
// pallet_pooled_staking
// pallet-pooled-staking
// --extrinsic
// *
// --steps
Expand Down Expand Up @@ -58,6 +58,7 @@ pub trait WeightInfo {
fn claim_manual_rewards(b: u32, ) -> Weight;
fn rebalance_hold() -> Weight;
fn update_candidate_position(b: u32, ) -> Weight;
fn swap_pool() -> Weight;
}

/// Weights for pallet_pooled_staking using the Substrate node and recommended hardware.
Expand All @@ -68,7 +69,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: Balances Holds (r:1 w:1)
/// Proof: Balances Holds (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen)
/// Proof: Balances Holds (max_values: None, max_size: Some(66), added: 2541, mode: MaxEncodedLen)
/// Storage: PooledStaking SortedEligibleCandidates (r:1 w:1)
/// Proof Skipped: PooledStaking SortedEligibleCandidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Session NextKeys (r:1 w:0)
Expand All @@ -79,10 +80,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof Skipped: PooledStaking PendingOperations (max_values: None, max_size: None, mode: Measured)
fn request_delegate() -> Weight {
// Proof Size summary in bytes:
// Measured: `1328`
// Estimated: `29543`
// Minimum execution time: 497_273_000 picoseconds.
Weight::from_parts(507_395_000, 29543)
// Measured: `1321`
// Estimated: `29536`
// Minimum execution time: 148_140_000 picoseconds.
Weight::from_parts(196_694_000, 29536)
.saturating_add(T::DbWeight::get().reads(17_u64))
.saturating_add(T::DbWeight::get().writes(9_u64))
}
Expand All @@ -93,18 +94,18 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: PooledStaking Pools (r:1000 w:800)
/// Proof Skipped: PooledStaking Pools (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances Holds (r:1 w:1)
/// Proof: Balances Holds (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen)
/// Proof: Balances Holds (max_values: None, max_size: Some(66), added: 2541, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// The range of component `b` is `[1, 100]`.
fn execute_pending_operations(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `550 + b * (390 ±0)`
// Measured: `543 + b * (390 ±0)`
// Estimated: `3593 + b * (25141 ±0)`
// Minimum execution time: 333_447_000 picoseconds.
Weight::from_parts(335_790_000, 3593)
// Standard Error: 594_634
.saturating_add(Weight::from_parts(174_012_935, 0).saturating_mul(b.into()))
// Minimum execution time: 97_115_000 picoseconds.
Weight::from_parts(103_358_000, 3593)
// Standard Error: 243_606
.saturating_add(Weight::from_parts(97_506_690, 0).saturating_mul(b.into()))
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().reads((11_u64).saturating_mul(b.into())))
.saturating_add(T::DbWeight::get().writes(2_u64))
Expand All @@ -115,15 +116,17 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof Skipped: PooledStaking Pools (max_values: None, max_size: None, mode: Measured)
/// Storage: PooledStaking SortedEligibleCandidates (r:1 w:1)
/// Proof Skipped: PooledStaking SortedEligibleCandidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Session CurrentIndex (r:1 w:0)
/// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: PooledStaking PendingOperations (r:1 w:1)
/// Proof Skipped: PooledStaking PendingOperations (max_values: None, max_size: None, mode: Measured)
fn request_undelegate() -> Weight {
// Proof Size summary in bytes:
// Measured: `557`
// Estimated: `33722`
// Minimum execution time: 249_510_000 picoseconds.
Weight::from_parts(252_589_000, 33722)
.saturating_add(T::DbWeight::get().reads(15_u64))
// Measured: `724`
// Estimated: `33889`
// Minimum execution time: 125_481_000 picoseconds.
Weight::from_parts(142_689_000, 33889)
.saturating_add(T::DbWeight::get().reads(16_u64))
.saturating_add(T::DbWeight::get().writes(11_u64))
}
/// Storage: PooledStaking Pools (r:300 w:100)
Expand All @@ -135,10 +138,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `360 + b * (456 ±0)`
// Estimated: `6196 + b * (7882 ±0)`
// Minimum execution time: 139_100_000 picoseconds.
Weight::from_parts(37_380_853, 6196)
// Standard Error: 543_344
.saturating_add(Weight::from_parts(98_370_210, 0).saturating_mul(b.into()))
// Minimum execution time: 67_358_000 picoseconds.
Weight::from_parts(62_976_252, 6196)
// Standard Error: 364_479
.saturating_add(Weight::from_parts(51_801_209, 0).saturating_mul(b.into()))
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(b.into())))
.saturating_add(T::DbWeight::get().writes(2_u64))
Expand All @@ -150,13 +153,13 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: System Account (r:2 w:2)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: Balances Holds (r:1 w:1)
/// Proof: Balances Holds (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen)
/// Proof: Balances Holds (max_values: None, max_size: Some(66), added: 2541, mode: MaxEncodedLen)
fn rebalance_hold() -> Weight {
// Proof Size summary in bytes:
// Measured: `987`
// Estimated: `11877`
// Minimum execution time: 224_748_000 picoseconds.
Weight::from_parts(234_677_000, 11877)
// Measured: `980`
// Estimated: `11870`
// Minimum execution time: 94_217_000 picoseconds.
Weight::from_parts(109_367_000, 11870)
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
Expand All @@ -171,16 +174,27 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `399 + b * (356 ±0)`
// Estimated: `1881 + b * (15206 ±0)`
// Minimum execution time: 107_339_000 picoseconds.
Weight::from_parts(108_246_000, 1881)
// Standard Error: 676_156
.saturating_add(Weight::from_parts(78_030_208, 0).saturating_mul(b.into()))
// Minimum execution time: 43_231_000 picoseconds.
Weight::from_parts(56_401_000, 1881)
// Standard Error: 91_302
.saturating_add(Weight::from_parts(35_820_280, 0).saturating_mul(b.into()))
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().reads((7_u64).saturating_mul(b.into())))
.saturating_add(T::DbWeight::get().writes(1_u64))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(b.into())))
.saturating_add(Weight::from_parts(0, 15206).saturating_mul(b.into()))
}
/// Storage: PooledStaking Pools (r:12 w:8)
/// Proof Skipped: PooledStaking Pools (max_values: None, max_size: None, mode: Measured)
fn swap_pool() -> Weight {
// Proof Size summary in bytes:
// Measured: `478`
// Estimated: `31168`
// Minimum execution time: 87_575_000 picoseconds.
Weight::from_parts(91_480_000, 31168)
.saturating_add(T::DbWeight::get().reads(12_u64))
.saturating_add(T::DbWeight::get().writes(8_u64))
}
}

// For backwards compatibility and tests
Expand All @@ -190,7 +204,7 @@ impl WeightInfo for () {
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: Balances Holds (r:1 w:1)
/// Proof: Balances Holds (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen)
/// Proof: Balances Holds (max_values: None, max_size: Some(66), added: 2541, mode: MaxEncodedLen)
/// Storage: PooledStaking SortedEligibleCandidates (r:1 w:1)
/// Proof Skipped: PooledStaking SortedEligibleCandidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Session NextKeys (r:1 w:0)
Expand All @@ -201,10 +215,10 @@ impl WeightInfo for () {
/// Proof Skipped: PooledStaking PendingOperations (max_values: None, max_size: None, mode: Measured)
fn request_delegate() -> Weight {
// Proof Size summary in bytes:
// Measured: `1328`
// Estimated: `29543`
// Minimum execution time: 497_273_000 picoseconds.
Weight::from_parts(507_395_000, 29543)
// Measured: `1321`
// Estimated: `29536`
// Minimum execution time: 148_140_000 picoseconds.
Weight::from_parts(196_694_000, 29536)
.saturating_add(RocksDbWeight::get().reads(17_u64))
.saturating_add(RocksDbWeight::get().writes(9_u64))
}
Expand All @@ -215,18 +229,18 @@ impl WeightInfo for () {
/// Storage: PooledStaking Pools (r:1000 w:800)
/// Proof Skipped: PooledStaking Pools (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances Holds (r:1 w:1)
/// Proof: Balances Holds (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen)
/// Proof: Balances Holds (max_values: None, max_size: Some(66), added: 2541, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// The range of component `b` is `[1, 100]`.
fn execute_pending_operations(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `550 + b * (390 ±0)`
// Measured: `543 + b * (390 ±0)`
// Estimated: `3593 + b * (25141 ±0)`
// Minimum execution time: 333_447_000 picoseconds.
Weight::from_parts(335_790_000, 3593)
// Standard Error: 594_634
.saturating_add(Weight::from_parts(174_012_935, 0).saturating_mul(b.into()))
// Minimum execution time: 97_115_000 picoseconds.
Weight::from_parts(103_358_000, 3593)
// Standard Error: 243_606
.saturating_add(Weight::from_parts(97_506_690, 0).saturating_mul(b.into()))
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().reads((11_u64).saturating_mul(b.into())))
.saturating_add(RocksDbWeight::get().writes(2_u64))
Expand All @@ -237,15 +251,17 @@ impl WeightInfo for () {
/// Proof Skipped: PooledStaking Pools (max_values: None, max_size: None, mode: Measured)
/// Storage: PooledStaking SortedEligibleCandidates (r:1 w:1)
/// Proof Skipped: PooledStaking SortedEligibleCandidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Session CurrentIndex (r:1 w:0)
/// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: PooledStaking PendingOperations (r:1 w:1)
/// Proof Skipped: PooledStaking PendingOperations (max_values: None, max_size: None, mode: Measured)
fn request_undelegate() -> Weight {
// Proof Size summary in bytes:
// Measured: `557`
// Estimated: `33722`
// Minimum execution time: 249_510_000 picoseconds.
Weight::from_parts(252_589_000, 33722)
.saturating_add(RocksDbWeight::get().reads(15_u64))
// Measured: `724`
// Estimated: `33889`
// Minimum execution time: 125_481_000 picoseconds.
Weight::from_parts(142_689_000, 33889)
.saturating_add(RocksDbWeight::get().reads(16_u64))
.saturating_add(RocksDbWeight::get().writes(11_u64))
}
/// Storage: PooledStaking Pools (r:300 w:100)
Expand All @@ -257,10 +273,10 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `360 + b * (456 ±0)`
// Estimated: `6196 + b * (7882 ±0)`
// Minimum execution time: 139_100_000 picoseconds.
Weight::from_parts(37_380_853, 6196)
// Standard Error: 543_344
.saturating_add(Weight::from_parts(98_370_210, 0).saturating_mul(b.into()))
// Minimum execution time: 67_358_000 picoseconds.
Weight::from_parts(62_976_252, 6196)
// Standard Error: 364_479
.saturating_add(Weight::from_parts(51_801_209, 0).saturating_mul(b.into()))
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().reads((3_u64).saturating_mul(b.into())))
.saturating_add(RocksDbWeight::get().writes(2_u64))
Expand All @@ -272,13 +288,13 @@ impl WeightInfo for () {
/// Storage: System Account (r:2 w:2)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: Balances Holds (r:1 w:1)
/// Proof: Balances Holds (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen)
/// Proof: Balances Holds (max_values: None, max_size: Some(66), added: 2541, mode: MaxEncodedLen)
fn rebalance_hold() -> Weight {
// Proof Size summary in bytes:
// Measured: `987`
// Estimated: `11877`
// Minimum execution time: 224_748_000 picoseconds.
Weight::from_parts(234_677_000, 11877)
// Measured: `980`
// Estimated: `11870`
// Minimum execution time: 94_217_000 picoseconds.
Weight::from_parts(109_367_000, 11870)
.saturating_add(RocksDbWeight::get().reads(7_u64))
.saturating_add(RocksDbWeight::get().writes(4_u64))
}
Expand All @@ -293,14 +309,25 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `399 + b * (356 ±0)`
// Estimated: `1881 + b * (15206 ±0)`
// Minimum execution time: 107_339_000 picoseconds.
Weight::from_parts(108_246_000, 1881)
// Standard Error: 676_156
.saturating_add(Weight::from_parts(78_030_208, 0).saturating_mul(b.into()))
// Minimum execution time: 43_231_000 picoseconds.
Weight::from_parts(56_401_000, 1881)
// Standard Error: 91_302
.saturating_add(Weight::from_parts(35_820_280, 0).saturating_mul(b.into()))
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().reads((7_u64).saturating_mul(b.into())))
.saturating_add(RocksDbWeight::get().writes(1_u64))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(b.into())))
.saturating_add(Weight::from_parts(0, 15206).saturating_mul(b.into()))
}
/// Storage: PooledStaking Pools (r:12 w:8)
/// Proof Skipped: PooledStaking Pools (max_values: None, max_size: None, mode: Measured)
fn swap_pool() -> Weight {
// Proof Size summary in bytes:
// Measured: `478`
// Estimated: `31168`
// Minimum execution time: 87_575_000 picoseconds.
Weight::from_parts(91_480_000, 31168)
.saturating_add(RocksDbWeight::get().reads(12_u64))
.saturating_add(RocksDbWeight::get().writes(8_u64))
}
}
Loading

0 comments on commit 92dcded

Please sign in to comment.