Skip to content

Commit 933d4f3

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 976f25c commit 933d4f3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/lib.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use sp_runtime::traits::{
2828
use frame_support::{Parameter, decl_module, decl_error, decl_event, decl_storage, ensure};
2929
use frame_support::dispatch::DispatchResult;
3030
use frame_support::traits::{Currency, ReservableCurrency, Get, BalanceStatus::Reserved};
31-
use frame_support::weights::constants::WEIGHT_PER_MICROS;
31+
use frame_support::weights::{Weight, constants::WEIGHT_PER_MICROS};
3232
use frame_system::{ensure_signed, ensure_root};
3333
use self::address::Address as RawAddress;
3434

@@ -40,6 +40,22 @@ mod benchmarking;
4040
pub type Address<T> = RawAddress<<T as frame_system::Trait>::AccountId, <T as Trait>::AccountIndex>;
4141
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
4242

43+
pub trait WeightInfo {
44+
fn claim(i: u32, ) -> Weight;
45+
fn transfer(i: u32, ) -> Weight;
46+
fn free(i: u32, ) -> Weight;
47+
fn force_transfer(i: u32, ) -> Weight;
48+
fn freeze(i: u32, ) -> Weight;
49+
}
50+
51+
impl WeightInfo for () {
52+
fn claim(_i: u32, ) -> Weight { 1_000_000_000 }
53+
fn transfer(_i: u32, ) -> Weight { 1_000_000_000 }
54+
fn free(_i: u32, ) -> Weight { 1_000_000_000 }
55+
fn force_transfer(_i: u32, ) -> Weight { 1_000_000_000 }
56+
fn freeze(_i: u32, ) -> Weight { 1_000_000_000 }
57+
}
58+
4359
/// The module's config trait.
4460
pub trait Trait: frame_system::Trait {
4561
/// Type used for storing an account's index; implies the maximum number of accounts the system
@@ -54,6 +70,9 @@ pub trait Trait: frame_system::Trait {
5470

5571
/// The overarching event type.
5672
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
73+
74+
/// Weight information for extrinsics in this pallet.
75+
type WeightInfo: WeightInfo;
5776
}
5877

5978
decl_storage! {

src/mock.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl frame_system::Trait for Test {
7474
type AccountData = pallet_balances::AccountData<u64>;
7575
type OnNewAccount = ();
7676
type OnKilledAccount = ();
77+
type SystemWeightInfo = ();
7778
}
7879

7980
parameter_types! {
@@ -86,6 +87,7 @@ impl pallet_balances::Trait for Test {
8687
type Event = MetaEvent;
8788
type ExistentialDeposit = ExistentialDeposit;
8889
type AccountStore = System;
90+
type WeightInfo = ();
8991
}
9092

9193
parameter_types! {
@@ -97,6 +99,7 @@ impl Trait for Test {
9799
type Currency = Balances;
98100
type Deposit = Deposit;
99101
type Event = MetaEvent;
102+
type WeightInfo = ();
100103
}
101104

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

0 commit comments

Comments
 (0)