Skip to content

Commit

Permalink
Co reducing fast-unstake bench time and more (#6552)
Browse files Browse the repository at this point in the history
* update stuff

* remove

* update

* update

* update weights

* fix tests

* update weights

* fix a few small things

* ".git/.scripts/commands/bench/bench.sh" runtime polkadot-dev pallet-fast-unstake

* ".git/.scripts/commands/bench/bench.sh" runtime polkadot-dev pallet-fast-unstake

* ".git/.scripts/commands/bench/bench.sh" runtime kusama-dev pallet-fast-unstake

* reduce batch size

* ".git/.scripts/commands/bench/bench.sh" runtime polkadot-dev pallet-fast-unstake

* update

* fix

* fix

* ".git/.scripts/commands/bench/bench.sh" runtime polkadot-dev pallet-fast-unstake

* update lockfile for {"substrate"}

* fmt

* Env gate migration try_fast_unstake_all

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

---------

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Co-authored-by: command-bot <>
Co-authored-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
kianenigma and ggwpez authored Jan 27, 2023
1 parent 99e9cf4 commit 1ee714a
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 82 deletions.
50 changes: 49 additions & 1 deletion relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,11 @@ impl pallet_fast_unstake::Config for Runtime {
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>,
>;
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
type Staking = Staking;
type MaxErasToCheckPerBlock = ConstU32<1>;
#[cfg(feature = "runtime-benchmarks")]
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -2133,6 +2136,19 @@ mod multiplier_tests {
})
}

#[test]
fn fast_unstake_estimate() {
use pallet_fast_unstake::WeightInfo;
let block_time = BlockWeights::get().max_block.ref_time() as f32;
let on_idle = weights::pallet_fast_unstake::WeightInfo::<Runtime>::on_idle_check(
1000,
<Runtime as pallet_fast_unstake::Config>::BatchSize::get(),
)
.ref_time() as f32;
println!("ratio of block weight for full batch fast-unstake {}", on_idle / block_time);
assert!(on_idle / block_time <= 0.5f32)
}

#[test]
#[ignore]
fn multiplier_growth_simulator() {
Expand Down Expand Up @@ -2251,4 +2267,36 @@ mod remote_tests {
.unwrap();
ext.execute_with(|| Runtime::on_runtime_upgrade(UpgradeCheckSelect::PreAndPost));
}

#[tokio::test]
async fn try_fast_unstake_all() {
if var("RUN_MIGRATION_TESTS").is_err() {
return
}

sp_tracing::try_init_simple();
let transport: Transport =
var("WS").unwrap_or("wss://kusama-rpc.polkadot.io:443".to_string()).into();
let maybe_state_snapshot: Option<SnapshotConfig> = var("SNAP").map(|s| s.into()).ok();
let mut ext = Builder::<Block>::default()
.mode(if let Some(state_snapshot) = maybe_state_snapshot {
Mode::OfflineOrElseOnline(
OfflineConfig { state_snapshot: state_snapshot.clone() },
OnlineConfig {
transport,
state_snapshot: Some(state_snapshot),
..Default::default()
},
)
} else {
Mode::Online(OnlineConfig { transport, ..Default::default() })
})
.build()
.await
.unwrap();
ext.execute_with(|| {
pallet_fast_unstake::ErasToCheckPerBlock::<Runtime>::put(1);
runtime_common::try_runtime::migrate_all_inactive_nominators::<Runtime>()
});
}
}
92 changes: 51 additions & 41 deletions relay/kusama/src/weights/pallet_fast_unstake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@
//! Autogenerated weights for `pallet_fast_unstake`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-01-23, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `runner-b3zmxxc-project-163-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! DATE: 2023-01-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024

// Executed Command:
// ./target/production/polkadot
// /home/benchbot/cargo_target_dir/production/polkadot
// benchmark
// pallet
// --chain=kusama-dev
// --steps=50
// --repeat=20
// --pallet=pallet_fast_unstake
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/polkadot/.git/.artifacts/bench.json
// --pallet=pallet-fast-unstake
// --chain=kusama-dev
// --header=./file_header.txt
// --output=./runtime/kusama/src/weights/

