Skip to content

Commit 93ea035

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 3e98022 commit 93ea035

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/lib.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,66 @@ type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trai
201201
type NegativeImbalanceOf<T> =
202202
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
203203

204+
pub trait WeightInfo {
205+
fn propose(p: u32, ) -> Weight;
206+
fn second(s: u32, ) -> Weight;
207+
fn vote_new(r: u32, ) -> Weight;
208+
fn vote_existing(r: u32, ) -> Weight;
209+
fn emergency_cancel(r: u32, ) -> Weight;
210+
fn external_propose(p: u32, v: u32, ) -> Weight;
211+
fn external_propose_majority(p: u32, ) -> Weight;
212+
fn external_propose_default(p: u32, ) -> Weight;
213+
fn fast_track(p: u32, ) -> Weight;
214+
fn veto_external(v: u32, ) -> Weight;
215+
fn cancel_referendum(r: u32, ) -> Weight;
216+
fn cancel_queued(r: u32, ) -> Weight;
217+
fn on_initialize_external(r: u32, ) -> Weight;
218+
fn on_initialize_public(r: u32, ) -> Weight;
219+
fn on_initialize_no_launch_no_maturing(r: u32, ) -> Weight;
220+
fn delegate(r: u32, ) -> Weight;
221+
fn undelegate(r: u32, ) -> Weight;
222+
fn clear_public_proposals(p: u32, ) -> Weight;
223+
fn note_preimage(b: u32, ) -> Weight;
224+
fn note_imminent_preimage(b: u32, ) -> Weight;
225+
fn reap_preimage(b: u32, ) -> Weight;
226+
fn unlock_remove(r: u32, ) -> Weight;
227+
fn unlock_set(r: u32, ) -> Weight;
228+
fn remove_vote(r: u32, ) -> Weight;
229+
fn remove_other_vote(r: u32, ) -> Weight;
230+
fn enact_proposal_execute(b: u32, ) -> Weight;
231+
fn enact_proposal_slash(b: u32, ) -> Weight;
232+
}
233+
234+
impl WeightInfo for () {
235+
fn propose(_p: u32, ) -> Weight { 1_000_000_000 }
236+
fn second(_s: u32, ) -> Weight { 1_000_000_000 }
237+
fn vote_new(_r: u32, ) -> Weight { 1_000_000_000 }
238+
fn vote_existing(_r: u32, ) -> Weight { 1_000_000_000 }
239+
fn emergency_cancel(_r: u32, ) -> Weight { 1_000_000_000 }
240+
fn external_propose(_p: u32, _v: u32, ) -> Weight { 1_000_000_000 }
241+
fn external_propose_majority(_p: u32, ) -> Weight { 1_000_000_000 }
242+
fn external_propose_default(_p: u32, ) -> Weight { 1_000_000_000 }
243+
fn fast_track(_p: u32, ) -> Weight { 1_000_000_000 }
244+
fn veto_external(_v: u32, ) -> Weight { 1_000_000_000 }
245+
fn cancel_referendum(_r: u32, ) -> Weight { 1_000_000_000 }
246+
fn cancel_queued(_r: u32, ) -> Weight { 1_000_000_000 }
247+
fn on_initialize_external(_r: u32, ) -> Weight { 1_000_000_000 }
248+
fn on_initialize_public(_r: u32, ) -> Weight { 1_000_000_000 }
249+
fn on_initialize_no_launch_no_maturing(_r: u32, ) -> Weight { 1_000_000_000 }
250+
fn delegate(_r: u32, ) -> Weight { 1_000_000_000 }
251+
fn undelegate(_r: u32, ) -> Weight { 1_000_000_000 }
252+
fn clear_public_proposals(_p: u32, ) -> Weight { 1_000_000_000 }
253+
fn note_preimage(_b: u32, ) -> Weight { 1_000_000_000 }
254+
fn note_imminent_preimage(_b: u32, ) -> Weight { 1_000_000_000 }
255+
fn reap_preimage(_b: u32, ) -> Weight { 1_000_000_000 }
256+
fn unlock_remove(_r: u32, ) -> Weight { 1_000_000_000 }
257+
fn unlock_set(_r: u32, ) -> Weight { 1_000_000_000 }
258+
fn remove_vote(_r: u32, ) -> Weight { 1_000_000_000 }
259+
fn remove_other_vote(_r: u32, ) -> Weight { 1_000_000_000 }
260+
fn enact_proposal_execute(_b: u32, ) -> Weight { 1_000_000_000 }
261+
fn enact_proposal_slash(_b: u32, ) -> Weight { 1_000_000_000 }
262+
}
263+
204264
pub trait Trait: frame_system::Trait + Sized {
205265
type Proposal: Parameter + Dispatchable<Origin=Self::Origin> + From<Call<Self>>;
206266
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
@@ -289,6 +349,9 @@ pub trait Trait: frame_system::Trait + Sized {
289349
/// Also used to compute weight, an overly big value can
290350
/// lead to extrinsic with very big weight: see `delegate` for instance.
291351
type MaxVotes: Get<u32>;
352+
353+
/// Weight information for extrinsics in this pallet.
354+
type WeightInfo: WeightInfo;
292355
}
293356

294357
#[derive(Clone, Encode, Decode, RuntimeDebug)]

src/tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl frame_system::Trait for Test {
116116
type AccountData = pallet_balances::AccountData<u64>;
117117
type OnNewAccount = ();
118118
type OnKilledAccount = ();
119+
type SystemWeightInfo = ();
119120
}
120121
parameter_types! {
121122
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();
@@ -127,6 +128,7 @@ impl pallet_scheduler::Trait for Test {
127128
type Call = Call;
128129
type MaximumWeight = MaximumSchedulerWeight;
129130
type ScheduleOrigin = EnsureRoot<u64>;
131+
type WeightInfo = ();
130132
}
131133
parameter_types! {
132134
pub const ExistentialDeposit: u64 = 1;
@@ -137,6 +139,7 @@ impl pallet_balances::Trait for Test {
137139
type DustRemoval = ();
138140
type ExistentialDeposit = ExistentialDeposit;
139141
type AccountStore = System;
142+
type WeightInfo = ();
140143
}
141144
parameter_types! {
142145
pub const LaunchPeriod: u64 = 2;
@@ -199,6 +202,7 @@ impl super::Trait for Test {
199202
type MaxVotes = MaxVotes;
200203
type OperationalPreimageOrigin = EnsureSignedBy<Six, u64>;
201204
type PalletsOrigin = OriginCaller;
205+
type WeightInfo = ();
202206
}
203207

204208
pub fn new_test_ext() -> sp_io::TestExternalities {

0 commit comments

Comments
 (0)