Skip to content

Commit 999722d

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 2cbf06d commit 999722d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

benchmarking/src/mock.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl frame_system::Trait for Test {
6666
type BlockExecutionWeight = ();
6767
type ExtrinsicBaseWeight = ();
6868
type MaximumExtrinsicWeight = ();
69+
type SystemWeightInfo = ();
6970
}
7071
parameter_types! {
7172
pub const ExistentialDeposit: Balance = 10;
@@ -76,6 +77,7 @@ impl pallet_balances::Trait for Test {
7677
type DustRemoval = ();
7778
type ExistentialDeposit = ExistentialDeposit;
7879
type AccountStore = System;
80+
type WeightInfo = ();
7981
}
8082

8183
parameter_types! {
@@ -85,6 +87,7 @@ impl pallet_timestamp::Trait for Test {
8587
type Moment = u64;
8688
type OnTimestampSet = ();
8789
type MinimumPeriod = MinimumPeriod;
90+
type WeightInfo = ();
8891
}
8992
impl pallet_session::historical::Trait for Test {
9093
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
@@ -127,6 +130,7 @@ impl pallet_session::Trait for Test {
127130
type ValidatorId = AccountId;
128131
type ValidatorIdOf = pallet_staking::StashOf<Test>;
129132
type DisabledValidatorsThreshold = ();
133+
type WeightInfo = ();
130134
}
131135
pallet_staking_reward_curve::build! {
132136
const I_NPOS: sp_runtime::curve::PiecewiseLinear<'static> = curve!(
@@ -178,6 +182,7 @@ impl pallet_staking::Trait for Test {
178182
type UnsignedPriority = ();
179183
type MaxIterations = ();
180184
type MinSolutionScoreBump = ();
185+
type WeightInfo = ();
181186
}
182187

183188
impl pallet_im_online::Trait for Test {
@@ -186,6 +191,7 @@ impl pallet_im_online::Trait for Test {
186191
type SessionDuration = Period;
187192
type ReportUnresponsiveness = Offences;
188193
type UnsignedPriority = ();
194+
type WeightInfo = ();
189195
}
190196

191197
parameter_types! {
@@ -197,6 +203,7 @@ impl pallet_offences::Trait for Test {
197203
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
198204
type OnOffenceHandler = Staking;
199205
type WeightSoftLimit = OffencesWeightSoftLimit;
206+
type WeightInfo = ();
200207
}
201208

202209
impl<T> frame_system::offchain::SendTransactionTypes<T> for Test where Call: From<T> {

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ pub type DeferredOffenceOf<T> = (
5151
SessionIndex,
5252
);
5353

54+
pub trait WeightInfo {
55+
fn report_offence_im_online(r: u32, o: u32, n: u32, ) -> Weight;
56+
fn report_offence_grandpa(r: u32, n: u32, ) -> Weight;
57+
fn report_offence_babe(r: u32, n: u32, ) -> Weight;
58+
fn on_initialize(d: u32, ) -> Weight;
59+
}
60+
61+
impl WeightInfo for () {
62+
fn report_offence_im_online(_r: u32, _o: u32, _n: u32, ) -> Weight { 1_000_000_000 }
63+
fn report_offence_grandpa(_r: u32, _n: u32, ) -> Weight { 1_000_000_000 }
64+
fn report_offence_babe(_r: u32, _n: u32, ) -> Weight { 1_000_000_000 }
65+
fn on_initialize(_d: u32, ) -> Weight { 1_000_000_000 }
66+
}
67+
5468
/// Offences trait
5569
pub trait Trait: frame_system::Trait {
5670
/// The overarching event type.
@@ -63,6 +77,8 @@ pub trait Trait: frame_system::Trait {
6377
/// `on_initialize`.
6478
/// Note it's going to be exceeded before we stop adding to it, so it has to be set conservatively.
6579
type WeightSoftLimit: Get<Weight>;
80+
/// Weight information for extrinsics in this pallet.
81+
type WeightInfo: WeightInfo;
6682
}
6783

6884
decl_storage! {

src/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ impl frame_system::Trait for Runtime {
120120
type AccountData = ();
121121
type OnNewAccount = ();
122122
type OnKilledAccount = ();
123+
type SystemWeightInfo = ();
123124
}
124125

125126
parameter_types! {
@@ -131,6 +132,7 @@ impl Trait for Runtime {
131132
type IdentificationTuple = u64;
132133
type OnOffenceHandler = OnOffenceHandler;
133134
type WeightSoftLimit = OffencesWeightSoftLimit;
135+
type WeightInfo = ();
134136
}
135137

136138
mod offences {

0 commit comments

Comments
 (0)