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

Add WeightInfo to all pallets with benchmarks. #6575

Merged
merged 13 commits into from
Jul 8, 2020
1 change: 1 addition & 0 deletions bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl system::Trait for Test {
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
apopiak marked this conversation as resolved.
Show resolved Hide resolved
}
impl Trait for Test {
type Event = ();
Expand Down
4 changes: 4 additions & 0 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ impl system::Trait for Runtime {
type OnKilledAccount = ();
/// The data to be stored in an account.
type AccountData = balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
}

impl aura::Trait for Runtime {
Expand Down Expand Up @@ -221,6 +223,7 @@ impl timestamp::Trait for Runtime {
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -235,6 +238,7 @@ impl balances::Trait for Runtime {
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
}

parameter_types! {
Expand Down
19 changes: 19 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ impl frame_system::Trait for Runtime {
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}

impl pallet_utility::Trait for Runtime {
type Event = Event;
type Call = Call;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -193,6 +195,7 @@ impl pallet_multisig::Trait for Runtime {
type DepositBase = DepositBase;
type DepositFactor = DepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = ();
}

parameter_types! {
Expand Down Expand Up @@ -246,6 +249,7 @@ impl pallet_proxy::Trait for Runtime {
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type MaxProxies = MaxProxies;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -259,6 +263,7 @@ impl pallet_scheduler::Trait for Runtime {
type Call = Call;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type WeightInfo = ();
}

parameter_types! {
Expand Down Expand Up @@ -296,6 +301,7 @@ impl pallet_indices::Trait for Runtime {
type Currency = Balances;
type Deposit = IndexDeposit;
type Event = Event;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -308,6 +314,7 @@ impl pallet_balances::Trait for Runtime {
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = frame_system::Module<Runtime>;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -334,6 +341,7 @@ impl pallet_timestamp::Trait for Runtime {
type Moment = Moment;
type OnTimestampSet = Babe;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}

parameter_types! {
Expand Down Expand Up @@ -370,6 +378,7 @@ impl pallet_session::Trait for Runtime {
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = ();
}

impl pallet_session::historical::Trait for Runtime {
Expand Down Expand Up @@ -426,6 +435,7 @@ impl pallet_staking::Trait for Runtime {
type MinSolutionScoreBump = MinSolutionScoreBump;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type UnsignedPriority = StakingUnsignedPriority;
type WeightInfo = ();
}

parameter_types! {
Expand Down Expand Up @@ -474,6 +484,7 @@ impl pallet_democracy::Trait for Runtime {
type Scheduler = Scheduler;
type PalletsOrigin = OriginCaller;
type MaxVotes = MaxVotes;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -488,6 +499,7 @@ impl pallet_collective::Trait<CouncilCollective> for Runtime {
type Event = Event;
type MotionDuration = CouncilMotionDuration;
type MaxProposals = CouncilMaxProposals;
type WeightInfo = ();
}

parameter_types! {
Expand Down Expand Up @@ -519,6 +531,7 @@ impl pallet_elections_phragmen::Trait for Runtime {
type DesiredMembers = DesiredMembers;
type DesiredRunnersUp = DesiredRunnersUp;
type TermDuration = TermDuration;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -533,6 +546,7 @@ impl pallet_collective::Trait<TechnicalCollective> for Runtime {
type Event = Event;
type MotionDuration = TechnicalMotionDuration;
type MaxProposals = TechnicalMaxProposals;
type WeightInfo = ();
}

type EnsureRootOrHalfCouncil = EnsureOneOf<
Expand Down Expand Up @@ -587,6 +601,7 @@ impl pallet_treasury::Trait for Runtime {
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type WeightInfo = ();
}

parameter_types! {
Expand Down Expand Up @@ -688,6 +703,7 @@ impl pallet_im_online::Trait for Runtime {
type SessionDuration = SessionDuration;
type ReportUnresponsiveness = Offences;
type UnsignedPriority = ImOnlineUnsignedPriority;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -699,6 +715,7 @@ impl pallet_offences::Trait for Runtime {
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type WeightSoftLimit = OffencesWeightSoftLimit;
type WeightInfo = ();
}

impl pallet_authority_discovery::Trait for Runtime {}
Expand Down Expand Up @@ -757,6 +774,7 @@ impl pallet_identity::Trait for Runtime {
type Slashed = Treasury;
type ForceOrigin = EnsureRootOrHalfCouncil;
type RegistrarOrigin = EnsureRootOrHalfCouncil;
type WeightInfo = ();
}

parameter_types! {
Expand Down Expand Up @@ -813,6 +831,7 @@ impl pallet_vesting::Trait for Runtime {
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = MinVestedTransfer;
type WeightInfo = ();
}

construct_runtime!(
Expand Down
1 change: 1 addition & 0 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ mod tests {
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl Trait for Test {
type Event = ();
Expand Down
2 changes: 2 additions & 0 deletions frame/atomic-swap/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl frame_system::Trait for Test {
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
Expand All @@ -64,6 +65,7 @@ impl pallet_balances::Trait for Test {
type Event = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
}
parameter_types! {
pub const ProofLimit: u32 = 1024;
Expand Down
2 changes: 2 additions & 0 deletions frame/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ impl frame_system::Trait for Test {
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}

impl pallet_timestamp::Trait for Test {
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}

impl Trait for Test {
Expand Down
2 changes: 2 additions & 0 deletions frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ mod tests {
type ValidatorIdOf = ConvertInto;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
type WeightInfo = ();
}

impl pallet_session::historical::Trait for Test {
Expand Down Expand Up @@ -167,6 +168,7 @@ mod tests {
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}

impl_outer_origin! {
Expand Down
1 change: 1 addition & 0 deletions frame/authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ mod tests {
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}

parameter_types! {
Expand Down
6 changes: 6 additions & 0 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl frame_system::Trait for Test {
type AccountData = pallet_balances::AccountData<u128>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Test
Expand All @@ -116,6 +117,7 @@ impl pallet_session::Trait for Test {
type SessionHandler = <MockSessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = MockSessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = ();
}

impl pallet_session::historical::Trait for Test {
Expand All @@ -142,6 +144,7 @@ impl pallet_timestamp::Trait for Test {
type Moment = u64;
type OnTimestampSet = Babe;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -154,6 +157,7 @@ impl pallet_balances::Trait for Test {
type Event = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
}

pallet_staking_reward_curve::build! {
Expand Down Expand Up @@ -213,6 +217,7 @@ impl pallet_staking::Trait for Test {
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = ();
type MinSolutionScoreBump = ();
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -224,6 +229,7 @@ impl pallet_offences::Trait for Test {
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type WeightSoftLimit = OffencesWeightSoftLimit;
type WeightInfo = ();
}

impl Trait for Test {
Expand Down
26 changes: 26 additions & 0 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ use sp_std::{cmp, result, mem, fmt::Debug, ops::BitOr, convert::Infallible};
use codec::{Codec, Encode, Decode};
use frame_support::{
StorageValue, Parameter, decl_event, decl_storage, decl_module, decl_error, ensure,
weights::Weight,
traits::{
Currency, OnKilledAccount, OnUnbalanced, TryDrop, StoredMap,
WithdrawReason, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement,
Expand All @@ -178,6 +179,22 @@ use frame_system::{self as system, ensure_signed, ensure_root};

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

pub trait WeightInfo {
fn transfer(u: u32, e: u32, ) -> Weight;
fn transfer_best_case(u: u32, e: u32, ) -> Weight;
fn transfer_keep_alive(u: u32, e: u32, ) -> Weight;
fn set_balance(u: u32, e: u32, ) -> Weight;
fn set_balance_killing(u: u32, e: u32, ) -> Weight;
}

impl WeightInfo for () {
fn transfer(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
fn transfer_best_case(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
fn transfer_keep_alive(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
fn set_balance(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
fn set_balance_killing(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
}

pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Trait {
/// The balance of an account.
type Balance: Parameter + Member + AtLeast32BitUnsigned + Codec + Default + Copy +
Expand All @@ -188,6 +205,9 @@ pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Trait {

/// The means of storing the balances of an account.
type AccountStore: StoredMap<Self::AccountId, AccountData<Self::Balance>>;

/// Weight information for the extrinsics in this pallet.
type WeightInfo: WeightInfo;
}

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

/// The means of storing the balances of an account.
type AccountStore: StoredMap<Self::AccountId, AccountData<Self::Balance>>;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}

impl<T: Trait<I>, I: Instance> Subtrait<I> for T {
type Balance = T::Balance;
type ExistentialDeposit = T::ExistentialDeposit;
type AccountStore = T::AccountStore;
type WeightInfo = <T as Trait<I>>::WeightInfo;
}

decl_event!(
Expand Down Expand Up @@ -872,13 +896,15 @@ impl<T: Subtrait<I>, I: Instance> frame_system::Trait for ElevatedTrait<T, I> {
type OnNewAccount = T::OnNewAccount;
type OnKilledAccount = T::OnKilledAccount;
type AccountData = T::AccountData;
type SystemWeightInfo = T::SystemWeightInfo;
}
impl<T: Subtrait<I>, I: Instance> Trait<I> for ElevatedTrait<T, I> {
type Balance = T::Balance;
type Event = ();
type DustRemoval = ();
type ExistentialDeposit = T::ExistentialDeposit;
type AccountStore = T::AccountStore;
type WeightInfo = <T as Subtrait<I>>::WeightInfo;
}

impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I> where
Expand Down
2 changes: 2 additions & 0 deletions frame/balances/src/tests_composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl frame_system::Trait for Test {
type AccountData = super::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
parameter_types! {
pub const TransactionByteFee: u64 = 1;
Expand All @@ -108,6 +109,7 @@ impl Trait for Test {
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = system::Module<Test>;
type WeightInfo = ();
}

pub struct ExtBuilder {
Expand Down
2 changes: 2 additions & 0 deletions frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl frame_system::Trait for Test {
type AccountData = super::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = Module<Test>;
type SystemWeightInfo = ();
}
parameter_types! {
pub const TransactionByteFee: u64 = 1;
Expand All @@ -113,6 +114,7 @@ impl Trait for Test {
system::CallKillAccount<Test>,
u64, super::AccountData<u64>
>;
type WeightInfo = ();
}

pub struct ExtBuilder {
Expand Down
Loading