Expand All @@ -46,40 +48,48 @@ pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_fast_unstake::WeightInfo for WeightInfo<T> {
// Storage: FastUnstake ErasToCheckPerBlock (r:1 w:0)
// Storage: Staking ValidatorCount (r:1 w:0)
// Storage: ElectionProviderMultiPhase CurrentPhase (r:1 w:0)
// Storage: FastUnstake Head (r:1 w:1)
// Storage: FastUnstake CounterForQueue (r:1 w:0)
// Storage: ElectionProviderMultiPhase CurrentPhase (r:1 w:0)
// Storage: Staking CurrentEra (r:1 w:0)
// Storage: Staking SlashingSpans (r:64 w:0)
// Storage: Staking Bonded (r:64 w:64)
// Storage: Staking Validators (r:64 w:0)
// Storage: Staking Nominators (r:64 w:0)
// Storage: System Account (r:64 w:64)
// Storage: Balances Locks (r:64 w:64)
// Storage: Staking Ledger (r:0 w:64)
// Storage: Staking Payee (r:0 w:64)
fn on_idle_unstake() -> Weight {
// Minimum execution time: 2_547_167 nanoseconds.
Weight::from_ref_time(2_569_186_000)
.saturating_add(T::DbWeight::get().reads(389))
.saturating_add(T::DbWeight::get().writes(321))
// Storage: Staking SlashingSpans (r:1 w:0)
// Storage: Staking Bonded (r:1 w:1)
// Storage: Staking Validators (r:1 w:0)
// Storage: Staking Nominators (r:1 w:0)
// Storage: System Account (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
// Storage: Staking Ledger (r:0 w:1)
// Storage: Staking Payee (r:0 w:1)
/// The range of component `b` is `[1, 64]`.
fn on_idle_unstake(b: u32, ) -> Weight {
// Minimum execution time: 77_225 nanoseconds.
Weight::from_ref_time(45_851_915)
// Standard Error: 27_205
.saturating_add(Weight::from_ref_time(34_256_381).saturating_mul(b.into()))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().reads((6_u64).saturating_mul(b.into())))
.saturating_add(T::DbWeight::get().writes(1))
.saturating_add(T::DbWeight::get().writes((5_u64).saturating_mul(b.into())))
}
// Storage: FastUnstake ErasToCheckPerBlock (r:1 w:0)
// Storage: Staking ValidatorCount (r:1 w:0)
// Storage: ElectionProviderMultiPhase CurrentPhase (r:1 w:0)
// Storage: FastUnstake Head (r:1 w:1)
// Storage: FastUnstake Queue (r:65 w:64)
// Storage: FastUnstake CounterForQueue (r:1 w:1)
// Storage: FastUnstake CounterForQueue (r:1 w:0)
// Storage: ElectionProviderMultiPhase CurrentPhase (r:1 w:0)
// Storage: Staking CurrentEra (r:1 w:0)
// Storage: Staking ErasStakers (r:56 w:0)
/// The range of component `x` is `[28, 3584]`.
fn on_idle_check(x: u32, ) -> Weight {
// Minimum execution time: 25_160_452 nanoseconds.
Weight::from_ref_time(25_413_896_000)
// Standard Error: 556_413
.saturating_add(Weight::from_ref_time(700_987_201).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(85))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into())))
.saturating_add(T::DbWeight::get().writes(66))
// Storage: Staking ErasStakers (r:2 w:0)
/// The range of component `v` is `[1, 256]`.
/// The range of component `b` is `[1, 64]`.
fn on_idle_check(v: u32, b: u32, ) -> Weight {
// Minimum execution time: 1_671_682 nanoseconds.
Weight::from_ref_time(1_683_909_000)
// Standard Error: 16_637_473
.saturating_add(Weight::from_ref_time(533_652_266).saturating_mul(v.into()))
// Standard Error: 66_568_424
.saturating_add(Weight::from_ref_time(2_085_678_765).saturating_mul(b.into()))
.saturating_add(T::DbWeight::get().reads(7))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(v.into())))
.saturating_add(T::DbWeight::get().writes(1))
}
// Storage: FastUnstake ErasToCheckPerBlock (r:1 w:0)
// Storage: Staking Ledger (r:1 w:1)
Expand All @@ -89,33 +99,33 @@ impl<T: frame_system::Config> pallet_fast_unstake::WeightInfo for WeightInfo<T>
// Storage: Staking Validators (r:1 w:0)
// Storage: Staking Nominators (r:1 w:1)
// Storage: Staking CounterForNominators (r:1 w:1)
// Storage: VoterList ListNodes (r:2 w:2)
// Storage: VoterList ListNodes (r:1 w:1)
// Storage: VoterList ListBags (r:1 w:1)
// Storage: VoterList CounterForListNodes (r:1 w:1)
// Storage: Staking CurrentEra (r:1 w:0)
// Storage: Balances Locks (r:1 w:1)
// Storage: FastUnstake CounterForQueue (r:1 w:1)
fn register_fast_unstake() -> Weight {
// Minimum execution time: 156_147 nanoseconds.
Weight::from_ref_time(158_284_000)
.saturating_add(T::DbWeight::get().reads(15))
.saturating_add(T::DbWeight::get().writes(10))
// Minimum execution time: 106_509 nanoseconds.
Weight::from_ref_time(107_537_000)
.saturating_add(T::DbWeight::get().reads(14))
.saturating_add(T::DbWeight::get().writes(9))
}
// Storage: FastUnstake ErasToCheckPerBlock (r:1 w:0)
// Storage: Staking Ledger (r:1 w:0)
// Storage: FastUnstake Queue (r:1 w:1)
// Storage: FastUnstake Head (r:1 w:0)
// Storage: FastUnstake CounterForQueue (r:1 w:1)
fn deregister() -> Weight {
// Minimum execution time: 62_835 nanoseconds.
Weight::from_ref_time(65_108_000)
// Minimum execution time: 43_328 nanoseconds.
Weight::from_ref_time(43_904_000)
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
}
// Storage: FastUnstake ErasToCheckPerBlock (r:0 w:1)
fn control() -> Weight {
// Minimum execution time: 3_747 nanoseconds.
Weight::from_ref_time(4_132_000)
// Minimum execution time: 4_153 nanoseconds.
Weight::from_ref_time(4_337_000)
.saturating_add(T::DbWeight::get().writes(1))
}
}
52 changes: 50 additions & 2 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,17 @@ impl pallet_staking::Config for Runtime {
impl pallet_fast_unstake::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type BatchSize = frame_support::traits::ConstU32<64>;
type BatchSize = frame_support::traits::ConstU32<16>;
type Deposit = frame_support::traits::ConstU128<{ UNITS }>;
type ControlOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>,
>;
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
type Staking = Staking;
type MaxErasToCheckPerBlock = ConstU32<1>;
#[cfg(feature = "runtime-benchmarks")]
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -2335,6 +2338,19 @@ mod multiplier_tests {
})
}

