Skip to content

Commit 0d59bbe

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 ba69a74 commit 0d59bbe

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

fuzzer/src/mock.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl frame_system::Trait for Test {
8181
type AccountData = pallet_balances::AccountData<u64>;
8282
type OnNewAccount = ();
8383
type OnKilledAccount = (Balances,);
84+
type SystemWeightInfo = ();
8485
}
8586
parameter_types! {
8687
pub const ExistentialDeposit: Balance = 10;
@@ -91,12 +92,14 @@ impl pallet_balances::Trait for Test {
9192
type DustRemoval = ();
9293
type ExistentialDeposit = ExistentialDeposit;
9394
type AccountStore = System;
95+
type WeightInfo = ();
9496
}
9597
impl pallet_indices::Trait for Test {
9698
type AccountIndex = AccountIndex;
9799
type Event = ();
98100
type Currency = Balances;
99101
type Deposit = ();
102+
type WeightInfo = ();
100103
}
101104
parameter_types! {
102105
pub const MinimumPeriod: u64 = 5;
@@ -105,6 +108,7 @@ impl pallet_timestamp::Trait for Test {
105108
type Moment = u64;
106109
type OnTimestampSet = ();
107110
type MinimumPeriod = MinimumPeriod;
111+
type WeightInfo = ();
108112
}
109113
impl pallet_session::historical::Trait for Test {
110114
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
@@ -142,6 +146,7 @@ impl pallet_session::Trait for Test {
142146
type ValidatorId = AccountId;
143147
type ValidatorIdOf = pallet_staking::StashOf<Test>;
144148
type DisabledValidatorsThreshold = ();
149+
type WeightInfo = ();
145150
}
146151
pallet_staking_reward_curve::build! {
147152
const I_NPOS: sp_runtime::curve::PiecewiseLinear<'static> = curve!(
@@ -189,4 +194,5 @@ impl pallet_staking::Trait for Test {
189194
type MinSolutionScoreBump = ();
190195
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
191196
type UnsignedPriority = ();
197+
type WeightInfo = ();
192198
}

src/lib.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,68 @@ pub mod weight {
829829
}
830830
}
831831

832+
pub trait WeightInfo {
833+
fn bond(u: u32, ) -> Weight;
834+
fn bond_extra(u: u32, ) -> Weight;
835+
fn unbond(u: u32, ) -> Weight;
836+
fn withdraw_unbonded_update(s: u32, ) -> Weight;
837+
fn withdraw_unbonded_kill(s: u32, ) -> Weight;
838+
fn validate(u: u32, ) -> Weight;
839+
fn nominate(n: u32, ) -> Weight;
840+
fn chill(u: u32, ) -> Weight;
841+
fn set_payee(u: u32, ) -> Weight;
842+
fn set_controller(u: u32, ) -> Weight;
843+
fn set_validator_count(c: u32, ) -> Weight;
844+
fn force_no_eras(i: u32, ) -> Weight;
845+
fn force_new_era(i: u32, ) -> Weight;
846+
fn force_new_era_always(i: u32, ) -> Weight;
847+
fn set_invulnerables(v: u32, ) -> Weight;
848+
fn force_unstake(s: u32, ) -> Weight;
849+
fn cancel_deferred_slash(s: u32, ) -> Weight;
850+
fn payout_stakers(n: u32, ) -> Weight;
851+
fn payout_stakers_alive_controller(n: u32, ) -> Weight;
852+
fn rebond(l: u32, ) -> Weight;
853+
fn set_history_depth(e: u32, ) -> Weight;
854+
fn reap_stash(s: u32, ) -> Weight;
855+
fn new_era(v: u32, n: u32, ) -> Weight;
856+
fn do_slash(l: u32, ) -> Weight;
857+
fn payout_all(v: u32, n: u32, ) -> Weight;
858+
fn submit_solution_initial(v: u32, n: u32, a: u32, w: u32, ) -> Weight;
859+
fn submit_solution_better(v: u32, n: u32, a: u32, w: u32, ) -> Weight;
860+
fn submit_solution_weaker(v: u32, n: u32, ) -> Weight;
861+
}
862+
863+
impl WeightInfo for () {
864+
fn bond(_u: u32, ) -> Weight { 1_000_000_000 }
865+
fn bond_extra(_u: u32, ) -> Weight { 1_000_000_000 }
866+
fn unbond(_u: u32, ) -> Weight { 1_000_000_000 }
867+
fn withdraw_unbonded_update(_s: u32, ) -> Weight { 1_000_000_000 }
868+
fn withdraw_unbonded_kill(_s: u32, ) -> Weight { 1_000_000_000 }
869+
fn validate(_u: u32, ) -> Weight { 1_000_000_000 }
870+
fn nominate(_n: u32, ) -> Weight { 1_000_000_000 }
871+
fn chill(_u: u32, ) -> Weight { 1_000_000_000 }
872+
fn set_payee(_u: u32, ) -> Weight { 1_000_000_000 }
873+
fn set_controller(_u: u32, ) -> Weight { 1_000_000_000 }
874+
fn set_validator_count(_c: u32, ) -> Weight { 1_000_000_000 }
875+
fn force_no_eras(_i: u32, ) -> Weight { 1_000_000_000 }
876+
fn force_new_era(_i: u32, ) -> Weight { 1_000_000_000 }
877+
fn force_new_era_always(_i: u32, ) -> Weight { 1_000_000_000 }
878+
fn set_invulnerables(_v: u32, ) -> Weight { 1_000_000_000 }
879+
fn force_unstake(_s: u32, ) -> Weight { 1_000_000_000 }
880+
fn cancel_deferred_slash(_s: u32, ) -> Weight { 1_000_000_000 }
881+
fn payout_stakers(_n: u32, ) -> Weight { 1_000_000_000 }
882+
fn payout_stakers_alive_controller(_n: u32, ) -> Weight { 1_000_000_000 }
883+
fn rebond(_l: u32, ) -> Weight { 1_000_000_000 }
884+
fn set_history_depth(_e: u32, ) -> Weight { 1_000_000_000 }
885+
fn reap_stash(_s: u32, ) -> Weight { 1_000_000_000 }
886+
fn new_era(_v: u32, _n: u32, ) -> Weight { 1_000_000_000 }
887+
fn do_slash(_l: u32, ) -> Weight { 1_000_000_000 }
888+
fn payout_all(_v: u32, _n: u32, ) -> Weight { 1_000_000_000 }
889+
fn submit_solution_initial(_v: u32, _n: u32, _a: u32, _w: u32, ) -> Weight { 1_000_000_000 }
890+
fn submit_solution_better(_v: u32, _n: u32, _a: u32, _w: u32, ) -> Weight { 1_000_000_000 }
891+
fn submit_solution_weaker(_v: u32, _n: u32, ) -> Weight { 1_000_000_000 }
892+
}
893+
832894
pub trait Trait: frame_system::Trait + SendTransactionTypes<Call<Self>> {
833895
/// The staking balance.
834896
type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
@@ -915,6 +977,9 @@ pub trait Trait: frame_system::Trait + SendTransactionTypes<Call<Self>> {
915977
/// This is exposed so that it can be tuned for particular runtime, when
916978
/// multiple pallets send unsigned transactions.
917979
type UnsignedPriority: Get<TransactionPriority>;
980+
981+
/// Weight information for extrinsics in this pallet.
982+
type WeightInfo: WeightInfo;
918983
}
919984

920985
/// Mode of era-forcing.

src/mock.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,15 @@ impl frame_system::Trait for Test {
224224
type AccountData = pallet_balances::AccountData<Balance>;
225225
type OnNewAccount = ();
226226
type OnKilledAccount = ();
227+
type SystemWeightInfo = ();
227228
}
228229
impl pallet_balances::Trait for Test {
229230
type Balance = Balance;
230231
type Event = MetaEvent;
231232
type DustRemoval = ();
232233
type ExistentialDeposit = ExistentialDeposit;
233234
type AccountStore = System;
235+
type WeightInfo = ();
234236
}
235237
parameter_types! {
236238
pub const Offset: BlockNumber = 0;
@@ -252,6 +254,7 @@ impl pallet_session::Trait for Test {
252254
type ValidatorIdOf = crate::StashOf<Test>;
253255
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
254256
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
257+
type WeightInfo = ();
255258
}
256259

257260
impl pallet_session::historical::Trait for Test {
@@ -271,6 +274,7 @@ impl pallet_timestamp::Trait for Test {
271274
type Moment = u64;
272275
type OnTimestampSet = ();
273276
type MinimumPeriod = MinimumPeriod;
277+
type WeightInfo = ();
274278
}
275279
pallet_staking_reward_curve::build! {
276280
const I_NPOS: PiecewiseLinear<'static> = curve!(
@@ -326,6 +330,7 @@ impl Trait for Test {
326330
type MinSolutionScoreBump = MinSolutionScoreBump;
327331
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
328332
type UnsignedPriority = UnsignedPriority;
333+
type WeightInfo = ();
329334
}
330335

331336
impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Test where

0 commit comments

Comments
 (0)