Skip to content

Commit 0493415

Browse files
committed
initial setup the benchmarking for the rewards pallet
1 parent d9ba357 commit 0493415

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

pallets/rewards/src/benchmarking.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ use super::*;
44

55
#[allow(unused)]
66
use crate::Pallet as Rewards;
7-
use frame_benchmarking::{benchmarks, whitelisted_caller};
8-
use frame_system::RawOrigin;
7+
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
8+
use frame_support::traits::{OnFinalize, OnInitialize,Currency};
9+
use frame_system::{DigestItemOf, EventRecord, RawOrigin};
10+
use sp_runtime::traits::Bounded;
911

1012
benchmarks! {
11-
do_something {
12-
let s in 0 .. 100;
13-
let caller: T::AccountId = whitelisted_caller();
14-
}: _(RawOrigin::Signed(caller), s)
13+
on_initialize {
14+
let author: T::AccountId = account("author", 0, 0);
15+
let author_digest = DigestItemOf::<T>::PreRuntime(sp_consensus_pow::POW_ENGINE_ID, author.encode());
16+
frame_system::Module::<T>::deposit_log(author_digest);
17+
18+
Reward::<T>::put(T::Currency::minimum_balance());
19+
20+
// Whitelist transient storage items
21+
frame_benchmarking::benchmarking::add_to_whitelist(Author::<T>::hashed_key().to_vec().into());
22+
23+
let block_number = frame_system::Module::<T>::block_number();
24+
}: { crate::Module::<T>::on_initialize(block_number); }
1525
verify {
16-
assert_eq!(Something::<T>::get(), Some(s));
26+
assert_eq!(Author::<T>::get(), Some(author));
1727
}
18-
19-
impl_benchmark_test_suite!(Rewards, crate::mock::new_test_ext(), crate::mock::Test);
2028
}

runtime/src/lib.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ impl pallet_fast_unstake::Config for Runtime {
635635
type Staking = Staking;
636636
type MaxErasToCheckPerBlock = ConstU32<1>;
637637
type WeightInfo = ();
638+
type MaxBackersPerValidator = ();
638639
}
639640

640641
parameter_types! {
@@ -1569,8 +1570,8 @@ impl pallet_nfts::Config for Runtime {
15691570
type MaxDeadlineDuration = MaxDeadlineDuration;
15701571
type Features = Features;
15711572
type WeightInfo = pallet_nfts::weights::SubstrateWeight<Runtime>;
1572-
#[cfg(feature = "runtime-benchmarks")]
1573-
type Helper = ();
1573+
// #[cfg(feature = "runtime-benchmarks")]
1574+
//type Helper = ();
15741575
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
15751576
type Locker = ();
15761577
}
@@ -1863,6 +1864,7 @@ mod benches {
18631864
[pallet_utility, Utility]
18641865
[pallet_vesting, Vesting]
18651866
[pallet_whitelist, Whitelist]
1867+
[rewards, Rewards]
18661868
);
18671869
}
18681870

@@ -2252,6 +2254,23 @@ impl_runtime_apis! {
22522254
let mut batches = Vec::<BenchmarkBatch>::new();
22532255
let params = (&config, &whitelist);
22542256
add_benchmarks!(params, batches);
2257+
// add_benchmark!(params, batches, balances, Balances);
2258+
// add_benchmark!(params, batches, collective, Council);
2259+
// add_benchmark!(params, batches, democracy, Democracy);
2260+
// add_benchmark!(params, batches, identity, Identity);
2261+
// add_benchmark!(params, batches, indices, Indices);
2262+
// add_benchmark!(params, batches, multisig, Multisig);
2263+
// add_benchmark!(params, batches, proxy, Proxy);
2264+
// add_benchmark!(params, batches, scheduler, Scheduler);
2265+
// add_benchmark!(params, batches, system, SystemBench::<Runtime>);
2266+
// add_benchmark!(params, batches, timestamp, Timestamp);
2267+
// add_benchmark!(params, batches, treasury, Treasury);
2268+
// add_benchmark!(params, batches, utility, Utility);
2269+
// add_benchmark!(params, batches, vesting, Vesting);
2270+
// add_benchmark!(params, batches, rewards, Rewards);
2271+
// add_benchmark!(params, batches, staking, Staking);
2272+
2273+
22552274
Ok(batches)
22562275
}
22572276
}

0 commit comments

Comments
 (0)