Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit e824e8a

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 d076f47 commit e824e8a

File tree

65 files changed

+632
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+632
-7
lines changed

bin/node-template/pallets/template/src/mock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl system::Trait for Test {
4848
type AccountData = ();
4949
type OnNewAccount = ();
5050
type OnKilledAccount = ();
51+
type SystemWeightInfo = ();
5152
}
5253
impl Trait for Test {
5354
type Event = ();

bin/node-template/runtime/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ impl system::Trait for Runtime {
189189
type OnKilledAccount = ();
190190
/// The data to be stored in an account.
191191
type AccountData = balances::AccountData<Balance>;
192+
/// Weight information for the extrinsics of this pallet.
193+
type SystemWeightInfo = ();
192194
}
193195

194196
impl aura::Trait for Runtime {
@@ -221,6 +223,7 @@ impl timestamp::Trait for Runtime {
221223
type Moment = u64;
222224
type OnTimestampSet = Aura;
223225
type MinimumPeriod = MinimumPeriod;
226+
type WeightInfo = ();
224227
}
225228

226229
parameter_types! {
@@ -235,6 +238,7 @@ impl balances::Trait for Runtime {
235238
type DustRemoval = ();
236239
type ExistentialDeposit = ExistentialDeposit;
237240
type AccountStore = System;
241+
type WeightInfo = ();
238242
}
239243

240244
parameter_types! {

bin/node/runtime/src/lib.rs

+19
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,13 @@ impl frame_system::Trait for Runtime {
171171
type AccountData = pallet_balances::AccountData<Balance>;
172172
type OnNewAccount = ();
173173
type OnKilledAccount = ();
174+
type SystemWeightInfo = ();
174175
}
175176

176177
impl pallet_utility::Trait for Runtime {
177178
type Event = Event;
178179
type Call = Call;
180+
type WeightInfo = ();
179181
}
180182

181183
parameter_types! {
@@ -193,6 +195,7 @@ impl pallet_multisig::Trait for Runtime {
193195
type DepositBase = DepositBase;
194196
type DepositFactor = DepositFactor;
195197
type MaxSignatories = MaxSignatories;
198+
type WeightInfo = ();
196199
}
197200

198201
parameter_types! {
@@ -246,6 +249,7 @@ impl pallet_proxy::Trait for Runtime {
246249
type ProxyDepositBase = ProxyDepositBase;
247250
type ProxyDepositFactor = ProxyDepositFactor;
248251
type MaxProxies = MaxProxies;
252+
type WeightInfo = ();
249253
}
250254

251255
parameter_types! {
@@ -259,6 +263,7 @@ impl pallet_scheduler::Trait for Runtime {
259263
type Call = Call;
260264
type MaximumWeight = MaximumSchedulerWeight;
261265
type ScheduleOrigin = EnsureRoot<AccountId>;
266+
type WeightInfo = ();
262267
}
263268

264269
parameter_types! {
@@ -296,6 +301,7 @@ impl pallet_indices::Trait for Runtime {
296301
type Currency = Balances;
297302
type Deposit = IndexDeposit;
298303
type Event = Event;
304+
type WeightInfo = ();
299305
}
300306

301307
parameter_types! {
@@ -308,6 +314,7 @@ impl pallet_balances::Trait for Runtime {
308314
type Event = Event;
309315
type ExistentialDeposit = ExistentialDeposit;
310316
type AccountStore = frame_system::Module<Runtime>;
317+
type WeightInfo = ();
311318
}
312319

313320
parameter_types! {
@@ -334,6 +341,7 @@ impl pallet_timestamp::Trait for Runtime {
334341
type Moment = Moment;
335342
type OnTimestampSet = Babe;
336343
type MinimumPeriod = MinimumPeriod;
344+
type WeightInfo = ();
337345
}
338346

339347
parameter_types! {
@@ -370,6 +378,7 @@ impl pallet_session::Trait for Runtime {
370378
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
371379
type Keys = SessionKeys;
372380
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
381+
type WeightInfo = ();
373382
}
374383

375384
impl pallet_session::historical::Trait for Runtime {
@@ -426,6 +435,7 @@ impl pallet_staking::Trait for Runtime {
426435
type MinSolutionScoreBump = MinSolutionScoreBump;
427436
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
428437
type UnsignedPriority = StakingUnsignedPriority;
438+
type WeightInfo = ();
429439
}
430440

431441
parameter_types! {
@@ -474,6 +484,7 @@ impl pallet_democracy::Trait for Runtime {
474484
type Scheduler = Scheduler;
475485
type PalletsOrigin = OriginCaller;
476486
type MaxVotes = MaxVotes;
487+
type WeightInfo = ();
477488
}
478489

479490
parameter_types! {
@@ -488,6 +499,7 @@ impl pallet_collective::Trait<CouncilCollective> for Runtime {
488499
type Event = Event;
489500
type MotionDuration = CouncilMotionDuration;
490501
type MaxProposals = CouncilMaxProposals;
502+
type WeightInfo = ();
491503
}
492504

493505
parameter_types! {
@@ -519,6 +531,7 @@ impl pallet_elections_phragmen::Trait for Runtime {
519531
type DesiredMembers = DesiredMembers;
520532
type DesiredRunnersUp = DesiredRunnersUp;
521533
type TermDuration = TermDuration;
534+
type WeightInfo = ();
522535
}
523536

524537
parameter_types! {
@@ -533,6 +546,7 @@ impl pallet_collective::Trait<TechnicalCollective> for Runtime {
533546
type Event = Event;
534547
type MotionDuration = TechnicalMotionDuration;
535548
type MaxProposals = TechnicalMaxProposals;
549+
type WeightInfo = ();
536550
}
537551

538552
type EnsureRootOrHalfCouncil = EnsureOneOf<
@@ -587,6 +601,7 @@ impl pallet_treasury::Trait for Runtime {
587601
type ProposalBondMinimum = ProposalBondMinimum;
588602
type SpendPeriod = SpendPeriod;
589603
type Burn = Burn;
604+
type WeightInfo = ();
590605
}
591606

592607
parameter_types! {
@@ -688,6 +703,7 @@ impl pallet_im_online::Trait for Runtime {
688703
type SessionDuration = SessionDuration;
689704
type ReportUnresponsiveness = Offences;
690705
type UnsignedPriority = ImOnlineUnsignedPriority;
706+
type WeightInfo = ();
691707
}
692708

693709
parameter_types! {
@@ -699,6 +715,7 @@ impl pallet_offences::Trait for Runtime {
699715
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
700716
type OnOffenceHandler = Staking;
701717
type WeightSoftLimit = OffencesWeightSoftLimit;
718+
type WeightInfo = ();
702719
}
703720

704721
impl pallet_authority_discovery::Trait for Runtime {}
@@ -757,6 +774,7 @@ impl pallet_identity::Trait for Runtime {
757774
type Slashed = Treasury;
758775
type ForceOrigin = EnsureRootOrHalfCouncil;
759776
type RegistrarOrigin = EnsureRootOrHalfCouncil;
777+
type WeightInfo = ();
760778
}
761779

762780
parameter_types! {
@@ -813,6 +831,7 @@ impl pallet_vesting::Trait for Runtime {
813831
type Currency = Balances;
814832
type BlockNumberToBalance = ConvertInto;
815833
type MinVestedTransfer = MinVestedTransfer;
834+
type WeightInfo = ();
816835
}
817836

818837
construct_runtime!(

frame/assets/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ mod tests {
328328
type AccountData = ();
329329
type OnNewAccount = ();
330330
type OnKilledAccount = ();
331+
type SystemWeightInfo = ();
331332
}
332333
impl Trait for Test {
333334
type Event = ();

frame/atomic-swap/src/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl frame_system::Trait for Test {
5454
type AccountData = pallet_balances::AccountData<u64>;
5555
type OnNewAccount = ();
5656
type OnKilledAccount = ();
57+
type SystemWeightInfo = ();
5758
}
5859
parameter_types! {
5960
pub const ExistentialDeposit: u64 = 1;
@@ -64,6 +65,7 @@ impl pallet_balances::Trait for Test {
6465
type Event = ();
6566
type ExistentialDeposit = ExistentialDeposit;
6667
type AccountStore = System;
68+
type WeightInfo = ();
6769
}
6870
parameter_types! {
6971
pub const ProofLimit: u32 = 1024;

frame/aura/src/mock.rs

+2
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ impl frame_system::Trait for Test {
7070
type AccountData = ();
7171
type OnNewAccount = ();
7272
type OnKilledAccount = ();
73+
type SystemWeightInfo = ();
7374
}
7475

7576
impl pallet_timestamp::Trait for Test {
7677
type Moment = u64;
7778
type OnTimestampSet = Aura;
7879
type MinimumPeriod = MinimumPeriod;
80+
type WeightInfo = ();
7981
}
8082

8183
impl Trait for Test {

frame/authority-discovery/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ mod tests {
123123
type ValidatorIdOf = ConvertInto;
124124
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
125125
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
126+
type WeightInfo = ();
126127
}
127128

128129
impl pallet_session::historical::Trait for Test {
@@ -167,6 +168,7 @@ mod tests {
167168
type AccountData = ();
168169
type OnNewAccount = ();
169170
type OnKilledAccount = ();
171+
type SystemWeightInfo = ();
170172
}
171173

172174
impl_outer_origin! {

frame/authorship/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ mod tests {
442442
type AccountData = ();
443443
type OnNewAccount = ();
444444
type OnKilledAccount = ();
445+
type SystemWeightInfo = ();
445446
}
446447

447448
parameter_types! {

frame/babe/src/mock.rs

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl frame_system::Trait for Test {
9090
type AccountData = pallet_balances::AccountData<u128>;
9191
type OnNewAccount = ();
9292
type OnKilledAccount = ();
93+
type SystemWeightInfo = ();
9394
}
9495

9596
impl<C> frame_system::offchain::SendTransactionTypes<C> for Test
@@ -116,6 +117,7 @@ impl pallet_session::Trait for Test {
116117
type SessionHandler = <MockSessionKeys as OpaqueKeys>::KeyTypeIdProviders;
117118
type Keys = MockSessionKeys;
118119
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
120+
type WeightInfo = ();
119121
}
120122

121123
impl pallet_session::historical::Trait for Test {
@@ -142,6 +144,7 @@ impl pallet_timestamp::Trait for Test {
142144
type Moment = u64;
143145
type OnTimestampSet = Babe;
144146
type MinimumPeriod = MinimumPeriod;
147+
type WeightInfo = ();
145148
}
146149

147150
parameter_types! {
@@ -154,6 +157,7 @@ impl pallet_balances::Trait for Test {
154157
type Event = ();
155158
type ExistentialDeposit = ExistentialDeposit;
156159
type AccountStore = System;
160+
type WeightInfo = ();
157161
}
158162

159163
pallet_staking_reward_curve::build! {
@@ -213,6 +217,7 @@ impl pallet_staking::Trait for Test {
213217
type UnsignedPriority = StakingUnsignedPriority;
214218
type MaxIterations = ();
215219
type MinSolutionScoreBump = ();
220+
type WeightInfo = ();
216221
}
217222

218223
parameter_types! {
@@ -224,6 +229,7 @@ impl pallet_offences::Trait for Test {
224229
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
225230
type OnOffenceHandler = Staking;
226231
type WeightSoftLimit = OffencesWeightSoftLimit;
232+
type WeightInfo = ();
227233
}
228234

229235
impl Trait for Test {

frame/balances/src/lib.rs

+26
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ use sp_std::{cmp, result, mem, fmt::Debug, ops::BitOr, convert::Infallible};
160160
use codec::{Codec, Encode, Decode};
161161
use frame_support::{
162162
StorageValue, Parameter, decl_event, decl_storage, decl_module, decl_error, ensure,
163+
weights::Weight,
163164
traits::{
164165
Currency, OnKilledAccount, OnUnbalanced, TryDrop, StoredMap,
165166
WithdrawReason, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement,
@@ -178,6 +179,22 @@ use frame_system::{self as system, ensure_signed, ensure_root};
178179

179180
pub use self::imbalances::{PositiveImbalance, NegativeImbalance};
180181

182+
pub trait WeightInfo {
183+
fn transfer(u: u32, e: u32, ) -> Weight;
184+
fn transfer_best_case(u: u32, e: u32, ) -> Weight;
185+
fn transfer_keep_alive(u: u32, e: u32, ) -> Weight;
186+
fn set_balance(u: u32, e: u32, ) -> Weight;
187+
fn set_balance_killing(u: u32, e: u32, ) -> Weight;
188+
}
189+
190+
impl WeightInfo for () {
191+
fn transfer(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
192+
fn transfer_best_case(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
193+
fn transfer_keep_alive(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
194+
fn set_balance(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
195+
fn set_balance_killing(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
196+
}
197+
181198
pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Trait {
182199
/// The balance of an account.
183200
type Balance: Parameter + Member + AtLeast32BitUnsigned + Codec + Default + Copy +
@@ -188,6 +205,9 @@ pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Trait {
188205

189206
/// The means of storing the balances of an account.
190207
type AccountStore: StoredMap<Self::AccountId, AccountData<Self::Balance>>;
208+
209+
/// Weight information for the extrinsics in this pallet.
210+
type WeightInfo: WeightInfo;
191211
}
192212

193213
pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {
@@ -206,12 +226,16 @@ pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {
206226

207227
/// The means of storing the balances of an account.
208228
type AccountStore: StoredMap<Self::AccountId, AccountData<Self::Balance>>;
229+
230+
/// Weight information for extrinsics in this pallet.
231+
type WeightInfo: WeightInfo;
209232
}
210233

211234
impl<T: Trait<I>, I: Instance> Subtrait<I> for T {
212235
type Balance = T::Balance;
213236
type ExistentialDeposit = T::ExistentialDeposit;
214237
type AccountStore = T::AccountStore;
238+
type WeightInfo = <T as Trait<I>>::WeightInfo;
215239
}
216240

217241
decl_event!(
@@ -872,13 +896,15 @@ impl<T: Subtrait<I>, I: Instance> frame_system::Trait for ElevatedTrait<T, I> {
872896
type OnNewAccount = T::OnNewAccount;
873897
type OnKilledAccount = T::OnKilledAccount;
874898
type AccountData = T::AccountData;
899+
type SystemWeightInfo = T::SystemWeightInfo;
875900
}
876901
impl<T: Subtrait<I>, I: Instance> Trait<I> for ElevatedTrait<T, I> {
877902
type Balance = T::Balance;
878903
type Event = ();
879904
type DustRemoval = ();
880905
type ExistentialDeposit = T::ExistentialDeposit;
881906
type AccountStore = T::AccountStore;
907+
type WeightInfo = <T as Subtrait<I>>::WeightInfo;
882908
}
883909

884910
impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I> where

frame/balances/src/tests_composite.rs

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl frame_system::Trait for Test {
9191
type AccountData = super::AccountData<u64>;
9292
type OnNewAccount = ();
9393
type OnKilledAccount = ();
94+
type SystemWeightInfo = ();
9495
}
9596
parameter_types! {
9697
pub const TransactionByteFee: u64 = 1;
@@ -108,6 +109,7 @@ impl Trait for Test {
108109
type Event = Event;
109110
type ExistentialDeposit = ExistentialDeposit;
110111
type AccountStore = system::Module<Test>;
112+
type WeightInfo = ();
111113
}
112114

113115
pub struct ExtBuilder {

frame/balances/src/tests_local.rs

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl frame_system::Trait for Test {
9191
type AccountData = super::AccountData<u64>;
9292
type OnNewAccount = ();
9393
type OnKilledAccount = Module<Test>;
94+
type SystemWeightInfo = ();
9495
}
9596
parameter_types! {
9697
pub const TransactionByteFee: u64 = 1;
@@ -113,6 +114,7 @@ impl Trait for Test {
113114
system::CallKillAccount<Test>,
114115
u64, super::AccountData<u64>
115116
>;
117+
type WeightInfo = ();
116118
}
117119

118120
pub struct ExtBuilder {

0 commit comments

Comments
 (0)