Skip to content

Commit 3c2c7a2

Browse files
committed
feat: remove BlockNumberFor clauses
1 parent 79104e1 commit 3c2c7a2

File tree

7 files changed

+46
-151
lines changed

7 files changed

+46
-151
lines changed

pallets/dapp-staking-migration/src/benchmarking.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ fn smart_contract<T: pallet_dapps_staking::Config>(index: u8) -> T::SmartContrac
3333
}
3434

3535
/// Initialize the old dApp staking pallet with some storage.
36-
pub(super) fn initial_config<T: Config>()
37-
where
38-
BlockNumberFor<T>: IsType<BlockNumber>,
39-
{
36+
pub(super) fn initial_config<T: Config>() {
4037
let dapps_number = <T as pallet_dapp_staking_v3::Config>::MaxNumberOfContracts::get();
4138
let dapps_number = (dapps_number as u8).min(100);
4239

@@ -69,10 +66,7 @@ where
6966
}
7067
}
7168

72-
#[benchmarks(
73-
where
74-
BlockNumberFor<T>: IsType<BlockNumber>,
75-
)]
69+
#[benchmarks]
7670
mod benchmarks {
7771
use super::*;
7872

pallets/dapp-staking-migration/src/lib.rs

+7-29
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ pub mod pallet {
9898
pub trait Config:
9999
// Tight coupling, but it's fine since pallet is supposed to be just temporary and will be removed after migration.
100100
frame_system::Config + pallet_dapp_staking_v3::Config + pallet_dapps_staking::Config
101-
where
102-
BlockNumberFor<Self>: IsType<BlockNumber>,
103101
{
104102
/// The overarching event type.
105103
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
@@ -114,21 +112,15 @@ pub mod pallet {
114112

115113
#[pallet::event]
116114
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
117-
pub enum Event<T: Config>
118-
where
119-
BlockNumberFor<T>: IsType<BlockNumber>,
120-
{
115+
pub enum Event<T: Config> {
121116
/// Number of entries migrated from v2 over to v3
122117
EntriesMigrated(u32),
123118
/// Number of entries deleted from v2
124119
EntriesDeleted(u32),
125120
}
126121

127122
#[pallet::call]
128-
impl<T: Config> Pallet<T>
129-
where
130-
BlockNumberFor<T>: IsType<BlockNumber>,
131-
{
123+
impl<T: Config> Pallet<T> {
132124
/// Attempt to execute migration steps, consuming up to the specified amount of weight.
133125
/// If no weight is specified, max allowed weight is used.
134126
///
@@ -161,10 +153,7 @@ pub mod pallet {
161153
}
162154

163155
#[pallet::hooks]
164-
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
165-
where
166-
BlockNumberFor<T>: IsType<BlockNumber>,
167-
{
156+
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
168157
fn integrity_test() {
169158
assert!(Pallet::<T>::max_call_weight().all_gte(Pallet::<T>::min_call_weight()));
170159

@@ -175,10 +164,7 @@ pub mod pallet {
175164
}
176165
}
177166

178-
impl<T: Config> Pallet<T>
179-
where
180-
BlockNumberFor<T>: IsType<BlockNumber>,
181-
{
167+
impl<T: Config> Pallet<T> {
182168
/// Execute migrations steps until the specified weight limit has been consumed.
183169
///
184170
/// Depending on the number of entries migrated and/or deleted, appropriate events are emitted.
@@ -533,13 +519,8 @@ pub mod pallet {
533519
}
534520
}
535521

536-
pub struct DappStakingMigrationHandler<T: Config>(PhantomData<T>)
537-
where
538-
BlockNumberFor<T>: IsType<BlockNumber>;
539-
impl<T: Config> frame_support::traits::OnRuntimeUpgrade for DappStakingMigrationHandler<T>
540-
where
541-
BlockNumberFor<T>: IsType<BlockNumber>,
542-
{
522+
pub struct DappStakingMigrationHandler<T: Config>(PhantomData<T>);
523+
impl<T: Config> frame_support::traits::OnRuntimeUpgrade for DappStakingMigrationHandler<T> {
543524
fn on_runtime_upgrade() -> Weight {
544525
// When upgrade happens, we need to put dApp staking v3 into maintenance mode immediately.
545526
// For the old pallet, since the storage cleanup is going to happen, maintenance mode must be ensured
@@ -732,10 +713,7 @@ pub mod pallet {
732713
#[cfg(feature = "try-runtime")]
733714
/// Used to help with `try-runtime` testing.
734715
#[derive(Encode, Decode)]
735-
struct Helper<T: Config>
736-
where
737-
BlockNumberFor<T>: IsType<BlockNumber>,
738-
{
716+
struct Helper<T: Config> {
739717
/// Vec of devs, with their associated smart contract & total reserved balance
740718
developers: Vec<(
741719
T::AccountId,

pallets/dapp-staking-v3/src/benchmarking/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ use utils::*;
3535
//
3636
// Without this optimization, benchmarks can take hours to execute for production runtimes.
3737

38-
#[benchmarks(
39-
where
40-
BlockNumberFor<T>: IsType<BlockNumber>,
41-
)]
38+
#[benchmarks()]
4239
mod benchmarks {
4340
use super::*;
4441

@@ -307,10 +304,10 @@ mod benchmarks {
307304

308305
// Hack
309306
// In order to speed up the benchmark, we reduce how long it takes to unlock the chunks
310-
let mut counter = 1;
307+
let mut counter = 1u32;
311308
Ledger::<T>::mutate(&staker, |ledger| {
312309
ledger.unlocking.iter_mut().for_each(|unlocking| {
313-
unlocking.unlock_block = (System::<T>::block_number() + counter.into()).into();
310+
unlocking.unlock_block = (System::<T>::block_number() + counter.into()).saturated_into();
314311
});
315312
counter += 1;
316313
});

pallets/dapp-staking-v3/src/benchmarking/utils.rs

+17-65
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,25 @@ use frame_system::Pallet as System;
2424

2525
/// Run to the specified block number.
2626
/// Function assumes first block has been initialized.
27-
pub(super) fn run_to_block<T: Config>(n: BlockNumberFor<T>)
28-
where
29-
BlockNumberFor<T>: IsType<BlockNumber>,
30-
{
27+
pub(super) fn run_to_block<T: Config>(n: BlockNumberFor<T>) {
3128
while System::<T>::block_number() < n {
3229
DappStaking::<T>::on_finalize(System::<T>::block_number());
33-
System::<T>::set_block_number(System::<T>::block_number() + 1.into());
30+
System::<T>::set_block_number(System::<T>::block_number() + 1u32.into());
3431
// This is performed outside of dapps staking but we expect it before on_initialize
3532
DappStaking::<T>::on_initialize(System::<T>::block_number());
3633
}
3734
}
3835

3936
/// Run for the specified number of blocks.
4037
/// Function assumes first block has been initialized.
41-
pub(super) fn run_for_blocks<T: Config>(n: BlockNumberFor<T>)
42-
where
43-
BlockNumberFor<T>: IsType<BlockNumber>,
44-
{
38+
pub(super) fn run_for_blocks<T: Config>(n: BlockNumberFor<T>) {
4539
run_to_block::<T>(System::<T>::block_number() + n);
4640
}
4741

4842
/// Advance blocks until the specified era has been reached.
4943
///
5044
/// Function has no effect if era is already passed.
51-
pub(super) fn advance_to_era<T: Config>(era: EraNumber)
52-
where
53-
BlockNumberFor<T>: IsType<BlockNumber>,
54-
{
45+
pub(super) fn advance_to_era<T: Config>(era: EraNumber) {
5546
assert!(era >= ActiveProtocolState::<T>::get().era);
5647
while ActiveProtocolState::<T>::get().era < era {
5748
run_for_blocks::<T>(One::one());
@@ -61,10 +52,7 @@ where
6152
/// Advance blocks until the specified era has been reached.
6253
///
6354
/// Relies on the `force` approach to advance one era per block.
64-
pub(super) fn force_advance_to_era<T: Config>(era: EraNumber)
65-
where
66-
BlockNumberFor<T>: IsType<BlockNumber>,
67-
{
55+
pub(super) fn force_advance_to_era<T: Config>(era: EraNumber) {
6856
assert!(era > ActiveProtocolState::<T>::get().era);
6957
while ActiveProtocolState::<T>::get().era < era {
7058
assert_ok!(DappStaking::<T>::force(
@@ -76,18 +64,12 @@ where
7664
}
7765

7866
/// Advance blocks until next era has been reached.
79-
pub(super) fn _advance_to_next_era<T: Config>()
80-
where
81-
BlockNumberFor<T>: IsType<BlockNumber>,
82-
{
67+
pub(super) fn _advance_to_next_era<T: Config>() {
8368
advance_to_era::<T>(ActiveProtocolState::<T>::get().era + 1);
8469
}
8570

8671
/// Advance to next era, in the next block using the `force` approach.
87-
pub(crate) fn force_advance_to_next_era<T: Config>()
88-
where
89-
BlockNumberFor<T>: IsType<BlockNumber>,
90-
{
72+
pub(crate) fn force_advance_to_next_era<T: Config>() {
9173
assert_ok!(DappStaking::<T>::force(
9274
RawOrigin::Root.into(),
9375
ForcingType::Era
@@ -98,10 +80,7 @@ where
9880
/// Advance blocks until next period has been reached.
9981
///
10082
/// Relies on the `force` approach to advance one subperiod per block.
101-
pub(super) fn force_advance_to_next_period<T: Config>()
102-
where
103-
BlockNumberFor<T>: IsType<BlockNumber>,
104-
{
83+
pub(super) fn force_advance_to_next_period<T: Config>() {
10584
let init_period_number = ActiveProtocolState::<T>::get().period_number();
10685
while ActiveProtocolState::<T>::get().period_number() == init_period_number {
10786
assert_ok!(DappStaking::<T>::force(
@@ -113,21 +92,15 @@ where
11392
}
11493

11594
/// Advance to the specified period, using the `force` approach.
116-
pub(super) fn force_advance_to_period<T: Config>(period: PeriodNumber)
117-
where
118-
BlockNumberFor<T>: IsType<BlockNumber>,
119-
{
95+
pub(super) fn force_advance_to_period<T: Config>(period: PeriodNumber) {
12096
assert!(period >= ActiveProtocolState::<T>::get().period_number());
12197
while ActiveProtocolState::<T>::get().period_number() < period {
12298
force_advance_to_next_subperiod::<T>();
12399
}
124100
}
125101

126102
/// Use the `force` approach to advance to the next subperiod immediately in the next block.
127-
pub(super) fn force_advance_to_next_subperiod<T: Config>()
128-
where
129-
BlockNumberFor<T>: IsType<BlockNumber>,
130-
{
103+
pub(super) fn force_advance_to_next_subperiod<T: Config>() {
131104
assert_ok!(DappStaking::<T>::force(
132105
RawOrigin::Root.into(),
133106
ForcingType::Subperiod
@@ -148,18 +121,12 @@ pub(super) const NUMBER_OF_SLOTS: u32 = 100;
148121
pub(super) const SEED: u32 = 9000;
149122

150123
/// Assert that the last event equals the provided one.
151-
pub(super) fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent)
152-
where
153-
BlockNumberFor<T>: IsType<BlockNumber>,
154-
{
124+
pub(super) fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
155125
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
156126
}
157127

158128
// Return all dApp staking events from the event buffer.
159-
pub(super) fn dapp_staking_events<T: Config>() -> Vec<crate::Event<T>>
160-
where
161-
BlockNumberFor<T>: IsType<BlockNumber>,
162-
{
129+
pub(super) fn dapp_staking_events<T: Config>() -> Vec<crate::Event<T>> {
163130
System::<T>::events()
164131
.into_iter()
165132
.map(|r| r.event)
@@ -171,10 +138,7 @@ where
171138
///
172139
/// **NOTE:** This assumes similar tier configuration for all runtimes.
173140
/// If we decide to change this, we'll need to provide a more generic init function.
174-
pub(super) fn initial_config<T: Config>()
175-
where
176-
BlockNumberFor<T>: IsType<BlockNumber>,
177-
{
141+
pub(super) fn initial_config<T: Config>() {
178142
let era_length = T::CycleConfiguration::blocks_per_era();
179143
let voting_period_length_in_eras = T::CycleConfiguration::eras_per_voting_subperiod();
180144

@@ -244,21 +208,15 @@ where
244208
}
245209

246210
/// Maximum number of contracts that 'makes sense' - considers both contract number limit & number of slots.
247-
pub(super) fn max_number_of_contracts<T: Config>() -> u32
248-
where
249-
BlockNumberFor<T>: IsType<BlockNumber>,
250-
{
211+
pub(super) fn max_number_of_contracts<T: Config>() -> u32 {
251212
T::MaxNumberOfContracts::get().min(NUMBER_OF_SLOTS).into()
252213
}
253214

254215
/// Registers & staked on the specified number of smart contracts
255216
///
256217
/// Stake amounts are decided in such a way to maximize tier filling rate.
257218
/// This means that all of the contracts should end up in some tier.
258-
pub(super) fn prepare_contracts_for_tier_assignment<T: Config>(x: u32)
259-
where
260-
BlockNumberFor<T>: IsType<BlockNumber>,
261-
{
219+
pub(super) fn prepare_contracts_for_tier_assignment<T: Config>(x: u32) {
262220
let developer: T::AccountId = whitelisted_caller();
263221
for id in 0..x {
264222
let smart_contract = T::BenchmarkHelper::get_smart_contract(id as u32);
@@ -308,20 +266,14 @@ fn trivial_fisher_yates_shuffle<T>(vector: &mut Vec<T>, random_seed: u64) {
308266
/// Returns max amount of rewards that can be claimed in a single claim reward call from a past period.
309267
///
310268
/// Bounded by era reward span length & number of eras per period (not length but absolute number).
311-
pub(super) fn max_claim_size_past_period<T: Config>() -> u32
312-
where
313-
BlockNumberFor<T>: IsType<BlockNumber>,
314-
{
269+
pub(super) fn max_claim_size_past_period<T: Config>() -> u32 {
315270
T::EraRewardSpanLength::get().min(T::CycleConfiguration::eras_per_build_and_earn_subperiod())
316271
}
317272

318273
/// Returns max amount of rewards that can be claimed in a single claim reward call from an ongoing period.
319274
///
320275
/// Bounded by era reward span length & number of eras per period (not length but absolute number).
321-
pub(super) fn max_claim_size_ongoing_period<T: Config>() -> u32
322-
where
323-
BlockNumberFor<T>: IsType<BlockNumber>,
324-
{
276+
pub(super) fn max_claim_size_ongoing_period<T: Config>() -> u32 {
325277
T::EraRewardSpanLength::get()
326278
.min(T::CycleConfiguration::eras_per_build_and_earn_subperiod() - 1)
327279
}

0 commit comments

Comments
 (0)