#[test]
fn fast_unstake_estimate() {
use pallet_fast_unstake::WeightInfo;
let block_time = BlockWeights::get().max_block.ref_time() as f32;
let on_idle = weights::pallet_fast_unstake::WeightInfo::<Runtime>::on_idle_check(
300,
<Runtime as pallet_fast_unstake::Config>::BatchSize::get(),
)
.ref_time() as f32;
println!("ratio of block weight for full batch fast-unstake {}", on_idle / block_time);
assert!(on_idle / block_time <= 0.5f32)
}

#[test]
#[ignore]
fn multiplier_growth_simulator() {
Expand Down Expand Up @@ -2453,4 +2469,36 @@ mod remote_tests {
.unwrap();
ext.execute_with(|| Runtime::on_runtime_upgrade(UpgradeCheckSelect::PreAndPost));
}

#[tokio::test]
async fn try_fast_unstake_all() {
if var("RUN_MIGRATION_TESTS").is_err() {
return
}

sp_tracing::try_init_simple();
let transport: Transport =
var("WS").unwrap_or("wss://rpc.polkadot.io:443".to_string()).into();
let maybe_state_snapshot: Option<SnapshotConfig> = var("SNAP").map(|s| s.into()).ok();
let mut ext = Builder::<Block>::default()
.mode(if let Some(state_snapshot) = maybe_state_snapshot {
Mode::OfflineOrElseOnline(
OfflineConfig { state_snapshot: state_snapshot.clone() },
OnlineConfig {
transport,
state_snapshot: Some(state_snapshot),
..Default::default()
},
)
} else {
Mode::Online(OnlineConfig { transport, ..Default::default() })
})
.build()
.await
.unwrap();
ext.execute_with(|| {
pallet_fast_unstake::ErasToCheckPerBlock::<Runtime>::put(1);
runtime_common::try_runtime::migrate_all_inactive_nominators::<Runtime>()
});
}
}
Loading

0 comments on commit 1ee714a

Please sign in to comment.