Skip to content

Commit 57b22f1

Browse files
committed
correct benchmark
1 parent 8c89ce5 commit 57b22f1

File tree

4 files changed

+51
-40
lines changed

4 files changed

+51
-40
lines changed

pallets/capacity/src/benchmarking.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
88
use parity_scale_codec::alloc::vec::Vec;
99

1010
const SEED: u32 = 0;
11+
const REWARD_POOL_TOTAL: u32 = 2_000_000;
1112

1213
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
1314
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
@@ -91,7 +92,7 @@ fn fill_reward_pool_chunks<T: Config>(current_era: RewardEra) {
9192
let history_limit: RewardEra = <T as Config>::ProviderBoostHistoryLimit::get();
9293
let starting_era: RewardEra = current_era - history_limit - 1u32;
9394
for era in starting_era..current_era {
94-
Capacity::<T>::update_provider_boost_reward_pool(era, 10_000u32.into());
95+
Capacity::<T>::update_provider_boost_reward_pool(era, REWARD_POOL_TOTAL.into());
9596
}
9697
}
9798

@@ -107,6 +108,16 @@ fn fill_boost_history<T: Config>(
107108
}
108109
}
109110

111+
fn unclaimed_rewards_total<T: Config>(caller: &T::AccountId) -> BalanceOf<T> {
112+
let zero_balance: BalanceOf<T> = 0u32.into();
113+
let rewards: Vec<UnclaimedRewardInfo<BalanceOf<T>, BlockNumberFor<T>>> =
114+
Capacity::<T>::list_unclaimed_rewards(caller).unwrap_or_default().to_vec();
115+
rewards
116+
.iter()
117+
.fold(zero_balance, |acc, reward_info| acc.saturating_add(reward_info.earned_amount))
118+
.into()
119+
}
120+
110121
benchmarks! {
111122
stake {
112123
let caller: T::AccountId = create_funded_account::<T>("account", SEED, 105u32);
@@ -246,17 +257,17 @@ benchmarks! {
246257
claim_staking_rewards {
247258
let caller: T::AccountId = create_funded_account::<T>("account", SEED, 5u32);
248259
let from_msa = 33;
249-
let from_msa_amount: BalanceOf<T> = T::MinimumStakingAmount::get().saturating_add(31u32.into());
250-
setup_provider_stake::<T>(&caller, &from_msa, from_msa_amount, false);
260+
let boost_amount: BalanceOf<T> = T::MinimumStakingAmount::get();
261+
setup_provider_stake::<T>(&caller, &from_msa, boost_amount, false);
251262
frame_system::Pallet::<T>::set_block_number(1002u32.into());
252-
let current_era: RewardEra = 100u32;
253-
set_era_and_reward_pool_at_block::<T>(current_era, 1001u32.into(), 1_000u32.into());
263+
let current_era: RewardEra = 100;
264+
set_era_and_reward_pool_at_block::<T>(current_era, 1001u32.into(), REWARD_POOL_TOTAL.into());
254265
fill_reward_pool_chunks::<T>(current_era);
255-
fill_boost_history::<T>(&caller, 1000u32.into(), current_era);
266+
fill_boost_history::<T>(&caller, 100u32.into(), current_era);
267+
let unclaimed_rewards = unclaimed_rewards_total::<T>(&caller);
256268
}: _ (RawOrigin::Signed(caller.clone()))
257269
verify {
258-
let expected_amount: BalanceOf<T> = 293u32.into();
259-
assert_last_event::<T>(Event::<T>::ProviderBoostRewardClaimed {account: caller.clone(), reward_amount: expected_amount}.into());
270+
assert_last_event::<T>(Event::<T>::ProviderBoostRewardClaimed {account: caller.clone(), reward_amount: unclaimed_rewards}.into());
260271
}
261272

262273
impl_benchmark_test_suite!(Capacity,

pallets/capacity/src/tests/claim_staking_rewards_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn claim_staking_rewards_mints_and_transfers_expected_total() {
6060
assert_eq!(Capacity::get_current_era().era_index, 4u32);
6161
assert_ok!(Capacity::claim_staking_rewards(RuntimeOrigin::signed(account)));
6262
System::assert_last_event(
63-
ProviderBoostRewardClaimed { account, reward_amount: 8u64 }.into(),
63+
Event::<Test>::ProviderBoostRewardClaimed { account, reward_amount: 8u64 }.into(),
6464
);
6565

6666
// should have 2 era's worth of payouts: 4 each for eras 2, 3

pallets/capacity/src/tests/eras_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ fn get_chunk_index_for_era_works() {
177177
TestCase { era: 10, expected: 3 },
178178
TestCase { era: 11, expected: 3 },
179179
TestCase { era: 12, expected: 3 },
180-
TestCase { era: 13, expected: 4 }, // This is not wrong; there is an extra chunk to leave space for cycling
180+
TestCase { era: 13, expected: 4 }, // This is not wrong; there is an extra chunk to leave space for cycling
181181
TestCase { era: 14, expected: 4 },
182182
TestCase { era: 15, expected: 4 },
183-
TestCase { era: 16, expected: 0 }, // So cycle restarts here, not at 13.
183+
TestCase { era: 16, expected: 0 }, // So cycle restarts here, not at 13.
184184
TestCase { era: 17, expected: 0 },
185185
TestCase { era: 18, expected: 0 },
186186
TestCase { era: 22, expected: 2 },

pallets/capacity/src/weights.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("frequency-bench")`, DB CACHE: `1024`
99
1010
// Executed Command:
11-
// ./scripts/../target/release/frequency
11+
// ./scripts/../target/bench-dev/frequency
1212
// benchmark
1313
// pallet
1414
// --pallet=pallet_capacity
@@ -65,8 +65,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
6565
// Proof Size summary in bytes:
6666
// Measured: `177`
6767
// Estimated: `6249`
68-
// Minimum execution time: 28_000_000 picoseconds.
69-
Weight::from_parts(29_000_000, 6249)
68+
// Minimum execution time: 33_000_000 picoseconds.
69+
Weight::from_parts(34_000_000, 6249)
7070
.saturating_add(T::DbWeight::get().reads(7_u64))
7171
.saturating_add(T::DbWeight::get().writes(4_u64))
7272
}
@@ -82,8 +82,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
8282
// Proof Size summary in bytes:
8383
// Measured: `226`
8484
// Estimated: `6249`
85-
// Minimum execution time: 18_000_000 picoseconds.
86-
Weight::from_parts(19_000_000, 6249)
85+
// Minimum execution time: 21_000_000 picoseconds.
86+
Weight::from_parts(22_000_000, 6249)
8787
.saturating_add(T::DbWeight::get().reads(4_u64))
8888
.saturating_add(T::DbWeight::get().writes(2_u64))
8989
}
@@ -108,7 +108,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
108108
// Proof Size summary in bytes:
109109
// Measured: `193`
110110
// Estimated: `5063`
111-
// Minimum execution time: 4_000_000 picoseconds.
111+
// Minimum execution time: 5_000_000 picoseconds.
112112
Weight::from_parts(5_000_000, 5063)
113113
.saturating_add(T::DbWeight::get().reads(2_u64))
114114
.saturating_add(T::DbWeight::get().writes(1_u64))
@@ -129,8 +129,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
129129
// Proof Size summary in bytes:
130130
// Measured: `359`
131131
// Estimated: `5591`
132-
// Minimum execution time: 26_000_000 picoseconds.
133-
Weight::from_parts(27_000_000, 5591)
132+
// Minimum execution time: 29_000_000 picoseconds.
133+
Weight::from_parts(30_000_000, 5591)
134134
.saturating_add(T::DbWeight::get().reads(6_u64))
135135
.saturating_add(T::DbWeight::get().writes(6_u64))
136136
}
@@ -140,7 +140,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
140140
// Proof Size summary in bytes:
141141
// Measured: `0`
142142
// Estimated: `0`
143-
// Minimum execution time: 3_000_000 picoseconds.
143+
// Minimum execution time: 4_000_000 picoseconds.
144144
Weight::from_parts(4_000_000, 0)
145145
.saturating_add(T::DbWeight::get().writes(1_u64))
146146
}
@@ -158,8 +158,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
158158
// Proof Size summary in bytes:
159159
// Measured: `353`
160160
// Estimated: `7601`
161-
// Minimum execution time: 25_000_000 picoseconds.
162-
Weight::from_parts(26_000_000, 7601)
161+
// Minimum execution time: 28_000_000 picoseconds.
162+
Weight::from_parts(29_000_000, 7601)
163163
.saturating_add(T::DbWeight::get().reads(7_u64))
164164
.saturating_add(T::DbWeight::get().writes(5_u64))
165165
}
@@ -185,8 +185,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
185185
// Proof Size summary in bytes:
186186
// Measured: `177`
187187
// Estimated: `6249`
188-
// Minimum execution time: 33_000_000 picoseconds.
189-
Weight::from_parts(33_000_000, 6249)
188+
// Minimum execution time: 37_000_000 picoseconds.
189+
Weight::from_parts(38_000_000, 6249)
190190
.saturating_add(T::DbWeight::get().reads(9_u64))
191191
.saturating_add(T::DbWeight::get().writes(6_u64))
192192
}
@@ -198,8 +198,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
198198
// Proof Size summary in bytes:
199199
// Measured: `1592`
200200
// Estimated: `20591`
201-
// Minimum execution time: 90_000_000 picoseconds.
202-
Weight::from_parts(95_000_000, 20591)
201+
// Minimum execution time: 104_000_000 picoseconds.
202+
Weight::from_parts(105_000_000, 20591)
203203
.saturating_add(T::DbWeight::get().reads(8_u64))
204204
.saturating_add(T::DbWeight::get().writes(1_u64))
205205
}
@@ -225,8 +225,8 @@ impl WeightInfo for () {
225225
// Proof Size summary in bytes:
226226
// Measured: `177`
227227
// Estimated: `6249`
228-
// Minimum execution time: 28_000_000 picoseconds.
229-
Weight::from_parts(29_000_000, 6249)
228+
// Minimum execution time: 33_000_000 picoseconds.
229+
Weight::from_parts(34_000_000, 6249)
230230
.saturating_add(RocksDbWeight::get().reads(7_u64))
231231
.saturating_add(RocksDbWeight::get().writes(4_u64))
232232
}
@@ -242,8 +242,8 @@ impl WeightInfo for () {
242242
// Proof Size summary in bytes:
243243
// Measured: `226`
244244
// Estimated: `6249`
245-
// Minimum execution time: 18_000_000 picoseconds.
246-
Weight::from_parts(19_000_000, 6249)
245+
// Minimum execution time: 21_000_000 picoseconds.
246+
Weight::from_parts(22_000_000, 6249)
247247
.saturating_add(RocksDbWeight::get().reads(4_u64))
248248
.saturating_add(RocksDbWeight::get().writes(2_u64))
249249
}
@@ -268,7 +268,7 @@ impl WeightInfo for () {
268268
// Proof Size summary in bytes:
269269
// Measured: `193`
270270
// Estimated: `5063`
271-
// Minimum execution time: 4_000_000 picoseconds.
271+
// Minimum execution time: 5_000_000 picoseconds.
272272
Weight::from_parts(5_000_000, 5063)
273273
.saturating_add(RocksDbWeight::get().reads(2_u64))
274274
.saturating_add(RocksDbWeight::get().writes(1_u64))
@@ -289,8 +289,8 @@ impl WeightInfo for () {
289289
// Proof Size summary in bytes:
290290
// Measured: `359`
291291
// Estimated: `5591`
292-
// Minimum execution time: 26_000_000 picoseconds.
293-
Weight::from_parts(27_000_000, 5591)
292+
// Minimum execution time: 29_000_000 picoseconds.
293+
Weight::from_parts(30_000_000, 5591)
294294
.saturating_add(RocksDbWeight::get().reads(6_u64))
295295
.saturating_add(RocksDbWeight::get().writes(6_u64))
296296
}
@@ -300,7 +300,7 @@ impl WeightInfo for () {
300300
// Proof Size summary in bytes:
301301
// Measured: `0`
302302
// Estimated: `0`
303-
// Minimum execution time: 3_000_000 picoseconds.
303+
// Minimum execution time: 4_000_000 picoseconds.
304304
Weight::from_parts(4_000_000, 0)
305305
.saturating_add(RocksDbWeight::get().writes(1_u64))
306306
}
@@ -318,8 +318,8 @@ impl WeightInfo for () {
318318
// Proof Size summary in bytes:
319319
// Measured: `353`
320320
// Estimated: `7601`
321-
// Minimum execution time: 25_000_000 picoseconds.
322-
Weight::from_parts(26_000_000, 7601)
321+
// Minimum execution time: 28_000_000 picoseconds.
322+
Weight::from_parts(29_000_000, 7601)
323323
.saturating_add(RocksDbWeight::get().reads(7_u64))
324324
.saturating_add(RocksDbWeight::get().writes(5_u64))
325325
}
@@ -345,8 +345,8 @@ impl WeightInfo for () {
345345
// Proof Size summary in bytes:
346346
// Measured: `177`
347347
// Estimated: `6249`
348-
// Minimum execution time: 33_000_000 picoseconds.
349-
Weight::from_parts(33_000_000, 6249)
348+
// Minimum execution time: 37_000_000 picoseconds.
349+
Weight::from_parts(38_000_000, 6249)
350350
.saturating_add(RocksDbWeight::get().reads(9_u64))
351351
.saturating_add(RocksDbWeight::get().writes(6_u64))
352352
}
@@ -358,8 +358,8 @@ impl WeightInfo for () {
358358
// Proof Size summary in bytes:
359359
// Measured: `1592`
360360
// Estimated: `20591`
361-
// Minimum execution time: 90_000_000 picoseconds.
362-
Weight::from_parts(95_000_000, 20591)
361+
// Minimum execution time: 104_000_000 picoseconds.
362+
Weight::from_parts(105_000_000, 20591)
363363
.saturating_add(RocksDbWeight::get().reads(8_u64))
364364
.saturating_add(RocksDbWeight::get().writes(1_u64))
365365
}

0 commit comments

Comments
 (0)