Skip to content

Commit 30fff46

Browse files
authored
Add WeightInfo to all pallets with benchmarks. (#6575)
* Start adding weight info * More weightinfo * finish weight info * more fixes * inital update of node runtime * fix the rest of the compilation * update balances * add docs * fix balances tests * Fix more tests * Fix compile * Fix pallet-evm tests
1 parent da18f59 commit 30fff46

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

benchmarking/src/mock.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ impl frame_system::Trait for Test {
8181
type ModuleToIndex = ();
8282
type AccountData = pallet_balances::AccountData<u64>;
8383
type OnNewAccount = ();
84-
type OnKilledAccount = (Balances,);
84+
type OnKilledAccount = Balances;
85+
type SystemWeightInfo = ();
8586
}
8687
parameter_types! {
8788
pub const ExistentialDeposit: Balance = 10;
@@ -92,6 +93,7 @@ impl pallet_balances::Trait for Test {
9293
type DustRemoval = ();
9394
type ExistentialDeposit = ExistentialDeposit;
9495
type AccountStore = System;
96+
type WeightInfo = ();
9597
}
9698

9799
parameter_types! {
@@ -101,6 +103,7 @@ impl pallet_timestamp::Trait for Test {
101103
type Moment = u64;
102104
type OnTimestampSet = ();
103105
type MinimumPeriod = MinimumPeriod;
106+
type WeightInfo = ();
104107
}
105108
impl pallet_session::historical::Trait for Test {
106109
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
@@ -138,6 +141,7 @@ impl pallet_session::Trait for Test {
138141
type ValidatorId = AccountId;
139142
type ValidatorIdOf = pallet_staking::StashOf<Test>;
140143
type DisabledValidatorsThreshold = ();
144+
type WeightInfo = ();
141145
}
142146
pallet_staking_reward_curve::build! {
143147
const I_NPOS: sp_runtime::curve::PiecewiseLinear<'static> = curve!(
@@ -185,6 +189,7 @@ impl pallet_staking::Trait for Test {
185189
type UnsignedPriority = UnsignedPriority;
186190
type MaxIterations = ();
187191
type MinSolutionScoreBump = ();
192+
type WeightInfo = ();
188193
}
189194

190195
impl crate::Trait for Test {}

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,16 @@ impl<T: Trait> ValidatorRegistration<T::ValidatorId> for Module<T> {
351351
}
352352
}
353353

354+
pub trait WeightInfo {
355+
fn set_keys(n: u32, ) -> Weight;
356+
fn purge_keys(n: u32, ) -> Weight;
357+
}
358+
359+
impl WeightInfo for () {
360+
fn set_keys(_n: u32, ) -> Weight { 1_000_000_000 }
361+
fn purge_keys(_n: u32, ) -> Weight { 1_000_000_000 }
362+
}
363+
354364
pub trait Trait: frame_system::Trait {
355365
/// The overarching event type.
356366
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
@@ -385,6 +395,9 @@ pub trait Trait: frame_system::Trait {
385395
/// After the threshold is reached `disabled` method starts to return true,
386396
/// which in combination with `pallet_staking` forces a new era.
387397
type DisabledValidatorsThreshold: Get<Perbill>;
398+
399+
/// Weight information for extrinsics in this pallet.
400+
type WeightInfo: WeightInfo;
388401
}
389402

390403
decl_storage! {

src/mock.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,14 @@ impl frame_system::Trait for Test {
197197
type AccountData = ();
198198
type OnNewAccount = ();
199199
type OnKilledAccount = ();
200+
type SystemWeightInfo = ();
200201
}
201202

202203
impl pallet_timestamp::Trait for Test {
203204
type Moment = u64;
204205
type OnTimestampSet = ();
205206
type MinimumPeriod = MinimumPeriod;
207+
type WeightInfo = ();
206208
}
207209

208210
parameter_types! {
@@ -222,6 +224,7 @@ impl Trait for Test {
222224
type Event = ();
223225
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
224226
type NextSessionRotation = ();
227+
type WeightInfo = ();
225228
}
226229

227230
#[cfg(feature = "historical")]

0 commit comments

Comments
 (0)