mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
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:
@@ -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 = ();
|
||||
|
||||
@@ -152,6 +152,7 @@ parameter_types! {
|
||||
}
|
||||
|
||||
impl pallet_balances::Trait for Test {
|
||||
type MaxLocks = ();
|
||||
type Balance = u128;
|
||||
type DustRemoval = ();
|
||||
type Event = ();
|
||||
|
||||
@@ -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 = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -1156,6 +1156,7 @@ mod tests {
|
||||
type DustRemoval = ();
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = frame_system::Module<Test>;
|
||||
type MaxLocks = ();
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -584,6 +584,7 @@ mod tests {
|
||||
type DustRemoval = ();
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
type MaxLocks = ();
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -1340,6 +1340,8 @@ where
|
||||
{
|
||||
type Moment = T::BlockNumber;
|
||||
|
||||
type MaxLocks = ();
|
||||
|
||||
fn set_lock(
|
||||
id: LockIdentifier,
|
||||
who: &T::AccountId,
|
||||
|
||||
@@ -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<T>,
|
||||
balances<T>,
|
||||
grandpa,
|
||||
offences,
|
||||
session,
|
||||
staking<T>,
|
||||
frame_system<T>,
|
||||
pallet_balances<T>,
|
||||
pallet_grandpa,
|
||||
pallet_offences,
|
||||
pallet_session,
|
||||
pallet_staking<T>,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,13 +101,13 @@ impl frame_system::Trait for Test {
|
||||
type AvailableBlockRatio = AvailableBlockRatio;
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = balances::AccountData<u128>;
|
||||
type AccountData = pallet_balances::AccountData<u128>;
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
}
|
||||
|
||||
impl<C> system::offchain::SendTransactionTypes<C> for Test
|
||||
impl<C> frame_system::offchain::SendTransactionTypes<C> for Test
|
||||
where
|
||||
Call: From<C>,
|
||||
{
|
||||
@@ -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<Self>;
|
||||
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
|
||||
type NextSessionRotation = session::PeriodicSessions<Period, Offset>;
|
||||
type SessionManager = session::historical::NoteHistoricalRoot<Self, Staking>;
|
||||
type ValidatorIdOf = pallet_staking::StashOf<Self>;
|
||||
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
|
||||
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
|
||||
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
|
||||
type SessionHandler = <TestSessionKeys as OpaqueKeys>::KeyTypeIdProviders;
|
||||
type Keys = TestSessionKeys;
|
||||
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
impl session::historical::Trait for Test {
|
||||
type FullIdentification = staking::Exposure<u64, u128>;
|
||||
type FullIdentificationOf = staking::ExposureOf<Self>;
|
||||
impl pallet_session::historical::Trait for Test {
|
||||
type FullIdentification = pallet_staking::Exposure<u64, u128>;
|
||||
type FullIdentificationOf = pallet_staking::ExposureOf<Self>;
|
||||
}
|
||||
|
||||
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<u128, u64> 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<Self::AccountId>;
|
||||
type SlashCancelOrigin = frame_system::EnsureRoot<Self::AccountId>;
|
||||
type SessionInterface = Self;
|
||||
type UnixTime = timestamp::Module<Test>;
|
||||
type UnixTime = pallet_timestamp::Module<Test>;
|
||||
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<Self>;
|
||||
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
|
||||
type OnOffenceHandler = Staking;
|
||||
type WeightSoftLimit = OffencesWeightSoftLimit;
|
||||
type WeightInfo = ();
|
||||
@@ -271,7 +265,7 @@ impl Trait for Test {
|
||||
type HandleEquivocation = super::EquivocationHandler<Self::KeyOwnerIdentification, Offences>;
|
||||
}
|
||||
|
||||
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::<u64>::Validator,
|
||||
pallet_staking::StakerStatus::<u64>::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::<Test> { keys: session_keys }
|
||||
pallet_session::GenesisConfig::<Test> { keys: session_keys }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
|
||||
balances::GenesisConfig::<Test> { balances }
|
||||
pallet_balances::GenesisConfig::<Test> { balances }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
|
||||
let staking_config = staking::GenesisConfig::<Test> {
|
||||
let staking_config = pallet_staking::GenesisConfig::<Test> {
|
||||
stakers,
|
||||
validator_count: 8,
|
||||
force_era: staking::Forcing::ForceNew,
|
||||
force_era: pallet_staking::Forcing::ForceNew,
|
||||
minimum_validator_count: 0,
|
||||
invulnerables: vec![],
|
||||
..Default::default()
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -82,6 +82,7 @@ parameter_types! {
|
||||
}
|
||||
|
||||
impl pallet_balances::Trait for Test {
|
||||
type MaxLocks = ();
|
||||
type Balance = u64;
|
||||
type DustRemoval = ();
|
||||
type Event = MetaEvent;
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -91,6 +91,7 @@ parameter_types! {
|
||||
}
|
||||
|
||||
impl pallet_balances::Trait for Test {
|
||||
type MaxLocks = ();
|
||||
type Balance = u128;
|
||||
type DustRemoval = ();
|
||||
type Event = TestEvent;
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -1110,6 +1110,9 @@ pub trait LockableCurrency<AccountId>: Currency<AccountId> {
|
||||
/// 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: Get<u32>;
|
||||
|
||||
/// 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
|
||||
|
||||
@@ -671,6 +671,7 @@ mod tests {
|
||||
type DustRemoval = ();
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
type MaxLocks = ();
|
||||
type WeightInfo = ();
|
||||
}
|
||||
thread_local! {
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
|
||||
|
||||
@@ -62,7 +61,7 @@ benchmarks! {
|
||||
_ { }
|
||||
|
||||
vest_locked {
|
||||
let l in 0 .. MAX_LOCKS;
|
||||
let l in 0 .. MaxLocksOf::<T>::get();
|
||||
|
||||
let caller = whitelisted_caller();
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
@@ -86,7 +85,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
vest_unlocked {
|
||||
let l in 0 .. MAX_LOCKS;
|
||||
let l in 0 .. MaxLocksOf::<T>::get();
|
||||
|
||||
let caller = whitelisted_caller();
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
@@ -110,7 +109,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
vest_other_locked {
|
||||
let l in 0 .. MAX_LOCKS;
|
||||
let l in 0 .. MaxLocksOf::<T>::get();
|
||||
|
||||
let other: T::AccountId = account("other", 0, SEED);
|
||||
let other_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(other.clone());
|
||||
@@ -137,7 +136,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
vest_other_unlocked {
|
||||
let l in 0 .. MAX_LOCKS;
|
||||
let l in 0 .. MaxLocksOf::<T>::get();
|
||||
|
||||
let other: T::AccountId = account("other", 0, SEED);
|
||||
let other_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(other.clone());
|
||||
@@ -164,7 +163,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
vested_transfer {
|
||||
let l in 0 .. MAX_LOCKS;
|
||||
let l in 0 .. MaxLocksOf::<T>::get();
|
||||
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
@@ -193,6 +192,38 @@ benchmarks! {
|
||||
"Lock not created",
|
||||
);
|
||||
}
|
||||
|
||||
force_vested_transfer {
|
||||
let l in 0 .. MaxLocksOf::<T>::get();
|
||||
|
||||
let source: T::AccountId = account("source", 0, SEED);
|
||||
let source_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(source.clone());
|
||||
T::Currency::make_free_balance_be(&source, BalanceOf::<T>::max_value());
|
||||
let target: T::AccountId = account("target", 0, SEED);
|
||||
let target_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(target.clone());
|
||||
// Give target existing locks
|
||||
add_locks::<T>(&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::<T>::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::<Test>());
|
||||
assert_ok!(test_benchmark_vest_other_unlocked::<Test>());
|
||||
assert_ok!(test_benchmark_vested_transfer::<Test>());
|
||||
assert_ok!(test_benchmark_force_vested_transfer::<Test>());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -61,8 +61,10 @@ use frame_support::traits::{
|
||||
use frame_system::{ensure_signed, ensure_root};
|
||||
|
||||
mod benchmarking;
|
||||
mod default_weights;
|
||||
|
||||
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
|
||||
type MaxLocksOf<T> = <<T as Trait>::Currency as LockableCurrency<<T as frame_system::Trait>::AccountId>>::MaxLocks;
|
||||
|
||||
pub trait WeightInfo {
|
||||
fn vest_locked(l: u32, ) -> Weight;
|
||||
@@ -70,14 +72,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 {
|
||||
@@ -171,7 +166,7 @@ decl_storage! {
|
||||
decl_event!(
|
||||
pub enum Event<T> where AccountId = <T as frame_system::Trait>::AccountId, Balance = BalanceOf<T> {
|
||||
/// 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.
|
||||
@@ -213,12 +208,10 @@ 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>
|
||||
#[weight = 50_000_000 + T::DbWeight::get().reads_writes(2, 2)]
|
||||
#[weight = T::WeightInfo::vest_locked(MaxLocksOf::<T>::get())
|
||||
.max(T::WeightInfo::vest_unlocked(MaxLocksOf::<T>::get()))
|
||||
]
|
||||
fn vest(origin) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
Self::update_lock(who)
|
||||
@@ -238,12 +231,10 @@ 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>
|
||||
#[weight = 50_000_000 + T::DbWeight::get().reads_writes(3, 3)]
|
||||
#[weight = T::WeightInfo::vest_other_locked(MaxLocksOf::<T>::get())
|
||||
.max(T::WeightInfo::vest_other_unlocked(MaxLocksOf::<T>::get()))
|
||||
]
|
||||
fn vest_other(origin, target: <T::Lookup as StaticLookup>::Source) -> DispatchResult {
|
||||
ensure_signed(origin)?;
|
||||
Self::update_lock(T::Lookup::lookup(target)?)
|
||||
@@ -264,10 +255,8 @@ 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>
|
||||
#[weight = 100_000_000 + T::DbWeight::get().reads_writes(3, 3)]
|
||||
#[weight = T::WeightInfo::vested_transfer(MaxLocksOf::<T>::get())]
|
||||
pub fn vested_transfer(
|
||||
origin,
|
||||
target: <T::Lookup as StaticLookup>::Source,
|
||||
@@ -303,10 +292,8 @@ 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>
|
||||
#[weight = 100_000_000 + T::DbWeight::get().reads_writes(4, 4)]
|
||||
#[weight = T::WeightInfo::force_vested_transfer(MaxLocksOf::<T>::get())]
|
||||
pub fn force_vested_transfer(
|
||||
origin,
|
||||
source: <T::Lookup as StaticLookup>::Source,
|
||||
@@ -463,12 +450,16 @@ mod tests {
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
}
|
||||
parameter_types! {
|
||||
pub const MaxLocks: u32 = 10;
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type DustRemoval = ();
|
||||
type Event = ();
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
type MaxLocks = MaxLocks;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
Reference in New Issue
Block a user