Skip to content

Commit bb91a4c

Browse files
authoredSep 17, 2024··
fix: more accurate weights for staking heavy operations (#725)
Fixes KILTprotocol/ticket#3564. ## How to test Cd into `chopsticks`, then `yarn install` and `yarn spawn`. Try to call `execute_scheduled_reward_change` with a regular account and `set_inflation` with sudo.
1 parent 7a09697 commit bb91a4c

File tree

6 files changed

+483
-126
lines changed

6 files changed

+483
-126
lines changed
 

‎pallets/parachain-staking/src/benchmarking.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ benchmarks! {
198198
Perquintill::from_percent(40),
199199
Perquintill::from_percent(10)
200200
);
201-
}: _(RawOrigin::Root, inflation.collator.max_rate, inflation.collator.reward_rate.annual, inflation.delegator.max_rate, inflation.delegator.reward_rate.annual)
201+
202+
let candidate_pool_size = candidates.len() as u32;
203+
}: _(RawOrigin::Root, inflation.collator.max_rate, inflation.collator.reward_rate.annual, inflation.delegator.max_rate, inflation.delegator.reward_rate.annual, candidate_pool_size)
202204
verify {
203205
assert_eq!(InflationConfig::<T>::get(), inflation);
204206
candidates.into_iter().for_each(|candidate| {
@@ -627,7 +629,8 @@ benchmarks! {
627629
let old = InflationConfig::<T>::get();
628630
assert_eq!(LastRewardReduction::<T>::get(), BlockNumberFor::<T>::zero());
629631
System::<T>::set_block_number(T::BLOCKS_PER_YEAR + BlockNumberFor::<T>::one());
630-
}: _(RawOrigin::Signed(collator))
632+
let candidate_pool_size = candidates.len() as u32;
633+
}: _(RawOrigin::Signed(collator), candidate_pool_size)
631634
verify {
632635
let new = InflationConfig::<T>::get();
633636
assert_eq!(LastRewardReduction::<T>::get(), BlockNumberFor::<T>::one());

‎pallets/parachain-staking/src/lib.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ pub mod pallet {
417417
UnstakingIsEmpty,
418418
/// Cannot claim rewards if empty.
419419
RewardsNotFound,
420+
/// Invalid input provided. The meaning of this error is
421+
/// extrinsic-dependent.
422+
InvalidInput,
420423
}
421424

422425
#[pallet::event]
@@ -762,16 +765,22 @@ pub mod pallet {
762765
///
763766
/// Emits `RoundInflationSet`.
764767
#[pallet::call_index(1)]
765-
#[pallet::weight(<T as pallet::Config>::WeightInfo::set_inflation(T::MaxTopCandidates::get(), T::MaxDelegatorsPerCollator::get()))]
768+
#[pallet::weight(<T as pallet::Config>::WeightInfo::set_inflation(*current_collator_candidate_pool_size, T::MaxDelegatorsPerCollator::get()))]
766769
pub fn set_inflation(
767770
origin: OriginFor<T>,
768771
collator_max_rate_percentage: Perquintill,
769772
collator_annual_reward_rate_percentage: Perquintill,
770773
delegator_max_rate_percentage: Perquintill,
771774
delegator_annual_reward_rate_percentage: Perquintill,
775+
current_collator_candidate_pool_size: u32,
772776
) -> DispatchResultWithPostInfo {
773777
ensure_root(origin)?;
774778

779+
ensure!(
780+
current_collator_candidate_pool_size >= CandidatePool::<T>::count(),
781+
Error::<T>::InvalidInput
782+
);
783+
775784
// Update inflation and increment rewards
776785
let (num_col, num_del) = Self::do_set_inflation(
777786
T::BLOCKS_PER_YEAR,
@@ -1725,10 +1734,18 @@ pub mod pallet {
17251734
///
17261735
/// Emits `RoundInflationSet`.
17271736
#[pallet::call_index(20)]
1728-
#[pallet::weight(<T as Config>::WeightInfo::execute_scheduled_reward_change(T::MaxTopCandidates::get(), T::MaxDelegatorsPerCollator::get()))]
1729-
pub fn execute_scheduled_reward_change(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
1737+
#[pallet::weight(<T as Config>::WeightInfo::execute_scheduled_reward_change(*current_collator_candidate_pool_size, T::MaxDelegatorsPerCollator::get()))]
1738+
pub fn execute_scheduled_reward_change(
1739+
origin: OriginFor<T>,
1740+
current_collator_candidate_pool_size: u32,
1741+
) -> DispatchResultWithPostInfo {
17301742
ensure_signed(origin)?;
17311743

1744+
ensure!(
1745+
current_collator_candidate_pool_size >= CandidatePool::<T>::count(),
1746+
Error::<T>::InvalidInput
1747+
);
1748+
17321749
let now = frame_system::Pallet::<T>::block_number();
17331750
let year = now / T::BLOCKS_PER_YEAR;
17341751

‎pallets/parachain-staking/src/tests/inflation.rs

+32-4
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818

1919
//! Unit testing
2020
21-
use frame_support::assert_ok;
21+
use frame_support::{assert_noop, assert_ok};
2222
use pallet_authorship::EventHandler;
2323
use sp_runtime::{traits::Zero, Perquintill};
2424

2525
use crate::{
2626
mock::{roll_to_claim_rewards, ExtBuilder, RuntimeOrigin, StakePallet, System, Test, DECIMALS},
27-
Config, InflationInfo, RewardRate, StakingInfo,
27+
Config, Error, InflationInfo, RewardRate, StakingInfo,
2828
};
2929

3030
#[test]
@@ -52,7 +52,8 @@ fn rewards_set_inflation() {
5252
hundred,
5353
hundred,
5454
hundred,
55-
hundred
55+
hundred,
56+
2
5657
));
5758
// rewards and counters should be set
5859
(1..=5).for_each(|id| {
@@ -89,7 +90,10 @@ fn rewards_yearly_inflation_adjustment() {
8990
});
9091

9192
// execute to trigger reward increment
92-
assert_ok!(StakePallet::execute_scheduled_reward_change(RuntimeOrigin::signed(1)));
93+
assert_ok!(StakePallet::execute_scheduled_reward_change(
94+
RuntimeOrigin::signed(1),
95+
2
96+
));
9397
(1..=5).for_each(|id| {
9498
assert!(
9599
!StakePallet::blocks_rewarded(id).is_zero(),
@@ -133,27 +137,51 @@ fn update_inflation() {
133137
Perquintill::from_percent(100),
134138
Perquintill::from_percent(100),
135139
Perquintill::from_percent(100),
140+
2
136141
));
137142
assert_ok!(StakePallet::set_inflation(
138143
RuntimeOrigin::root(),
139144
Perquintill::from_percent(100),
140145
Perquintill::from_percent(0),
141146
Perquintill::from_percent(100),
142147
Perquintill::from_percent(100),
148+
2
143149
));
144150
assert_ok!(StakePallet::set_inflation(
145151
RuntimeOrigin::root(),
146152
Perquintill::from_percent(100),
147153
Perquintill::from_percent(100),
148154
Perquintill::from_percent(0),
149155
Perquintill::from_percent(100),
156+
2
150157
));
151158
assert_ok!(StakePallet::set_inflation(
152159
RuntimeOrigin::root(),
153160
Perquintill::from_percent(100),
154161
Perquintill::from_percent(100),
155162
Perquintill::from_percent(100),
156163
Perquintill::from_percent(0),
164+
2
157165
));
158166
});
159167
}
168+
169+
#[test]
170+
fn too_small_candidate_size_provided_for_new_inflation() {
171+
ExtBuilder::default()
172+
.with_balances(vec![(1, 10), (2, 100)])
173+
.with_collators(vec![(1, 10), (2, 10)])
174+
.build_and_execute_with_sanity_tests(|| {
175+
assert_noop!(
176+
StakePallet::set_inflation(
177+
RuntimeOrigin::root(),
178+
Perquintill::from_percent(0),
179+
Perquintill::from_percent(100),
180+
Perquintill::from_percent(100),
181+
Perquintill::from_percent(100),
182+
1
183+
),
184+
Error::<Test>::InvalidInput
185+
);
186+
});
187+
}

‎pallets/parachain-staking/src/tests/rewards.rs

+25-3
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,10 @@ fn adjust_reward_rates() {
332332
roll_to_claim_rewards(<Test as Config>::BLOCKS_PER_YEAR + 1, vec![]);
333333
// reward reduction should not happen automatically anymore
334334
assert_eq!(StakePallet::last_reward_reduction(), 0u64);
335-
assert_ok!(StakePallet::execute_scheduled_reward_change(RuntimeOrigin::signed(1)));
335+
assert_ok!(StakePallet::execute_scheduled_reward_change(
336+
RuntimeOrigin::signed(1),
337+
2
338+
));
336339
assert_eq!(StakePallet::last_reward_reduction(), 1u64);
337340
let inflation_1 = InflationInfo::new(
338341
<Test as Config>::BLOCKS_PER_YEAR,
@@ -363,7 +366,10 @@ fn adjust_reward_rates() {
363366
roll_to_claim_rewards(2 * <Test as Config>::BLOCKS_PER_YEAR + 1, vec![]);
364367
// reward reduction should not happen automatically anymore
365368
assert_eq!(StakePallet::last_reward_reduction(), 1u64);
366-
assert_ok!(StakePallet::execute_scheduled_reward_change(RuntimeOrigin::signed(1)));
369+
assert_ok!(StakePallet::execute_scheduled_reward_change(
370+
RuntimeOrigin::signed(1),
371+
2
372+
));
367373
assert_eq!(StakePallet::last_reward_reduction(), 2u64);
368374
let inflation_2 = InflationInfo::new(
369375
<Test as Config>::BLOCKS_PER_YEAR,
@@ -393,7 +399,10 @@ fn adjust_reward_rates() {
393399
roll_to_claim_rewards(3 * <Test as Config>::BLOCKS_PER_YEAR + 1, vec![]);
394400
// reward reduction should not happen automatically anymore
395401
assert_eq!(StakePallet::last_reward_reduction(), 2u64);
396-
assert_ok!(StakePallet::execute_scheduled_reward_change(RuntimeOrigin::signed(1)));
402+
assert_ok!(StakePallet::execute_scheduled_reward_change(
403+
RuntimeOrigin::signed(1),
404+
2
405+
));
397406
assert_eq!(StakePallet::last_reward_reduction(), 3u64);
398407
let inflation_3 = InflationInfo::new(
399408
<Test as Config>::BLOCKS_PER_YEAR,
@@ -994,3 +1003,16 @@ fn api_get_unclaimed_staking_rewards() {
9941003
assert!(StakePallet::get_unclaimed_staking_rewards(&3).is_zero());
9951004
});
9961005
}
1006+
1007+
#[test]
1008+
fn too_small_candidate_size_provided_for_reward_adjustment() {
1009+
ExtBuilder::default()
1010+
.with_balances(vec![(1, 10), (2, 100)])
1011+
.with_collators(vec![(1, 10), (2, 10)])
1012+
.build_and_execute_with_sanity_tests(|| {
1013+
assert_noop!(
1014+
StakePallet::execute_scheduled_reward_change(RuntimeOrigin::signed(1), 1),
1015+
Error::<Test>::InvalidInput
1016+
);
1017+
});
1018+
}

‎runtimes/peregrine/src/weights/parachain_staking.rs

+63-62
Original file line numberDiff line numberDiff line change
@@ -106,41 +106,42 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
106106
.saturating_add(Weight::from_parts(0, 0))
107107
.saturating_add(T::DbWeight::get().writes(1))
108108
}
109-
/// Storage: ParachainStaking CandidatePool (r:76 w:0)
110-
/// Proof: ParachainStaking CandidatePool (max_values: None, max_size: Some(1790), added: 4265, mode: MaxEncodedLen)
111-
/// Storage: ParachainStaking BlocksAuthored (r:75 w:0)
112-
/// Proof: ParachainStaking BlocksAuthored (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen)
113-
/// Storage: ParachainStaking BlocksRewarded (r:2700 w:2700)
114-
/// Proof: ParachainStaking BlocksRewarded (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen)
115-
/// Storage: ParachainStaking Rewards (r:2700 w:2700)
116-
/// Proof: ParachainStaking Rewards (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen)
117-
/// Storage: ParachainStaking TotalCollatorStake (r:1 w:0)
118-
/// Proof: ParachainStaking TotalCollatorStake (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
119-
/// Storage: ParachainStaking InflationConfig (r:1 w:1)
120-
/// Proof: ParachainStaking InflationConfig (max_values: Some(1), max_size: Some(96), added: 591, mode: MaxEncodedLen)
121-
/// Storage: ParachainStaking CounterForCandidatePool (r:1 w:0)
122-
/// Proof: ParachainStaking CounterForCandidatePool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
109+
110+
/// Storage: `ParachainStaking::CounterForCandidatePool` (r:1 w:0)
111+
/// Proof: `ParachainStaking::CounterForCandidatePool` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
112+
/// Storage: `ParachainStaking::CandidatePool` (r:76 w:0)
113+
/// Proof: `ParachainStaking::CandidatePool` (`max_values`: None, `max_size`: Some(1790), added: 4265, mode: `MaxEncodedLen`)
114+
/// Storage: `ParachainStaking::BlocksAuthored` (r:75 w:0)
115+
/// Proof: `ParachainStaking::BlocksAuthored` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
116+
/// Storage: `ParachainStaking::BlocksRewarded` (r:2700 w:2700)
117+
/// Proof: `ParachainStaking::BlocksRewarded` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
118+
/// Storage: `ParachainStaking::Rewards` (r:2700 w:2700)
119+
/// Proof: `ParachainStaking::Rewards` (`max_values`: None, `max_size`: Some(56), added: 2531, mode: `MaxEncodedLen`)
120+
/// Storage: `ParachainStaking::TotalCollatorStake` (r:1 w:0)
121+
/// Proof: `ParachainStaking::TotalCollatorStake` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
122+
/// Storage: `ParachainStaking::InflationConfig` (r:1 w:1)
123+
/// Proof: `ParachainStaking::InflationConfig` (`max_values`: Some(1), `max_size`: Some(96), added: 591, mode: `MaxEncodedLen`)
123124
/// The range of component `n` is `[0, 75]`.
124125
/// The range of component `m` is `[0, 35]`.
125126
fn set_inflation(n: u32, m: u32, ) -> Weight {
126127
// Proof Size summary in bytes:
127-
// Measured: `0 + n * (3647 ±0) + m * (7587 ±0)`
128-
// Estimated: `383346 + n * (77565 ±30_589) + m * (151620 ±65_549)`
129-
// Minimum execution time: 749_094_000 picoseconds.
130-
Weight::from_parts(749_094_000, 0)
131-
.saturating_add(Weight::from_parts(0, 383346))
132-
// Standard Error: 86_792_174
133-
.saturating_add(Weight::from_parts(100_338_066, 0).saturating_mul(n.into()))
134-
// Standard Error: 185_983_231
135-
.saturating_add(Weight::from_parts(214_452_085, 0).saturating_mul(m.into()))
128+
// Measured: `0 + m * (7573 ±0) + n * (3709 ±0)`
129+
// Estimated: `183222 + m * (64823 ±2_167) + n * (31965 ±1_009)`
130+
// Minimum execution time: 704_611_000 picoseconds.
131+
Weight::from_parts(707_105_000, 0)
132+
.saturating_add(Weight::from_parts(0, 183222))
133+
// Standard Error: 4_876_636
134+
.saturating_add(Weight::from_parts(150_694_630, 0).saturating_mul(n.into()))
135+
// Standard Error: 10_470_032
136+
.saturating_add(Weight::from_parts(290_425_882, 0).saturating_mul(m.into()))
136137
.saturating_add(T::DbWeight::get().reads(152))
137-
.saturating_add(T::DbWeight::get().reads((30_u64).saturating_mul(n.into())))
138-
.saturating_add(T::DbWeight::get().reads((60_u64).saturating_mul(m.into())))
138+
.saturating_add(T::DbWeight::get().reads((27_u64).saturating_mul(n.into())))
139+
.saturating_add(T::DbWeight::get().reads((51_u64).saturating_mul(m.into())))
139140
.saturating_add(T::DbWeight::get().writes(145))
140-
.saturating_add(T::DbWeight::get().writes((28_u64).saturating_mul(n.into())))
141-
.saturating_add(T::DbWeight::get().writes((60_u64).saturating_mul(m.into())))
142-
.saturating_add(Weight::from_parts(0, 77565).saturating_mul(n.into()))
143-
.saturating_add(Weight::from_parts(0, 151620).saturating_mul(m.into()))
141+
.saturating_add(T::DbWeight::get().writes((25_u64).saturating_mul(n.into())))
142+
.saturating_add(T::DbWeight::get().writes((51_u64).saturating_mul(m.into())))
143+
.saturating_add(Weight::from_parts(0, 64823).saturating_mul(m.into()))
144+
.saturating_add(Weight::from_parts(0, 31965).saturating_mul(n.into()))
144145
}
145146
/// Storage: ParachainStaking MaxSelectedCandidates (r:1 w:1)
146147
/// Proof: ParachainStaking MaxSelectedCandidates (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
@@ -674,43 +675,43 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
674675
.saturating_add(T::DbWeight::get().reads(2))
675676
.saturating_add(T::DbWeight::get().writes(2))
676677
}
677-
/// Storage: ParachainStaking LastRewardReduction (r:1 w:1)
678-
/// Proof: ParachainStaking LastRewardReduction (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen)
679-
/// Storage: ParachainStaking InflationConfig (r:1 w:1)
680-
/// Proof: ParachainStaking InflationConfig (max_values: Some(1), max_size: Some(96), added: 591, mode: MaxEncodedLen)
681-
/// Storage: ParachainStaking CandidatePool (r:76 w:0)
682-
/// Proof: ParachainStaking CandidatePool (max_values: None, max_size: Some(1790), added: 4265, mode: MaxEncodedLen)
683-
/// Storage: ParachainStaking BlocksAuthored (r:75 w:0)
684-
/// Proof: ParachainStaking BlocksAuthored (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen)
685-
/// Storage: ParachainStaking BlocksRewarded (r:2700 w:2700)
686-
/// Proof: ParachainStaking BlocksRewarded (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen)
687-
/// Storage: ParachainStaking Rewards (r:2700 w:2700)
688-
/// Proof: ParachainStaking Rewards (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen)
689-
/// Storage: ParachainStaking TotalCollatorStake (r:1 w:0)
690-
/// Proof: ParachainStaking TotalCollatorStake (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
691-
/// Storage: ParachainStaking CounterForCandidatePool (r:1 w:0)
692-
/// Proof: ParachainStaking CounterForCandidatePool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
678+
/// Storage: `ParachainStaking::CounterForCandidatePool` (r:1 w:0)
679+
/// Proof: `ParachainStaking::CounterForCandidatePool` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
680+
/// Storage: `ParachainStaking::LastRewardReduction` (r:1 w:1)
681+
/// Proof: `ParachainStaking::LastRewardReduction` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
682+
/// Storage: `ParachainStaking::InflationConfig` (r:1 w:1)
683+
/// Proof: `ParachainStaking::InflationConfig` (`max_values`: Some(1), `max_size`: Some(96), added: 591, mode: `MaxEncodedLen`)
684+
/// Storage: `ParachainStaking::CandidatePool` (r:76 w:0)
685+
/// Proof: `ParachainStaking::CandidatePool` (`max_values`: None, `max_size`: Some(1790), added: 4265, mode: `MaxEncodedLen`)
686+
/// Storage: `ParachainStaking::BlocksAuthored` (r:75 w:0)
687+
/// Proof: `ParachainStaking::BlocksAuthored` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
688+
/// Storage: `ParachainStaking::BlocksRewarded` (r:2700 w:2700)
689+
/// Proof: `ParachainStaking::BlocksRewarded` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
690+
/// Storage: `ParachainStaking::Rewards` (r:2700 w:2700)
691+
/// Proof: `ParachainStaking::Rewards` (`max_values`: None, `max_size`: Some(56), added: 2531, mode: `MaxEncodedLen`)
692+
/// Storage: `ParachainStaking::TotalCollatorStake` (r:1 w:0)
693+
/// Proof: `ParachainStaking::TotalCollatorStake` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
693694
/// The range of component `n` is `[0, 75]`.
694695
/// The range of component `m` is `[0, 35]`.
695696
fn execute_scheduled_reward_change(n: u32, m: u32, ) -> Weight {
696697
// Proof Size summary in bytes:
697-
// Measured: `0 + n * (3587 ±0) + m * (7587 ±0)`
698-
// Estimated: `383849 + n * (77565 ±0) + m * (151620 ±65_549)`
699-
// Minimum execution time: 449_942_000 picoseconds.
700-
Weight::from_parts(449_942_000, 0)
701-
.saturating_add(Weight::from_parts(0, 383849))
702-
// Standard Error: 84_159_623
703-
.saturating_add(Weight::from_parts(100_410_008, 0).saturating_mul(n.into()))
704-
// Standard Error: 180_342_051
705-
.saturating_add(Weight::from_parts(208_232_902, 0).saturating_mul(m.into()))
698+
// Measured: `0 + m * (7573 ±0) + n * (3647 ±0)`
699+
// Estimated: `183222 + m * (64823 ±2_167) + n * (31965 ±1_009)`
700+
// Minimum execution time: 683_160_000 picoseconds.
701+
Weight::from_parts(687_351_000, 0)
702+
.saturating_add(Weight::from_parts(0, 183222))
703+
// Standard Error: 4_643_820
704+
.saturating_add(Weight::from_parts(141_740_256, 0).saturating_mul(n.into()))
705+
// Standard Error: 9_970_180
706+
.saturating_add(Weight::from_parts(280_674_034, 0).saturating_mul(m.into()))
706707
.saturating_add(T::DbWeight::get().reads(153))
707-
.saturating_add(T::DbWeight::get().reads((30_u64).saturating_mul(n.into())))
708-
.saturating_add(T::DbWeight::get().reads((60_u64).saturating_mul(m.into())))
708+
.saturating_add(T::DbWeight::get().reads((27_u64).saturating_mul(n.into())))
709+
.saturating_add(T::DbWeight::get().reads((51_u64).saturating_mul(m.into())))
709710
.saturating_add(T::DbWeight::get().writes(146))
710-
.saturating_add(T::DbWeight::get().writes((28_u64).saturating_mul(n.into())))
711-
.saturating_add(T::DbWeight::get().writes((60_u64).saturating_mul(m.into())))
712-
.saturating_add(Weight::from_parts(0, 77565).saturating_mul(n.into()))
713-
.saturating_add(Weight::from_parts(0, 151620).saturating_mul(m.into()))
711+
.saturating_add(T::DbWeight::get().writes((25_u64).saturating_mul(n.into())))
712+
.saturating_add(T::DbWeight::get().writes((51_u64).saturating_mul(m.into())))
713+
.saturating_add(Weight::from_parts(0, 64823).saturating_mul(m.into()))
714+
.saturating_add(Weight::from_parts(0, 31965).saturating_mul(n.into()))
714715
}
715716
}
716717

@@ -761,7 +762,7 @@ mod tests {
761762
.max_extrinsic
762763
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
763764
.proof_size()
764-
> 383346
765+
> 183222
765766
);
766767
}
767768
#[test]
@@ -977,7 +978,7 @@ mod tests {
977978
.max_extrinsic
978979
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
979980
.proof_size()
980-
> 383849
981+
> 183222
981982
);
982983
}
983984
}

‎runtimes/spiritnet/src/weights/parachain_staking.rs

+338-52
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,41 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
8282
Weight::from_parts(3_573_000 as u64, 0)
8383
.saturating_add(T::DbWeight::get().writes(1 as u64))
8484
}
85-
// Storage: ParachainStaking CandidatePool (r:76 w:0)
86-
// Proof: ParachainStaking CandidatePool (max_values: None, max_size: Some(1790), added: 4265, mode: MaxEncodedLen)
87-
// Storage: ParachainStaking BlocksAuthored (r:75 w:0)
88-
// Proof: ParachainStaking BlocksAuthored (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen)
89-
// Storage: ParachainStaking BlocksRewarded (r:2700 w:2700)
90-
// Proof: ParachainStaking BlocksRewarded (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen)
91-
// Storage: ParachainStaking Rewards (r:2700 w:2700)
92-
// Proof: ParachainStaking Rewards (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen)
93-
// Storage: ParachainStaking TotalCollatorStake (r:1 w:0)
94-
// Proof: ParachainStaking TotalCollatorStake (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
95-
// Storage: ParachainStaking InflationConfig (r:1 w:1)
96-
// Proof: ParachainStaking InflationConfig (max_values: Some(1), max_size: Some(96), added: 591, mode: MaxEncodedLen)
97-
// Storage: ParachainStaking CounterForCandidatePool (r:1 w:0)
98-
// Proof: ParachainStaking CounterForCandidatePool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
85+
/// Storage: `ParachainStaking::CounterForCandidatePool` (r:1 w:0)
86+
/// Proof: `ParachainStaking::CounterForCandidatePool` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
87+
/// Storage: `ParachainStaking::CandidatePool` (r:76 w:0)
88+
/// Proof: `ParachainStaking::CandidatePool` (`max_values`: None, `max_size`: Some(1790), added: 4265, mode: `MaxEncodedLen`)
89+
/// Storage: `ParachainStaking::BlocksAuthored` (r:75 w:0)
90+
/// Proof: `ParachainStaking::BlocksAuthored` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
91+
/// Storage: `ParachainStaking::BlocksRewarded` (r:2700 w:2700)
92+
/// Proof: `ParachainStaking::BlocksRewarded` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
93+
/// Storage: `ParachainStaking::Rewards` (r:2700 w:2700)
94+
/// Proof: `ParachainStaking::Rewards` (`max_values`: None, `max_size`: Some(56), added: 2531, mode: `MaxEncodedLen`)
95+
/// Storage: `ParachainStaking::TotalCollatorStake` (r:1 w:0)
96+
/// Proof: `ParachainStaking::TotalCollatorStake` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
97+
/// Storage: `ParachainStaking::InflationConfig` (r:1 w:1)
98+
/// Proof: `ParachainStaking::InflationConfig` (`max_values`: Some(1), `max_size`: Some(96), added: 591, mode: `MaxEncodedLen`)
99+
/// The range of component `n` is `[0, 75]`.
100+
/// The range of component `m` is `[0, 35]`.
99101
fn set_inflation(n: u32, m: u32, ) -> Weight {
100-
Weight::from_parts(663_557_000 as u64, 0)
101-
// Standard Error: 4_566_075
102-
.saturating_add(Weight::from_parts(143_112_464 as u64, 0).saturating_mul(n as u64))
103-
// Standard Error: 9_803_263
104-
.saturating_add(Weight::from_parts(269_841_967 as u64, 0).saturating_mul(m as u64))
105-
.saturating_add(T::DbWeight::get().reads(152 as u64))
106-
.saturating_add(T::DbWeight::get().reads((27 as u64).saturating_mul(n as u64)))
107-
.saturating_add(T::DbWeight::get().reads((51 as u64).saturating_mul(m as u64)))
108-
.saturating_add(T::DbWeight::get().writes(145 as u64))
109-
.saturating_add(T::DbWeight::get().writes((25 as u64).saturating_mul(n as u64)))
110-
.saturating_add(T::DbWeight::get().writes((51 as u64).saturating_mul(m as u64)))
102+
// Proof Size summary in bytes:
103+
// Measured: `0 + m * (7573 ±0) + n * (3709 ±0)`
104+
// Estimated: `183222 + m * (64823 ±2_167) + n * (31965 ±1_009)`
105+
// Minimum execution time: 704_611_000 picoseconds.
106+
Weight::from_parts(707_105_000, 0)
107+
.saturating_add(Weight::from_parts(0, 183222))
108+
// Standard Error: 4_876_636
109+
.saturating_add(Weight::from_parts(150_694_630, 0).saturating_mul(n.into()))
110+
// Standard Error: 10_470_032
111+
.saturating_add(Weight::from_parts(290_425_882, 0).saturating_mul(m.into()))
112+
.saturating_add(T::DbWeight::get().reads(152))
113+
.saturating_add(T::DbWeight::get().reads((27_u64).saturating_mul(n.into())))
114+
.saturating_add(T::DbWeight::get().reads((51_u64).saturating_mul(m.into())))
115+
.saturating_add(T::DbWeight::get().writes(145))
116+
.saturating_add(T::DbWeight::get().writes((25_u64).saturating_mul(n.into())))
117+
.saturating_add(T::DbWeight::get().writes((51_u64).saturating_mul(m.into())))
118+
.saturating_add(Weight::from_parts(0, 64823).saturating_mul(m.into()))
119+
.saturating_add(Weight::from_parts(0, 31965).saturating_mul(n.into()))
111120
}
112121
// Storage: ParachainStaking MaxSelectedCandidates (r:1 w:1)
113122
// Proof: ParachainStaking MaxSelectedCandidates (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
@@ -523,33 +532,310 @@ impl<T: frame_system::Config> parachain_staking::WeightInfo for WeightInfo<T> {
523532
.saturating_add(T::DbWeight::get().reads(2 as u64))
524533
.saturating_add(T::DbWeight::get().writes(2 as u64))
525534
}
526-
// Storage: ParachainStaking LastRewardReduction (r:1 w:1)
527-
// Proof: ParachainStaking LastRewardReduction (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen)
528-
// Storage: ParachainStaking InflationConfig (r:1 w:1)
529-
// Proof: ParachainStaking InflationConfig (max_values: Some(1), max_size: Some(96), added: 591, mode: MaxEncodedLen)
530-
// Storage: ParachainStaking CandidatePool (r:76 w:0)
531-
// Proof: ParachainStaking CandidatePool (max_values: None, max_size: Some(1790), added: 4265, mode: MaxEncodedLen)
532-
// Storage: ParachainStaking BlocksAuthored (r:75 w:0)
533-
// Proof: ParachainStaking BlocksAuthored (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen)
534-
// Storage: ParachainStaking BlocksRewarded (r:2700 w:2700)
535-
// Proof: ParachainStaking BlocksRewarded (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen)
536-
// Storage: ParachainStaking Rewards (r:2700 w:2700)
537-
// Proof: ParachainStaking Rewards (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen)
538-
// Storage: ParachainStaking TotalCollatorStake (r:1 w:0)
539-
// Proof: ParachainStaking TotalCollatorStake (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
540-
// Storage: ParachainStaking CounterForCandidatePool (r:1 w:0)
541-
// Proof: ParachainStaking CounterForCandidatePool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
535+
/// Storage: `ParachainStaking::CounterForCandidatePool` (r:1 w:0)
536+
/// Proof: `ParachainStaking::CounterForCandidatePool` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
537+
/// Storage: `ParachainStaking::LastRewardReduction` (r:1 w:1)
538+
/// Proof: `ParachainStaking::LastRewardReduction` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
539+
/// Storage: `ParachainStaking::InflationConfig` (r:1 w:1)
540+
/// Proof: `ParachainStaking::InflationConfig` (`max_values`: Some(1), `max_size`: Some(96), added: 591, mode: `MaxEncodedLen`)
541+
/// Storage: `ParachainStaking::CandidatePool` (r:76 w:0)
542+
/// Proof: `ParachainStaking::CandidatePool` (`max_values`: None, `max_size`: Some(1790), added: 4265, mode: `MaxEncodedLen`)
543+
/// Storage: `ParachainStaking::BlocksAuthored` (r:75 w:0)
544+
/// Proof: `ParachainStaking::BlocksAuthored` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
545+
/// Storage: `ParachainStaking::BlocksRewarded` (r:2700 w:2700)
546+
/// Proof: `ParachainStaking::BlocksRewarded` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
547+
/// Storage: `ParachainStaking::Rewards` (r:2700 w:2700)
548+
/// Proof: `ParachainStaking::Rewards` (`max_values`: None, `max_size`: Some(56), added: 2531, mode: `MaxEncodedLen`)
549+
/// Storage: `ParachainStaking::TotalCollatorStake` (r:1 w:0)
550+
/// Proof: `ParachainStaking::TotalCollatorStake` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
551+
/// The range of component `n` is `[0, 75]`.
552+
/// The range of component `m` is `[0, 35]`.
542553
fn execute_scheduled_reward_change(n: u32, m: u32, ) -> Weight {
543-
Weight::from_parts(657_155_000 as u64, 0)
544-
// Standard Error: 4_390_482
545-
.saturating_add(Weight::from_parts(136_436_522 as u64, 0).saturating_mul(n as u64))
546-
// Standard Error: 9_426_268
547-
.saturating_add(Weight::from_parts(263_946_048 as u64, 0).saturating_mul(m as u64))
548-
.saturating_add(T::DbWeight::get().reads(153 as u64))
549-
.saturating_add(T::DbWeight::get().reads((27 as u64).saturating_mul(n as u64)))
550-
.saturating_add(T::DbWeight::get().reads((51 as u64).saturating_mul(m as u64)))
551-
.saturating_add(T::DbWeight::get().writes(146 as u64))
552-
.saturating_add(T::DbWeight::get().writes((25 as u64).saturating_mul(n as u64)))
553-
.saturating_add(T::DbWeight::get().writes((51 as u64).saturating_mul(m as u64)))
554+
// Proof Size summary in bytes:
555+
// Measured: `0 + m * (7573 ±0) + n * (3647 ±0)`
556+
// Estimated: `183222 + m * (64823 ±2_167) + n * (31965 ±1_009)`
557+
// Minimum execution time: 683_160_000 picoseconds.
558+
Weight::from_parts(687_351_000, 0)
559+
.saturating_add(Weight::from_parts(0, 183222))
560+
// Standard Error: 4_643_820
561+
.saturating_add(Weight::from_parts(141_740_256, 0).saturating_mul(n.into()))
562+
// Standard Error: 9_970_180
563+
.saturating_add(Weight::from_parts(280_674_034, 0).saturating_mul(m.into()))
564+
.saturating_add(T::DbWeight::get().reads(153))
565+
.saturating_add(T::DbWeight::get().reads((27_u64).saturating_mul(n.into())))
566+
.saturating_add(T::DbWeight::get().reads((51_u64).saturating_mul(m.into())))
567+
.saturating_add(T::DbWeight::get().writes(146))
568+
.saturating_add(T::DbWeight::get().writes((25_u64).saturating_mul(n.into())))
569+
.saturating_add(T::DbWeight::get().writes((51_u64).saturating_mul(m.into())))
570+
.saturating_add(Weight::from_parts(0, 64823).saturating_mul(m.into()))
571+
.saturating_add(Weight::from_parts(0, 31965).saturating_mul(n.into()))
572+
}
573+
}
574+
575+
#[cfg(test)]
576+
mod tests {
577+
#[test]
578+
fn test_on_initialize_no_action() {
579+
assert!(
580+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
581+
.per_class
582+
.get(frame_support::dispatch::DispatchClass::Normal)
583+
.max_extrinsic
584+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
585+
.proof_size()
586+
> 515
587+
);
588+
}
589+
#[test]
590+
fn test_on_initialize_round_update() {
591+
assert!(
592+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
593+
.per_class
594+
.get(frame_support::dispatch::DispatchClass::Normal)
595+
.max_extrinsic
596+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
597+
.proof_size()
598+
> 515
599+
);
600+
}
601+
#[test]
602+
fn test_on_initialize_network_rewards() {
603+
assert!(
604+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
605+
.per_class
606+
.get(frame_support::dispatch::DispatchClass::Normal)
607+
.max_extrinsic
608+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
609+
.proof_size()
610+
> 4723
611+
);
612+
}
613+
#[test]
614+
fn test_set_inflation() {
615+
assert!(
616+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
617+
.per_class
618+
.get(frame_support::dispatch::DispatchClass::Normal)
619+
.max_extrinsic
620+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
621+
.proof_size()
622+
> 183222
623+
);
624+
}
625+
#[test]
626+
fn test_set_max_selected_candidates() {
627+
assert!(
628+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
629+
.per_class
630+
.get(frame_support::dispatch::DispatchClass::Normal)
631+
.max_extrinsic
632+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
633+
.proof_size()
634+
> 5168
635+
);
636+
}
637+
#[test]
638+
fn test_set_blocks_per_round() {
639+
assert!(
640+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
641+
.per_class
642+
.get(frame_support::dispatch::DispatchClass::Normal)
643+
.max_extrinsic
644+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
645+
.proof_size()
646+
> 515
647+
);
648+
}
649+
#[test]
650+
fn test_force_remove_candidate() {
651+
assert!(
652+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
653+
.per_class
654+
.get(frame_support::dispatch::DispatchClass::Normal)
655+
.max_extrinsic
656+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
657+
.proof_size()
658+
> 116721
659+
);
660+
}
661+
#[test]
662+
fn test_join_candidates() {
663+
assert!(
664+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
665+
.per_class
666+
.get(frame_support::dispatch::DispatchClass::Normal)
667+
.max_extrinsic
668+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
669+
.proof_size()
670+
> 22098
671+
);
672+
}
673+
#[test]
674+
fn test_init_leave_candidates() {
675+
assert!(
676+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
677+
.per_class
678+
.get(frame_support::dispatch::DispatchClass::Normal)
679+
.max_extrinsic
680+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
681+
.proof_size()
682+
> 78143
683+
);
684+
}
685+
#[test]
686+
fn test_cancel_leave_candidates() {
687+
assert!(
688+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
689+
.per_class
690+
.get(frame_support::dispatch::DispatchClass::Normal)
691+
.max_extrinsic
692+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
693+
.proof_size()
694+
> 13653
695+
);
696+
}
697+
#[test]
698+
fn test_execute_leave_candidates() {
699+
assert!(
700+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
701+
.per_class
702+
.get(frame_support::dispatch::DispatchClass::Normal)
703+
.max_extrinsic
704+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
705+
.proof_size()
706+
> 25299
707+
);
708+
}
709+
#[test]
710+
fn test_candidate_stake_more() {
711+
assert!(
712+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
713+
.per_class
714+
.get(frame_support::dispatch::DispatchClass::Normal)
715+
.max_extrinsic
716+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
717+
.proof_size()
718+
> 27204
719+
);
720+
}
721+
#[test]
722+
fn test_candidate_stake_less() {
723+
assert!(
724+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
725+
.per_class
726+
.get(frame_support::dispatch::DispatchClass::Normal)
727+
.max_extrinsic
728+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
729+
.proof_size()
730+
> 20312
731+
);
732+
}
733+
#[test]
734+
fn test_join_delegators() {
735+
assert!(
736+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
737+
.per_class
738+
.get(frame_support::dispatch::DispatchClass::Normal)
739+
.max_extrinsic
740+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
741+
.proof_size()
742+
> 30914
743+
);
744+
}
745+
#[test]
746+
fn test_delegator_stake_more() {
747+
assert!(
748+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
749+
.per_class
750+
.get(frame_support::dispatch::DispatchClass::Normal)
751+
.max_extrinsic
752+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
753+
.proof_size()
754+
> 29256
755+
);
756+
}
757+
#[test]
758+
fn test_delegator_stake_less() {
759+
assert!(
760+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
761+
.per_class
762+
.get(frame_support::dispatch::DispatchClass::Normal)
763+
.max_extrinsic
764+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
765+
.proof_size()
766+
> 22875
767+
);
768+
}
769+
#[test]
770+
fn test_leave_delegators() {
771+
assert!(
772+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
773+
.per_class
774+
.get(frame_support::dispatch::DispatchClass::Normal)
775+
.max_extrinsic
776+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
777+
.proof_size()
778+
> 22875
779+
);
780+
}
781+
#[test]
782+
fn test_unlock_unstaked() {
783+
assert!(
784+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
785+
.per_class
786+
.get(frame_support::dispatch::DispatchClass::Normal)
787+
.max_extrinsic
788+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
789+
.proof_size()
790+
> 9137
791+
);
792+
}
793+
#[test]
794+
fn test_increment_delegator_rewards() {
795+
assert!(
796+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
797+
.per_class
798+
.get(frame_support::dispatch::DispatchClass::Normal)
799+
.max_extrinsic
800+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
801+
.proof_size()
802+
> 11258
803+
);
804+
}
805+
#[test]
806+
fn test_increment_collator_rewards() {
807+
assert!(
808+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
809+
.per_class
810+
.get(frame_support::dispatch::DispatchClass::Normal)
811+
.max_extrinsic
812+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
813+
.proof_size()
814+
> 12960
815+
);
816+
}
817+
#[test]
818+
fn test_claim_rewards() {
819+
assert!(
820+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
821+
.per_class
822+
.get(frame_support::dispatch::DispatchClass::Normal)
823+
.max_extrinsic
824+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
825+
.proof_size()
826+
> 5138
827+
);
828+
}
829+
#[test]
830+
fn test_execute_scheduled_reward_change() {
831+
assert!(
832+
<crate::Runtime as frame_system::Config>::BlockWeights::get()
833+
.per_class
834+
.get(frame_support::dispatch::DispatchClass::Normal)
835+
.max_extrinsic
836+
.unwrap_or_else(<sp_weights::Weight as sp_runtime::traits::Bounded>::max_value)
837+
.proof_size()
838+
> 183222
839+
);
554840
}
555841
}

0 commit comments

Comments
 (0)
Please sign in to comment.