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
This commit is contained in:
Shawn Tabrizi
2020-09-16 21:48:10 +02:00
committed by GitHub
parent 0a6f7b08d7
commit 9aa8698cfc
37 changed files with 273 additions and 71 deletions
+18
View File
@@ -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 {
@@ -221,6 +225,10 @@ 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 {
@@ -228,6 +236,7 @@ impl<T: Trait<I>, I: Instance> Subtrait<I> for T {
type ExistentialDeposit = T::ExistentialDeposit;
type AccountStore = T::AccountStore;
type WeightInfo = <T as Trait<I>>::WeightInfo;
type MaxLocks = T::MaxLocks;
}
decl_event!(
@@ -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();
@@ -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
@@ -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(
@@ -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 = ();
}
@@ -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 = ();
@@ -114,6 +117,7 @@ impl Trait for Test {
system::CallKillAccount<Test>,
u64, super::AccountData<u64>
>;
type MaxLocks = MaxLocks;
type WeightInfo = ();
}