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

Commit 9167fe0

Browse files
shawntabrizibkchr
authored andcommitted
WeightInfo for Vesting Pallet (#7103)
* 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
1 parent 4e4c321 commit 9167fe0

File tree

37 files changed

+273
-71
lines changed

37 files changed

+273
-71
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ impl pallet_timestamp::Trait for Runtime {
227227

228228
parameter_types! {
229229
pub const ExistentialDeposit: u128 = 500;
230+
pub const MaxLocks: u32 = 50;
230231
}
231232

232233
impl pallet_balances::Trait for Runtime {
234+
type MaxLocks = MaxLocks;
233235
/// The type for recording an account's balance.
234236
type Balance = Balance;
235237
/// The ubiquitous event type.
@@ -423,7 +425,7 @@ impl_runtime_apis! {
423425
None
424426
}
425427
}
426-
428+
427429
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
428430
fn account_nonce(account: AccountId) -> Index {
429431
System::account_nonce(account)

bin/node/runtime/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,13 @@ impl pallet_indices::Trait for Runtime {
325325

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

330333
impl pallet_balances::Trait for Runtime {
334+
type MaxLocks = MaxLocks;
331335
type Balance = Balance;
332336
type DustRemoval = ();
333337
type Event = Event;
@@ -856,7 +860,7 @@ impl pallet_vesting::Trait for Runtime {
856860
type Currency = Balances;
857861
type BlockNumberToBalance = ConvertInto;
858862
type MinVestedTransfer = MinVestedTransfer;
859-
type WeightInfo = ();
863+
type WeightInfo = weights::pallet_vesting::WeightInfo;
860864
}
861865

862866
construct_runtime!(

bin/node/runtime/src/weights/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ pub mod pallet_democracy;
2222
pub mod pallet_proxy;
2323
pub mod pallet_timestamp;
2424
pub mod pallet_utility;
25+
pub mod pallet_vesting;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2020 Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6
19+
20+
#![allow(unused_parens)]
21+
#![allow(unused_imports)]
22+
23+
use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
24+
25+
pub struct WeightInfo;
26+
impl pallet_vesting::WeightInfo for WeightInfo {
27+
fn vest_locked(l: u32, ) -> Weight {
28+
(82109000 as Weight)
29+
.saturating_add((332000 as Weight).saturating_mul(l as Weight))
30+
.saturating_add(DbWeight::get().reads(2 as Weight))
31+
.saturating_add(DbWeight::get().writes(1 as Weight))
32+
}
33+
fn vest_unlocked(l: u32, ) -> Weight {
34+
(88419000 as Weight)
35+
.saturating_add((3000 as Weight).saturating_mul(l as Weight))
36+
.saturating_add(DbWeight::get().reads(2 as Weight))
37+
.saturating_add(DbWeight::get().writes(2 as Weight))
38+
}
39+
fn vest_other_locked(l: u32, ) -> Weight {
40+
(81277000 as Weight)
41+
.saturating_add((321000 as Weight).saturating_mul(l as Weight))
42+
.saturating_add(DbWeight::get().reads(3 as Weight))
43+
.saturating_add(DbWeight::get().writes(2 as Weight))
44+
}
45+
fn vest_other_unlocked(l: u32, ) -> Weight {
46+
(87584000 as Weight)
47+
.saturating_add((19000 as Weight).saturating_mul(l as Weight))
48+
.saturating_add(DbWeight::get().reads(3 as Weight))
49+
.saturating_add(DbWeight::get().writes(3 as Weight))
50+
}
51+
fn vested_transfer(l: u32, ) -> Weight {
52+
(185916000 as Weight)
53+
.saturating_add((625000 as Weight).saturating_mul(l as Weight))
54+
.saturating_add(DbWeight::get().reads(3 as Weight))
55+
.saturating_add(DbWeight::get().writes(3 as Weight))
56+
}
57+
fn force_vested_transfer(l: u32, ) -> Weight {
58+
(185916000 as Weight)
59+
.saturating_add((625000 as Weight).saturating_mul(l as Weight))
60+
.saturating_add(DbWeight::get().reads(4 as Weight))
61+
.saturating_add(DbWeight::get().writes(4 as Weight))
62+
}
63+
}

frame/atomic-swap/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ parameter_types! {
5555
pub const ExistentialDeposit: u64 = 1;
5656
}
5757
impl pallet_balances::Trait for Test {
58+
type MaxLocks = ();
5859
type Balance = u64;
5960
type DustRemoval = ();
6061
type Event = ();

frame/babe/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ parameter_types! {
152152
}
153153

154154
impl pallet_balances::Trait for Test {
155+
type MaxLocks = ();
155156
type Balance = u128;
156157
type DustRemoval = ();
157158
type Event = ();

frame/balances/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Trait {
200200

201201
/// Weight information for the extrinsics in this pallet.
202202
type WeightInfo: WeightInfo;
203+
204+
/// The maximum number of locks that should exist on an account.
205+
/// Not strictly enforced, but used for weight estimation.
206+
type MaxLocks: Get<u32>;
203207
}
204208

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

222226
/// Weight information for extrinsics in this pallet.
223227
type WeightInfo: WeightInfo;
228+
229+
/// The maximum number of locks that should exist on an account.
230+
/// Not strictly enforced, but used for weight estimation.
231+
type MaxLocks: Get<u32>;
224232
}
225233

226234
impl<T: Trait<I>, I: Instance> Subtrait<I> for T {
227235
type Balance = T::Balance;
228236
type ExistentialDeposit = T::ExistentialDeposit;
229237
type AccountStore = T::AccountStore;
230238
type WeightInfo = <T as Trait<I>>::WeightInfo;
239+
type MaxLocks = T::MaxLocks;
231240
}
232241

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

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

905921
impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I> where
@@ -1285,6 +1301,8 @@ where
12851301
{
12861302
type Moment = T::BlockNumber;
12871303

1304+
type MaxLocks = T::MaxLocks;
1305+
12881306
// Set a lock on the balance of `who`.
12891307
// Is a no-op if lock amount is zero or `reasons` `is_none()`.
12901308
fn set_lock(

frame/balances/src/tests_composite.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ impl pallet_transaction_payment::Trait for Test {
103103
type WeightToFee = IdentityFee<u64>;
104104
type FeeMultiplierUpdate = ();
105105
}
106+
106107
impl Trait for Test {
107108
type Balance = u64;
108109
type DustRemoval = ();
109110
type Event = Event;
110111
type ExistentialDeposit = ExistentialDeposit;
111112
type AccountStore = system::Module<Test>;
113+
type MaxLocks = ();
112114
type WeightInfo = ();
113115
}
114116

frame/balances/src/tests_local.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ impl pallet_transaction_payment::Trait for Test {
103103
type WeightToFee = IdentityFee<u64>;
104104
type FeeMultiplierUpdate = ();
105105
}
106+
parameter_types! {
107+
pub const MaxLocks: u32 = 50;
108+
}
106109
impl Trait for Test {
107110
type Balance = u64;
108111
type DustRemoval = ();
@@ -114,6 +117,7 @@ impl Trait for Test {
114117
system::CallKillAccount<Test>,
115118
u64, super::AccountData<u64>
116119
>;
120+
type MaxLocks = MaxLocks;
117121
type WeightInfo = ();
118122
}
119123

frame/contracts/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ impl frame_system::Trait for Test {
144144
type SystemWeightInfo = ();
145145
}
146146
impl pallet_balances::Trait for Test {
147+
type MaxLocks = ();
147148
type Balance = u64;
148149
type Event = MetaEvent;
149150
type DustRemoval = ();

0 commit comments

Comments
 (0)