Skip to content

Commit

Permalink
chore: scale up max delegators per collator to 35 from 25 (#311)
Browse files Browse the repository at this point in the history
* refactor: rn + move primitives to runtime common

* chore: increase max delegators per collator

* refactor: use extend_lock instead of custom impl

* cargo run --quiet --release -p kilt-parachain --features=runtime-benchmarks -- benchmark --chain=spiritnet-dev --steps=50 --repeat=20 --pallet=parachain-staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./runtimes/spiritnet/src/weights/parachain_staking.rs --template=.maintain/runtime-weight-template.hbs

* cargo run --quiet --release -p kilt-parachain --features=runtime-benchmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=parachain-staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=pallets/parachain-staking/src/default_weights.rs --template=.maintain/weight-template.hbs

* refactor: rm unused weight param in execute_exit

Co-authored-by: kiltbot <>
  • Loading branch information
wischli authored Jan 18, 2022
1 parent 0b39270 commit 8dd0a38
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 321 deletions.
2 changes: 1 addition & 1 deletion pallets/parachain-staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ benchmarks! {
execute_leave_candidates {
let n in (T::MinCollators::get() + 1) .. T::MaxTopCandidates::get() - 1;
let m in 0 .. T::MaxDelegatorsPerCollator::get();
let u in 1 .. (T::MaxUnstakeRequests::get() as u32 - 1);

let u = T::MaxUnstakeRequests::get() as u32 - 1;
let candidates = setup_collator_candidates::<T>(n, None);
for (i, c) in candidates.iter().enumerate() {
fill_delegators::<T>(m, c.clone(), i.saturated_into::<u32>());
Expand Down
284 changes: 140 additions & 144 deletions pallets/parachain-staking/src/default_weights.rs

Large diffs are not rendered by default.

21 changes: 3 additions & 18 deletions pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,6 @@ pub mod pallet {
#[pallet::weight(<T as pallet::Config>::WeightInfo::execute_leave_candidates(
T::MaxTopCandidates::get(),
T::MaxDelegatorsPerCollator::get(),
T::MaxUnstakeRequests::get()
))]
pub fn execute_leave_candidates(
origin: OriginFor<T>,
Expand All @@ -1241,7 +1240,6 @@ pub mod pallet {
Ok(Some(<T as pallet::Config>::WeightInfo::execute_leave_candidates(
T::MaxTopCandidates::get(),
num_delegators,
T::MaxUnstakeRequests::get(),
))
.into())
}
Expand Down Expand Up @@ -2511,22 +2509,9 @@ pub mod pallet {
Ok(())
})?;

// Handle case of collator/delegator decreasing their stake and increasing
// afterwards which results in amount != locked
//
// Example: if delegator has 100 staked and decreases by 30 and then increases
// by 20, 80 have been delegated to the collator but
// amount = 80, more = 30, locked = 100.
//
// This would immediately unlock 20 for the delegator
let amount: BalanceOf<T> = if let Some(BalanceLock { amount: locked, .. }) =
Locks::<T>::get(who).iter().find(|l| l.id == STAKING_ID)
{
BalanceOf::<T>::from(*locked).max(amount)
} else {
amount
};
T::Currency::set_lock(STAKING_ID, who, amount, WithdrawReasons::all());
// Either set a new lock or potentially extend the existing one if amount
// exceeds the currently locked amount
T::Currency::extend_lock(STAKING_ID, who, amount, WithdrawReasons::all());

Ok(unstaking_len)
}
Expand Down
1 change: 1 addition & 0 deletions runtimes/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub mod staking {
#[cfg(not(feature = "fast-gov"))]
pub const MAX_CANDIDATES: u32 = 75;

pub const MAX_DELEGATORS_PER_COLLATOR: u32 = 35;
pub const MIN_DELEGATOR_STAKE: Balance = 20 * KILT;

pub const NETWORK_REWARD_RATE: Perquintill = Perquintill::from_percent(10);
Expand Down
2 changes: 1 addition & 1 deletion runtimes/peregrine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ parameter_types! {
pub const MaxDelegationsPerRound: u32 = 1;
/// Maximum 25 delegators per collator at launch, might be increased later
#[derive(Debug, PartialEq)]
pub const MaxDelegatorsPerCollator: u32 = 25;
pub const MaxDelegatorsPerCollator: u32 = constants::staking::MAX_DELEGATORS_PER_COLLATOR;
/// Maximum 1 collator per delegator at launch, will be increased later
#[derive(Debug, PartialEq)]
pub const MaxCollatorsPerDelegator: u32 = 1;
Expand Down
158 changes: 78 additions & 80 deletions runtimes/peregrine/src/weights/parachain_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
//! Autogenerated weights for parachain_staking
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2021-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128
//! DATE: 2022-01-12, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("spiritnet-dev"), DB CACHE: 128
// Executed Command:
// target/release/kilt-parachain
// benchmark
// --chain=dev
// --chain=spiritnet-dev
// --steps=50
// --repeat=20
// --pallet=parachain-staking
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --output=./runtimes/peregrine/src/weights/parachain_staking.rs
// --output=./runtimes/spiritnet/src/weights/parachain_staking.rs
// --template=.maintain/runtime-weight-template.hbs


Expand All @@ -50,20 +50,20 @@ pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking Round (r:1 w:0)
fn on_initialize_no_action() -> Weight {
(4_300_000 as Weight)
(4_132_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
}
// Storage: ParachainStaking Round (r:1 w:1)
fn on_initialize_round_update() -> Weight {
(17_737_000 as Weight)
(17_658_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: ParachainStaking Round (r:1 w:1)
// Storage: ParachainStaking LastRewardReduction (r:1 w:1)
// Storage: ParachainStaking InflationConfig (r:1 w:1)
fn on_initialize_new_year() -> Weight {
(33_144_000 as Weight)
(33_675_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
Expand All @@ -74,18 +74,18 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking MaxSelectedCandidates (r:1 w:0)
// Storage: System Account (r:1 w:1)
fn on_initialize_network_rewards() -> Weight {
(69_124_000 as Weight)
(71_823_000 as Weight)
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
// Storage: ParachainStaking ForceNewRound (r:0 w:1)
fn force_new_round() -> Weight {
(2_608_000 as Weight)
(2_623_000 as Weight)
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: ParachainStaking InflationConfig (r:0 w:1)
fn set_inflation() -> Weight {
(16_028_000 as Weight)
(16_098_000 as Weight)
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: ParachainStaking MaxSelectedCandidates (r:1 w:1)
Expand All @@ -94,35 +94,35 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking CandidatePool (r:1 w:0)
fn set_max_selected_candidates(n: u32, m: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 13_000
.saturating_add((10_603_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 38_000
.saturating_add((12_526_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 17_000
.saturating_add((11_600_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 33_000
.saturating_add((10_491_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(n as Weight)))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: ParachainStaking Round (r:1 w:1)
fn set_blocks_per_round() -> Weight {
(18_844_000 as Weight)
(18_909_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: ParachainStaking CandidatePool (r:17 w:1)
// Storage: ParachainStaking TopCandidates (r:1 w:1)
// Storage: ParachainStaking Unstaking (r:26 w:26)
// Storage: ParachainStaking DelegatorState (r:25 w:25)
// Storage: ParachainStaking Unstaking (r:36 w:36)
// Storage: ParachainStaking DelegatorState (r:35 w:35)
// Storage: Session Validators (r:1 w:0)
// Storage: Session DisabledValidators (r:1 w:1)
// Storage: System Digest (r:1 w:1)
// Storage: ParachainStaking CandidateCount (r:1 w:1)
// Storage: ParachainStaking MaxSelectedCandidates (r:1 w:0)
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
fn force_remove_candidate(n: u32, m: u32, ) -> Weight {
(2_447_000 as Weight)
// Standard Error: 17_000
.saturating_add((3_029_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 49_000
.saturating_add((26_350_000 as Weight).saturating_mul(m as Weight))
(0 as Weight)
// Standard Error: 16_000
.saturating_add((4_053_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 30_000
.saturating_add((27_552_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads(25 as Weight))
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(m as Weight)))
.saturating_add(T::DbWeight::get().writes(7 as Weight))
Expand All @@ -139,11 +139,11 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
// Storage: ParachainStaking CandidateCount (r:1 w:1)
fn join_candidates(n: u32, m: u32, ) -> Weight {
(13_021_000 as Weight)
(0 as Weight)
// Standard Error: 17_000
.saturating_add((2_088_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 65_000
.saturating_add((5_189_000 as Weight).saturating_mul(m as Weight))
.saturating_add((2_616_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 42_000
.saturating_add((4_780_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads(10 as Weight))
.saturating_add(T::DbWeight::get().writes(7 as Weight))
}
Expand All @@ -153,11 +153,11 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking MaxSelectedCandidates (r:1 w:0)
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
fn init_leave_candidates(n: u32, m: u32, ) -> Weight {
(43_225_000 as Weight)
// Standard Error: 15_000
.saturating_add((2_362_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 40_000
.saturating_add((7_929_000 as Weight).saturating_mul(m as Weight))
(22_114_000 as Weight)
// Standard Error: 20_000
.saturating_add((2_809_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 36_000
.saturating_add((6_859_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads(21 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
Expand All @@ -167,29 +167,27 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
fn cancel_leave_candidates(n: u32, m: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 12_000
.saturating_add((2_169_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 34_000
.saturating_add((5_859_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 17_000
.saturating_add((2_703_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 30_000
.saturating_add((5_312_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: ParachainStaking CandidatePool (r:1 w:1)
// Storage: ParachainStaking Round (r:1 w:0)
// Storage: ParachainStaking Unstaking (r:26 w:26)
// Storage: ParachainStaking DelegatorState (r:25 w:25)
// Storage: ParachainStaking Unstaking (r:36 w:36)
// Storage: ParachainStaking DelegatorState (r:35 w:35)
// Storage: Session Validators (r:1 w:0)
// Storage: Session DisabledValidators (r:1 w:1)
// Storage: System Digest (r:1 w:1)
// Storage: ParachainStaking CandidateCount (r:1 w:1)
fn execute_leave_candidates(n: u32, m: u32, u: u32, ) -> Weight {
fn execute_leave_candidates(n: u32, m: u32 ) -> Weight {
(0 as Weight)
// Standard Error: 14_000
.saturating_add((3_188_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 39_000
.saturating_add((26_693_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 171_000
.saturating_add((1_156_000 as Weight).saturating_mul(u as Weight))
// Standard Error: 15_000
.saturating_add((4_365_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 27_000
.saturating_add((27_649_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(m as Weight)))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
Expand All @@ -205,12 +203,12 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
fn candidate_stake_more(n: u32, m: u32, u: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 15_000
.saturating_add((2_754_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 57_000
.saturating_add((7_491_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 219_000
.saturating_add((1_867_000 as Weight).saturating_mul(u as Weight))
// Standard Error: 17_000
.saturating_add((3_390_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 41_000
.saturating_add((6_747_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 244_000
.saturating_add((1_599_000 as Weight).saturating_mul(u as Weight))
.saturating_add(T::DbWeight::get().reads(8 as Weight))
.saturating_add(T::DbWeight::get().writes(6 as Weight))
}
Expand All @@ -221,10 +219,10 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
fn candidate_stake_less(n: u32, m: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 16_000
.saturating_add((2_721_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 60_000
.saturating_add((7_123_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 18_000
.saturating_add((3_186_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 44_000
.saturating_add((6_373_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
Expand All @@ -240,10 +238,10 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
fn join_delegators(n: u32, m: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 17_000
.saturating_add((2_940_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 71_000
.saturating_add((8_122_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 19_000
.saturating_add((3_590_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 52_000
.saturating_add((7_320_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads(11 as Weight))
.saturating_add(T::DbWeight::get().writes(8 as Weight))
}
Expand All @@ -257,12 +255,12 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
fn delegator_stake_more(n: u32, m: u32, u: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 18_000
.saturating_add((2_913_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 75_000
.saturating_add((8_012_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 300_000
.saturating_add((3_084_000 as Weight).saturating_mul(u as Weight))
// Standard Error: 20_000
.saturating_add((3_595_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 53_000
.saturating_add((7_254_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 341_000
.saturating_add((2_585_000 as Weight).saturating_mul(u as Weight))
.saturating_add(T::DbWeight::get().reads(8 as Weight))
.saturating_add(T::DbWeight::get().writes(7 as Weight))
}
Expand All @@ -274,10 +272,10 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
fn delegator_stake_less(n: u32, m: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 17_000
.saturating_add((2_546_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 73_000
.saturating_add((7_267_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 20_000
.saturating_add((3_196_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 53_000
.saturating_add((6_643_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
Expand All @@ -289,10 +287,10 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
fn revoke_delegation(n: u32, m: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 19_000
.saturating_add((2_464_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 79_000
.saturating_add((6_947_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 18_000
.saturating_add((3_036_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 47_000
.saturating_add((6_328_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
Expand All @@ -304,26 +302,26 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
// Storage: ParachainStaking TotalCollatorStake (r:1 w:1)
fn leave_delegators(n: u32, m: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 17_000
.saturating_add((2_480_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 73_000
.saturating_add((6_903_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 18_000
.saturating_add((3_032_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 48_000
.saturating_add((6_252_000 as Weight).saturating_mul(m as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
// Storage: ParachainStaking Unstaking (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
// Storage: System Account (r:1 w:1)
fn unlock_unstaked(u: u32, ) -> Weight {
(40_391_000 as Weight)
// Standard Error: 17_000
.saturating_add((385_000 as Weight).saturating_mul(u as Weight))
(41_774_000 as Weight)
// Standard Error: 16_000
.saturating_add((462_000 as Weight).saturating_mul(u as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: ParachainStaking MaxCollatorCandidateStake (r:0 w:1)
fn set_max_candidate_stake() -> Weight {
(14_557_000 as Weight)
(14_650_000 as Weight)
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
}
Loading

0 comments on commit 8dd0a38

Please sign in to comment.