From 20a77424686b169d254b542ec4b128dce6a4ef8b Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 14 Sep 2020 18:16:02 +0200 Subject: [PATCH 01/10] WeightInfo for Vesting Pallet --- bin/node/runtime/src/lib.rs | 6 +- bin/node/runtime/src/weights/mod.rs | 1 + .../runtime/src/weights/pallet_vesting.rs | 63 +++++++++++++++++++ frame/vesting/src/benchmarking.rs | 44 +++++++++++-- frame/vesting/src/default_weights.rs | 62 ++++++++++++++++++ frame/vesting/src/lib.rs | 31 ++++----- 6 files changed, 186 insertions(+), 21 deletions(-) create mode 100644 bin/node/runtime/src/weights/pallet_vesting.rs create mode 100644 frame/vesting/src/default_weights.rs diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index eeac6d83b8777..80daf0e4c4665 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -849,6 +849,9 @@ impl pallet_society::Trait for Runtime { parameter_types! { pub const MinVestedTransfer: Balance = 100 * 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_vesting::Trait for Runtime { @@ -856,7 +859,8 @@ impl pallet_vesting::Trait for Runtime { type Currency = Balances; type BlockNumberToBalance = ConvertInto; type MinVestedTransfer = MinVestedTransfer; - type WeightInfo = (); + type MaxLocks = MaxLocks; + type WeightInfo = weights::pallet_vesting::WeightInfo; } construct_runtime!( diff --git a/bin/node/runtime/src/weights/mod.rs b/bin/node/runtime/src/weights/mod.rs index 372b13a093e27..86cab773b18e3 100644 --- a/bin/node/runtime/src/weights/mod.rs +++ b/bin/node/runtime/src/weights/mod.rs @@ -22,3 +22,4 @@ pub mod pallet_democracy; pub mod pallet_proxy; pub mod pallet_timestamp; pub mod pallet_utility; +pub mod pallet_vesting; diff --git a/bin/node/runtime/src/weights/pallet_vesting.rs b/bin/node/runtime/src/weights/pallet_vesting.rs new file mode 100644 index 0000000000000..b2a4b57e64415 --- /dev/null +++ b/bin/node/runtime/src/weights/pallet_vesting.rs @@ -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)) + } +} diff --git a/frame/vesting/src/benchmarking.rs b/frame/vesting/src/benchmarking.rs index 974289aac3218..644cf246dfdc8 100644 --- a/frame/vesting/src/benchmarking.rs +++ b/frame/vesting/src/benchmarking.rs @@ -28,7 +28,6 @@ use sp_runtime::traits::Bounded; use crate::Module as Vesting; const SEED: u32 = 0; -const MAX_LOCKS: u32 = 20; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -62,7 +61,7 @@ benchmarks! { _ { } vest_locked { - let l in 0 .. MAX_LOCKS; + let l in 0 .. T::MaxLocks::get(); let caller = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -86,7 +85,7 @@ benchmarks! { } vest_unlocked { - let l in 0 .. MAX_LOCKS; + let l in 0 .. T::MaxLocks::get(); let caller = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -110,7 +109,7 @@ benchmarks! { } vest_other_locked { - let l in 0 .. MAX_LOCKS; + let l in 0 .. T::MaxLocks::get(); let other: T::AccountId = account("other", 0, SEED); let other_lookup: ::Source = T::Lookup::unlookup(other.clone()); @@ -137,7 +136,7 @@ benchmarks! { } vest_other_unlocked { - let l in 0 .. MAX_LOCKS; + let l in 0 .. T::MaxLocks::get(); let other: T::AccountId = account("other", 0, SEED); let other_lookup: ::Source = T::Lookup::unlookup(other.clone()); @@ -164,7 +163,7 @@ benchmarks! { } vested_transfer { - let l in 0 .. MAX_LOCKS; + let l in 0 .. T::MaxLocks::get(); let caller: T::AccountId = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -193,6 +192,38 @@ benchmarks! { "Lock not created", ); } + + force_vested_transfer { + let l in 0 .. T::MaxLocks::get(); + + let source: T::AccountId = account("source", 0, SEED); + let source_lookup: ::Source = T::Lookup::unlookup(source.clone()); + T::Currency::make_free_balance_be(&source, BalanceOf::::max_value()); + let target: T::AccountId = account("target", 0, SEED); + let target_lookup: ::Source = T::Lookup::unlookup(target.clone()); + // Give target existing locks + add_locks::(&target, l as u8); + + let transfer_amount = T::MinVestedTransfer::get(); + + let vesting_schedule = VestingInfo { + locked: transfer_amount, + per_block: 10.into(), + starting_block: 1.into(), + }; + }: _(RawOrigin::Root, source_lookup, target_lookup, vesting_schedule) + verify { + assert_eq!( + T::MinVestedTransfer::get(), + T::Currency::free_balance(&target), + "Transfer didn't happen", + ); + assert_eq!( + Vesting::::vesting_balance(&target), + Some(T::MinVestedTransfer::get()), + "Lock not created", + ); + } } #[cfg(test)] @@ -209,6 +240,7 @@ mod tests { assert_ok!(test_benchmark_vest_other_locked::()); assert_ok!(test_benchmark_vest_other_unlocked::()); assert_ok!(test_benchmark_vested_transfer::()); + assert_ok!(test_benchmark_force_vested_transfer::()); }); } } diff --git a/frame/vesting/src/default_weights.rs b/frame/vesting/src/default_weights.rs new file mode 100644 index 0000000000000..dac9224d69ab0 --- /dev/null +++ b/frame/vesting/src/default_weights.rs @@ -0,0 +1,62 @@ +// 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}; + +impl crate::WeightInfo for () { + 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)) + } +} diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index 2fe8e033bb25e..8de7618651425 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -61,6 +61,7 @@ use frame_support::traits::{ use frame_system::{ensure_signed, ensure_root}; mod benchmarking; +mod default_weights; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -70,14 +71,7 @@ pub trait WeightInfo { fn vest_other_locked(l: u32, ) -> Weight; fn vest_other_unlocked(l: u32, ) -> Weight; fn vested_transfer(l: u32, ) -> Weight; -} - -impl WeightInfo for () { - fn vest_locked(_l: u32, ) -> Weight { 1_000_000_000 } - fn vest_unlocked(_l: u32, ) -> Weight { 1_000_000_000 } - fn vest_other_locked(_l: u32, ) -> Weight { 1_000_000_000 } - fn vest_other_unlocked(_l: u32, ) -> Weight { 1_000_000_000 } - fn vested_transfer(_l: u32, ) -> Weight { 1_000_000_000 } + fn force_vested_transfer(l: u32, ) -> Weight; } pub trait Trait: frame_system::Trait { @@ -93,6 +87,10 @@ pub trait Trait: frame_system::Trait { /// The minimum amount transferred to call `vested_transfer`. type MinVestedTransfer: Get>; + /// The maximum number of balance locks for a user. Used for weight estimation, + /// and not enforced by this pallet. + type MaxLocks: Get; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; } @@ -171,7 +169,7 @@ decl_storage! { decl_event!( pub enum Event where AccountId = ::AccountId, Balance = BalanceOf { /// The amount vested has been updated. This could indicate more funds are available. The - /// balance given is the amount which is left unvested (and thus locked). + /// balance given is the amount which is left unvested (and thus locked). /// \[account, unvested\] VestingUpdated(AccountId, Balance), /// An \[account\] has become fully vested. No further vesting can happen. @@ -218,7 +216,9 @@ decl_module! { /// - Locked: 44.43 + .284 * l µs (min square analysis) /// - Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # - #[weight = 50_000_000 + T::DbWeight::get().reads_writes(2, 2)] + #[weight = T::WeightInfo::vest_locked(T::MaxLocks::get()) + .max(T::WeightInfo::vest_unlocked(T::MaxLocks::get())) + ] fn vest(origin) -> DispatchResult { let who = ensure_signed(origin)?; Self::update_lock(who) @@ -243,8 +243,9 @@ decl_module! { /// - Locked: 48.16 + .103 * l µs (min square analysis) /// - Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # - #[weight = 50_000_000 + T::DbWeight::get().reads_writes(3, 3)] - fn vest_other(origin, target: ::Source) -> DispatchResult { + #[weight = T::WeightInfo::vest_other_locked(T::MaxLocks::get()) + .max(T::WeightInfo::vest_other_unlocked(T::MaxLocks::get())) + ] fn vest_other(origin, target: ::Source) -> DispatchResult { ensure_signed(origin)?; Self::update_lock(T::Lookup::lookup(target)?) } @@ -267,7 +268,7 @@ decl_module! { /// - Benchmark: 100.3 + .365 * l µs (min square analysis) /// - Using 100 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # - #[weight = 100_000_000 + T::DbWeight::get().reads_writes(3, 3)] + #[weight = T::WeightInfo::vested_transfer(T::MaxLocks::get())] pub fn vested_transfer( origin, target: ::Source, @@ -306,7 +307,7 @@ decl_module! { /// - Benchmark: 100.3 + .365 * l µs (min square analysis) /// - Using 100 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # - #[weight = 100_000_000 + T::DbWeight::get().reads_writes(4, 4)] + #[weight = T::WeightInfo::force_vested_transfer(T::MaxLocks::get())] pub fn force_vested_transfer( origin, source: ::Source, @@ -473,12 +474,14 @@ mod tests { } parameter_types! { pub const MinVestedTransfer: u64 = 256 * 2; + pub const MaxLocks: u32 = 10; } impl Trait for Test { type Event = (); type Currency = Balances; type BlockNumberToBalance = Identity; type MinVestedTransfer = MinVestedTransfer; + type MaxLocks = MaxLocks; type WeightInfo = (); } type System = frame_system::Module; From bf7bedc17786366d366192ce9597bfde43bb79d5 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 14 Sep 2020 18:54:55 +0200 Subject: [PATCH 02/10] clean up weight docs --- frame/vesting/src/lib.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index 8de7618651425..2dcab693fae40 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -211,10 +211,6 @@ decl_module! { /// - DbWeight: 2 Reads, 2 Writes /// - Reads: Vesting Storage, Balances Locks, [Sender Account] /// - Writes: Vesting Storage, Balances Locks, [Sender Account] - /// - Benchmark: - /// - Unlocked: 48.76 + .048 * l µs (min square analysis) - /// - Locked: 44.43 + .284 * l µs (min square analysis) - /// - Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # #[weight = T::WeightInfo::vest_locked(T::MaxLocks::get()) .max(T::WeightInfo::vest_unlocked(T::MaxLocks::get())) @@ -238,10 +234,6 @@ decl_module! { /// - DbWeight: 3 Reads, 3 Writes /// - Reads: Vesting Storage, Balances Locks, Target Account /// - Writes: Vesting Storage, Balances Locks, Target Account - /// - Benchmark: - /// - Unlocked: 44.3 + .294 * l µs (min square analysis) - /// - Locked: 48.16 + .103 * l µs (min square analysis) - /// - Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # #[weight = T::WeightInfo::vest_other_locked(T::MaxLocks::get()) .max(T::WeightInfo::vest_other_unlocked(T::MaxLocks::get())) @@ -265,8 +257,6 @@ decl_module! { /// - DbWeight: 3 Reads, 3 Writes /// - Reads: Vesting Storage, Balances Locks, Target Account, [Sender Account] /// - Writes: Vesting Storage, Balances Locks, Target Account, [Sender Account] - /// - Benchmark: 100.3 + .365 * l µs (min square analysis) - /// - Using 100 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # #[weight = T::WeightInfo::vested_transfer(T::MaxLocks::get())] pub fn vested_transfer( @@ -304,8 +294,6 @@ decl_module! { /// - DbWeight: 4 Reads, 4 Writes /// - Reads: Vesting Storage, Balances Locks, Target Account, Source Account /// - Writes: Vesting Storage, Balances Locks, Target Account, Source Account - /// - Benchmark: 100.3 + .365 * l µs (min square analysis) - /// - Using 100 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # #[weight = T::WeightInfo::force_vested_transfer(T::MaxLocks::get())] pub fn force_vested_transfer( From 50e37a9da4891bd70f0c20c8ddcf865f13a0bc4f Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 14 Sep 2020 20:11:53 +0200 Subject: [PATCH 03/10] Update lib.rs --- frame/vesting/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index 2dcab693fae40..fa4d7b2e5f9e4 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -237,7 +237,8 @@ decl_module! { /// # #[weight = T::WeightInfo::vest_other_locked(T::MaxLocks::get()) .max(T::WeightInfo::vest_other_unlocked(T::MaxLocks::get())) - ] fn vest_other(origin, target: ::Source) -> DispatchResult { + ] + fn vest_other(origin, target: ::Source) -> DispatchResult { ensure_signed(origin)?; Self::update_lock(T::Lookup::lookup(target)?) } @@ -462,14 +463,13 @@ mod tests { } parameter_types! { pub const MinVestedTransfer: u64 = 256 * 2; - pub const MaxLocks: u32 = 10; } impl Trait for Test { type Event = (); type Currency = Balances; type BlockNumberToBalance = Identity; type MinVestedTransfer = MinVestedTransfer; - type MaxLocks = MaxLocks; + type MaxLocks = (); type WeightInfo = (); } type System = frame_system::Module; From df5699ec22fc51fb67219143d36107092fc3635f Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 16 Sep 2020 15:33:32 +0200 Subject: [PATCH 04/10] try to pipe max locks --- frame/balances/src/lib.rs | 12 ++++++++++++ frame/balances/src/tests_composite.rs | 5 +++++ frame/balances/src/tests_local.rs | 4 ++++ frame/support/src/traits.rs | 3 +++ frame/vesting/src/lib.rs | 22 +++++++++++----------- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 331c5a27dfa74..d6d34a92926df 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -200,6 +200,10 @@ pub trait Subtrait: 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; } pub trait Trait: frame_system::Trait { @@ -221,6 +225,10 @@ pub trait Trait: 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; } impl, I: Instance> Subtrait for T { @@ -228,6 +236,7 @@ impl, I: Instance> Subtrait for T { type ExistentialDeposit = T::ExistentialDeposit; type AccountStore = T::AccountStore; type WeightInfo = >::WeightInfo; + type MaxLocks = T::MaxLocks; } decl_event!( @@ -900,6 +909,7 @@ impl, I: Instance> Trait for ElevatedTrait { type ExistentialDeposit = T::ExistentialDeposit; type AccountStore = T::AccountStore; type WeightInfo = >::WeightInfo; + type MaxLocks = T::MaxLocks; } impl, I: Instance> Currency for Module where @@ -1285,6 +1295,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( diff --git a/frame/balances/src/tests_composite.rs b/frame/balances/src/tests_composite.rs index 8e764112ba24c..0fa52bf68c995 100644 --- a/frame/balances/src/tests_composite.rs +++ b/frame/balances/src/tests_composite.rs @@ -103,12 +103,17 @@ impl pallet_transaction_payment::Trait for Test { type WeightToFee = IdentityFee; type FeeMultiplierUpdate = (); } + +parameter_types! { + pub const MaxLocks: u32 = 10; +} impl Trait for Test { type Balance = u64; type DustRemoval = (); type Event = Event; type ExistentialDeposit = ExistentialDeposit; type AccountStore = system::Module; + type MaxLocks = MaxLocks; type WeightInfo = (); } diff --git a/frame/balances/src/tests_local.rs b/frame/balances/src/tests_local.rs index 86abc2b6044ce..75813c6b1bc9a 100644 --- a/frame/balances/src/tests_local.rs +++ b/frame/balances/src/tests_local.rs @@ -103,6 +103,9 @@ impl pallet_transaction_payment::Trait for Test { type WeightToFee = IdentityFee; type FeeMultiplierUpdate = (); } +parameter_types! { + pub const MaxLocks: u32 = 50; +} impl Trait for Test { type Balance = u64; type DustRemoval = (); @@ -114,6 +117,7 @@ impl Trait for Test { system::CallKillAccount, u64, super::AccountData >; + type MaxLocks = MaxLocks; type WeightInfo = (); } diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 6f50f38a23369..bf890dfc6c759 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -1110,6 +1110,9 @@ pub trait LockableCurrency: Currency { /// The quantity used to denote time; usually just a `BlockNumber`. type Moment; + /// The maximum number of locks a user should have on their account. + type MaxLocks; + /// Create a new balance lock on account `who`. /// /// If the new lock is valid (i.e. not already expired), it will push the struct to diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index fa4d7b2e5f9e4..8cbc775958443 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -64,6 +64,7 @@ mod benchmarking; mod default_weights; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; +type MaxLocksOf = <::Currency as LockableCurrency<::AccountId>>::MaxLocks; pub trait WeightInfo { fn vest_locked(l: u32, ) -> Weight; @@ -87,10 +88,6 @@ pub trait Trait: frame_system::Trait { /// The minimum amount transferred to call `vested_transfer`. type MinVestedTransfer: Get>; - /// The maximum number of balance locks for a user. Used for weight estimation, - /// and not enforced by this pallet. - type MaxLocks: Get; - /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; } @@ -212,8 +209,8 @@ decl_module! { /// - Reads: Vesting Storage, Balances Locks, [Sender Account] /// - Writes: Vesting Storage, Balances Locks, [Sender Account] /// # - #[weight = T::WeightInfo::vest_locked(T::MaxLocks::get()) - .max(T::WeightInfo::vest_unlocked(T::MaxLocks::get())) + #[weight = T::WeightInfo::vest_locked( as Get>::get()) + .max(T::WeightInfo::vest_unlocked( as Get>::get())) ] fn vest(origin) -> DispatchResult { let who = ensure_signed(origin)?; @@ -235,8 +232,8 @@ decl_module! { /// - Reads: Vesting Storage, Balances Locks, Target Account /// - Writes: Vesting Storage, Balances Locks, Target Account /// # - #[weight = T::WeightInfo::vest_other_locked(T::MaxLocks::get()) - .max(T::WeightInfo::vest_other_unlocked(T::MaxLocks::get())) + #[weight = T::WeightInfo::vest_other_locked( as Get>::get()) + .max(T::WeightInfo::vest_other_unlocked( as Get>::get())) ] fn vest_other(origin, target: ::Source) -> DispatchResult { ensure_signed(origin)?; @@ -259,7 +256,7 @@ decl_module! { /// - Reads: Vesting Storage, Balances Locks, Target Account, [Sender Account] /// - Writes: Vesting Storage, Balances Locks, Target Account, [Sender Account] /// # - #[weight = T::WeightInfo::vested_transfer(T::MaxLocks::get())] + #[weight = T::WeightInfo::vested_transfer( as Get>::get())] pub fn vested_transfer( origin, target: ::Source, @@ -296,7 +293,7 @@ decl_module! { /// - Reads: Vesting Storage, Balances Locks, Target Account, Source Account /// - Writes: Vesting Storage, Balances Locks, Target Account, Source Account /// # - #[weight = T::WeightInfo::force_vested_transfer(T::MaxLocks::get())] + #[weight = T::WeightInfo::force_vested_transfer( as Get>::get())] pub fn force_vested_transfer( origin, source: ::Source, @@ -453,6 +450,9 @@ mod tests { type OnKilledAccount = (); type SystemWeightInfo = (); } + parameter_types! { + pub const MaxLocks: u32 = 10; + } impl pallet_balances::Trait for Test { type Balance = u64; type DustRemoval = (); @@ -460,6 +460,7 @@ mod tests { type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); + type MaxLocks = MaxLocks; } parameter_types! { pub const MinVestedTransfer: u64 = 256 * 2; @@ -469,7 +470,6 @@ mod tests { type Currency = Balances; type BlockNumberToBalance = Identity; type MinVestedTransfer = MinVestedTransfer; - type MaxLocks = (); type WeightInfo = (); } type System = frame_system::Module; From bfa00471fecf78f7de86b75977dfa3e8138f66d7 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 16 Sep 2020 16:11:55 +0200 Subject: [PATCH 05/10] Update for new type --- bin/node-template/runtime/src/lib.rs | 4 +++- bin/node/runtime/src/lib.rs | 8 ++++---- frame/atomic-swap/src/tests.rs | 1 + frame/babe/src/mock.rs | 1 + frame/contracts/src/tests.rs | 1 + frame/democracy/src/tests.rs | 1 + frame/elections-phragmen/src/lib.rs | 2 ++ frame/elections/src/mock.rs | 1 + frame/evm/src/tests.rs | 1 + frame/example/src/lib.rs | 1 + frame/executive/src/lib.rs | 2 ++ frame/identity/src/lib.rs | 1 + frame/indices/src/mock.rs | 1 + frame/multisig/src/tests.rs | 1 + frame/nicks/src/lib.rs | 1 + frame/offences/benchmarking/src/mock.rs | 1 + frame/proxy/src/tests.rs | 1 + frame/recovery/src/mock.rs | 1 + frame/scored-pool/src/mock.rs | 1 + frame/session/benchmarking/src/mock.rs | 1 + frame/society/src/mock.rs | 1 + frame/staking/fuzzer/src/mock.rs | 1 + frame/staking/src/mock.rs | 1 + frame/support/src/traits.rs | 2 +- frame/transaction-payment/src/lib.rs | 2 ++ frame/treasury/src/tests.rs | 1 + frame/utility/src/tests.rs | 1 + frame/vesting/src/lib.rs | 13 +++++++------ 28 files changed, 42 insertions(+), 12 deletions(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 06e34e4551673..91fffb7f8e155 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -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. @@ -423,7 +425,7 @@ impl_runtime_apis! { None } } - + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { fn account_nonce(account: AccountId) -> Index { System::account_nonce(account) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 80daf0e4c4665..5737fcfd2e2f1 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -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; @@ -849,9 +853,6 @@ impl pallet_society::Trait for Runtime { parameter_types! { pub const MinVestedTransfer: Balance = 100 * 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_vesting::Trait for Runtime { @@ -859,7 +860,6 @@ impl pallet_vesting::Trait for Runtime { type Currency = Balances; type BlockNumberToBalance = ConvertInto; type MinVestedTransfer = MinVestedTransfer; - type MaxLocks = MaxLocks; type WeightInfo = weights::pallet_vesting::WeightInfo; } diff --git a/frame/atomic-swap/src/tests.rs b/frame/atomic-swap/src/tests.rs index 6690a24d364d6..528203fc39096 100644 --- a/frame/atomic-swap/src/tests.rs +++ b/frame/atomic-swap/src/tests.rs @@ -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 = (); diff --git a/frame/babe/src/mock.rs b/frame/babe/src/mock.rs index 8a0356d8da7e8..34e9ff113d42c 100644 --- a/frame/babe/src/mock.rs +++ b/frame/babe/src/mock.rs @@ -152,6 +152,7 @@ parameter_types! { } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u128; type DustRemoval = (); type Event = (); diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index bd1242ff6701a..1c30021793146 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -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 = (); diff --git a/frame/democracy/src/tests.rs b/frame/democracy/src/tests.rs index 13c6a09a04bc1..aed6739c77ebb 100644 --- a/frame/democracy/src/tests.rs +++ b/frame/democracy/src/tests.rs @@ -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 = (); diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 0b93dd6c13b9c..a80056548dc54 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -1148,9 +1148,11 @@ mod tests { parameter_types! { pub const ExistentialDeposit: u64 = 1; + pub const MaxLocks: u32 = 10; } impl pallet_balances::Trait for Test { + type MaxLocks = MaxLocks; type Balance = u64; type Event = Event; type DustRemoval = (); diff --git a/frame/elections/src/mock.rs b/frame/elections/src/mock.rs index c9b2523c4bc8a..adde24c25d32f 100644 --- a/frame/elections/src/mock.rs +++ b/frame/elections/src/mock.rs @@ -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; diff --git a/frame/evm/src/tests.rs b/frame/evm/src/tests.rs index 652d6c723b9d3..f741e3e4fc048 100644 --- a/frame/evm/src/tests.rs +++ b/frame/evm/src/tests.rs @@ -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 = (); diff --git a/frame/example/src/lib.rs b/frame/example/src/lib.rs index b41c8196c018f..e2b00daf31cd7 100644 --- a/frame/example/src/lib.rs +++ b/frame/example/src/lib.rs @@ -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 = (); diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 24dccf8b0b4a4..1c56176fde3a9 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -577,8 +577,10 @@ mod tests { type Balance = u64; parameter_types! { pub const ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 10; } impl pallet_balances::Trait for Runtime { + type MaxLocks = MaxLocks; type Balance = Balance; type Event = MetaEvent; type DustRemoval = (); diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 65f1597622c56..e69255ab1980b 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -1387,6 +1387,7 @@ mod tests { pub const ExistentialDeposit: u64 = 1; } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u64; type Event = (); type DustRemoval = (); diff --git a/frame/indices/src/mock.rs b/frame/indices/src/mock.rs index 97e7a954f8f58..a47e1251d63db 100644 --- a/frame/indices/src/mock.rs +++ b/frame/indices/src/mock.rs @@ -82,6 +82,7 @@ parameter_types! { } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u64; type DustRemoval = (); type Event = MetaEvent; diff --git a/frame/multisig/src/tests.rs b/frame/multisig/src/tests.rs index 888dcecb3a8fd..b727ec8cdb41d 100644 --- a/frame/multisig/src/tests.rs +++ b/frame/multisig/src/tests.rs @@ -90,6 +90,7 @@ parameter_types! { pub const ExistentialDeposit: u64 = 1; } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u64; type Event = TestEvent; type DustRemoval = (); diff --git a/frame/nicks/src/lib.rs b/frame/nicks/src/lib.rs index a1faedaf1cee6..ca90da1750b3c 100644 --- a/frame/nicks/src/lib.rs +++ b/frame/nicks/src/lib.rs @@ -293,6 +293,7 @@ mod tests { pub const ExistentialDeposit: u64 = 1; } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u64; type Event = (); type DustRemoval = (); diff --git a/frame/offences/benchmarking/src/mock.rs b/frame/offences/benchmarking/src/mock.rs index ad6e8a14d5622..12a14e90b0e53 100644 --- a/frame/offences/benchmarking/src/mock.rs +++ b/frame/offences/benchmarking/src/mock.rs @@ -72,6 +72,7 @@ parameter_types! { pub const ExistentialDeposit: Balance = 10; } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = Balance; type Event = Event; type DustRemoval = (); diff --git a/frame/proxy/src/tests.rs b/frame/proxy/src/tests.rs index 00d84e65ad1d6..ea9b321ee0a8e 100644 --- a/frame/proxy/src/tests.rs +++ b/frame/proxy/src/tests.rs @@ -92,6 +92,7 @@ parameter_types! { pub const ExistentialDeposit: u64 = 1; } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u64; type Event = TestEvent; type DustRemoval = (); diff --git a/frame/recovery/src/mock.rs b/frame/recovery/src/mock.rs index 6b8ef169c0076..9256ec9425de5 100644 --- a/frame/recovery/src/mock.rs +++ b/frame/recovery/src/mock.rs @@ -91,6 +91,7 @@ parameter_types! { } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u128; type DustRemoval = (); type Event = TestEvent; diff --git a/frame/scored-pool/src/mock.rs b/frame/scored-pool/src/mock.rs index 4581f49bbbcb6..2341832748f68 100644 --- a/frame/scored-pool/src/mock.rs +++ b/frame/scored-pool/src/mock.rs @@ -78,6 +78,7 @@ impl frame_system::Trait for Test { } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u64; type Event = (); type DustRemoval = (); diff --git a/frame/session/benchmarking/src/mock.rs b/frame/session/benchmarking/src/mock.rs index d4eac4247734f..c1f75ec4e0965 100644 --- a/frame/session/benchmarking/src/mock.rs +++ b/frame/session/benchmarking/src/mock.rs @@ -88,6 +88,7 @@ parameter_types! { pub const ExistentialDeposit: Balance = 10; } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = Balance; type Event = (); type DustRemoval = (); diff --git a/frame/society/src/mock.rs b/frame/society/src/mock.rs index 1ca828bf37196..03fa9b60f74dd 100644 --- a/frame/society/src/mock.rs +++ b/frame/society/src/mock.rs @@ -89,6 +89,7 @@ impl frame_system::Trait for Test { } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u64; type Event = (); type DustRemoval = (); diff --git a/frame/staking/fuzzer/src/mock.rs b/frame/staking/fuzzer/src/mock.rs index 1f5b29b56b6b6..766f088f40388 100644 --- a/frame/staking/fuzzer/src/mock.rs +++ b/frame/staking/fuzzer/src/mock.rs @@ -87,6 +87,7 @@ parameter_types! { pub const ExistentialDeposit: Balance = 10; } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = Balance; type Event = (); type DustRemoval = (); diff --git a/frame/staking/src/mock.rs b/frame/staking/src/mock.rs index dcdacfbaacb04..31e41e21360a0 100644 --- a/frame/staking/src/mock.rs +++ b/frame/staking/src/mock.rs @@ -227,6 +227,7 @@ impl frame_system::Trait for Test { type SystemWeightInfo = (); } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = Balance; type Event = MetaEvent; type DustRemoval = (); diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index bf890dfc6c759..32983b414d304 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -1111,7 +1111,7 @@ pub trait LockableCurrency: Currency { type Moment; /// The maximum number of locks a user should have on their account. - type MaxLocks; + type MaxLocks: Get; /// Create a new balance lock on account `who`. /// diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 4e4bc5311dacd..7c5e063a8f676 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -663,9 +663,11 @@ mod tests { parameter_types! { pub const ExistentialDeposit: u64 = 1; + pub const MaxLocks: u32 = 10; } impl pallet_balances::Trait for Runtime { + type MaxLocks = MaxLocks; type Balance = u64; type Event = Event; type DustRemoval = (); diff --git a/frame/treasury/src/tests.rs b/frame/treasury/src/tests.rs index f9928c37b36a3..a4e1e3d8d77b2 100644 --- a/frame/treasury/src/tests.rs +++ b/frame/treasury/src/tests.rs @@ -90,6 +90,7 @@ parameter_types! { pub const ExistentialDeposit: u64 = 1; } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u64; type Event = Event; type DustRemoval = (); diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 611c42907ca04..cf5b0dd7568e7 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -89,6 +89,7 @@ parameter_types! { pub const ExistentialDeposit: u64 = 1; } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u64; type DustRemoval = (); type Event = TestEvent; diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index 8cbc775958443..4157fdb8ee19e 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -209,8 +209,8 @@ decl_module! { /// - Reads: Vesting Storage, Balances Locks, [Sender Account] /// - Writes: Vesting Storage, Balances Locks, [Sender Account] /// # - #[weight = T::WeightInfo::vest_locked( as Get>::get()) - .max(T::WeightInfo::vest_unlocked( as Get>::get())) + #[weight = T::WeightInfo::vest_locked(MaxLocksOf::::get()) + .max(T::WeightInfo::vest_unlocked(MaxLocksOf::::get())) ] fn vest(origin) -> DispatchResult { let who = ensure_signed(origin)?; @@ -232,8 +232,8 @@ decl_module! { /// - Reads: Vesting Storage, Balances Locks, Target Account /// - Writes: Vesting Storage, Balances Locks, Target Account /// # - #[weight = T::WeightInfo::vest_other_locked( as Get>::get()) - .max(T::WeightInfo::vest_other_unlocked( as Get>::get())) + #[weight = T::WeightInfo::vest_other_locked(MaxLocksOf::::get()) + .max(T::WeightInfo::vest_other_unlocked(MaxLocksOf::::get())) ] fn vest_other(origin, target: ::Source) -> DispatchResult { ensure_signed(origin)?; @@ -256,7 +256,7 @@ decl_module! { /// - Reads: Vesting Storage, Balances Locks, Target Account, [Sender Account] /// - Writes: Vesting Storage, Balances Locks, Target Account, [Sender Account] /// # - #[weight = T::WeightInfo::vested_transfer( as Get>::get())] + #[weight = T::WeightInfo::vested_transfer(MaxLocksOf::::get())] pub fn vested_transfer( origin, target: ::Source, @@ -293,7 +293,7 @@ decl_module! { /// - Reads: Vesting Storage, Balances Locks, Target Account, Source Account /// - Writes: Vesting Storage, Balances Locks, Target Account, Source Account /// # - #[weight = T::WeightInfo::force_vested_transfer( as Get>::get())] + #[weight = T::WeightInfo::force_vested_transfer(MaxLocksOf::::get())] pub fn force_vested_transfer( origin, source: ::Source, @@ -454,6 +454,7 @@ mod tests { pub const MaxLocks: u32 = 10; } impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u64; type DustRemoval = (); type Event = (); From 65c59c9be0c37795c45f70f8d546c7b8f7729d8d Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 16 Sep 2020 16:28:39 +0200 Subject: [PATCH 06/10] add warning when locks > MaxLocks --- frame/balances/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index d6d34a92926df..8eb4908062591 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -672,6 +672,12 @@ impl, I: Instance> Module { /// Update the account entry for `who`, given the locks. fn update_locks(who: &T::AccountId, locks: &[BalanceLock]) { + if locks.len() as u32 > T::MaxLocks::get() { + frame_support::print( + "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(); From eac01a275dd0dfc5f2370df385898e98a1b099ad Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 16 Sep 2020 16:31:34 +0200 Subject: [PATCH 07/10] Update lib.rs --- frame/generic-asset/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frame/generic-asset/src/lib.rs b/frame/generic-asset/src/lib.rs index 534a97cf5372a..6c3683312d0a8 100644 --- a/frame/generic-asset/src/lib.rs +++ b/frame/generic-asset/src/lib.rs @@ -1340,6 +1340,8 @@ where { type Moment = T::BlockNumber; + type MaxLocks = (); + fn set_lock( id: LockIdentifier, who: &T::AccountId, From 3f970a4587b2b9456dca16a66078acc83eeba1e8 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 16 Sep 2020 16:41:43 +0200 Subject: [PATCH 08/10] fix compile --- frame/vesting/src/benchmarking.rs | 12 ++++++------ frame/vesting/src/lib.rs | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/frame/vesting/src/benchmarking.rs b/frame/vesting/src/benchmarking.rs index 644cf246dfdc8..7c5478472f8ab 100644 --- a/frame/vesting/src/benchmarking.rs +++ b/frame/vesting/src/benchmarking.rs @@ -61,7 +61,7 @@ benchmarks! { _ { } vest_locked { - let l in 0 .. T::MaxLocks::get(); + let l in 0 .. MaxLocksOf::::get(); let caller = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -85,7 +85,7 @@ benchmarks! { } vest_unlocked { - let l in 0 .. T::MaxLocks::get(); + let l in 0 .. MaxLocksOf::::get(); let caller = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -109,7 +109,7 @@ benchmarks! { } vest_other_locked { - let l in 0 .. T::MaxLocks::get(); + let l in 0 .. MaxLocksOf::::get(); let other: T::AccountId = account("other", 0, SEED); let other_lookup: ::Source = T::Lookup::unlookup(other.clone()); @@ -136,7 +136,7 @@ benchmarks! { } vest_other_unlocked { - let l in 0 .. T::MaxLocks::get(); + let l in 0 .. MaxLocksOf::::get(); let other: T::AccountId = account("other", 0, SEED); let other_lookup: ::Source = T::Lookup::unlookup(other.clone()); @@ -163,7 +163,7 @@ benchmarks! { } vested_transfer { - let l in 0 .. T::MaxLocks::get(); + let l in 0 .. MaxLocksOf::::get(); let caller: T::AccountId = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -194,7 +194,7 @@ benchmarks! { } force_vested_transfer { - let l in 0 .. T::MaxLocks::get(); + let l in 0 .. MaxLocksOf::::get(); let source: T::AccountId = account("source", 0, SEED); let source_lookup: ::Source = T::Lookup::unlookup(source.clone()); diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index 4157fdb8ee19e..c9d8d04f7c973 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -461,7 +461,6 @@ mod tests { type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); - type MaxLocks = MaxLocks; } parameter_types! { pub const MinVestedTransfer: u64 = 256 * 2; From 8e62e8e99ce6201929e05c36e96deb58f951f224 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 16 Sep 2020 18:15:20 +0200 Subject: [PATCH 09/10] remove aliasing, fix trait def --- frame/grandpa/src/mock.rs | 70 ++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/frame/grandpa/src/mock.rs b/frame/grandpa/src/mock.rs index 684712df7d078..81026c756273a 100644 --- a/frame/grandpa/src/mock.rs +++ b/frame/grandpa/src/mock.rs @@ -41,21 +41,14 @@ use sp_runtime::{ }; use sp_staking::SessionIndex; -use frame_system as system; -use pallet_balances as balances; -use pallet_offences as offences; -use pallet_session as session; -use pallet_staking as staking; -use pallet_timestamp as timestamp; - impl_outer_origin! { pub enum Origin for Test {} } impl_outer_dispatch! { pub enum Call for Test where origin: Origin { - grandpa::Grandpa, - staking::Staking, + pallet_grandpa::Grandpa, + pallet_staking::Staking, } } @@ -67,12 +60,12 @@ impl_opaque_keys! { impl_outer_event! { pub enum TestEvent for Test { - system, - balances, - grandpa, - offences, - session, - staking, + frame_system, + pallet_balances, + pallet_grandpa, + pallet_offences, + pallet_session, + pallet_staking, } } @@ -108,13 +101,13 @@ impl frame_system::Trait for Test { type AvailableBlockRatio = AvailableBlockRatio; type Version = (); type ModuleToIndex = (); - type AccountData = balances::AccountData; + type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); } -impl system::offchain::SendTransactionTypes for Test +impl frame_system::offchain::SendTransactionTypes for Test where Call: From, { @@ -129,22 +122,22 @@ parameter_types! { } /// Custom `SessionHandler` since we use `TestSessionKeys` as `Keys`. -impl session::Trait for Test { +impl pallet_session::Trait for Test { type Event = TestEvent; type ValidatorId = u64; - type ValidatorIdOf = staking::StashOf; - type ShouldEndSession = session::PeriodicSessions; - type NextSessionRotation = session::PeriodicSessions; - type SessionManager = session::historical::NoteHistoricalRoot; + type ValidatorIdOf = pallet_staking::StashOf; + type ShouldEndSession = pallet_session::PeriodicSessions; + type NextSessionRotation = pallet_session::PeriodicSessions; + type SessionManager = pallet_session::historical::NoteHistoricalRoot; type SessionHandler = ::KeyTypeIdProviders; type Keys = TestSessionKeys; type DisabledValidatorsThreshold = DisabledValidatorsThreshold; type WeightInfo = (); } -impl session::historical::Trait for Test { - type FullIdentification = staking::Exposure; - type FullIdentificationOf = staking::ExposureOf; +impl pallet_session::historical::Trait for Test { + type FullIdentification = pallet_staking::Exposure; + type FullIdentificationOf = pallet_staking::ExposureOf; } parameter_types! { @@ -162,7 +155,8 @@ parameter_types! { pub const ExistentialDeposit: u128 = 1; } -impl balances::Trait for Test { +impl pallet_balances::Trait for Test { + type MaxLocks = (); type Balance = u128; type DustRemoval = (); type Event = TestEvent; @@ -175,7 +169,7 @@ parameter_types! { pub const MinimumPeriod: u64 = 3; } -impl timestamp::Trait for Test { +impl pallet_timestamp::Trait for Test { type Moment = u64; type OnTimestampSet = (); type MinimumPeriod = MinimumPeriod; @@ -218,7 +212,7 @@ impl Convert for CurrencyToVoteHandler { } } -impl staking::Trait for Test { +impl pallet_staking::Trait for Test { type RewardRemainder = (); type CurrencyToVote = CurrencyToVoteHandler; type Event = TestEvent; @@ -228,9 +222,9 @@ impl staking::Trait for Test { type SessionsPerEra = SessionsPerEra; type BondingDuration = BondingDuration; type SlashDeferDuration = SlashDeferDuration; - type SlashCancelOrigin = system::EnsureRoot; + type SlashCancelOrigin = frame_system::EnsureRoot; type SessionInterface = Self; - type UnixTime = timestamp::Module; + type UnixTime = pallet_timestamp::Module; type RewardCurve = RewardCurve; type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; type NextNewSession = Session; @@ -246,9 +240,9 @@ parameter_types! { pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get(); } -impl offences::Trait for Test { +impl pallet_offences::Trait for Test { type Event = TestEvent; - type IdentificationTuple = session::historical::IdentificationTuple; + type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; type WeightSoftLimit = OffencesWeightSoftLimit; type WeightInfo = (); @@ -271,7 +265,7 @@ impl Trait for Test { type HandleEquivocation = super::EquivocationHandler; } -mod grandpa { +mod pallet_grandpa { pub use crate::Event; } @@ -331,7 +325,7 @@ pub fn new_test_ext_raw_authorities(authorities: AuthorityList) -> sp_io::TestEx i as u64, i as u64 + 1000, 10_000, - staking::StakerStatus::::Validator, + pallet_staking::StakerStatus::::Validator, ) }) .collect(); @@ -342,18 +336,18 @@ pub fn new_test_ext_raw_authorities(authorities: AuthorityList) -> sp_io::TestEx // NOTE: this will initialize the grandpa authorities // through OneSessionHandler::on_genesis_session - session::GenesisConfig:: { keys: session_keys } + pallet_session::GenesisConfig:: { keys: session_keys } .assimilate_storage(&mut t) .unwrap(); - balances::GenesisConfig:: { balances } + pallet_balances::GenesisConfig:: { balances } .assimilate_storage(&mut t) .unwrap(); - let staking_config = staking::GenesisConfig:: { + let staking_config = pallet_staking::GenesisConfig:: { stakers, validator_count: 8, - force_era: staking::Forcing::ForceNew, + force_era: pallet_staking::Forcing::ForceNew, minimum_validator_count: 0, invulnerables: vec![], ..Default::default() From 8c761a697fbe9ab085fe389ae9566af7225a356e Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 16 Sep 2020 20:02:29 +0200 Subject: [PATCH 10/10] Update --- frame/balances/src/lib.rs | 2 +- frame/balances/src/tests_composite.rs | 5 +---- frame/elections-phragmen/src/lib.rs | 3 +-- frame/executive/src/lib.rs | 3 +-- frame/transaction-payment/src/lib.rs | 3 +-- frame/vesting/src/lib.rs | 2 +- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 8eb4908062591..471efb90bf3ff 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -673,7 +673,7 @@ impl, I: Instance> Module { /// Update the account entry for `who`, given the locks. fn update_locks(who: &T::AccountId, locks: &[BalanceLock]) { if locks.len() as u32 > T::MaxLocks::get() { - frame_support::print( + frame_support::debug::warn!( "Warning: A user has more currency locks than expected. \ A runtime configuration adjustment may be needed." ); diff --git a/frame/balances/src/tests_composite.rs b/frame/balances/src/tests_composite.rs index 0fa52bf68c995..90ad145f22521 100644 --- a/frame/balances/src/tests_composite.rs +++ b/frame/balances/src/tests_composite.rs @@ -104,16 +104,13 @@ impl pallet_transaction_payment::Trait for Test { type FeeMultiplierUpdate = (); } -parameter_types! { - pub const MaxLocks: u32 = 10; -} impl Trait for Test { type Balance = u64; type DustRemoval = (); type Event = Event; type ExistentialDeposit = ExistentialDeposit; type AccountStore = system::Module; - type MaxLocks = MaxLocks; + type MaxLocks = (); type WeightInfo = (); } diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index a80056548dc54..93b11e8d95c57 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -1148,16 +1148,15 @@ mod tests { parameter_types! { pub const ExistentialDeposit: u64 = 1; - pub const MaxLocks: u32 = 10; } impl pallet_balances::Trait for Test { - type MaxLocks = MaxLocks; type Balance = u64; type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Module; + type MaxLocks = (); type WeightInfo = (); } diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 1c56176fde3a9..cd9642fb82c9d 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -577,15 +577,14 @@ mod tests { type Balance = u64; parameter_types! { pub const ExistentialDeposit: Balance = 1; - pub const MaxLocks: u32 = 10; } impl pallet_balances::Trait for Runtime { - type MaxLocks = MaxLocks; type Balance = Balance; type Event = MetaEvent; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; + type MaxLocks = (); type WeightInfo = (); } diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 7c5e063a8f676..bfd69ea29e3b9 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -663,16 +663,15 @@ mod tests { parameter_types! { pub const ExistentialDeposit: u64 = 1; - pub const MaxLocks: u32 = 10; } impl pallet_balances::Trait for Runtime { - type MaxLocks = MaxLocks; type Balance = u64; type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; + type MaxLocks = (); type WeightInfo = (); } thread_local! { diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index c9d8d04f7c973..223dc168645f4 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -454,12 +454,12 @@ mod tests { pub const MaxLocks: u32 = 10; } impl pallet_balances::Trait for Test { - type MaxLocks = (); type Balance = u64; type DustRemoval = (); type Event = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; + type MaxLocks = MaxLocks; type WeightInfo = (); } parameter_types! {