diff --git a/pallets/pooled-staking/src/benchmarking.rs b/pallets/pooled-staking/src/benchmarking.rs index 89b77a77a..3a97b3ddf 100644 --- a/pallets/pooled-staking/src/benchmarking.rs +++ b/pallets/pooled-staking/src/benchmarking.rs @@ -454,6 +454,77 @@ mod benchmarks { Ok(()) } + #[benchmark] + fn swap_pool() -> Result<(), BenchmarkError> { + const USER_SEED: u32 = 1; + + let source_stake = min_candidate_stk::() * 10u32.into(); + + let (caller, _deposit_amount) = create_funded_user::("caller", USER_SEED, source_stake); + + T::EligibleCandidatesFilter::make_candidate_eligible(&caller, true); + + PooledStaking::::request_delegate( + RawOrigin::Signed(caller.clone()).into(), + caller.clone(), + TargetPool::AutoCompounding, + source_stake, + )?; + + let timer = T::JoiningRequestTimer::now(); + + T::JoiningRequestTimer::skip_to_elapsed(); + + PooledStaking::::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::::stake_to_shares_or_init( + &caller, + Stake(source_stake), + ) + .unwrap() + .0; + + let target_shares = + crate::pools::ManualRewards::::stake_to_shares_or_init(&caller, Stake(target_stake)) + .unwrap() + .0; + + assert_last_event::( + 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(), diff --git a/pallets/pooled-staking/src/lib.rs b/pallets/pooled-staking/src/lib.rs index 6e054f84b..042bbfc0a 100644 --- a/pallets/pooled-staking/src/lib.rs +++ b/pallets/pooled-staking/src/lib.rs @@ -536,7 +536,6 @@ pub mod pallet { source_pool: TargetPool, amount: SharesOrStake, ) -> DispatchResultWithPostInfo { - // We don't care about the sender. let delegator = ensure_signed(origin)?; Calls::::swap_pool(candidate, delegator, source_pool, amount) diff --git a/pallets/pooled-staking/src/weights.rs b/pallets/pooled-staking/src/weights.rs index 3d646099c..df5d16d6e 100644 --- a/pallets/pooled-staking/src/weights.rs +++ b/pallets/pooled-staking/src/weights.rs @@ -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: @@ -30,7 +30,7 @@ // --execution=wasm // --wasm-execution=compiled // --pallet -// pallet_pooled_staking +// pallet-pooled-staking // --extrinsic // * // --steps @@ -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. @@ -68,7 +69,7 @@ impl WeightInfo for SubstrateWeight { /// 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) @@ -79,10 +80,10 @@ impl WeightInfo for SubstrateWeight { /// 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)) } @@ -93,18 +94,18 @@ impl WeightInfo for SubstrateWeight { /// 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)) @@ -115,15 +116,17 @@ impl WeightInfo for SubstrateWeight { /// 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) @@ -135,10 +138,10 @@ impl WeightInfo for SubstrateWeight { // 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)) @@ -150,13 +153,13 @@ impl WeightInfo for SubstrateWeight { /// 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)) } @@ -171,16 +174,27 @@ impl WeightInfo for SubstrateWeight { // 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 @@ -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) @@ -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)) } @@ -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)) @@ -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) @@ -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)) @@ -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)) } @@ -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)) + } } diff --git a/runtime/dancebox/src/lib.rs b/runtime/dancebox/src/lib.rs index 5387da8a9..a496370a9 100644 --- a/runtime/dancebox/src/lib.rs +++ b/runtime/dancebox/src/lib.rs @@ -483,11 +483,6 @@ pub struct CollatorsFromInvulnerablesAndThenFromStaking; /// Play the role of the session manager. impl SessionManager for CollatorsFromInvulnerablesAndThenFromStaking { fn new_session(index: SessionIndex) -> Option> { - log::info!( - "assembling new collators for new session {} at #{:?}", - index, - >::block_number(), - ); let invulnerables = Invulnerables::invulnerables().to_vec(); let candidates_staking =