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

Commit

Permalink
WeightInfo for Vesting Pallet (#7103)
Browse files Browse the repository at this point in the history
* WeightInfo for Vesting Pallet

* clean up weight docs

* Update lib.rs

* try to pipe max locks

* Update for new type

* add warning when locks > MaxLocks

* Update lib.rs

* fix compile

* remove aliasing, fix trait def

* Update
  • Loading branch information
shawntabrizi authored and bkchr committed Sep 18, 2020
1 parent 4e4c321 commit 9167fe0
Show file tree
Hide file tree
Showing 37 changed files with 273 additions and 71 deletions.
4 changes: 3 additions & 1 deletion bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ impl pallet_timestamp::Trait for Runtime {

parameter_types! {
pub const ExistentialDeposit: u128 = 500;
pub const MaxLocks: u32 = 50;
}

impl pallet_balances::Trait for Runtime {
type MaxLocks = MaxLocks;
/// The type for recording an account's balance.
type Balance = Balance;
/// The ubiquitous event type.
Expand Down Expand Up @@ -423,7 +425,7 @@ impl_runtime_apis! {
None
}
}

impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(account: AccountId) -> Index {
System::account_nonce(account)
Expand Down
6 changes: 5 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,13 @@ impl pallet_indices::Trait for Runtime {

parameter_types! {
pub const ExistentialDeposit: Balance = 1 * DOLLARS;
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
pub const MaxLocks: u32 = 50;
}

impl pallet_balances::Trait for Runtime {
type MaxLocks = MaxLocks;
type Balance = Balance;
type DustRemoval = ();
type Event = Event;
Expand Down Expand Up @@ -856,7 +860,7 @@ impl pallet_vesting::Trait for Runtime {
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = MinVestedTransfer;
type WeightInfo = ();
type WeightInfo = weights::pallet_vesting::WeightInfo;
}

construct_runtime!(
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ pub mod pallet_democracy;
pub mod pallet_proxy;
pub mod pallet_timestamp;
pub mod pallet_utility;
pub mod pallet_vesting;
63 changes: 63 additions & 0 deletions bin/node/runtime/src/weights/pallet_vesting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// This file is part of Substrate.

// Copyright (C) 2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6

#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};

pub struct WeightInfo;
impl pallet_vesting::WeightInfo for WeightInfo {
fn vest_locked(l: u32, ) -> Weight {
(82109000 as Weight)
.saturating_add((332000 as Weight).saturating_mul(l as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn vest_unlocked(l: u32, ) -> Weight {
(88419000 as Weight)
.saturating_add((3000 as Weight).saturating_mul(l as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn vest_other_locked(l: u32, ) -> Weight {
(81277000 as Weight)
.saturating_add((321000 as Weight).saturating_mul(l as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn vest_other_unlocked(l: u32, ) -> Weight {
(87584000 as Weight)
.saturating_add((19000 as Weight).saturating_mul(l as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn vested_transfer(l: u32, ) -> Weight {
(185916000 as Weight)
.saturating_add((625000 as Weight).saturating_mul(l as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn force_vested_transfer(l: u32, ) -> Weight {
(185916000 as Weight)
.saturating_add((625000 as Weight).saturating_mul(l as Weight))
.saturating_add(DbWeight::get().reads(4 as Weight))
.saturating_add(DbWeight::get().writes(4 as Weight))
}
}
1 change: 1 addition & 0 deletions frame/atomic-swap/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
type MaxLocks = ();
type Balance = u64;
type DustRemoval = ();
type Event = ();
Expand Down
1 change: 1 addition & 0 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ parameter_types! {
}

impl pallet_balances::Trait for Test {
type MaxLocks = ();
type Balance = u128;
type DustRemoval = ();
type Event = ();
Expand Down
18 changes: 18 additions & 0 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Trait {

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

/// The maximum number of locks that should exist on an account.
/// Not strictly enforced, but used for weight estimation.
type MaxLocks: Get<u32>;
}

pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {
Expand All @@ -221,13 +225,18 @@ pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {

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

/// The maximum number of locks that should exist on an account.
/// Not strictly enforced, but used for weight estimation.
type MaxLocks: Get<u32>;
}

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;
type MaxLocks = T::MaxLocks;
}

decl_event!(
Expand Down Expand Up @@ -663,6 +672,12 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {

/// Update the account entry for `who`, given the locks.
fn update_locks(who: &T::AccountId, locks: &[BalanceLock<T::Balance>]) {
if locks.len() as u32 > T::MaxLocks::get() {
frame_support::debug::warn!(
"Warning: A user has more currency locks than expected. \
A runtime configuration adjustment may be needed."
);
}
Self::mutate_account(who, |b| {
b.misc_frozen = Zero::zero();
b.fee_frozen = Zero::zero();
Expand Down Expand Up @@ -900,6 +915,7 @@ impl<T: Subtrait<I>, I: Instance> Trait<I> for ElevatedTrait<T, I> {
type ExistentialDeposit = T::ExistentialDeposit;
type AccountStore = T::AccountStore;
type WeightInfo = <T as Subtrait<I>>::WeightInfo;
type MaxLocks = T::MaxLocks;
}

impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I> where
Expand Down Expand Up @@ -1285,6 +1301,8 @@ where
{
type Moment = T::BlockNumber;

type MaxLocks = T::MaxLocks;

// Set a lock on the balance of `who`.
// Is a no-op if lock amount is zero or `reasons` `is_none()`.
fn set_lock(
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 @@ -103,12 +103,14 @@ impl pallet_transaction_payment::Trait for Test {
type WeightToFee = IdentityFee<u64>;
type FeeMultiplierUpdate = ();
}

impl Trait for Test {
type Balance = u64;
type DustRemoval = ();
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = system::Module<Test>;
type MaxLocks = ();
type WeightInfo = ();
}

Expand Down
4 changes: 4 additions & 0 deletions frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ impl pallet_transaction_payment::Trait for Test {
type WeightToFee = IdentityFee<u64>;
type FeeMultiplierUpdate = ();
}
parameter_types! {
pub const MaxLocks: u32 = 50;
}
impl Trait for Test {
type Balance = u64;
type DustRemoval = ();
Expand All @@ -114,6 +117,7 @@ impl Trait for Test {
system::CallKillAccount<Test>,
u64, super::AccountData<u64>
>;
type MaxLocks = MaxLocks;
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl frame_system::Trait for Test {
type SystemWeightInfo = ();
}
impl pallet_balances::Trait for Test {
type MaxLocks = ();
type Balance = u64;
type Event = MetaEvent;
type DustRemoval = ();
Expand Down
1 change: 1 addition & 0 deletions frame/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
type MaxLocks = ();
type Balance = u64;
type Event = Event;
type DustRemoval = ();
Expand Down
1 change: 1 addition & 0 deletions frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ mod tests {
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = frame_system::Module<Test>;
type MaxLocks = ();
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions frame/elections/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
type MaxLocks = ();
type Balance = u64;
type DustRemoval = ();
type Event = Event;
Expand Down
1 change: 1 addition & 0 deletions frame/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
type MaxLocks = ();
type Balance = u64;
type DustRemoval = ();
type Event = ();
Expand Down
1 change: 1 addition & 0 deletions frame/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ mod tests {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
type MaxLocks = ();
type Balance = u64;
type DustRemoval = ();
type Event = ();
Expand Down
1 change: 1 addition & 0 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ mod tests {
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type MaxLocks = ();
type WeightInfo = ();
}

Expand Down
2 changes: 2 additions & 0 deletions frame/generic-asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,8 @@ where
{
type Moment = T::BlockNumber;

type MaxLocks = ();

fn set_lock(
id: LockIdentifier,
who: &T::AccountId,
Expand Down
Loading

0 comments on commit 9167fe0

Please sign in to comment.