From b0cd680482a59d2d2baba2dfb50dc5db47f87a35 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Thu, 12 Jan 2023 14:21:11 +0700 Subject: [PATCH 01/90] + nomination pool commission --- .../nomination-pools/benchmarking/src/lib.rs | 132 +- .../nomination-pools/benchmarking/src/mock.rs | 5 +- frame/nomination-pools/fuzzer/src/call.rs | 9 +- frame/nomination-pools/src/lib.rs | 407 ++++- frame/nomination-pools/src/migration.rs | 91 +- frame/nomination-pools/src/mock.rs | 33 +- frame/nomination-pools/src/tests.rs | 1384 +++++++++++++++-- frame/nomination-pools/src/weights.rs | 385 ++--- .../nomination-pools/test-staking/src/mock.rs | 5 +- 9 files changed, 2078 insertions(+), 373 deletions(-) diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index 9b063539152b7..b5706e396c0d9 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -28,11 +28,15 @@ use frame_election_provider_support::SortedListProvider; use frame_support::{assert_ok, ensure, traits::Get}; use frame_system::RawOrigin as RuntimeOrigin; use pallet_nomination_pools::{ - BalanceOf, BondExtra, BondedPoolInner, BondedPools, ConfigOp, MaxPoolMembers, - MaxPoolMembersPerPool, MaxPools, Metadata, MinCreateBond, MinJoinBond, Pallet as Pools, - PoolMembers, PoolRoles, PoolState, RewardPools, SubPoolsStorage, + BalanceOf, BondExtra, BondedPoolInner, BondedPools, Commission, CommissionChangeRate, ConfigOp, + GlobalMaxCommission, LastPoolId, MaxPoolMembers, MaxPoolMembersPerPool, MaxPools, Metadata, + MinCreateBond, MinJoinBond, Pallet as Pools, PoolMembers, PoolRoles, PoolState, RewardPools, + SubPoolsStorage, +}; +use sp_runtime::{ + traits::{Bounded, StaticLookup, Zero}, + Perbill, }; -use sp_runtime::traits::{Bounded, StaticLookup, Zero}; use sp_staking::{EraIndex, StakingInterface}; // `frame_benchmarking::benchmarks!` macro needs this use pallet_nomination_pools::Call; @@ -67,6 +71,7 @@ fn create_funded_user_with_balance( fn create_pool_account( n: u32, balance: BalanceOf, + commission: Option, ) -> (T::AccountId, T::AccountId) { let ed = CurrencyOf::::minimum_balance(); let pool_creator: T::AccountId = @@ -82,6 +87,16 @@ fn create_pool_account( ) .unwrap(); + if let Some(c) = commission { + let pool_id = LastPoolId::::get(); + Pools::::set_commission( + RuntimeOrigin::Signed(pool_creator.clone()).into(), + pool_id, + Some((c, pool_creator.clone())), + ) + .expect("pool just created, commission can be set by root; qed"); + } + let pool_account = pallet_nomination_pools::BondedPools::::iter() .find(|(_, bonded_pool)| bonded_pool.roles.depositor == pool_creator) .map(|(pool_id, _)| Pools::::create_bonded_account(pool_id)) @@ -132,14 +147,18 @@ impl ListScenario { sp_std::mem::forget(i); // Create accounts with the origin weight - let (pool_creator1, pool_origin1) = create_pool_account::(USER_SEED + 1, origin_weight); + let (pool_creator1, pool_origin1) = + create_pool_account::(USER_SEED + 1, origin_weight, Some(Perbill::from_percent(50))); + T::Staking::nominate( &pool_origin1, // NOTE: these don't really need to be validators. vec![account("random_validator", 0, USER_SEED)], )?; - let (_, pool_origin2) = create_pool_account::(USER_SEED + 2, origin_weight); + let (_, pool_origin2) = + create_pool_account::(USER_SEED + 2, origin_weight, Some(Perbill::from_percent(50))); + T::Staking::nominate( &pool_origin2, vec![account("random_validator", 0, USER_SEED)].clone(), @@ -155,7 +174,9 @@ impl ListScenario { dest_weight_as_vote.try_into().map_err(|_| "could not convert u64 to Balance")?; // Create an account with the worst case destination weight - let (_, pool_dest1) = create_pool_account::(USER_SEED + 3, dest_weight); + let (_, pool_dest1) = + create_pool_account::(USER_SEED + 3, dest_weight, Some(Perbill::from_percent(50))); + T::Staking::nominate(&pool_dest1, vec![account("random_validator", 0, USER_SEED)])?; let weight_of = pallet_staking::Pallet::::weight_of_fn(); @@ -262,16 +283,17 @@ frame_benchmarking::benchmarks! { }: bond_extra(RuntimeOrigin::Signed(scenario.creator1.clone()), BondExtra::Rewards) verify { + // commission of 50% deducted here. assert!( T::Staking::active_stake(&scenario.origin1).unwrap() >= - scenario.dest_weight + scenario.dest_weight / 2u32.into() ); } claim_payout { let origin_weight = Pools::::depositor_min_bond() * 2u32.into(); let ed = CurrencyOf::::minimum_balance(); - let (depositor, pool_account) = create_pool_account::(0, origin_weight); + let (depositor, pool_account) = create_pool_account::(0, origin_weight, Some(Perbill::from_percent(50))); let reward_account = Pools::::create_reward_account(1); // Send funds to the reward account of the pool @@ -331,7 +353,7 @@ frame_benchmarking::benchmarks! { let s in 0 .. MAX_SPANS; let min_create_bond = Pools::::depositor_min_bond(); - let (depositor, pool_account) = create_pool_account::(0, min_create_bond); + let (depositor, pool_account) = create_pool_account::(0, min_create_bond, None); // Add a new member let min_join_bond = MinJoinBond::::get().max(CurrencyOf::::minimum_balance()); @@ -373,7 +395,7 @@ frame_benchmarking::benchmarks! { let s in 0 .. MAX_SPANS; let min_create_bond = Pools::::depositor_min_bond(); - let (depositor, pool_account) = create_pool_account::(0, min_create_bond); + let (depositor, pool_account) = create_pool_account::(0, min_create_bond, None); // Add a new member let min_join_bond = MinJoinBond::::get().max(CurrencyOf::::minimum_balance()); @@ -419,7 +441,7 @@ frame_benchmarking::benchmarks! { let s in 0 .. MAX_SPANS; let min_create_bond = Pools::::depositor_min_bond(); - let (depositor, pool_account) = create_pool_account::(0, min_create_bond); + let (depositor, pool_account) = create_pool_account::(0, min_create_bond, None); let depositor_lookup = T::Lookup::unlookup(depositor.clone()); // We set the pool to the destroying state so the depositor can leave @@ -509,15 +531,16 @@ frame_benchmarking::benchmarks! { assert_eq!( new_pool, BondedPoolInner { - points: min_create_bond, - state: PoolState::Open, + commission: Commission::default(), member_counter: 1, + points: min_create_bond, roles: PoolRoles { depositor: depositor.clone(), root: Some(depositor.clone()), nominator: Some(depositor.clone()), state_toggler: Some(depositor.clone()), }, + state: PoolState::Open, } ); assert_eq!( @@ -531,7 +554,7 @@ frame_benchmarking::benchmarks! { // Create a pool let min_create_bond = Pools::::depositor_min_bond() * 2u32.into(); - let (depositor, pool_account) = create_pool_account::(0, min_create_bond); + let (depositor, pool_account) = create_pool_account::(0, min_create_bond, None); // Create some accounts to nominate. For the sake of benchmarking they don't need to be // actual validators @@ -548,15 +571,16 @@ frame_benchmarking::benchmarks! { assert_eq!( new_pool, BondedPoolInner { - points: min_create_bond, - state: PoolState::Open, + commission: Commission::default(), member_counter: 1, + points: min_create_bond, roles: PoolRoles { depositor: depositor.clone(), root: Some(depositor.clone()), nominator: Some(depositor.clone()), state_toggler: Some(depositor.clone()), - } + }, + state: PoolState::Open, } ); assert_eq!( @@ -568,7 +592,7 @@ frame_benchmarking::benchmarks! { set_state { // Create a pool let min_create_bond = Pools::::depositor_min_bond(); - let (depositor, pool_account) = create_pool_account::(0, min_create_bond); + let (depositor, pool_account) = create_pool_account::(0, min_create_bond, None); BondedPools::::mutate(&1, |maybe_pool| { // Force the pool into an invalid state maybe_pool.as_mut().map(|mut pool| pool.points = min_create_bond * 10u32.into()); @@ -585,7 +609,7 @@ frame_benchmarking::benchmarks! { let n in 1 .. ::MaxMetadataLen::get(); // Create a pool - let (depositor, pool_account) = create_pool_account::(0, Pools::::depositor_min_bond() * 2u32.into()); + let (depositor, pool_account) = create_pool_account::(0, Pools::::depositor_min_bond() * 2u32.into(), None); // Create metadata of the max possible size let metadata: Vec = (0..n).map(|_| 42).collect(); @@ -603,18 +627,20 @@ frame_benchmarking::benchmarks! { ConfigOp::Set(BalanceOf::::max_value()), ConfigOp::Set(u32::MAX), ConfigOp::Set(u32::MAX), - ConfigOp::Set(u32::MAX) + ConfigOp::Set(u32::MAX), + ConfigOp::Set(Perbill::max_value()) ) verify { assert_eq!(MinJoinBond::::get(), BalanceOf::::max_value()); assert_eq!(MinCreateBond::::get(), BalanceOf::::max_value()); assert_eq!(MaxPools::::get(), Some(u32::MAX)); assert_eq!(MaxPoolMembers::::get(), Some(u32::MAX)); assert_eq!(MaxPoolMembersPerPool::::get(), Some(u32::MAX)); + assert_eq!(GlobalMaxCommission::::get(), Some(Perbill::max_value())); } update_roles { let first_id = pallet_nomination_pools::LastPoolId::::get() + 1; - let (root, _) = create_pool_account::(0, Pools::::depositor_min_bond() * 2u32.into()); + let (root, _) = create_pool_account::(0, Pools::::depositor_min_bond() * 2u32.into(), None); let random: T::AccountId = account("but is anything really random in computers..?", 0, USER_SEED); }:_( RuntimeOrigin::Signed(root.clone()), @@ -636,7 +662,7 @@ frame_benchmarking::benchmarks! { chill { // Create a pool - let (depositor, pool_account) = create_pool_account::(0, Pools::::depositor_min_bond() * 2u32.into()); + let (depositor, pool_account) = create_pool_account::(0, Pools::::depositor_min_bond() * 2u32.into(), None); // Nominate with the pool. let validators: Vec<_> = (0..T::MaxNominations::get()) @@ -652,9 +678,67 @@ frame_benchmarking::benchmarks! { assert!(T::Staking::nominations(Pools::::create_bonded_account(1)).is_none()); } + set_commission { + // Create a pool - do not set a commission yet. + let (depositor, pool_account) = create_pool_account::(0, Pools::::depositor_min_bond() * 2u32.into(), None); + // set a max commission + Pools::::set_commission_max(RuntimeOrigin::Signed(depositor.clone()).into(), 1u32.into(), Perbill::from_percent(50)).unwrap(); + // set a change rate + Pools::::set_commission_change_rate(RuntimeOrigin::Signed(depositor.clone()).into(), 1u32.into(), CommissionChangeRate { + max_increase: Perbill::from_percent(20), + min_delay: 0u32.into(), + }).unwrap(); + + }:_(RuntimeOrigin::Signed(depositor.clone()), 1u32.into(), Some((Perbill::from_percent(20), depositor.clone()))) + verify { + assert_eq!(BondedPools::::get(1).unwrap().commission, Commission { + current: Some((Perbill::from_percent(20), depositor)), + max: Some(Perbill::from_percent(50)), + change_rate: Some(CommissionChangeRate { + max_increase: Perbill::from_percent(20), + min_delay: 0u32.into() + }), + throttle_from: Some(1u32.into()), + }); + } + + set_commission_max { + // Create a pool, setting a commission that will update when max commission is set. + let (depositor, pool_account) = create_pool_account::(0, Pools::::depositor_min_bond() * 2u32.into(), Some(Perbill::from_percent(50))); + }:_(RuntimeOrigin::Signed(depositor.clone()), 1u32.into(), Perbill::from_percent(50)) + verify { + assert_eq!( + BondedPools::::get(1).unwrap().commission, Commission { + current: Some((Perbill::from_percent(50), depositor)), + max: Some(Perbill::from_percent(50)), + change_rate: None, + throttle_from: Some(0u32.into()), + }); + } + + set_commission_change_rate { + // Create a pool + let (depositor, pool_account) = create_pool_account::(0, Pools::::depositor_min_bond() * 2u32.into(), None); + }:_(RuntimeOrigin::Signed(depositor.clone()), 1u32.into(), CommissionChangeRate { + max_increase: Perbill::from_percent(50), + min_delay: 1000u32.into(), + }) + verify { + assert_eq!( + BondedPools::::get(1).unwrap().commission, Commission { + current: None, + max: None, + change_rate: Some(CommissionChangeRate { + max_increase: Perbill::from_percent(50), + min_delay: 1000u32.into(), + }), + throttle_from: Some(1_u32.into()), + }); + } + impl_benchmark_test_suite!( Pallet, crate::mock::new_test_ext(), crate::mock::Runtime ); -} +} \ No newline at end of file diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index 06a66838594c7..f8840286e630b 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -20,7 +20,7 @@ use frame_election_provider_support::VoteWeight; use frame_support::{pallet_prelude::*, parameter_types, traits::ConstU64, PalletId}; use sp_runtime::{ traits::{Convert, IdentityLookup}, - FixedU128, + FixedU128, Perbill, }; type AccountId = u128; @@ -195,7 +195,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities { max_pools: Some(3), max_members_per_pool: Some(3), max_members: Some(3 * 3), + global_max_commission: Some(Perbill::from_percent(500)), } .assimilate_storage(&mut storage); sp_io::TestExternalities::from(storage) -} +} \ No newline at end of file diff --git a/frame/nomination-pools/fuzzer/src/call.rs b/frame/nomination-pools/fuzzer/src/call.rs index b07903609e8ab..5e48a236b2b44 100644 --- a/frame/nomination-pools/fuzzer/src/call.rs +++ b/frame/nomination-pools/fuzzer/src/call.rs @@ -33,11 +33,11 @@ use pallet_nomination_pools::{ mock::*, pallet as pools, pallet::{BondedPools, Call as PoolsCall, Event as PoolsEvents, PoolMembers}, - BondExtra, BondedPool, LastPoolId, MaxPoolMembers, MaxPoolMembersPerPool, MaxPools, - MinCreateBond, MinJoinBond, PoolId, + BondExtra, BondedPool, GlobalMaxCommission, LastPoolId, MaxPoolMembers, MaxPoolMembersPerPool, + MaxPools, MinCreateBond, MinJoinBond, PoolId, }; use rand::{seq::SliceRandom, Rng}; -use sp_runtime::{assert_eq_error_rate, Perquintill}; +use sp_runtime::{assert_eq_error_rate, Perbill, Perquintill}; const ERA: BlockNumber = 1000; const MAX_ED_MULTIPLE: Balance = 10_000; @@ -224,6 +224,7 @@ fn main() { MaxPoolMembers::::set(Some(10_000)); MaxPoolMembersPerPool::::set(Some(1000)); MaxPools::::set(Some(1_000)); + GlobalMaxCommission::::set(Some(Perbill::from_percent(90))); MinCreateBond::::set(10 * ExistentialDeposit::get()); MinJoinBond::::set(5 * ExistentialDeposit::get()); @@ -350,4 +351,4 @@ fn main() { }) }) } -} +} \ No newline at end of file diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 3cb8abedda2fb..69ba5e5c4696e 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -334,9 +334,10 @@ use scale_info::TypeInfo; use sp_core::U256; use sp_runtime::{ traits::{ - AccountIdConversion, CheckedAdd, CheckedSub, Convert, Saturating, StaticLookup, Zero, + AccountIdConversion, Bounded, CheckedAdd, CheckedSub, Convert, Saturating, StaticLookup, + Zero, }, - FixedPointNumber, + FixedPointNumber, Perbill, }; use sp_staking::{EraIndex, OnStakerSlash, StakingInterface}; use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, ops::Div, vec::Vec}; @@ -582,25 +583,234 @@ pub struct PoolRoles { pub state_toggler: Option, } +/// Pool commission. +/// +/// The pool `root` can set commission configuration after pool creation. By default, all commission +/// values are `None`. Pool `root` can also set `max` and `change_rate` configurations before +/// setting an initial `current` commission. +/// +/// `current` is a tuple of the commission percentage and payee of commission. `throttle_from` +/// keeps track of which block `current` was last updated. A `max` commission value can only be +/// decreased after the initial value is set, to prevent commission from repeatedly increasing. +/// +/// An optional commission `change_rate` allows the pool to set strict limits to how much commission +/// can change in each update, and how often updates can take place. +#[derive( + Encode, Decode, DefaultNoBound, MaxEncodedLen, TypeInfo, DebugNoBound, PartialEq, Copy, Clone, +)] +#[codec(mel_bound(T: Config))] +#[scale_info(skip_type_params(T))] +pub struct Commission { + /// Optional commission rate of the pool along with the account commission is paid to. + pub current: Option<(Perbill, T::AccountId)>, + /// Optional maximum commission that can be set by the pool `root`. Once set, this value can + /// only be updated to a decreased value. + pub max: Option, + /// Optional configuration around how often commission can be updated, and when the last + /// commission update took place. + pub change_rate: Option>, + /// The block throttling should be checked from. This value will be updated on all commission + /// updates and when setting an initial `change_rate`. + pub throttle_from: Option, +} + +impl Commission { + /// Returns true if the current commission updating to `to` would exhaust the change rate + /// limits. + /// + /// A commission update will be throttled (disallowed) if: + /// 1. not enough blocks have passed since the `throttle_from` block, if exists, or + /// 2. the new commission is greater than the maximum allowed increase. + fn throttling(&self, to: &Perbill) -> bool { + if let Some(t) = self.change_rate.as_ref() { + let commission_as_percent = + self.current.as_ref().map(|(x, _)| *x).unwrap_or(Perbill::zero()); + + // do not throttle if `to` is the same or a decrease in commission. + if *to <= commission_as_percent { + return false + } + // Test for `max_increase` throttling. + // + // Throttled if the attempted increase in commission is greater than `max_increase`. + if (*to).saturating_sub(commission_as_percent) > t.max_increase { + return true + } + + // Test for `min_delay` throttling. + // + // Note: matching `None` is defensive only. `throttle_from` should always exist where + // `change_rate` has already been set, so this scenario should never happen. + return self.throttle_from.map_or_else( + || { + defensive!("throttle_from should exist if change_rate is set"); + false + }, + |f| { + // if `min_delay` is zero (no delay), not throttling. + if t.min_delay == Zero::zero() { + return false + } else { + // throttling if blocks passed is less than `min_delay`. + let blocks_surpassed = + >::block_number().saturating_sub(f); + return blocks_surpassed < t.min_delay + } + }, + ) + } + false + } + + /// Set the pool's commission. + /// + /// Update commission based on `current`. If a `None` is supplied, allow the commission to be + /// removed without any change rate restrictions. If `change_rate` is present, update + /// `throttle_from` to the current block. If the supplied commission is zero, `None` will be + /// inserted and `payee` will be ignored. + fn try_update_current(&mut self, current: &Option<(Perbill, T::AccountId)>) -> DispatchResult { + self.current = match current { + None => None, + Some((commission, payee)) => { + ensure!(!self.throttling(&commission), Error::::CommissionChangeThrottled); + ensure!( + self.max.map_or(true, |m| commission <= &m), + Error::::CommissionExceedsMaximum + ); + if commission.is_zero() { + None + } else { + Some((*commission, payee.clone())) + } + }, + }; + let _ = self.register_update(); + Ok(()) + } + + /// Set the pool's maximum commission. + /// + /// The pool's maximum commission can initially be set to any value, and only smaller values + /// thereafter. If larger values are attempted, this function will return a dispatch error. + /// + /// If `current.0` is larger than the updated max commission value, `current.0` will also be + /// updated to the new maximum. This will also register a `throttle_from` update. + fn try_update_max(&mut self, new_max: Perbill) -> DispatchResult { + if let Some(old) = self.max.as_mut() { + if new_max > *old { + return Err(Error::::MaxCommissionRestricted.into()) + } + *old = new_max; + } else { + self.max = Some(new_max) + }; + let updated_current = self + .current + .as_mut() + .map(|(c, _)| { + let u = *c > new_max; + *c = (*c).min(new_max); + u + }) + .unwrap_or(false); + + if updated_current { + self.register_update(); + } + Ok(()) + } + + /// Set the pool's commission `change_rate`. + /// + /// Once a change rate configuration has been set, only more restrictive values can be set + /// thereafter. These restrictions translate to increased `min_delay` values and decreased + /// `max_increase` values. + /// + /// Update `throttle_from` to the current block upon setting change rate for the first time, so + /// throttling can be checked from this block. + fn try_update_change_rate( + &mut self, + change_rate: CommissionChangeRate, + ) -> DispatchResult { + ensure!(!&self.less_restrictive(&change_rate), Error::::CommissionChangeRateNotAllowed); + + if self.change_rate.is_none() { + self.throttle_from = Some(>::block_number()); + } + self.change_rate = Some(change_rate); + Ok(()) + } + + /// Gets the current commission (if any) and payee to be paid. + /// + /// `None` is returned if a commission has not been set. Commission is bounded to + /// `GlobalMaxCommission`. + fn maybe_commission_and_payee( + &self, + pending_rewards: &BalanceOf, + ) -> Option<(BalanceOf, T::AccountId)> { + self.current.as_ref().map(|(commission, payee)| { + ( + *commission.min(&GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())) * + *pending_rewards, + payee.clone(), + ) + }) + } + + /// Updates a commission's `throttle_from` field to the current block. + fn register_update(&mut self) { + self.throttle_from = Some(>::block_number()); + } + + /// Checks whether a change rate is less restrictive than the current change rate, if any. + /// + /// No change rate will always be less restrictive than some change rate, so where no + /// `change_rate` is currently set, `false` is returned. + fn less_restrictive(&self, new: &CommissionChangeRate) -> bool { + self.change_rate + .as_ref() + .map(|c| new.max_increase > c.max_increase || new.min_delay < c.min_delay) + .unwrap_or(false) + } +} + +/// Pool commission change rate preferences. +/// +/// The pool root is able to set a commission change rate for their pool. A commission change rate +/// consists of 2 values; (1) the maximum allowed commission change, and (2) the minimum amount of +/// blocks that must elapse before commission updates are allowed again. +/// +/// Commission change rates are not applied to decreases in commission. +#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Debug, PartialEq, Copy, Clone)] +pub struct CommissionChangeRate { + /// The maximum amount the commission can be updated by per `min_delay` period. + pub max_increase: Perbill, + /// How often an update can take place. + pub min_delay: BlockNumber, +} + /// Pool permissions and state #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, DebugNoBound, PartialEq, Clone)] #[codec(mel_bound(T: Config))] #[scale_info(skip_type_params(T))] pub struct BondedPoolInner { - /// Total points of all the members in the pool who are actively bonded. - pub points: BalanceOf, - /// The current state of the pool. - pub state: PoolState, + /// The commission rate of the pool. + pub commission: Commission, /// Count of members that belong to the pool. pub member_counter: u32, + /// Total points of all the members in the pool who are actively bonded. + pub points: BalanceOf, /// See [`PoolRoles`]. pub roles: PoolRoles, + /// The current state of the pool. + pub state: PoolState, } /// A wrapper for bonded pools, with utility functions. /// -/// The main purpose of this is to wrap a [`BondedPoolInner`], with the account + id of the pool, -/// for easier access. +/// The main purpose of this is to wrap a [`BondedPoolInner`], with the account +/// + id of the pool, for easier access. #[derive(RuntimeDebugNoBound)] #[cfg_attr(feature = "std", derive(Clone, PartialEq))] pub struct BondedPool { @@ -629,10 +839,11 @@ impl BondedPool { Self { id, inner: BondedPoolInner { + commission: Commission::default(), + member_counter: Zero::zero(), + points: Zero::zero(), roles, state: PoolState::Open, - points: Zero::zero(), - member_counter: Zero::zero(), }, } } @@ -762,6 +973,10 @@ impl BondedPool { self.is_root(who) || self.is_state_toggler(who) } + fn can_set_commission(&self, who: &T::AccountId) -> bool { + self.is_root(who) + } + fn is_destroying(&self) -> bool { matches!(self.state, PoolState::Destroying) } @@ -1171,9 +1386,10 @@ pub mod pallet { use super::*; use frame_support::traits::StorageVersion; use frame_system::{ensure_signed, pallet_prelude::*}; + use sp_runtime::Perbill; /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(3); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); #[pallet::pallet] #[pallet::generate_store(pub(crate) trait Store)] @@ -1276,6 +1492,12 @@ pub mod pallet { #[pallet::storage] pub type MaxPoolMembersPerPool = StorageValue<_, u32, OptionQuery>; + /// The maximum commission that can be charged by a pool. Used on commission payouts to bound + /// pool commissions that are > GlobalMaxCommission, necessary if a future `GlobalMaxCommission` + /// is lower than some current pool commissions. + #[pallet::storage] + pub type GlobalMaxCommission = StorageValue<_, Perbill, OptionQuery>; + /// Active members. /// /// TWOX-NOTE: SAFE since `AccountId` is a secure hash. @@ -1289,13 +1511,13 @@ pub mod pallet { pub type BondedPools = CountedStorageMap<_, Twox64Concat, PoolId, BondedPoolInner>; - /// Reward pools. This is where there rewards for each pool accumulate. When a members payout - /// is claimed, the balance comes out fo the reward pool. Keyed by the bonded pools account. + /// Reward pools. This is where there rewards for each pool accumulate. When a members payout is + /// claimed, the balance comes out fo the reward pool. Keyed by the bonded pools account. #[pallet::storage] pub type RewardPools = CountedStorageMap<_, Twox64Concat, PoolId, RewardPool>; - /// Groups of unbonding pools. Each group of unbonding pools belongs to a bonded pool, - /// hence the name sub-pools. Keyed by the bonded pools account. + /// Groups of unbonding pools. Each group of unbonding pools belongs to a + /// bonded pool, hence the name sub-pools. Keyed by the bonded pools account. #[pallet::storage] pub type SubPoolsStorage = CountedStorageMap<_, Twox64Concat, PoolId, SubPools>; @@ -1323,6 +1545,7 @@ pub mod pallet { pub max_pools: Option, pub max_members_per_pool: Option, pub max_members: Option, + pub global_max_commission: Option, } #[cfg(feature = "std")] @@ -1334,6 +1557,7 @@ pub mod pallet { max_pools: Some(16), max_members_per_pool: Some(32), max_members: Some(16 * 32), + global_max_commission: None, } } } @@ -1352,6 +1576,9 @@ pub mod pallet { if let Some(max_members) = self.max_members { MaxPoolMembers::::put(max_members); } + if let Some(global_max_commission) = self.global_max_commission { + GlobalMaxCommission::::put(global_max_commission); + } } } @@ -1364,7 +1591,12 @@ pub mod pallet { /// A member has became bonded in a pool. Bonded { member: T::AccountId, pool_id: PoolId, bonded: BalanceOf, joined: bool }, /// A payout has been made to a member. - PaidOut { member: T::AccountId, pool_id: PoolId, payout: BalanceOf }, + PaidOut { + member: T::AccountId, + pool_id: PoolId, + payout: BalanceOf, + commission: BalanceOf, + }, /// A member has unbonded from their pool. /// /// - `balance` is the corresponding balance of the number of points that has been @@ -1414,6 +1646,15 @@ pub mod pallet { PoolSlashed { pool_id: PoolId, balance: BalanceOf }, /// The unbond pool at `era` of pool `pool_id` has been slashed to `balance`. UnbondingPoolSlashed { pool_id: PoolId, era: EraIndex, balance: BalanceOf }, + /// A pool's commission setting has been changed. + PoolCommissionUpdated { pool_id: PoolId, current: Option<(Perbill, T::AccountId)> }, + /// A pool's maximum commission setting has been changed. + PoolMaxCommissionUpdated { pool_id: PoolId, max_commission: Perbill }, + /// A pool's commission `change_rate` has been changed. + PoolCommissionChangeRateUpdated { + pool_id: PoolId, + change_rate: CommissionChangeRate, + }, } #[pallet::error] @@ -1469,6 +1710,18 @@ pub mod pallet { Defensive(DefensiveError), /// Partial unbonding now allowed permissionlessly. PartialUnbondNotAllowedPermissionlessly, + /// No commission has been set. + NoCommissionSet, + /// No account has been set to receive commission. + NoCommissionPayeeSet, + /// The pool's max commission cannot be set higher than the existing value. + MaxCommissionRestricted, + /// The supplied commission exceeds the max allowed commission. + CommissionExceedsMaximum, + /// Not enough blocks have surpassed since the last commission update. + CommissionChangeThrottled, + /// The submitted changes to commission change rate are not allowed. + CommissionChangeRateNotAllowed, /// Pool id currently in use. PoolIdInUse, /// Pool id provided is not correct/usable. @@ -1604,7 +1857,7 @@ pub mod pallet { } /// A bonded member can use this to claim their payout based on the rewards that the pool - /// has accumulated since their last claimed payout (OR since joining if this is there first + /// has accumulated since their last claimed payout (OR since joining if this is their first /// time claiming rewards). The payout will be transferred to the member's account. /// /// The member will earn rewards pro rata based on the members stake vs the sum of the @@ -2019,6 +2272,7 @@ pub mod pallet { /// * `max_pools` - Set [`MaxPools`]. /// * `max_members` - Set [`MaxPoolMembers`]. /// * `max_members_per_pool` - Set [`MaxPoolMembersPerPool`]. + /// * `global_max_commission` - Set [`GlobalMaxCommission`]. #[pallet::call_index(11)] #[pallet::weight(T::WeightInfo::set_configs())] pub fn set_configs( @@ -2028,6 +2282,7 @@ pub mod pallet { max_pools: ConfigOp, max_members: ConfigOp, max_members_per_pool: ConfigOp, + global_max_commission: ConfigOp, ) -> DispatchResult { ensure_root(origin)?; @@ -2046,6 +2301,7 @@ pub mod pallet { config_op_exp!(MaxPools::, max_pools); config_op_exp!(MaxPoolMembers::, max_members); config_op_exp!(MaxPoolMembersPerPool::, max_members_per_pool); + config_op_exp!(GlobalMaxCommission::, global_max_commission); Ok(()) } @@ -2117,6 +2373,76 @@ pub mod pallet { ensure!(bonded_pool.can_nominate(&who), Error::::NotNominator); T::Staking::chill(&bonded_pool.bonded_account()) } + + /// Set the commission of a pool. + /// + /// The dispatch origin of this call must be signed by the `root` role of the pool. Both a + /// commission percentage and a commission payee must be provided in the `current` tuple. + /// Where a `current` of `None` is provided, any current commission will be removed. + #[pallet::call_index(14)] + #[pallet::weight(T::WeightInfo::set_commission())] + pub fn set_commission( + origin: OriginFor, + pool_id: PoolId, + new_commission: Option<(Perbill, T::AccountId)>, + ) -> DispatchResult { + let who = ensure_signed(origin)?; + let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; + ensure!(bonded_pool.can_set_commission(&who), Error::::DoesNotHavePermission); + + bonded_pool.commission.try_update_current(&new_commission)?; + bonded_pool.put(); + Self::deposit_event(Event::::PoolCommissionUpdated { + pool_id, + current: new_commission, + }); + Ok(()) + } + + /// Set the maximum commission of a pool. + /// + /// The dispatch origin of this call must be signed by the `root` role of the pool. + #[pallet::call_index(15)] + #[pallet::weight(T::WeightInfo::set_commission_max())] + pub fn set_commission_max( + origin: OriginFor, + pool_id: PoolId, + max_commission: Perbill, + ) -> DispatchResult { + let who = ensure_signed(origin)?; + let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; + ensure!(bonded_pool.can_set_commission(&who), Error::::DoesNotHavePermission); + + bonded_pool.commission.try_update_max(max_commission)?; + bonded_pool.put(); + + Self::deposit_event(Event::::PoolMaxCommissionUpdated { pool_id, max_commission }); + Ok(()) + } + + /// Set the commission change rate for a pool. + /// + /// The dispatch origin of this call must be signed by the `root` role of the pool. + #[pallet::call_index(16)] + #[pallet::weight(T::WeightInfo::set_commission_change_rate())] + pub fn set_commission_change_rate( + origin: OriginFor, + pool_id: PoolId, + change_rate: CommissionChangeRate, + ) -> DispatchResult { + let who = ensure_signed(origin)?; + let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; + ensure!(bonded_pool.can_set_commission(&who), Error::::DoesNotHavePermission); + + bonded_pool.commission.try_update_change_rate(change_rate)?; + bonded_pool.put(); + + Self::deposit_event(Event::::PoolCommissionChangeRateUpdated { + pool_id, + change_rate, + }); + Ok(()) + } } #[pallet::hooks] @@ -2320,7 +2646,7 @@ impl Pallet { let current_reward_counter = reward_pool.current_reward_counter(bonded_pool.id, bonded_pool.points)?; - let pending_rewards = member.pending_rewards(current_reward_counter)?; + let mut pending_rewards = member.pending_rewards(current_reward_counter)?; if pending_rewards.is_zero() { return Ok(pending_rewards) @@ -2330,20 +2656,45 @@ impl Pallet { member.last_recorded_reward_counter = current_reward_counter; reward_pool.register_claimed_reward(pending_rewards); - // Transfer payout to the member. - T::Currency::transfer( - &bonded_pool.reward_account(), - &member_account, - pending_rewards, - // defensive: the depositor has put existential deposit into the pool and it stays - // untouched, reward account shall not die. - ExistenceRequirement::AllowDeath, - )?; + // Gets the commission percentage and payee to be paid if commission has been set. + // Otherwise, `None` is returned. + let maybe_commission = &bonded_pool.commission.maybe_commission_and_payee(&pending_rewards); + + if let Some((pool_commission, payee)) = maybe_commission { + // Deduct any outstanding commission from the reward being claimed. + pending_rewards = pending_rewards.saturating_sub(*pool_commission); + + // Send any non-zero `pool_commission` to the commission `payee`. + if pool_commission > &Zero::zero() { + T::Currency::transfer( + &bonded_pool.reward_account(), + &payee, + *pool_commission, + ExistenceRequirement::KeepAlive, + )?; + } + } + + // Transfer remaining payout to the member. + // + // In scenarios where commission is 100%, `pending_rewards` will be zero. We therefore check + // if there is a non-zero payout to be transferred. + if pending_rewards > Zero::zero() { + T::Currency::transfer( + &bonded_pool.reward_account(), + &member_account, + pending_rewards, + // defensive: the depositor has put existential deposit into the pool and it stays + // untouched, reward account shall not die. + ExistenceRequirement::KeepAlive, + )?; + } Self::deposit_event(Event::::PaidOut { member: member_account.clone(), pool_id: member.pool_id, payout: pending_rewards, + commission: maybe_commission.as_ref().map(|(c, _)| *c).unwrap_or(Zero::zero()), }); Ok(pending_rewards) @@ -2607,4 +2958,4 @@ impl OnStakerSlash> for Pallet { SubPoolsStorage::::insert(pool_id, sub_pools); } } -} +} \ No newline at end of file diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index b73141c95f72c..01ea0ccb8b2a8 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -52,9 +52,12 @@ pub mod v1 { impl OldBondedPoolInner { fn migrate_to_v1(self) -> BondedPoolInner { + // Note: `commission` field not introduced to `BondedPoolInner` until + // migration 4. BondedPoolInner { - member_counter: self.member_counter, points: self.points, + commission: Commission::default(), + member_counter: self.member_counter, state: self.state, roles: self.roles.migrate_to_v1(), } @@ -283,6 +286,7 @@ pub mod v2 { member: who.clone(), pool_id: id, payout: last_claim, + commission: Zero::zero(), }); }); @@ -449,3 +453,88 @@ pub mod v3 { } } } + +pub mod v4 { + use super::*; + + #[derive(Decode)] + pub struct OldBondedPoolInner { + pub points: BalanceOf, + pub state: PoolState, + pub member_counter: u32, + pub roles: PoolRoles, + } + + impl OldBondedPoolInner { + fn migrate_to_v4(self) -> BondedPoolInner { + BondedPoolInner { + commission: Commission::default(), + member_counter: self.member_counter, + points: self.points, + state: self.state, + roles: self.roles, + } + } + } + + /// This migration adds a `commission` field to every `BondedPoolInner`, if + /// any. + pub struct MigrateToV4(sp_std::marker::PhantomData); + impl OnRuntimeUpgrade for MigrateToV4 { + fn on_runtime_upgrade() -> Weight { + let current = Pallet::::current_storage_version(); + let onchain = Pallet::::on_chain_storage_version(); + + log!( + info, + "Running migration with current storage version {:?} / onchain {:?}", + current, + onchain + ); + + if current == 4 && onchain == 3 { + GlobalMaxCommission::::set(Some(Zero::zero())); + log!(info, "Set initial global max commission to 0%"); + + let mut translated = 0u64; + BondedPools::::translate::, _>(|_key, old_value| { + translated.saturating_inc(); + Some(old_value.migrate_to_v4()) + }); + + current.put::>(); + log!(info, "Upgraded {} pools, storage to version {:?}", translated, current); + + // reads: translated + onchain version. + // writes: translated + current.put + initial global commission. + T::DbWeight::get().reads_writes(translated + 1, translated + 2) + } else { + log!(info, "Migration did not execute. This probably should be removed"); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + ensure!( + Pallet::::current_storage_version() > Pallet::::on_chain_storage_version(), + "the on_chain version is equal or more than the current one" + ); + Ok(Vec::new()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: Vec) -> Result<(), &'static str> { + // ensure all BondedPools items now contain an `inner.commission: Commission` field. + ensure!( + BondedPools::::iter().all(|(_, inner)| inner.commission.current.is_none() && + inner.commission.max.is_none() && + inner.commission.change_rate.is_none() && + inner.commission.throttle_from.is_none()), + "a commission value has been incorrectly set" + ); + ensure!(Pallet::::on_chain_storage_version() == 4, "wrong storage version"); + Ok(()) + } + } +} \ No newline at end of file diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 99d521df3241b..8108dcac97e94 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -251,11 +251,17 @@ pub struct ExtBuilder { members: Vec<(AccountId, Balance)>, max_members: Option, max_members_per_pool: Option, + global_max_commission: Option, } impl Default for ExtBuilder { fn default() -> Self { - Self { members: Default::default(), max_members: Some(4), max_members_per_pool: Some(3) } + Self { + members: Default::default(), + max_members: Some(4), + max_members_per_pool: Some(3), + global_max_commission: Some(Perbill::from_percent(90)), + } } } @@ -297,6 +303,11 @@ impl ExtBuilder { self } + pub fn global_max_commission(mut self, commission: Option) -> Self { + self.global_max_commission = commission; + self + } + pub fn build(self) -> sp_io::TestExternalities { sp_tracing::try_init_simple(); let mut storage = @@ -308,6 +319,7 @@ impl ExtBuilder { max_pools: Some(2), max_members_per_pool: self.max_members_per_pool, max_members: self.max_members, + global_max_commission: self.global_max_commission, } .assimilate_storage(&mut storage); @@ -354,6 +366,23 @@ parameter_types! { storage BalancesEvents: u32 = 0; } +/// Helper to run a specified amount of blocks. +pub fn run_blocks(n: u64) { + let current_block = System::block_number(); + run_to_block(n + current_block); +} + +/// Helper to run to a specific block. +pub fn run_to_block(n: u64) { + let current_block = System::block_number(); + assert!(n > current_block); + while System::block_number() < n { + Pools::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + Pools::on_initialize(System::block_number()); + } +} + /// All events of this pallet. pub fn pool_events_since_last_call() -> Vec> { let events = System::events() @@ -406,4 +435,4 @@ mod test { assert_eq!(BalanceToU256::convert(0u32.into()), U256::zero()); assert_eq!(BalanceToU256::convert(Balance::max_value()), Balance::max_value().into()) } -} +} \ No newline at end of file diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 7d5d418bbf2c8..a85bca50b5535 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -3,17 +3,17 @@ // Copyright (C) 2020-2022 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 +// 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 +// 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. +// 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. use super::*; use crate::{mock::*, Event}; @@ -55,10 +55,11 @@ fn test_setup_works() { BondedPool:: { id: last_pool, inner: BondedPoolInner { - state: PoolState::Open, - points: 10, + commission: Commission::default(), member_counter: 1, - roles: DEFAULT_ROLES + points: 10, + roles: DEFAULT_ROLES, + state: PoolState::Open, }, } ); @@ -98,10 +99,11 @@ mod bonded_pool { let mut bonded_pool = BondedPool:: { id: 123123, inner: BondedPoolInner { - state: PoolState::Open, - points: 100, + commission: Commission::default(), member_counter: 1, + points: 100, roles: DEFAULT_ROLES, + state: PoolState::Open, }, }; @@ -153,10 +155,11 @@ mod bonded_pool { let mut bonded_pool = BondedPool:: { id: 123123, inner: BondedPoolInner { - state: PoolState::Open, - points: 100, + commission: Commission::default(), member_counter: 1, + points: 100, roles: DEFAULT_ROLES, + state: PoolState::Open, }, }; @@ -201,10 +204,11 @@ mod bonded_pool { let pool = BondedPool:: { id: 123, inner: BondedPoolInner { - state: PoolState::Open, - points: 100, + commission: Commission::default(), member_counter: 1, + points: 100, roles: DEFAULT_ROLES, + state: PoolState::Open, }, }; @@ -430,10 +434,11 @@ mod join { let bonded = |points, member_counter| BondedPool:: { id: 1, inner: BondedPoolInner { - state: PoolState::Open, - points, + commission: Commission::default(), member_counter, + points, roles: DEFAULT_ROLES, + state: PoolState::Open, }, }; ExtBuilder::default().with_check(0).build_and_execute(|| { @@ -513,10 +518,11 @@ mod join { BondedPool:: { id: 123, inner: BondedPoolInner { + commission: Commission::default(), member_counter: 1, - state: PoolState::Open, points: 100, roles: DEFAULT_ROLES, + state: PoolState::Open, }, } .put(); @@ -582,10 +588,11 @@ mod join { BondedPool:: { id: 123, inner: BondedPoolInner { - state: PoolState::Open, - points: 100, + commission: Commission::default(), member_counter: 1, + points: 100, roles: DEFAULT_ROLES, + state: PoolState::Open, }, } .put(); @@ -708,7 +715,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 },] ); // last recorded reward counter at the time of this member's payout is 1 assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 1)); @@ -724,7 +731,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40, commission: 0 }] ); assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 1)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 50)); @@ -737,7 +744,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50, commission: 0 }] ); assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 1)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 100)); @@ -753,7 +760,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 }] ); assert_eq!(PoolMembers::::get(10).unwrap(), del_float(10, 1.5)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 105)); @@ -766,7 +773,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20, commission: 0 }] ); assert_eq!(PoolMembers::::get(40).unwrap(), del_float(40, 1.5)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 125)); @@ -783,7 +790,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50, commission: 0 }] ); assert_eq!(PoolMembers::::get(50).unwrap(), del_float(50, 2.0)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 175)); @@ -796,7 +803,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 }] ); assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 2)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 180)); @@ -813,7 +820,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40, commission: 0 }] ); // We expect a payout of 40 @@ -832,7 +839,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2, commission: 0 }] ); assert_eq!(PoolMembers::::get(10).unwrap(), del_float(10, 6.2)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 222)); @@ -845,7 +852,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188, commission: 0 }] ); assert_eq!(PoolMembers::::get(40).unwrap(), del_float(40, 6.2)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 410)); @@ -858,7 +865,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210, commission: 0 }] ); assert_eq!(PoolMembers::::get(50).unwrap(), del_float(50, 6.2)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 620)); @@ -890,6 +897,59 @@ mod claim_payout { }); } + #[test] + fn claim_payout_bounds_commission_above_global() { + ExtBuilder::default().build_and_execute(|| { + // temporarily remove global maximum so a higher commission can be set. + GlobalMaxCommission::::set(None); + + let (mut member, bonded_pool, mut reward_pool) = + Pools::get_member_with_pools(&10).unwrap(); + + // top up commission payee account to existential deposit + let _ = Balances::deposit_creating(&2, 5); + + // Set a commission pool 1 to 75%, with a payee set to `2` + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + bonded_pool.id, + Some((Perbill::from_percent(75), 2)), + )); + + // re-introduce the global maximum to 50% - 25% lower than the current commission of the + // pool. + GlobalMaxCommission::::set(Some(Perbill::from_percent(50))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(75), 2)) + } + ] + ); + + // The pool earns 10 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10)); + + assert_ok!(Pools::do_reward_payout( + &10, + &mut member, + &mut BondedPool::::get(1).unwrap(), + &mut reward_pool + )); + + // commission applied is 50%, not 75%. Has been bounded by `GlobalMaxCommission`. + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 5 },] + ); + }) + } + #[test] fn do_reward_payout_works_with_a_pool_of_1() { let del = |last_recorded_reward_counter| del_float(10, last_recorded_reward_counter); @@ -922,7 +982,7 @@ mod claim_payout { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 5 } + Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 } ] ); assert_eq!(payout, 5); @@ -940,7 +1000,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }] ); assert_eq!(payout, 10); assert_eq!(reward_pool, rew(0, 0, 15)); @@ -999,7 +1059,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }] ); assert_eq!(payout, 10); assert_eq!(del_10, del(10, 1)); @@ -1013,7 +1073,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40, commission: 0 }] ); assert_eq!(payout, 40); assert_eq!(del_40, del(40, 1)); @@ -1027,7 +1087,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50, commission: 0 }] ); assert_eq!(payout, 50); assert_eq!(del_50, del(50, 1)); @@ -1044,7 +1104,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 }] ); assert_eq!(payout, 5); assert_eq!(del_10, del_float(10, 1.5)); @@ -1058,7 +1118,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20, commission: 0 }] ); assert_eq!(payout, 20); assert_eq!(del_40, del_float(40, 1.5)); @@ -1075,7 +1135,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50, commission: 0 }] ); assert_eq!(payout, 50); assert_eq!(del_50, del_float(50, 2.0)); @@ -1089,7 +1149,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 }] ); assert_eq!(payout, 5); assert_eq!(del_10, del_float(10, 2.0)); @@ -1106,7 +1166,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40, commission: 0 }] ); assert_eq!(payout, 40); assert_eq!(del_10, del_float(10, 6.0)); @@ -1169,8 +1229,8 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 20, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10, commission: 0 }, ] ); @@ -1183,8 +1243,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10, commission: 0 }, ] ); }); @@ -1212,8 +1272,8 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 3 + 3 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 3 + 3, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3, commission: 0 }, ] ); @@ -1226,8 +1286,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 4 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 4 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 4, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 4, commission: 0 }, ] ); @@ -1240,8 +1300,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 3 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 3, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3, commission: 0 }, ] ); }); @@ -1276,9 +1336,19 @@ mod claim_payout { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 30 + 100 / 2 + 60 / 3 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 100 / 2 + 60 / 3 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 60 / 3 }, + Event::PaidOut { + member: 10, + pool_id: 1, + payout: 30 + 100 / 2 + 60 / 3, + commission: 0 + }, + Event::PaidOut { + member: 20, + pool_id: 1, + payout: 100 / 2 + 60 / 3, + commission: 0 + }, + Event::PaidOut { member: 30, pool_id: 1, payout: 60 / 3, commission: 0 }, ] ); @@ -1292,9 +1362,9 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 10, commission: 0 }, ] ); }); @@ -1377,9 +1447,9 @@ mod claim_payout { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 20 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 10 } + Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20, commission: 0 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 10, commission: 0 } ] ); @@ -1397,9 +1467,9 @@ mod claim_payout { pool_events_since_last_call(), vec![ Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: false }, - Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 40 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 40 } + Event::PaidOut { member: 10, pool_id: 1, payout: 20, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40, commission: 0 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 40, commission: 0 } ] ); }); @@ -1425,8 +1495,8 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 20 } + Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20, commission: 0 } ] ); @@ -1443,8 +1513,8 @@ mod claim_payout { pool_events_since_last_call(), vec![ Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10, era: 3 }, - Event::PaidOut { member: 10, pool_id: 1, payout: 50 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 50 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 50, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 50, commission: 0 }, ] ); }); @@ -1474,8 +1544,8 @@ mod claim_payout { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 20 } + Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20, commission: 0 } ] ); @@ -1489,8 +1559,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 40 } + Event::PaidOut { member: 10, pool_id: 1, payout: 20, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40, commission: 0 } ] ); @@ -1504,8 +1574,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 40 } + Event::PaidOut { member: 10, pool_id: 1, payout: 20, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40, commission: 0 } ] ); @@ -1514,7 +1584,12 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 30, pool_id: 1, payout: 10 + 20 + 20 }] + vec![Event::PaidOut { + member: 30, + pool_id: 1, + payout: 10 + 20 + 20, + commission: 0 + }] ); }); } @@ -1539,7 +1614,7 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 } + Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 } ] ); @@ -1557,9 +1632,9 @@ mod claim_payout { pool_events_since_last_call(), vec![ // 20 + 40, which means the extra amount they bonded did not impact us. - Event::PaidOut { member: 20, pool_id: 1, payout: 60 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 60, commission: 0 }, Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: false }, - Event::PaidOut { member: 10, pool_id: 1, payout: 20 } + Event::PaidOut { member: 10, pool_id: 1, payout: 20, commission: 0 } ] ); @@ -1573,8 +1648,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 15 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 45 } + Event::PaidOut { member: 10, pool_id: 1, payout: 15, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 45, commission: 0 } ] ); }); @@ -1641,7 +1716,7 @@ mod claim_payout { Event::Bonded { member: 20, pool_id: 2, bonded: 10, joined: true }, Event::Created { depositor: 30, pool_id: 3 }, Event::Bonded { member: 30, pool_id: 3, bonded: 10, joined: true }, - Event::PaidOut { member: 30, pool_id: 3, payout: 10 } + Event::PaidOut { member: 30, pool_id: 3, payout: 10, commission: 0 } ] ); }) @@ -1788,9 +1863,9 @@ mod claim_payout { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false }, - Event::PaidOut { member: 10, pool_id: 1, payout: 15 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 15, commission: 0 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false }, - Event::PaidOut { member: 20, pool_id: 1, payout: 15 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 15, commission: 0 }, Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: false } ] ); @@ -1820,7 +1895,7 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }] ); } @@ -1837,7 +1912,7 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 20, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20, commission: 0 }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: false } ] ); @@ -1934,12 +2009,12 @@ mod claim_payout { Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, Event::Bonded { member: 30, pool_id: 1, bonded: 20, joined: true }, Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10, era: 3 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 15 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 15, commission: 0 }, Event::Unbonded { member: 30, pool_id: 1, balance: 10, points: 10, era: 3 }, Event::Unbonded { member: 30, pool_id: 1, balance: 5, points: 5, era: 3 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 7 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 7, commission: 0 }, Event::Unbonded { member: 20, pool_id: 1, balance: 5, points: 5, era: 3 }, - Event::PaidOut { member: 10, pool_id: 1, payout: 7 } + Event::PaidOut { member: 10, pool_id: 1, payout: 7, commission: 0 } ] ); }) @@ -1970,8 +2045,8 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 13 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 26 } + Event::PaidOut { member: 10, pool_id: 1, payout: 13, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 26, commission: 0 } ] ); @@ -2056,10 +2131,10 @@ mod claim_payout { bonded: 5000000000000000, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 100000000 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 150000000 }, - Event::PaidOut { member: 21, pool_id: 1, payout: 250000000 }, - Event::PaidOut { member: 22, pool_id: 1, payout: 500000000 } + Event::PaidOut { member: 10, pool_id: 1, payout: 100000000, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 150000000, commission: 0 }, + Event::PaidOut { member: 21, pool_id: 1, payout: 250000000, commission: 0 }, + Event::PaidOut { member: 22, pool_id: 1, payout: 500000000, commission: 0 } ] ); }) @@ -2359,10 +2434,11 @@ mod unbond { BondedPool { id: 1, inner: BondedPoolInner { - state: PoolState::Destroying, - points: 0, + commission: Commission::default(), member_counter: 1, + points: 0, roles: DEFAULT_ROLES, + state: PoolState::Destroying, } } ); @@ -2395,10 +2471,11 @@ mod unbond { BondedPool { id: 1, inner: BondedPoolInner { - state: PoolState::Open, - points: 560, + commission: Commission::default(), member_counter: 3, + points: 560, roles: DEFAULT_ROLES, + state: PoolState::Open, } } ); @@ -2409,7 +2486,7 @@ mod unbond { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, - Event::PaidOut { member: 40, pool_id: 1, payout: 40 }, + Event::PaidOut { member: 40, pool_id: 1, payout: 40, commission: 0 }, Event::Unbonded { member: 40, pool_id: 1, points: 6, balance: 6, era: 3 } ] ); @@ -2435,10 +2512,11 @@ mod unbond { BondedPool { id: 1, inner: BondedPoolInner { - state: PoolState::Destroying, - points: 10, + commission: Commission::default(), member_counter: 3, - roles: DEFAULT_ROLES + points: 10, + roles: DEFAULT_ROLES, + state: PoolState::Destroying, } } ); @@ -2451,7 +2529,7 @@ mod unbond { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 550, pool_id: 1, payout: 550 }, + Event::PaidOut { member: 550, pool_id: 1, payout: 550, commission: 0 }, Event::Unbonded { member: 550, pool_id: 1, @@ -2478,10 +2556,11 @@ mod unbond { BondedPool { id: 1, inner: BondedPoolInner { - state: PoolState::Destroying, - points: 0, + commission: Commission::default(), member_counter: 1, - roles: DEFAULT_ROLES + points: 0, + roles: DEFAULT_ROLES, + state: PoolState::Destroying, } } ); @@ -2495,7 +2574,7 @@ mod unbond { Event::MemberRemoved { pool_id: 1, member: 40 }, Event::Withdrawn { member: 550, pool_id: 1, points: 92, balance: 92 }, Event::MemberRemoved { pool_id: 1, member: 550 }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2, era: 6 } ] ); @@ -2606,10 +2685,11 @@ mod unbond { BondedPool { id: 1, inner: BondedPoolInner { + commission: Commission::default(), + member_counter: 3, + points: 10, // Only 10 points because 200 + 100 was unbonded roles: DEFAULT_ROLES, state: PoolState::Blocked, - points: 10, // Only 10 points because 200 + 100 was unbonded - member_counter: 3, } } ); @@ -2756,10 +2836,11 @@ mod unbond { BondedPool:: { id: 1, inner: BondedPoolInner { - state: PoolState::Open, - points: 10, + commission: Commission::default(), member_counter: 1, + points: 10, roles: DEFAULT_ROLES, + state: PoolState::Open, }, } .put(); @@ -3031,7 +3112,7 @@ mod unbond { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10, commission: 0 }, Event::Unbonded { member: 20, pool_id: 1, balance: 2, points: 2, era: 3 } ] ); @@ -3047,7 +3128,7 @@ mod unbond { pool_events_since_last_call(), vec![ // 2/3 of ed, which is 20's share. - Event::PaidOut { member: 20, pool_id: 1, payout: 6 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 6, commission: 0 }, Event::Unbonded { member: 20, pool_id: 1, points: 3, balance: 3, era: 4 } ] ); @@ -3062,7 +3143,7 @@ mod unbond { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3, commission: 0 }, Event::Unbonded { member: 20, pool_id: 1, points: 5, balance: 5, era: 5 } ] ); @@ -3468,10 +3549,11 @@ mod withdraw_unbonded { BondedPool { id: 1, inner: BondedPoolInner { + commission: Commission::default(), + member_counter: 3, points: 10, + roles: DEFAULT_ROLES, state: PoolState::Open, - member_counter: 3, - roles: DEFAULT_ROLES } } ); @@ -3548,10 +3630,11 @@ mod withdraw_unbonded { BondedPool { id: 1, inner: BondedPoolInner { - points: 10, - state: PoolState::Open, + commission: Commission::default(), member_counter: 2, + points: 10, roles: DEFAULT_ROLES, + state: PoolState::Open, } } ); @@ -4101,15 +4184,16 @@ mod create { BondedPool { id: 2, inner: BondedPoolInner { + commission: Commission::default(), points: StakingMock::minimum_nominator_bond(), member_counter: 1, - state: PoolState::Open, roles: PoolRoles { depositor: 11, root: Some(123), nominator: Some(456), state_toggler: Some(789) - } + }, + state: PoolState::Open, } } ); @@ -4165,10 +4249,11 @@ mod create { BondedPool:: { id: 2, inner: BondedPoolInner { - state: PoolState::Open, - points: 10, + commission: Commission::default(), member_counter: 1, + points: 10, roles: DEFAULT_ROLES, + state: PoolState::Open, }, } .put(); @@ -4411,12 +4496,14 @@ mod set_configs { ConfigOp::Set(3u32), ConfigOp::Set(4u32), ConfigOp::Set(5u32), + ConfigOp::Set(Perbill::from_percent(6)) )); assert_eq!(MinJoinBond::::get(), 1); assert_eq!(MinCreateBond::::get(), 2); assert_eq!(MaxPools::::get(), Some(3)); assert_eq!(MaxPoolMembers::::get(), Some(4)); assert_eq!(MaxPoolMembersPerPool::::get(), Some(5)); + assert_eq!(GlobalMaxCommission::::get(), Some(Perbill::from_percent(6))); // Noop does nothing assert_storage_noop!(assert_ok!(Pools::set_configs( @@ -4426,6 +4513,7 @@ mod set_configs { ConfigOp::Noop, ConfigOp::Noop, ConfigOp::Noop, + ConfigOp::Noop, ))); // Removing works @@ -4436,12 +4524,14 @@ mod set_configs { ConfigOp::Remove, ConfigOp::Remove, ConfigOp::Remove, + ConfigOp::Remove, )); assert_eq!(MinJoinBond::::get(), 0); assert_eq!(MinCreateBond::::get(), 0); assert_eq!(MaxPools::::get(), None); assert_eq!(MaxPoolMembers::::get(), None); assert_eq!(MaxPoolMembersPerPool::::get(), None); + assert_eq!(GlobalMaxCommission::::get(), None); }); } } @@ -4520,7 +4610,12 @@ mod bond_extra { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: claimable_reward }, + Event::PaidOut { + member: 10, + pool_id: 1, + payout: claimable_reward, + commission: 0 + }, Event::Bonded { member: 10, pool_id: 1, @@ -4575,9 +4670,9 @@ mod bond_extra { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 1 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 1, commission: 0 }, Event::Bonded { member: 10, pool_id: 1, bonded: 1, joined: false }, - Event::PaidOut { member: 20, pool_id: 1, payout: 2 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 2, commission: 0 }, Event::Bonded { member: 20, pool_id: 1, bonded: 2, joined: false } ] ); @@ -4825,7 +4920,7 @@ mod reward_counter_precision { assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1173 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1173, commission: 0 }] ); }) } @@ -4858,8 +4953,18 @@ mod reward_counter_precision { pool_events_since_last_call(), vec![ Event::Bonded { member: 20, pool_id: 1, bonded: 5000000000000, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 7333333333333333333 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 3666666666666666666 } + Event::PaidOut { + member: 10, + pool_id: 1, + payout: 7333333333333333333, + commission: 0 + }, + Event::PaidOut { + member: 20, + pool_id: 1, + payout: 3666666666666666666, + commission: 0 + } ] ); }) @@ -4910,7 +5015,12 @@ mod reward_counter_precision { assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 15937424600999999996 }] + vec![Event::PaidOut { + member: 10, + pool_id: 1, + payout: 15937424600999999996, + commission: 0 + }] ); // now let a small member join with 10 DOTs. @@ -4926,7 +5036,7 @@ mod reward_counter_precision { vec![ Event::Bonded { member: 30, pool_id: 1, bonded: 100000000000, joined: true }, // quite small, but working fine. - Event::PaidOut { member: 30, pool_id: 1, payout: 38 } + Event::PaidOut { member: 30, pool_id: 1, payout: 38, commission: 0 } ] ); }) @@ -5006,7 +5116,7 @@ mod reward_counter_precision { bonded: 100000000000, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 9999997 } + Event::PaidOut { member: 10, pool_id: 1, payout: 9999997, commission: 0 } ] ); @@ -5019,7 +5129,12 @@ mod reward_counter_precision { assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10000000 }] + vec![Event::PaidOut { + member: 10, + pool_id: 1, + payout: 10000000, + commission: 0 + }] ); // earn some more rewards, this time 20 can also claim. @@ -5032,8 +5147,8 @@ mod reward_counter_precision { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 10000000 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 1 } + Event::PaidOut { member: 10, pool_id: 1, payout: 10000000, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 1, commission: 0 } ] ); }); @@ -5082,7 +5197,7 @@ mod reward_counter_precision { bonded: 100000000000, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 9999997 } + Event::PaidOut { member: 10, pool_id: 1, payout: 9999997, commission: 0 } ] ); @@ -5100,3 +5215,1000 @@ mod reward_counter_precision { }); } } + +mod commission { + use super::*; + + #[test] + fn set_commission_works() { + ExtBuilder::default().build_and_execute(|| { + // Set a commission for pool 1. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(50), 900)) + )); + + let commission_as_percent = BondedPool::::get(1) + .unwrap() + .commission + .current + .as_ref() + .map(|(x, _)| *x) + .unwrap_or(Perbill::zero()); + assert_eq!(commission_as_percent, Perbill::from_percent(50)); + + // update commission only. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(25), 900)) + )); + + // update payee only. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(25), 901)) + )); + + // remove the commission for pool 1. + assert_ok!(Pools::set_commission(RuntimeOrigin::signed(900), 1, None)); + + // test whether supplying a 0% commission along with a payee results in a None `current` + // being inserted. + // + // set an initial commission of 10% + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(10), 900)) + )); + // set the commission to 0% + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(0), 900)) + )); + // commssion current should now be None, and `throttle_from` the current block. + assert_eq!( + BondedPool::::get(1).unwrap().commission, + Commission { current: None, max: None, change_rate: None, throttle_from: Some(1) } + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(50), 900)) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(25), 900)) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(25), 901)) + }, + Event::PoolCommissionUpdated { pool_id: 1, current: None }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(10), 900)) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(0), 900)) + } + ] + ); + }); + } + + #[test] + fn set_commission_handles_errors() { + ExtBuilder::default().build_and_execute(|| { + // Provided pool does not exist + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(900), + 9999, + Some((Perbill::from_percent(1), 900)), + ), + Error::::PoolNotFound + ); + // Sender does not have permission to set commission + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(1), + 1, + Some((Perbill::from_percent(5), 900)), + ), + Error::::DoesNotHavePermission + ); + + // Commission clamps to 100% where > 100% is provided. + // + // attempt to set a commission at 101%. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(101), 900)), + )); + // ensure the commission actually set was at 100%. + assert_eq!( + BondedPool::::get(1).unwrap().commission, + Commission { + current: Some((Perbill::from_percent(100), 900)), + max: None, + change_rate: None, + throttle_from: Some(1_u64), + } + ); + + // Set the initial commission to 5%. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(5), 900)), + )); + + // Change rate test. + // + // Set a change rate to be a +1% commission increase every 2 blocks. + assert_ok!(Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { max_increase: Perbill::from_percent(1), min_delay: 2_u64 } + )); + assert_eq!( + BondedPool::::get(1).unwrap().commission, + Commission { + current: Some((Perbill::from_percent(5), 900)), + max: None, + change_rate: Some(CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 2_u64 + }), + throttle_from: Some(1_u64), + } + ); + + // Now try to increase commission to 10% (5% increase). This should be throttled. + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(10), 900)) + ), + Error::::CommissionChangeThrottled + ); + + // Run to block 3 + run_blocks(2); + + // Now try to increase commission by 1% and provide an initial payee. This should + // succeed and set the `throttle_from` field. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(6), 900)) + )); + assert_eq!( + BondedPool::::get(1).unwrap().commission, + Commission { + current: Some((Perbill::from_percent(6), 900)), + max: None, + change_rate: Some(CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 2_u64 + }), + throttle_from: Some(3_u64), + } + ); + + // Attempt to increase the commission an additional 1% (now 7%). this will fail as + // `throttle_from` is now the current block. At least 2 blocks need to pass before we + // can set commission again. + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(7), 900)) + ), + Error::::CommissionChangeThrottled + ); + + // Run 2 blocks into the future, to block 3. + run_blocks(2); + + // Can now successfully increase the commission again, to 7%. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(7), 900)), + )); + + // Run 2 blocks into the future, to block 5. + run_blocks(2); + + // Now surpassed the `min_delay` threshold, but the `max_increase` threshold is + // still at play. An attempted commission change now to 8% (+2% increase) should fail. + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(9), 900)), + ), + Error::::CommissionChangeThrottled + ); + + // Now set a max commission to the current 5%. This will also update the current + // commission to 5%. + assert_ok!(Pools::set_commission_max( + RuntimeOrigin::signed(900), + 1, + Perbill::from_percent(5) + )); + assert_eq!( + BondedPool::::get(1).unwrap().commission, + Commission { + current: Some((Perbill::from_percent(5), 900)), + max: Some(Perbill::from_percent(5)), + change_rate: Some(CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 2 + }), + throttle_from: Some(7) + } + ); + + // Run 2 blocks into the future so we are eligible to update commission again. + run_blocks(2); + + // Now attempt again to increase the commission by 1%, to 6%. This is within the + // change rate allowance, but `max_commission` will now prevent us from going any + // higher. + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(6), 900)), + ), + Error::::CommissionExceedsMaximum + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(100), 900)) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(5), 900)) + }, + Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 2 + } + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(6), 900)) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(7), 900)) + }, + Event::PoolMaxCommissionUpdated { + pool_id: 1, + max_commission: Perbill::from_percent(5) + } + ] + ); + }); + } + + #[test] + fn set_commission_max_works_with_error_tests() { + ExtBuilder::default().build_and_execute(|| { + // Provided pool does not exist + assert_noop!( + Pools::set_commission_max( + RuntimeOrigin::signed(900), + 9999, + Perbill::from_percent(1) + ), + Error::::PoolNotFound + ); + // Sender does not have permission to set commission + assert_noop!( + Pools::set_commission_max(RuntimeOrigin::signed(1), 1, Perbill::from_percent(5)), + Error::::DoesNotHavePermission + ); + + // Max commission clamps to 100% where > 100% is provided. + // + // attempt to set a commission at 101%. + + assert_ok!(Pools::set_commission_max( + RuntimeOrigin::signed(900), + 1, + Perbill::from_percent(101) + )); + // ensure max commission actually set was at 100%. + assert_eq!( + BondedPool::::get(1).unwrap().commission, + Commission { + current: None, + max: Some(Perbill::from_percent(100)), + change_rate: None, + throttle_from: None, + } + ); + + // Set a max commission commission pool 1 to 80% + assert_ok!(Pools::set_commission_max( + RuntimeOrigin::signed(900), + 1, + Perbill::from_percent(80) + )); + assert_eq!( + BondedPools::::get(1).unwrap().commission.max, + Some(Perbill::from_percent(80)) + ); + + // We attempt to increase the max commission to 90%, but increasing is + // disallowed due to pool's max commission. + assert_noop!( + Pools::set_commission_max(RuntimeOrigin::signed(900), 1, Perbill::from_percent(90)), + Error::::MaxCommissionRestricted + ); + + // We will now set a commission to 75% and then amend the max commission + // to 50%. The max commission change should decrease the current + // commission to 50%. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(75), 900)) + )); + assert_ok!(Pools::set_commission_max( + RuntimeOrigin::signed(900), + 1, + Perbill::from_percent(50) + )); + assert_eq!( + BondedPools::::get(1).unwrap().commission, + Commission { + current: Some((Perbill::from_percent(50), 900)), + max: Some(Perbill::from_percent(50)), + change_rate: None, + throttle_from: Some(1), + } + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolMaxCommissionUpdated { + pool_id: 1, + max_commission: Perbill::from_percent(100) + }, + Event::PoolMaxCommissionUpdated { + pool_id: 1, + max_commission: Perbill::from_percent(80) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(75), 900)), + }, + Event::PoolMaxCommissionUpdated { + pool_id: 1, + max_commission: Perbill::from_percent(50) + } + ] + ); + }); + } + + #[test] + fn max_commission_after_current_commission_works() { + ExtBuilder::default().build_and_execute(|| { + // set pool commission to 50% first. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(50), 900)), + )); + + // now set the max commission to something less than the current + // commission. + assert_ok!(Pools::set_commission_max( + RuntimeOrigin::signed(900), + 1, + Perbill::from_percent(25) + )); + + // the current commission should now be 25%. + assert_eq!( + BondedPools::::get(1).unwrap().commission, + Commission { + current: Some((Perbill::from_percent(25), 900)), + max: Some(Perbill::from_percent(25)), + change_rate: None, + throttle_from: Some(1), + } + ); + }) + } + + #[test] + fn set_commission_change_rate_works_with_errors() { + ExtBuilder::default().build_and_execute(|| { + // Provided pool does not exist + assert_noop!( + Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 9999, + CommissionChangeRate { + max_increase: Perbill::from_percent(5), + min_delay: 1000_u64 + } + ), + Error::::PoolNotFound + ); + // Sender does not have permission to set commission + assert_noop!( + Pools::set_commission_change_rate( + RuntimeOrigin::signed(1), + 1, + CommissionChangeRate { + max_increase: Perbill::from_percent(5), + min_delay: 1000_u64 + } + ), + Error::::DoesNotHavePermission + ); + + // Set a commission change rate for pool 1 + assert_ok!(Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { max_increase: Perbill::from_percent(5), min_delay: 10_u64 } + )); + assert_eq!( + BondedPools::::get(1).unwrap().commission.change_rate, + Some(CommissionChangeRate { + max_increase: Perbill::from_percent(5), + min_delay: 10_u64 + }) + ); + + // We now try to half the min_delay - this will be disallowed. A greater delay between + // commission changes is seen as more restrictive. + assert_noop!( + Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { + max_increase: Perbill::from_percent(5), + min_delay: 5_u64 + } + ), + Error::::CommissionChangeRateNotAllowed + ); + + // We now try to increase the allowed max_increase - this will fail. A smaller allowed + // commission change is seen as more restrictive. + assert_noop!( + Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { + max_increase: Perbill::from_percent(10), + min_delay: 10_u64 + } + ), + Error::::CommissionChangeRateNotAllowed + ); + + // Successful more restrictive change of min_delay with the current max_increase + assert_ok!(Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { max_increase: Perbill::from_percent(5), min_delay: 20_u64 } + )); + + // Successful more restrictive change of max_increase with the current min_delay + assert_ok!(Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { max_increase: Perbill::from_percent(4), min_delay: 20_u64 } + )); + + // Successful more restrictive change of both max_increase and min_delay + assert_ok!(Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { max_increase: Perbill::from_percent(3), min_delay: 30_u64 } + )); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(5), + min_delay: 10 + } + }, + Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(5), + min_delay: 20 + } + }, + Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(4), + min_delay: 20 + } + }, + Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(3), + min_delay: 30 + } + } + ] + ); + }); + } + + #[test] + fn change_rate_does_not_apply_to_decreasing_commission() { + ExtBuilder::default().build_and_execute(|| { + // set initial commission of the pool to 10%. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(10), 900)) + )); + + // Set a commission change rate for pool 1, 1% every 10 blocks + assert_ok!(Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { max_increase: Perbill::from_percent(1), min_delay: 10_u64 } + )); + assert_eq!( + BondedPools::::get(1).unwrap().commission.change_rate, + Some(CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 10_u64 + }) + ); + + // run `min_delay` blocks to allow a commission update. + run_blocks(10_u64); + + // Test `max_increase`: attempt to decrease the commission by 5%. Should succeed. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(5), 900)) + )); + + // Test `min_delay`: *immediately* attempt to decrease the commission by 2%. Should + // succeed. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(3), 900)) + )); + + // run `min_delay` blocks to allow a commission update. + run_blocks(10_u64); + + // Attempt to *increase* the commission by 5%. Should fail. + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(8), 900)) + ), + Error::::CommissionChangeThrottled + ); + + // Sanity check: the resulting pool Commission state. + assert_eq!( + BondedPools::::get(1).unwrap().commission, + Commission { + current: Some((Perbill::from_percent(3), 900)), + max: None, + change_rate: Some(CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 10_u64 + }), + throttle_from: Some(11), + } + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(10), 900)) + }, + Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 10 + } + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(5), 900)) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(3), 900)) + } + ] + ); + }); + } + + #[test] + fn set_commission_max_to_zero_works() { + ExtBuilder::default().build_and_execute(|| { + // 0% max commission test. + // + // set commission max 0%. + assert_ok!(Pools::set_commission_max(RuntimeOrigin::signed(900), 1, Zero::zero())); + + // a max commission of 0% essentially freezes the current commission, even when None. + // All commission update attempts will fail. + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(1), 900)) + ), + Error::::CommissionExceedsMaximum + ); + }) + } + + #[test] + fn set_commission_change_rate_zero_max_increase_works() { + ExtBuilder::default().build_and_execute(|| { + // 0% max increase test. + // + // set commission change rate to 0% per 10 blocks + assert_ok!(Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { max_increase: Perbill::from_percent(0), min_delay: 10_u64 } + )); + + // even though there is a min delay of 10 blocks, a max increase of 0% essentially + // freezes the commission. All commission update attempts will fail. + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(1), 900)) + ), + Error::::CommissionChangeThrottled + ); + }) + } + + #[test] + fn set_commission_change_rate_zero_min_delay_works() { + ExtBuilder::default().build_and_execute(|| { + // 0% min delay test. + // + // set commission change rate to 1% with a 0 block `min_delay`. + assert_ok!(Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { max_increase: Perbill::from_percent(1), min_delay: 0_u64 } + )); + assert_eq!( + BondedPools::::get(1).unwrap().commission, + Commission { + current: None, + max: None, + change_rate: Some(CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 0 + }), + throttle_from: Some(1) + } + ); + + // since there is no min delay, we should be able to immediately set the commission. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(1), 900)) + )); + + // sanity check: increasing again to more than +1% will fail. + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(3), 900)) + ), + Error::::CommissionChangeThrottled + ); + }) + } + + #[test] + fn set_commission_change_rate_zero_value_works() { + ExtBuilder::default().build_and_execute(|| { + // Check zero values play nice. 0 `min_delay` and 0% max_increase test. + // + // set commission change rate to 0% per 0 blocks. + assert_ok!(Pools::set_commission_change_rate( + RuntimeOrigin::signed(900), + 1, + CommissionChangeRate { max_increase: Perbill::from_percent(0), min_delay: 0_u64 } + )); + + // even though there is no min delay, a max increase of 0% essentially freezes the + // commission. All commission update attempts will fail. + assert_noop!( + Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(1), 900)) + ), + Error::::CommissionChangeThrottled + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(0), + min_delay: 0_u64 + } + } + ] + ); + }) + } + + #[test] + fn do_reward_payout_with_various_commissions() { + ExtBuilder::default().build_and_execute(|| { + let (mut member, bonded_pool, mut reward_pool) = + Pools::get_member_with_pools(&10).unwrap(); + + // top up commission payee account to existential deposit + let _ = Balances::deposit_creating(&2, 5); + + // Set a commission pool 1 to 33%, with a payee set to `2` + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + bonded_pool.id, + Some((Perbill::from_percent(33), 2)), + )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(33), 2)) + }, + ] + ); + + // The pool earns 10 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10)); + + assert_ok!(Pools::do_reward_payout( + &10, + &mut member, + &mut BondedPool::::get(1).unwrap(), + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 7, commission: 3 },] + ); + + // The pool earns 17 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 17)); + assert_ok!(Pools::do_reward_payout( + &10, + &mut member, + &mut BondedPool::::get(1).unwrap(), + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 11, commission: 6 },] + ); + + // The pool earns 50 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); + assert_ok!(Pools::do_reward_payout( + &10, + &mut member, + &mut BondedPool::::get(1).unwrap(), + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 34, commission: 16 },] + ); + + // The pool earns 10439 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10439)); + assert_ok!(Pools::do_reward_payout( + &10, + &mut member, + &mut BondedPool::::get(1).unwrap(), + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 6994, commission: 3445 },] + ); + }) + } + + #[test] + fn do_reward_payout_with_100_percent_commission() { + ExtBuilder::default().build_and_execute(|| { + // turn off GlobalMaxCommission for this test. + GlobalMaxCommission::::set(None); + + let (mut member, bonded_pool, mut reward_pool) = + Pools::get_member_with_pools(&10).unwrap(); + + // top up commission payee account to existential deposit + let _ = Balances::deposit_creating(&2, 5); + + // Set a commission pool 1 to 100%, with a payee set to `2` + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + bonded_pool.id, + Some((Perbill::from_percent(100), 2)), + )); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(100), 2)) + } + ] + ); + + // The pool earns 10 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10)); + + // Ensure the commission equals the total amount of points. + let maybe_commission = &BondedPools::::get(1) + .unwrap() + .commission + .maybe_commission_and_payee(&10); + assert_eq!(*maybe_commission, Some((10_u128, 2_u128))); + + // execute the payout + assert_ok!(Pools::do_reward_payout( + &10, + &mut member, + &mut BondedPool::::get(1).unwrap(), + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 0, commission: 10 },] + ); + }) + } + + #[test] + fn global_max_prevents_100_percent_commission_payout() { + ExtBuilder::default().build_and_execute(|| { + // Note: GlobalMaxCommission is set at 90%. + + let (mut member, bonded_pool, mut reward_pool) = + Pools::get_member_with_pools(&10).unwrap(); + + // top up the commission payee account to existential deposit + let _ = Balances::deposit_creating(&2, 5); + + // Set a commission pool 1 to 100%, with a payee set to `2` + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + bonded_pool.id, + Some((Perbill::from_percent(100), 2)), + )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(100), 2)) + } + ] + ); + + // The pool earns 10 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10)); + + // Ensure the commission equals 90% of the total points. + let maybe_commission = &BondedPools::::get(1) + .unwrap() + .commission + .maybe_commission_and_payee(&10); + assert_eq!(*maybe_commission, Some((9_u128, 2_u128))); + + // execute the payout + assert_ok!(Pools::do_reward_payout( + &10, + &mut member, + &mut BondedPool::::get(1).unwrap(), + &mut reward_pool + )); + + // Confirm the commission was only 9 points out of 10 points, and the payout was 1 out + // of 10 points, reflecting the 90% global max commission. + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1, commission: 9 },] + ); + }) + } +} \ No newline at end of file diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index 1062b1749d417..2dc3611737e13 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -1,42 +1,32 @@ -// This file is part of Substrate. - -// Copyright (C) 2022 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. //! Autogenerated weights for pallet_nomination_pools //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-11-07, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `bm2`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2022-12-27, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Rosss-MacBook-Pro-2.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/production/substrate +// target/release/substrate // benchmark // pallet -// --chain=dev -// --steps=50 -// --repeat=20 -// --pallet=pallet_nomination_pools -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=./frame/nomination-pools/src/weights.rs -// --header=./HEADER-APACHE2 -// --template=./.maintain/frame-weight-template.hbs +// --execution +// wasm +// --wasm-execution +// compiled +// --dev +// --pallet +// pallet-nomination-pools +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --output +// frame/nomination-pools/src/weights.rs +// --template +// .maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -62,6 +52,9 @@ pub trait WeightInfo { fn set_configs() -> Weight; fn update_roles() -> Weight; fn chill() -> Weight; + fn set_commission() -> Weight; + fn set_commission_max() -> Weight; + fn set_commission_change_rate() -> Weight; } /// Weights for pallet_nomination_pools using the Substrate node and recommended hardware. @@ -81,10 +74,10 @@ impl WeightInfo for SubstrateWeight { // Storage: VoterList ListNodes (r:3 w:3) // Storage: VoterList ListBags (r:2 w:2) fn join() -> Weight { - // Minimum execution time: 159_948 nanoseconds. - Weight::from_ref_time(161_133_000 as u64) - .saturating_add(T::DbWeight::get().reads(17 as u64)) - .saturating_add(T::DbWeight::get().writes(12 as u64)) + // Minimum execution time: 142_000 nanoseconds. + Weight::from_ref_time(145_000_000) + .saturating_add(T::DbWeight::get().reads(17)) + .saturating_add(T::DbWeight::get().writes(12)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) @@ -96,35 +89,37 @@ impl WeightInfo for SubstrateWeight { // Storage: VoterList ListNodes (r:3 w:3) // Storage: VoterList ListBags (r:2 w:2) fn bond_extra_transfer() -> Weight { - // Minimum execution time: 155_517 nanoseconds. - Weight::from_ref_time(159_101_000 as u64) - .saturating_add(T::DbWeight::get().reads(14 as u64)) - .saturating_add(T::DbWeight::get().writes(12 as u64)) + // Minimum execution time: 137_000 nanoseconds. + Weight::from_ref_time(142_000_000) + .saturating_add(T::DbWeight::get().reads(14)) + .saturating_add(T::DbWeight::get().writes(12)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) // Storage: NominationPools RewardPools (r:1 w:1) // Storage: System Account (r:3 w:3) + // Storage: NominationPools GlobalMaxCommission (r:1 w:0) // Storage: Staking Bonded (r:1 w:0) // Storage: Staking Ledger (r:1 w:1) // Storage: Balances Locks (r:1 w:1) // Storage: VoterList ListNodes (r:3 w:3) // Storage: VoterList ListBags (r:2 w:2) fn bond_extra_reward() -> Weight { - // Minimum execution time: 172_788 nanoseconds. - Weight::from_ref_time(174_212_000 as u64) - .saturating_add(T::DbWeight::get().reads(14 as u64)) - .saturating_add(T::DbWeight::get().writes(13 as u64)) + // Minimum execution time: 166_000 nanoseconds. + Weight::from_ref_time(169_000_000) + .saturating_add(T::DbWeight::get().reads(15)) + .saturating_add(T::DbWeight::get().writes(13)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) // Storage: NominationPools RewardPools (r:1 w:1) // Storage: System Account (r:1 w:1) + // Storage: NominationPools GlobalMaxCommission (r:1 w:0) fn claim_payout() -> Weight { - // Minimum execution time: 64_560 nanoseconds. - Weight::from_ref_time(64_950_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(4 as u64)) + // Minimum execution time: 64_000 nanoseconds. + Weight::from_ref_time(65_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) @@ -141,10 +136,10 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools SubPoolsStorage (r:1 w:1) // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) fn unbond() -> Weight { - // Minimum execution time: 161_398 nanoseconds. - Weight::from_ref_time(162_991_000 as u64) - .saturating_add(T::DbWeight::get().reads(18 as u64)) - .saturating_add(T::DbWeight::get().writes(13 as u64)) + // Minimum execution time: 143_000 nanoseconds. + Weight::from_ref_time(150_000_000) + .saturating_add(T::DbWeight::get().reads(18)) + .saturating_add(T::DbWeight::get().writes(13)) } // Storage: NominationPools BondedPools (r:1 w:0) // Storage: Staking Bonded (r:1 w:0) @@ -153,12 +148,12 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn pool_withdraw_unbonded(s: u32, ) -> Weight { - // Minimum execution time: 66_036 nanoseconds. - Weight::from_ref_time(67_183_304 as u64) - // Standard Error: 565 - .saturating_add(Weight::from_ref_time(57_830 as u64).saturating_mul(s as u64)) - .saturating_add(T::DbWeight::get().reads(5 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) + // Minimum execution time: 52_000 nanoseconds. + Weight::from_ref_time(53_724_243) + // Standard Error: 1_649 + .saturating_add(Weight::from_ref_time(23_177).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: Staking CurrentEra (r:1 w:0) @@ -171,12 +166,12 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools CounterForPoolMembers (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_update(s: u32, ) -> Weight { - // Minimum execution time: 111_156 nanoseconds. - Weight::from_ref_time(112_507_059 as u64) - // Standard Error: 655 - .saturating_add(Weight::from_ref_time(53_711 as u64).saturating_mul(s as u64)) - .saturating_add(T::DbWeight::get().reads(9 as u64)) - .saturating_add(T::DbWeight::get().writes(7 as u64)) + // Minimum execution time: 95_000 nanoseconds. + Weight::from_ref_time(99_545_463) + // Standard Error: 5_079 + .saturating_add(Weight::from_ref_time(31_957).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(7)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: Staking CurrentEra (r:1 w:0) @@ -199,13 +194,11 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools CounterForBondedPools (r:1 w:1) // Storage: Staking Payee (r:0 w:1) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_kill(s: u32, ) -> Weight { - // Minimum execution time: 168_270 nanoseconds. - Weight::from_ref_time(170_059_380 as u64) - // Standard Error: 1_506 - .saturating_add(Weight::from_ref_time(1_258 as u64).saturating_mul(s as u64)) - .saturating_add(T::DbWeight::get().reads(20 as u64)) - .saturating_add(T::DbWeight::get().writes(17 as u64)) + fn withdraw_unbonded_kill(_s: u32, ) -> Weight { + // Minimum execution time: 148_000 nanoseconds. + Weight::from_ref_time(153_276_873) + .saturating_add(T::DbWeight::get().reads(20)) + .saturating_add(T::DbWeight::get().writes(17)) } // Storage: NominationPools LastPoolId (r:1 w:1) // Storage: Staking MinNominatorBond (r:1 w:0) @@ -229,10 +222,10 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn create() -> Weight { - // Minimum execution time: 146_153 nanoseconds. - Weight::from_ref_time(146_955_000 as u64) - .saturating_add(T::DbWeight::get().reads(21 as u64)) - .saturating_add(T::DbWeight::get().writes(15 as u64)) + // Minimum execution time: 131_000 nanoseconds. + Weight::from_ref_time(132_000_000) + .saturating_add(T::DbWeight::get().reads(21)) + .saturating_add(T::DbWeight::get().writes(15)) } // Storage: NominationPools BondedPools (r:1 w:0) // Storage: Staking Bonded (r:1 w:0) @@ -248,51 +241,52 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking CounterForNominators (r:1 w:1) /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { - // Minimum execution time: 71_380 nanoseconds. - Weight::from_ref_time(71_060_388 as u64) - // Standard Error: 2_587 - .saturating_add(Weight::from_ref_time(1_185_729 as u64).saturating_mul(n as u64)) - .saturating_add(T::DbWeight::get().reads(12 as u64)) - .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(n as u64))) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // Minimum execution time: 59_000 nanoseconds. + Weight::from_ref_time(58_398_812) + // Standard Error: 7_443 + .saturating_add(Weight::from_ref_time(1_436_557).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(12)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) + .saturating_add(T::DbWeight::get().writes(5)) } // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Bonded (r:1 w:0) // Storage: Staking Ledger (r:1 w:0) fn set_state() -> Weight { - // Minimum execution time: 46_275 nanoseconds. - Weight::from_ref_time(46_689_000 as u64) - .saturating_add(T::DbWeight::get().reads(3 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + // Minimum execution time: 34_000 nanoseconds. + Weight::from_ref_time(35_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: NominationPools BondedPools (r:1 w:0) // Storage: NominationPools Metadata (r:1 w:1) // Storage: NominationPools CounterForMetadata (r:1 w:1) /// The range of component `n` is `[1, 256]`. fn set_metadata(n: u32, ) -> Weight { - // Minimum execution time: 19_246 nanoseconds. - Weight::from_ref_time(20_415_018 as u64) - // Standard Error: 95 - .saturating_add(Weight::from_ref_time(2_040 as u64).saturating_mul(n as u64)) - .saturating_add(T::DbWeight::get().reads(3 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) + // Minimum execution time: 12_000 nanoseconds. + Weight::from_ref_time(13_360_093) + // Standard Error: 294 + .saturating_add(Weight::from_ref_time(514).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) } // Storage: NominationPools MinJoinBond (r:0 w:1) // Storage: NominationPools MaxPoolMembers (r:0 w:1) // Storage: NominationPools MaxPoolMembersPerPool (r:0 w:1) // Storage: NominationPools MinCreateBond (r:0 w:1) + // Storage: NominationPools GlobalMaxCommission (r:0 w:1) // Storage: NominationPools MaxPools (r:0 w:1) fn set_configs() -> Weight { - // Minimum execution time: 9_231 nanoseconds. - Weight::from_ref_time(9_526_000 as u64) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // Minimum execution time: 6_000 nanoseconds. + Weight::from_ref_time(7_000_000) + .saturating_add(T::DbWeight::get().writes(6)) } // Storage: NominationPools BondedPools (r:1 w:1) fn update_roles() -> Weight { - // Minimum execution time: 31_246 nanoseconds. - Weight::from_ref_time(31_762_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + // Minimum execution time: 22_000 nanoseconds. + Weight::from_ref_time(23_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: NominationPools BondedPools (r:1 w:0) // Storage: Staking Bonded (r:1 w:0) @@ -304,10 +298,31 @@ impl WeightInfo for SubstrateWeight { // Storage: VoterList ListBags (r:1 w:1) // Storage: VoterList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - // Minimum execution time: 73_812 nanoseconds. - Weight::from_ref_time(74_790_000 as u64) - .saturating_add(T::DbWeight::get().reads(9 as u64)) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // Minimum execution time: 58_000 nanoseconds. + Weight::from_ref_time(60_000_000) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(5)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission() -> Weight { + // Minimum execution time: 24_000 nanoseconds. + Weight::from_ref_time(24_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission_max() -> Weight { + // Minimum execution time: 21_000 nanoseconds. + Weight::from_ref_time(22_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission_change_rate() -> Weight { + // Minimum execution time: 22_000 nanoseconds. + Weight::from_ref_time(23_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } } @@ -327,10 +342,10 @@ impl WeightInfo for () { // Storage: VoterList ListNodes (r:3 w:3) // Storage: VoterList ListBags (r:2 w:2) fn join() -> Weight { - // Minimum execution time: 159_948 nanoseconds. - Weight::from_ref_time(161_133_000 as u64) - .saturating_add(RocksDbWeight::get().reads(17 as u64)) - .saturating_add(RocksDbWeight::get().writes(12 as u64)) + // Minimum execution time: 142_000 nanoseconds. + Weight::from_ref_time(145_000_000) + .saturating_add(RocksDbWeight::get().reads(17)) + .saturating_add(RocksDbWeight::get().writes(12)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) @@ -342,35 +357,37 @@ impl WeightInfo for () { // Storage: VoterList ListNodes (r:3 w:3) // Storage: VoterList ListBags (r:2 w:2) fn bond_extra_transfer() -> Weight { - // Minimum execution time: 155_517 nanoseconds. - Weight::from_ref_time(159_101_000 as u64) - .saturating_add(RocksDbWeight::get().reads(14 as u64)) - .saturating_add(RocksDbWeight::get().writes(12 as u64)) + // Minimum execution time: 137_000 nanoseconds. + Weight::from_ref_time(142_000_000) + .saturating_add(RocksDbWeight::get().reads(14)) + .saturating_add(RocksDbWeight::get().writes(12)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) // Storage: NominationPools RewardPools (r:1 w:1) // Storage: System Account (r:3 w:3) + // Storage: NominationPools GlobalMaxCommission (r:1 w:0) // Storage: Staking Bonded (r:1 w:0) // Storage: Staking Ledger (r:1 w:1) // Storage: Balances Locks (r:1 w:1) // Storage: VoterList ListNodes (r:3 w:3) // Storage: VoterList ListBags (r:2 w:2) fn bond_extra_reward() -> Weight { - // Minimum execution time: 172_788 nanoseconds. - Weight::from_ref_time(174_212_000 as u64) - .saturating_add(RocksDbWeight::get().reads(14 as u64)) - .saturating_add(RocksDbWeight::get().writes(13 as u64)) + // Minimum execution time: 166_000 nanoseconds. + Weight::from_ref_time(169_000_000) + .saturating_add(RocksDbWeight::get().reads(15)) + .saturating_add(RocksDbWeight::get().writes(13)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) // Storage: NominationPools RewardPools (r:1 w:1) // Storage: System Account (r:1 w:1) + // Storage: NominationPools GlobalMaxCommission (r:1 w:0) fn claim_payout() -> Weight { - // Minimum execution time: 64_560 nanoseconds. - Weight::from_ref_time(64_950_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(4 as u64)) + // Minimum execution time: 64_000 nanoseconds. + Weight::from_ref_time(65_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(4)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) @@ -387,10 +404,10 @@ impl WeightInfo for () { // Storage: NominationPools SubPoolsStorage (r:1 w:1) // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) fn unbond() -> Weight { - // Minimum execution time: 161_398 nanoseconds. - Weight::from_ref_time(162_991_000 as u64) - .saturating_add(RocksDbWeight::get().reads(18 as u64)) - .saturating_add(RocksDbWeight::get().writes(13 as u64)) + // Minimum execution time: 143_000 nanoseconds. + Weight::from_ref_time(150_000_000) + .saturating_add(RocksDbWeight::get().reads(18)) + .saturating_add(RocksDbWeight::get().writes(13)) } // Storage: NominationPools BondedPools (r:1 w:0) // Storage: Staking Bonded (r:1 w:0) @@ -399,12 +416,12 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn pool_withdraw_unbonded(s: u32, ) -> Weight { - // Minimum execution time: 66_036 nanoseconds. - Weight::from_ref_time(67_183_304 as u64) - // Standard Error: 565 - .saturating_add(Weight::from_ref_time(57_830 as u64).saturating_mul(s as u64)) - .saturating_add(RocksDbWeight::get().reads(5 as u64)) - .saturating_add(RocksDbWeight::get().writes(2 as u64)) + // Minimum execution time: 52_000 nanoseconds. + Weight::from_ref_time(53_724_243) + // Standard Error: 1_649 + .saturating_add(Weight::from_ref_time(23_177).saturating_mul(s.into())) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(2)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: Staking CurrentEra (r:1 w:0) @@ -417,12 +434,12 @@ impl WeightInfo for () { // Storage: NominationPools CounterForPoolMembers (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_update(s: u32, ) -> Weight { - // Minimum execution time: 111_156 nanoseconds. - Weight::from_ref_time(112_507_059 as u64) - // Standard Error: 655 - .saturating_add(Weight::from_ref_time(53_711 as u64).saturating_mul(s as u64)) - .saturating_add(RocksDbWeight::get().reads(9 as u64)) - .saturating_add(RocksDbWeight::get().writes(7 as u64)) + // Minimum execution time: 95_000 nanoseconds. + Weight::from_ref_time(99_545_463) + // Standard Error: 5_079 + .saturating_add(Weight::from_ref_time(31_957).saturating_mul(s.into())) + .saturating_add(RocksDbWeight::get().reads(9)) + .saturating_add(RocksDbWeight::get().writes(7)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: Staking CurrentEra (r:1 w:0) @@ -445,13 +462,11 @@ impl WeightInfo for () { // Storage: NominationPools CounterForBondedPools (r:1 w:1) // Storage: Staking Payee (r:0 w:1) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_kill(s: u32, ) -> Weight { - // Minimum execution time: 168_270 nanoseconds. - Weight::from_ref_time(170_059_380 as u64) - // Standard Error: 1_506 - .saturating_add(Weight::from_ref_time(1_258 as u64).saturating_mul(s as u64)) - .saturating_add(RocksDbWeight::get().reads(20 as u64)) - .saturating_add(RocksDbWeight::get().writes(17 as u64)) + fn withdraw_unbonded_kill(_s: u32, ) -> Weight { + // Minimum execution time: 148_000 nanoseconds. + Weight::from_ref_time(153_276_873) + .saturating_add(RocksDbWeight::get().reads(20)) + .saturating_add(RocksDbWeight::get().writes(17)) } // Storage: NominationPools LastPoolId (r:1 w:1) // Storage: Staking MinNominatorBond (r:1 w:0) @@ -475,10 +490,10 @@ impl WeightInfo for () { // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn create() -> Weight { - // Minimum execution time: 146_153 nanoseconds. - Weight::from_ref_time(146_955_000 as u64) - .saturating_add(RocksDbWeight::get().reads(21 as u64)) - .saturating_add(RocksDbWeight::get().writes(15 as u64)) + // Minimum execution time: 131_000 nanoseconds. + Weight::from_ref_time(132_000_000) + .saturating_add(RocksDbWeight::get().reads(21)) + .saturating_add(RocksDbWeight::get().writes(15)) } // Storage: NominationPools BondedPools (r:1 w:0) // Storage: Staking Bonded (r:1 w:0) @@ -494,51 +509,52 @@ impl WeightInfo for () { // Storage: Staking CounterForNominators (r:1 w:1) /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { - // Minimum execution time: 71_380 nanoseconds. - Weight::from_ref_time(71_060_388 as u64) - // Standard Error: 2_587 - .saturating_add(Weight::from_ref_time(1_185_729 as u64).saturating_mul(n as u64)) - .saturating_add(RocksDbWeight::get().reads(12 as u64)) - .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(n as u64))) - .saturating_add(RocksDbWeight::get().writes(5 as u64)) + // Minimum execution time: 59_000 nanoseconds. + Weight::from_ref_time(58_398_812) + // Standard Error: 7_443 + .saturating_add(Weight::from_ref_time(1_436_557).saturating_mul(n.into())) + .saturating_add(RocksDbWeight::get().reads(12)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into()))) + .saturating_add(RocksDbWeight::get().writes(5)) } // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Bonded (r:1 w:0) // Storage: Staking Ledger (r:1 w:0) fn set_state() -> Weight { - // Minimum execution time: 46_275 nanoseconds. - Weight::from_ref_time(46_689_000 as u64) - .saturating_add(RocksDbWeight::get().reads(3 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + // Minimum execution time: 34_000 nanoseconds. + Weight::from_ref_time(35_000_000) + .saturating_add(RocksDbWeight::get().reads(3)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: NominationPools BondedPools (r:1 w:0) // Storage: NominationPools Metadata (r:1 w:1) // Storage: NominationPools CounterForMetadata (r:1 w:1) /// The range of component `n` is `[1, 256]`. fn set_metadata(n: u32, ) -> Weight { - // Minimum execution time: 19_246 nanoseconds. - Weight::from_ref_time(20_415_018 as u64) - // Standard Error: 95 - .saturating_add(Weight::from_ref_time(2_040 as u64).saturating_mul(n as u64)) - .saturating_add(RocksDbWeight::get().reads(3 as u64)) - .saturating_add(RocksDbWeight::get().writes(2 as u64)) + // Minimum execution time: 12_000 nanoseconds. + Weight::from_ref_time(13_360_093) + // Standard Error: 294 + .saturating_add(Weight::from_ref_time(514).saturating_mul(n.into())) + .saturating_add(RocksDbWeight::get().reads(3)) + .saturating_add(RocksDbWeight::get().writes(2)) } // Storage: NominationPools MinJoinBond (r:0 w:1) // Storage: NominationPools MaxPoolMembers (r:0 w:1) // Storage: NominationPools MaxPoolMembersPerPool (r:0 w:1) // Storage: NominationPools MinCreateBond (r:0 w:1) + // Storage: NominationPools GlobalMaxCommission (r:0 w:1) // Storage: NominationPools MaxPools (r:0 w:1) fn set_configs() -> Weight { - // Minimum execution time: 9_231 nanoseconds. - Weight::from_ref_time(9_526_000 as u64) - .saturating_add(RocksDbWeight::get().writes(5 as u64)) + // Minimum execution time: 6_000 nanoseconds. + Weight::from_ref_time(7_000_000) + .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: NominationPools BondedPools (r:1 w:1) fn update_roles() -> Weight { - // Minimum execution time: 31_246 nanoseconds. - Weight::from_ref_time(31_762_000 as u64) - .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + // Minimum execution time: 22_000 nanoseconds. + Weight::from_ref_time(23_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: NominationPools BondedPools (r:1 w:0) // Storage: Staking Bonded (r:1 w:0) @@ -550,9 +566,30 @@ impl WeightInfo for () { // Storage: VoterList ListBags (r:1 w:1) // Storage: VoterList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - // Minimum execution time: 73_812 nanoseconds. - Weight::from_ref_time(74_790_000 as u64) - .saturating_add(RocksDbWeight::get().reads(9 as u64)) - .saturating_add(RocksDbWeight::get().writes(5 as u64)) + // Minimum execution time: 58_000 nanoseconds. + Weight::from_ref_time(60_000_000) + .saturating_add(RocksDbWeight::get().reads(9)) + .saturating_add(RocksDbWeight::get().writes(5)) } -} + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission() -> Weight { + // Minimum execution time: 24_000 nanoseconds. + Weight::from_ref_time(24_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission_max() -> Weight { + // Minimum execution time: 21_000 nanoseconds. + Weight::from_ref_time(22_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission_change_rate() -> Weight { + // Minimum execution time: 22_000 nanoseconds. + Weight::from_ref_time(23_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) + } +} \ No newline at end of file diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index c67aec0134b07..919bf1b75779d 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -25,7 +25,7 @@ use frame_support::{ }; use sp_runtime::{ traits::{Convert, IdentityLookup}, - FixedU128, + FixedU128, Perbill, }; type AccountId = u128; @@ -209,6 +209,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { max_pools: Some(3), max_members_per_pool: Some(5), max_members: Some(3 * 5), + global_max_commission: Some(Perbill::from_percent(90)), } .assimilate_storage(&mut storage) .unwrap(); @@ -266,4 +267,4 @@ pub(crate) fn staking_events_since_last_call() -> Vec Date: Thu, 12 Jan 2023 14:28:34 +0700 Subject: [PATCH 02/90] fmt --- frame/nomination-pools/benchmarking/src/lib.rs | 2 +- frame/nomination-pools/benchmarking/src/mock.rs | 2 +- frame/nomination-pools/fuzzer/src/call.rs | 2 +- frame/nomination-pools/src/lib.rs | 2 +- frame/nomination-pools/src/migration.rs | 2 +- frame/nomination-pools/src/mock.rs | 2 +- frame/nomination-pools/src/tests.rs | 2 +- frame/nomination-pools/test-staking/src/mock.rs | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index b5706e396c0d9..7b0062b9c9231 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -741,4 +741,4 @@ frame_benchmarking::benchmarks! { crate::mock::new_test_ext(), crate::mock::Runtime ); -} \ No newline at end of file +} diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index f8840286e630b..db097004ef73b 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -199,4 +199,4 @@ pub fn new_test_ext() -> sp_io::TestExternalities { } .assimilate_storage(&mut storage); sp_io::TestExternalities::from(storage) -} \ No newline at end of file +} diff --git a/frame/nomination-pools/fuzzer/src/call.rs b/frame/nomination-pools/fuzzer/src/call.rs index 5e48a236b2b44..121271bb67f6e 100644 --- a/frame/nomination-pools/fuzzer/src/call.rs +++ b/frame/nomination-pools/fuzzer/src/call.rs @@ -351,4 +351,4 @@ fn main() { }) }) } -} \ No newline at end of file +} diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 69ba5e5c4696e..a09e55e5d543b 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2958,4 +2958,4 @@ impl OnStakerSlash> for Pallet { SubPoolsStorage::::insert(pool_id, sub_pools); } } -} \ No newline at end of file +} diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 01ea0ccb8b2a8..ad87eb0fbe45c 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -537,4 +537,4 @@ pub mod v4 { Ok(()) } } -} \ No newline at end of file +} diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 8108dcac97e94..e779cae67814c 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -435,4 +435,4 @@ mod test { assert_eq!(BalanceToU256::convert(0u32.into()), U256::zero()); assert_eq!(BalanceToU256::convert(Balance::max_value()), Balance::max_value().into()) } -} \ No newline at end of file +} diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index a85bca50b5535..4bd4973fc7704 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -6211,4 +6211,4 @@ mod commission { ); }) } -} \ No newline at end of file +} diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index 919bf1b75779d..fb3aef130a77d 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -267,4 +267,4 @@ pub(crate) fn staking_events_since_last_call() -> Vec Date: Fri, 13 Jan 2023 16:02:30 +0700 Subject: [PATCH 03/90] use register_update() --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index a09e55e5d543b..2012c011cffcd 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -735,7 +735,7 @@ impl Commission { ensure!(!&self.less_restrictive(&change_rate), Error::::CommissionChangeRateNotAllowed); if self.change_rate.is_none() { - self.throttle_from = Some(>::block_number()); + self.register_update(); } self.change_rate = Some(change_rate); Ok(()) From ffb4dde61fbd9f676547a6aa96956d04428a0d06 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 13 Jan 2023 17:01:35 +0000 Subject: [PATCH 04/90] Update frame/nomination-pools/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gonçalo Pestana --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 2012c011cffcd..b6280b33e9cca 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -609,7 +609,7 @@ pub struct Commission { /// Optional configuration around how often commission can be updated, and when the last /// commission update took place. pub change_rate: Option>, - /// The block throttling should be checked from. This value will be updated on all commission + /// The block from where throttling should be checked from. This value will be updated on all commission /// updates and when setting an initial `change_rate`. pub throttle_from: Option, } From 7d81de28047c7ef8174b104adb4628db9310e7c9 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 13 Jan 2023 17:10:19 +0000 Subject: [PATCH 05/90] Update frame/nomination-pools/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gonçalo Pestana --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index b6280b33e9cca..b29b756cee088 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -644,7 +644,7 @@ impl Commission { return self.throttle_from.map_or_else( || { defensive!("throttle_from should exist if change_rate is set"); - false + true }, |f| { // if `min_delay` is zero (no delay), not throttling. From 6aaf1957311e19a96da4bfd1346ba99bf2497e58 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 14 Jan 2023 00:24:12 +0700 Subject: [PATCH 06/90] fmt --- frame/nomination-pools/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index b29b756cee088..55629b9101f3e 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -609,8 +609,8 @@ pub struct Commission { /// Optional configuration around how often commission can be updated, and when the last /// commission update took place. pub change_rate: Option>, - /// The block from where throttling should be checked from. This value will be updated on all commission - /// updates and when setting an initial `change_rate`. + /// The block from where throttling should be checked from. This value will be updated on all + /// commission updates and when setting an initial `change_rate`. pub throttle_from: Option, } From b9eae6e7d632c0fc22bb4ca41bda52ee431e835a Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 14 Jan 2023 13:04:29 +0700 Subject: [PATCH 07/90] amend comments --- frame/nomination-pools/src/lib.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 55629b9101f3e..25461d670d8cf 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -665,9 +665,8 @@ impl Commission { /// Set the pool's commission. /// /// Update commission based on `current`. If a `None` is supplied, allow the commission to be - /// removed without any change rate restrictions. If `change_rate` is present, update - /// `throttle_from` to the current block. If the supplied commission is zero, `None` will be - /// inserted and `payee` will be ignored. + /// removed without any change rate restrictions. Updates `throttle_from` to the current block. + /// If the supplied commission is zero, `None` will be inserted and `payee` will be ignored. fn try_update_current(&mut self, current: &Option<(Perbill, T::AccountId)>) -> DispatchResult { self.current = match current { None => None, @@ -2379,6 +2378,9 @@ pub mod pallet { /// The dispatch origin of this call must be signed by the `root` role of the pool. Both a /// commission percentage and a commission payee must be provided in the `current` tuple. /// Where a `current` of `None` is provided, any current commission will be removed. + /// + /// - If a `None` is supplied to `new_commission`, existing commission will be removed. + /// - If a payee is supplied with 0% commission, a `None` value will be set. #[pallet::call_index(14)] #[pallet::weight(T::WeightInfo::set_commission())] pub fn set_commission( @@ -2402,6 +2404,10 @@ pub mod pallet { /// Set the maximum commission of a pool. /// /// The dispatch origin of this call must be signed by the `root` role of the pool. + /// + /// - Initial max can be set to any `Perbill`, and only smaller values thereafter. + /// - Current commission will be lowered in the event it is higher than a new max + /// commission. #[pallet::call_index(15)] #[pallet::weight(T::WeightInfo::set_commission_max())] pub fn set_commission_max( @@ -2422,7 +2428,9 @@ pub mod pallet { /// Set the commission change rate for a pool. /// - /// The dispatch origin of this call must be signed by the `root` role of the pool. + /// The dispatch origin of this call must be signed by the `root` role of the pool. Initial + /// change rate is not bounded, whereas subsequent updates can only be more restrictive than + /// the current. #[pallet::call_index(16)] #[pallet::weight(T::WeightInfo::set_commission_change_rate())] pub fn set_commission_change_rate( From cd46c397f5b7308ae980221709c291331f9dfca3 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 14 Jan 2023 19:42:29 +0700 Subject: [PATCH 08/90] + test for set_commission --- frame/nomination-pools/src/tests.rs | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 4bd4973fc7704..368a7044bfca5 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5275,6 +5275,35 @@ mod commission { BondedPool::::get(1).unwrap().commission, Commission { current: None, max: None, change_rate: None, throttle_from: Some(1) } ); + // set the commission to 0% + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(0), 900)) + )); + + // test for updating payee only when commission = max commission + // + // set max commission to 10% + assert_ok!(Pools::set_commission_max( + RuntimeOrigin::signed(900), + 1, + Perbill::from_percent(10) + )); + + // set commission to 10% + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(10), 900)) + )); + + // update payee only and keep current commission + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(10), 901)) + )); assert_eq!( pool_events_since_last_call(), @@ -5301,6 +5330,22 @@ mod commission { Event::PoolCommissionUpdated { pool_id: 1, current: Some((Perbill::from_percent(0), 900)) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(0), 900)) + }, + Event::PoolMaxCommissionUpdated { + pool_id: 1, + max_commission: Perbill::from_percent(10) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(10), 900)) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(10), 901)) } ] ); From ae4464634ee43a7f3ca15843fe18d09354ce93bf Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sun, 15 Jan 2023 11:18:56 +0700 Subject: [PATCH 09/90] fix --- frame/nomination-pools/benchmarking/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index db097004ef73b..2d6be75e5efac 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -195,7 +195,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { max_pools: Some(3), max_members_per_pool: Some(3), max_members: Some(3 * 3), - global_max_commission: Some(Perbill::from_percent(500)), + global_max_commission: Some(Perbill::from_percent(50)), } .assimilate_storage(&mut storage); sp_io::TestExternalities::from(storage) From 6b424e74d7435f17c14b851bf15a01d1af54d075 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sun, 15 Jan 2023 04:20:10 +0000 Subject: [PATCH 10/90] Update frame/nomination-pools/fuzzer/src/call.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- frame/nomination-pools/fuzzer/src/call.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/fuzzer/src/call.rs b/frame/nomination-pools/fuzzer/src/call.rs index 121271bb67f6e..561b5be3174c1 100644 --- a/frame/nomination-pools/fuzzer/src/call.rs +++ b/frame/nomination-pools/fuzzer/src/call.rs @@ -224,7 +224,7 @@ fn main() { MaxPoolMembers::::set(Some(10_000)); MaxPoolMembersPerPool::::set(Some(1000)); MaxPools::::set(Some(1_000)); - GlobalMaxCommission::::set(Some(Perbill::from_percent(90))); + GlobalMaxCommission::::set(Some(Perbill::zero())); MinCreateBond::::set(10 * ExistentialDeposit::get()); MinJoinBond::::set(5 * ExistentialDeposit::get()); From 39bf0649100a799fa6885530ec71d280233929e2 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sun, 15 Jan 2023 11:22:18 +0700 Subject: [PATCH 11/90] rm comment --- frame/nomination-pools/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 25461d670d8cf..c0dc1a2b371e9 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2380,7 +2380,6 @@ pub mod pallet { /// Where a `current` of `None` is provided, any current commission will be removed. /// /// - If a `None` is supplied to `new_commission`, existing commission will be removed. - /// - If a payee is supplied with 0% commission, a `None` value will be set. #[pallet::call_index(14)] #[pallet::weight(T::WeightInfo::set_commission())] pub fn set_commission( From 9d0d65a5c6f9d3c4d1beb80f794cfeb0e3387207 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 3 Feb 2023 14:18:42 +0800 Subject: [PATCH 12/90] use PalletError --- frame/nomination-pools/src/lib.rs | 38 ++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index c0dc1a2b371e9..5845bd49a199b 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -328,7 +328,7 @@ use frame_support::{ Currency, Defensive, DefensiveOption, DefensiveResult, DefensiveSaturating, ExistenceRequirement, Get, }, - DefaultNoBound, + DefaultNoBound, PalletError, }; use scale_info::TypeInfo; use sp_core::U256; @@ -396,6 +396,23 @@ enum BondType { Later, } +#[derive(Debug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo, PalletError)] +pub enum CommissionError { + /// Commission change has been throttled. + CommissionChangeThrottled, + // Commission exceeds the pool's maximum commission. + CommissionExceedsMaximum, +} + +impl From for Error { + fn from(t: CommissionError) -> Self { + match t { + CommissionError::CommissionChangeThrottled => Error::::CommissionChangeThrottled, + CommissionError::CommissionExceedsMaximum => Error::::CommissionExceedsMaximum, + } + } +} + /// How to increase the bond of a member. #[derive(Encode, Decode, Clone, Copy, Debug, PartialEq, Eq, TypeInfo)] pub enum BondExtra { @@ -667,14 +684,17 @@ impl Commission { /// Update commission based on `current`. If a `None` is supplied, allow the commission to be /// removed without any change rate restrictions. Updates `throttle_from` to the current block. /// If the supplied commission is zero, `None` will be inserted and `payee` will be ignored. - fn try_update_current(&mut self, current: &Option<(Perbill, T::AccountId)>) -> DispatchResult { + fn try_update_current( + &mut self, + current: &Option<(Perbill, T::AccountId)>, + ) -> Result<(), CommissionError> { self.current = match current { None => None, Some((commission, payee)) => { - ensure!(!self.throttling(&commission), Error::::CommissionChangeThrottled); + ensure!(!self.throttling(&commission), CommissionError::CommissionChangeThrottled); ensure!( self.max.map_or(true, |m| commission <= &m), - Error::::CommissionExceedsMaximum + CommissionError::CommissionExceedsMaximum ); if commission.is_zero() { None @@ -1727,7 +1747,8 @@ pub mod pallet { InvalidPoolId, } - #[derive(Encode, Decode, PartialEq, TypeInfo, frame_support::PalletError, RuntimeDebug)] + + #[derive(Encode, Decode, PartialEq, TypeInfo, PalletError, RuntimeDebug)] pub enum DefensiveError { /// There isn't enough space in the unbond pool. NotEnoughSpaceInUnbondPool, @@ -2391,7 +2412,12 @@ pub mod pallet { let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; ensure!(bonded_pool.can_set_commission(&who), Error::::DoesNotHavePermission); - bonded_pool.commission.try_update_current(&new_commission)?; + bonded_pool + .commission + .try_update_current(&new_commission) + .map_err::, _>(Into::into) + .map_err::(Into::into)?; + bonded_pool.put(); Self::deposit_event(Event::::PoolCommissionUpdated { pool_id, From acad3e47da727e60d34b40061e4bbf830ad67513 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 3 Feb 2023 14:52:06 +0800 Subject: [PATCH 13/90] some feedback item amendments --- frame/nomination-pools/src/lib.rs | 5 -- frame/nomination-pools/src/tests.rs | 92 +---------------------------- 2 files changed, 1 insertion(+), 96 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 5845bd49a199b..3e9ffaca135f0 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1729,10 +1729,6 @@ pub mod pallet { Defensive(DefensiveError), /// Partial unbonding now allowed permissionlessly. PartialUnbondNotAllowedPermissionlessly, - /// No commission has been set. - NoCommissionSet, - /// No account has been set to receive commission. - NoCommissionPayeeSet, /// The pool's max commission cannot be set higher than the existing value. MaxCommissionRestricted, /// The supplied commission exceeds the max allowed commission. @@ -1747,7 +1743,6 @@ pub mod pallet { InvalidPoolId, } - #[derive(Encode, Decode, PartialEq, TypeInfo, PalletError, RuntimeDebug)] pub enum DefensiveError { /// There isn't enough space in the unbond pool. diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 368a7044bfca5..ce5185f42d087 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -900,9 +900,6 @@ mod claim_payout { #[test] fn claim_payout_bounds_commission_above_global() { ExtBuilder::default().build_and_execute(|| { - // temporarily remove global maximum so a higher commission can be set. - GlobalMaxCommission::::set(None); - let (mut member, bonded_pool, mut reward_pool) = Pools::get_member_with_pools(&10).unwrap(); @@ -5374,25 +5371,6 @@ mod commission { Error::::DoesNotHavePermission ); - // Commission clamps to 100% where > 100% is provided. - // - // attempt to set a commission at 101%. - assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), - 1, - Some((Perbill::from_percent(101), 900)), - )); - // ensure the commission actually set was at 100%. - assert_eq!( - BondedPool::::get(1).unwrap().commission, - Commission { - current: Some((Perbill::from_percent(100), 900)), - max: None, - change_rate: None, - throttle_from: Some(1_u64), - } - ); - // Set the initial commission to 5%. assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), @@ -5530,10 +5508,6 @@ mod commission { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(100), 900)) - }, Event::PoolCommissionUpdated { pool_id: 1, current: Some((Perbill::from_percent(5), 900)) @@ -5580,26 +5554,6 @@ mod commission { Error::::DoesNotHavePermission ); - // Max commission clamps to 100% where > 100% is provided. - // - // attempt to set a commission at 101%. - - assert_ok!(Pools::set_commission_max( - RuntimeOrigin::signed(900), - 1, - Perbill::from_percent(101) - )); - // ensure max commission actually set was at 100%. - assert_eq!( - BondedPool::::get(1).unwrap().commission, - Commission { - current: None, - max: Some(Perbill::from_percent(100)), - change_rate: None, - throttle_from: None, - } - ); - // Set a max commission commission pool 1 to 80% assert_ok!(Pools::set_commission_max( RuntimeOrigin::signed(900), @@ -5646,17 +5600,13 @@ mod commission { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PoolMaxCommissionUpdated { - pool_id: 1, - max_commission: Perbill::from_percent(100) - }, Event::PoolMaxCommissionUpdated { pool_id: 1, max_commission: Perbill::from_percent(80) }, Event::PoolCommissionUpdated { pool_id: 1, - current: Some((Perbill::from_percent(75), 900)), + current: Some((Perbill::from_percent(75), 900)) }, Event::PoolMaxCommissionUpdated { pool_id: 1, @@ -5667,37 +5617,6 @@ mod commission { }); } - #[test] - fn max_commission_after_current_commission_works() { - ExtBuilder::default().build_and_execute(|| { - // set pool commission to 50% first. - assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), - 1, - Some((Perbill::from_percent(50), 900)), - )); - - // now set the max commission to something less than the current - // commission. - assert_ok!(Pools::set_commission_max( - RuntimeOrigin::signed(900), - 1, - Perbill::from_percent(25) - )); - - // the current commission should now be 25%. - assert_eq!( - BondedPools::::get(1).unwrap().commission, - Commission { - current: Some((Perbill::from_percent(25), 900)), - max: Some(Perbill::from_percent(25)), - change_rate: None, - throttle_from: Some(1), - } - ); - }) - } - #[test] fn set_commission_change_rate_works_with_errors() { ExtBuilder::default().build_and_execute(|| { @@ -5869,9 +5788,6 @@ mod commission { Some((Perbill::from_percent(3), 900)) )); - // run `min_delay` blocks to allow a commission update. - run_blocks(10_u64); - // Attempt to *increase* the commission by 5%. Should fail. assert_noop!( Pools::set_commission( @@ -5929,7 +5845,6 @@ mod commission { fn set_commission_max_to_zero_works() { ExtBuilder::default().build_and_execute(|| { // 0% max commission test. - // // set commission max 0%. assert_ok!(Pools::set_commission_max(RuntimeOrigin::signed(900), 1, Zero::zero())); @@ -5949,8 +5864,6 @@ mod commission { #[test] fn set_commission_change_rate_zero_max_increase_works() { ExtBuilder::default().build_and_execute(|| { - // 0% max increase test. - // // set commission change rate to 0% per 10 blocks assert_ok!(Pools::set_commission_change_rate( RuntimeOrigin::signed(900), @@ -5974,8 +5887,6 @@ mod commission { #[test] fn set_commission_change_rate_zero_min_delay_works() { ExtBuilder::default().build_and_execute(|| { - // 0% min delay test. - // // set commission change rate to 1% with a 0 block `min_delay`. assert_ok!(Pools::set_commission_change_rate( RuntimeOrigin::signed(900), @@ -6018,7 +5929,6 @@ mod commission { fn set_commission_change_rate_zero_value_works() { ExtBuilder::default().build_and_execute(|| { // Check zero values play nice. 0 `min_delay` and 0% max_increase test. - // // set commission change rate to 0% per 0 blocks. assert_ok!(Pools::set_commission_change_rate( RuntimeOrigin::signed(900), From e25b79ce9c5dcade203faabdb5b9a5c76137dfcc Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sun, 19 Feb 2023 15:16:26 +0700 Subject: [PATCH 14/90] update weights --- frame/nomination-pools/src/weights.rs | 1328 ++++++++++--------------- 1 file changed, 509 insertions(+), 819 deletions(-) diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index ae73015940f80..3d483b4b5f38e 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -18,26 +18,31 @@ //! Autogenerated weights for pallet_nomination_pools //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-01-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bm2`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2022-12-27, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Rosss-MacBook-Pro-2.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/production/substrate +// target/release/substrate // benchmark // pallet -// --chain=dev -// --steps=50 -// --repeat=20 -// --pallet=pallet_nomination_pools -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=./frame/nomination-pools/src/weights.rs -// --header=./HEADER-APACHE2 -// --template=./.maintain/frame-weight-template.hbs +// --execution +// wasm +// --wasm-execution +// compiled +// --dev +// --pallet +// pallet-nomination-pools +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --output +// frame/nomination-pools/src/weights.rs +// --template +// .maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -63,859 +68,544 @@ pub trait WeightInfo { fn set_configs() -> Weight; fn update_roles() -> Weight; fn chill() -> Weight; + fn set_commission() -> Weight; + fn set_commission_max() -> Weight; + fn set_commission_change_rate() -> Weight; } /// Weights for pallet_nomination_pools using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: NominationPools MinJoinBond (r:1 w:0) - /// Proof: NominationPools MinJoinBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) - /// Proof: NominationPools MaxPoolMembersPerPool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembers (r:1 w:0) - /// Proof: NominationPools MaxPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForPoolMembers (r:1 w:1) - /// Proof: NominationPools CounterForPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:3 w:3) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:2 w:2) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) + // Storage: NominationPools MinJoinBond (r:1 w:0) + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: System Account (r:2 w:1) + // Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) + // Storage: NominationPools MaxPoolMembers (r:1 w:0) + // Storage: NominationPools CounterForPoolMembers (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: VoterList ListNodes (r:3 w:3) + // Storage: VoterList ListBags (r:2 w:2) fn join() -> Weight { - // Proof Size summary in bytes: - // Measured: `3573` - // Estimated: `37988` - // Minimum execution time: 140_155 nanoseconds. - Weight::from_parts(141_098_000, 37988) - .saturating_add(T::DbWeight::get().reads(17_u64)) - .saturating_add(T::DbWeight::get().writes(12_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: System Account (r:3 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:3 w:3) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:2 w:2) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) + // Minimum execution time: 142_000 nanoseconds. + Weight::from_ref_time(145_000_000) + .saturating_add(T::DbWeight::get().reads(17)) + .saturating_add(T::DbWeight::get().writes(12)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: System Account (r:3 w:2) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: VoterList ListNodes (r:3 w:3) + // Storage: VoterList ListBags (r:2 w:2) fn bond_extra_transfer() -> Weight { - // Proof Size summary in bytes: - // Measured: `3615` - // Estimated: `38583` - // Minimum execution time: 136_048 nanoseconds. - Weight::from_parts(136_767_000, 38583) - .saturating_add(T::DbWeight::get().reads(14_u64)) - .saturating_add(T::DbWeight::get().writes(12_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: System Account (r:3 w:3) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:3 w:3) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:2 w:2) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) + // Minimum execution time: 137_000 nanoseconds. + Weight::from_ref_time(142_000_000) + .saturating_add(T::DbWeight::get().reads(14)) + .saturating_add(T::DbWeight::get().writes(12)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: System Account (r:3 w:3) + // Storage: NominationPools GlobalMaxCommission (r:1 w:0) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: VoterList ListNodes (r:3 w:3) + // Storage: VoterList ListBags (r:2 w:2) fn bond_extra_reward() -> Weight { - // Proof Size summary in bytes: - // Measured: `3615` - // Estimated: `38583` - // Minimum execution time: 151_473 nanoseconds. - Weight::from_parts(152_375_000, 38583) - .saturating_add(T::DbWeight::get().reads(14_u64)) - .saturating_add(T::DbWeight::get().writes(13_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Minimum execution time: 166_000 nanoseconds. + Weight::from_ref_time(169_000_000) + .saturating_add(T::DbWeight::get().reads(15)) + .saturating_add(T::DbWeight::get().writes(13)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: NominationPools GlobalMaxCommission (r:1 w:0) fn claim_payout() -> Weight { - // Proof Size summary in bytes: - // Measured: `1189` - // Estimated: `10489` - // Minimum execution time: 51_146 nanoseconds. - Weight::from_parts(51_570_000, 10489) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Staking Nominators (r:1 w:0) - /// Proof: Staking Nominators (max_values: None, max_size: Some(558), added: 3033, mode: MaxEncodedLen) - /// Storage: Staking MinNominatorBond (r:1 w:0) - /// Proof: Staking MinNominatorBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:3 w:3) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:2 w:2) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) - /// Storage: NominationPools SubPoolsStorage (r:1 w:1) - /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) - /// Proof: NominationPools CounterForSubPoolsStorage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 64_000 nanoseconds. + Weight::from_ref_time(65_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: System Account (r:2 w:1) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: Staking Nominators (r:1 w:0) + // Storage: Staking MinNominatorBond (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) + // Storage: VoterList ListNodes (r:3 w:3) + // Storage: VoterList ListBags (r:2 w:2) + // Storage: NominationPools SubPoolsStorage (r:1 w:1) + // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) fn unbond() -> Weight { - // Proof Size summary in bytes: - // Measured: `3858` - // Estimated: `67379` - // Minimum execution time: 141_400 nanoseconds. - Weight::from_parts(141_822_000, 67379) - .saturating_add(T::DbWeight::get().reads(18_u64)) - .saturating_add(T::DbWeight::get().writes(13_u64)) - } - /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + // Minimum execution time: 143_000 nanoseconds. + Weight::from_ref_time(150_000_000) + .saturating_add(T::DbWeight::get().reads(18)) + .saturating_add(T::DbWeight::get().writes(13)) + } + // Storage: NominationPools BondedPools (r:1 w:0) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn pool_withdraw_unbonded(s: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1779` - // Estimated: `13025` - // Minimum execution time: 49_021 nanoseconds. - Weight::from_parts(49_954_282, 13025) - // Standard Error: 378 - .saturating_add(Weight::from_ref_time(5_165).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools SubPoolsStorage (r:1 w:1) - /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForPoolMembers (r:1 w:1) - /// Proof: NominationPools CounterForPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 52_000 nanoseconds. + Weight::from_ref_time(53_724_243) + // Standard Error: 1_649 + .saturating_add(Weight::from_ref_time(23_177).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools SubPoolsStorage (r:1 w:1) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: NominationPools CounterForPoolMembers (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_update(s: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `2303` - // Estimated: `45696` - // Minimum execution time: 92_473 nanoseconds. - Weight::from_parts(93_901_972, 45696) - // Standard Error: 618 - .saturating_add(Weight::from_ref_time(12_032).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools SubPoolsStorage (r:1 w:1) - /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:1) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Staking SlashingSpans (r:1 w:0) - /// Proof Skipped: Staking SlashingSpans (max_values: None, max_size: None, mode: Measured) - /// Storage: Staking Validators (r:1 w:0) - /// Proof: Staking Validators (max_values: None, max_size: Some(45), added: 2520, mode: MaxEncodedLen) - /// Storage: Staking Nominators (r:1 w:0) - /// Proof: Staking Nominators (max_values: None, max_size: Some(558), added: 3033, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForPoolMembers (r:1 w:1) - /// Proof: NominationPools CounterForPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools ReversePoolIdLookup (r:1 w:1) - /// Proof: NominationPools ReversePoolIdLookup (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) - /// Proof: NominationPools CounterForReversePoolIdLookup (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForRewardPools (r:1 w:1) - /// Proof: NominationPools CounterForRewardPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) - /// Proof: NominationPools CounterForSubPoolsStorage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools Metadata (r:1 w:1) - /// Proof: NominationPools Metadata (max_values: None, max_size: Some(270), added: 2745, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForBondedPools (r:1 w:1) - /// Proof: NominationPools CounterForBondedPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Staking Payee (r:0 w:1) - /// Proof: Staking Payee (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + // Minimum execution time: 95_000 nanoseconds. + Weight::from_ref_time(99_545_463) + // Standard Error: 5_079 + .saturating_add(Weight::from_ref_time(31_957).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(7)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools SubPoolsStorage (r:1 w:1) + // Storage: Staking Bonded (r:1 w:1) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Staking SlashingSpans (r:1 w:0) + // Storage: Staking Validators (r:1 w:0) + // Storage: Staking Nominators (r:1 w:0) + // Storage: System Account (r:2 w:2) + // Storage: Balances Locks (r:1 w:1) + // Storage: NominationPools CounterForPoolMembers (r:1 w:1) + // Storage: NominationPools ReversePoolIdLookup (r:1 w:1) + // Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: NominationPools CounterForRewardPools (r:1 w:1) + // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) + // Storage: NominationPools Metadata (r:1 w:1) + // Storage: NominationPools CounterForBondedPools (r:1 w:1) + // Storage: Staking Payee (r:0 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `2690` - // Estimated: `68812` - // Minimum execution time: 150_063 nanoseconds. - Weight::from_parts(152_321_387, 68812) - .saturating_add(T::DbWeight::get().reads(20_u64)) - .saturating_add(T::DbWeight::get().writes(17_u64)) - } - /// Storage: NominationPools LastPoolId (r:1 w:1) - /// Proof: NominationPools LastPoolId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Staking MinNominatorBond (r:1 w:0) - /// Proof: Staking MinNominatorBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools MinCreateBond (r:1 w:0) - /// Proof: NominationPools MinCreateBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools MinJoinBond (r:1 w:0) - /// Proof: NominationPools MinJoinBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPools (r:1 w:0) - /// Proof: NominationPools MaxPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForBondedPools (r:1 w:1) - /// Proof: NominationPools CounterForBondedPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) - /// Proof: NominationPools MaxPoolMembersPerPool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembers (r:1 w:0) - /// Proof: NominationPools MaxPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForPoolMembers (r:1 w:1) - /// Proof: NominationPools CounterForPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:1) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForRewardPools (r:1 w:1) - /// Proof: NominationPools CounterForRewardPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools ReversePoolIdLookup (r:1 w:1) - /// Proof: NominationPools ReversePoolIdLookup (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) - /// Proof: NominationPools CounterForReversePoolIdLookup (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Payee (r:0 w:1) - /// Proof: Staking Payee (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + // Minimum execution time: 148_000 nanoseconds. + Weight::from_ref_time(153_276_873) + .saturating_add(T::DbWeight::get().reads(20)) + .saturating_add(T::DbWeight::get().writes(17)) + } + // Storage: NominationPools LastPoolId (r:1 w:1) + // Storage: Staking MinNominatorBond (r:1 w:0) + // Storage: NominationPools MinCreateBond (r:1 w:0) + // Storage: NominationPools MinJoinBond (r:1 w:0) + // Storage: NominationPools MaxPools (r:1 w:0) + // Storage: NominationPools CounterForBondedPools (r:1 w:1) + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) + // Storage: NominationPools MaxPoolMembers (r:1 w:0) + // Storage: NominationPools CounterForPoolMembers (r:1 w:1) + // Storage: System Account (r:2 w:2) + // Storage: Staking Bonded (r:1 w:1) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: NominationPools CounterForRewardPools (r:1 w:1) + // Storage: NominationPools ReversePoolIdLookup (r:1 w:1) + // Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: Staking Payee (r:0 w:1) fn create() -> Weight { - // Proof Size summary in bytes: - // Measured: `1321` - // Estimated: `31522` - // Minimum execution time: 131_430 nanoseconds. - Weight::from_parts(132_214_000, 31522) - .saturating_add(T::DbWeight::get().reads(21_u64)) - .saturating_add(T::DbWeight::get().writes(15_u64)) - } - /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:0) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Staking MinNominatorBond (r:1 w:0) - /// Proof: Staking MinNominatorBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: Staking Nominators (r:1 w:1) - /// Proof: Staking Nominators (max_values: None, max_size: Some(558), added: 3033, mode: MaxEncodedLen) - /// Storage: Staking MaxNominatorsCount (r:1 w:0) - /// Proof: Staking MaxNominatorsCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Staking Validators (r:17 w:0) - /// Proof: Staking Validators (max_values: None, max_size: Some(45), added: 2520, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:1 w:1) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:1 w:1) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) - /// Storage: VoterList CounterForListNodes (r:1 w:1) - /// Proof: VoterList CounterForListNodes (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Staking CounterForNominators (r:1 w:1) - /// Proof: Staking CounterForNominators (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 131_000 nanoseconds. + Weight::from_ref_time(132_000_000) + .saturating_add(T::DbWeight::get().reads(21)) + .saturating_add(T::DbWeight::get().writes(15)) + } + // Storage: NominationPools BondedPools (r:1 w:0) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:0) + // Storage: Staking MinNominatorBond (r:1 w:0) + // Storage: Staking Nominators (r:1 w:1) + // Storage: Staking MaxNominatorsCount (r:1 w:0) + // Storage: Staking Validators (r:2 w:0) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: VoterList ListNodes (r:1 w:1) + // Storage: VoterList ListBags (r:1 w:1) + // Storage: VoterList CounterForListNodes (r:1 w:1) + // Storage: Staking CounterForNominators (r:1 w:1) /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1909` - // Estimated: `21998 + n * (2520 ±0)` - // Minimum execution time: 61_798 nanoseconds. - Weight::from_parts(61_504_758, 21998) - // Standard Error: 4_046 - .saturating_add(Weight::from_ref_time(1_159_175).saturating_mul(n.into())) - .saturating_add(T::DbWeight::get().reads(12_u64)) + // Minimum execution time: 59_000 nanoseconds. + Weight::from_ref_time(58_398_812) + // Standard Error: 7_443 + .saturating_add(Weight::from_ref_time(1_436_557).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(12)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) - .saturating_add(T::DbWeight::get().writes(5_u64)) - .saturating_add(Weight::from_proof_size(2520).saturating_mul(n.into())) - } - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:0) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) + .saturating_add(T::DbWeight::get().writes(5)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:0) fn set_state() -> Weight { - // Proof Size summary in bytes: - // Measured: `1498` - // Estimated: `8752` - // Minimum execution time: 32_433 nanoseconds. - Weight::from_parts(32_894_000, 8752) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools Metadata (r:1 w:1) - /// Proof: NominationPools Metadata (max_values: None, max_size: Some(270), added: 2745, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForMetadata (r:1 w:1) - /// Proof: NominationPools CounterForMetadata (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 34_000 nanoseconds. + Weight::from_ref_time(35_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:0) + // Storage: NominationPools Metadata (r:1 w:1) + // Storage: NominationPools CounterForMetadata (r:1 w:1) /// The range of component `n` is `[1, 256]`. fn set_metadata(n: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `559` - // Estimated: `5883` - // Minimum execution time: 13_608 nanoseconds. - Weight::from_parts(13_966_346, 5883) - // Standard Error: 44 - .saturating_add(Weight::from_ref_time(1_511).saturating_mul(n.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// Storage: NominationPools MinJoinBond (r:0 w:1) - /// Proof: NominationPools MinJoinBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembers (r:0 w:1) - /// Proof: NominationPools MaxPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembersPerPool (r:0 w:1) - /// Proof: NominationPools MaxPoolMembersPerPool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools MinCreateBond (r:0 w:1) - /// Proof: NominationPools MinCreateBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPools (r:0 w:1) - /// Proof: NominationPools MaxPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 12_000 nanoseconds. + Weight::from_ref_time(13_360_093) + // Standard Error: 294 + .saturating_add(Weight::from_ref_time(514).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: NominationPools MinJoinBond (r:0 w:1) + // Storage: NominationPools MaxPoolMembers (r:0 w:1) + // Storage: NominationPools MaxPoolMembersPerPool (r:0 w:1) + // Storage: NominationPools MinCreateBond (r:0 w:1) + // Storage: NominationPools GlobalMaxCommission (r:0 w:1) + // Storage: NominationPools MaxPools (r:0 w:1) fn set_configs() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 5_832 nanoseconds. - Weight::from_ref_time(6_117_000) - .saturating_add(T::DbWeight::get().writes(5_u64)) - } - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + // Minimum execution time: 6_000 nanoseconds. + Weight::from_ref_time(7_000_000) + .saturating_add(T::DbWeight::get().writes(6)) + } + // Storage: NominationPools BondedPools (r:1 w:1) fn update_roles() -> Weight { - // Proof Size summary in bytes: - // Measured: `559` - // Estimated: `2639` - // Minimum execution time: 18_160 nanoseconds. - Weight::from_parts(18_567_000, 2639) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:0) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Staking Validators (r:1 w:0) - /// Proof: Staking Validators (max_values: None, max_size: Some(45), added: 2520, mode: MaxEncodedLen) - /// Storage: Staking Nominators (r:1 w:1) - /// Proof: Staking Nominators (max_values: None, max_size: Some(558), added: 3033, mode: MaxEncodedLen) - /// Storage: Staking CounterForNominators (r:1 w:1) - /// Proof: Staking CounterForNominators (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:1 w:1) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:1 w:1) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) - /// Storage: VoterList CounterForListNodes (r:1 w:1) - /// Proof: VoterList CounterForListNodes (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 22_000 nanoseconds. + Weight::from_ref_time(23_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:0) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:0) + // Storage: Staking Validators (r:1 w:0) + // Storage: Staking Nominators (r:1 w:1) + // Storage: Staking CounterForNominators (r:1 w:1) + // Storage: VoterList ListNodes (r:1 w:1) + // Storage: VoterList ListBags (r:1 w:1) + // Storage: VoterList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - // Proof Size summary in bytes: - // Measured: `2136` - // Estimated: `20489` - // Minimum execution time: 58_991 nanoseconds. - Weight::from_parts(59_528_000, 20489) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 58_000 nanoseconds. + Weight::from_ref_time(60_000_000) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(5)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission() -> Weight { + // Minimum execution time: 24_000 nanoseconds. + Weight::from_ref_time(24_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission_max() -> Weight { + // Minimum execution time: 21_000 nanoseconds. + Weight::from_ref_time(22_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission_change_rate() -> Weight { + // Minimum execution time: 22_000 nanoseconds. + Weight::from_ref_time(23_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } } // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: NominationPools MinJoinBond (r:1 w:0) - /// Proof: NominationPools MinJoinBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) - /// Proof: NominationPools MaxPoolMembersPerPool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembers (r:1 w:0) - /// Proof: NominationPools MaxPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForPoolMembers (r:1 w:1) - /// Proof: NominationPools CounterForPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:3 w:3) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:2 w:2) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) + // Storage: NominationPools MinJoinBond (r:1 w:0) + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: System Account (r:2 w:1) + // Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) + // Storage: NominationPools MaxPoolMembers (r:1 w:0) + // Storage: NominationPools CounterForPoolMembers (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: VoterList ListNodes (r:3 w:3) + // Storage: VoterList ListBags (r:2 w:2) fn join() -> Weight { - // Proof Size summary in bytes: - // Measured: `3573` - // Estimated: `37988` - // Minimum execution time: 140_155 nanoseconds. - Weight::from_parts(141_098_000, 37988) - .saturating_add(RocksDbWeight::get().reads(17_u64)) - .saturating_add(RocksDbWeight::get().writes(12_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: System Account (r:3 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:3 w:3) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:2 w:2) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) + // Minimum execution time: 142_000 nanoseconds. + Weight::from_ref_time(145_000_000) + .saturating_add(RocksDbWeight::get().reads(17)) + .saturating_add(RocksDbWeight::get().writes(12)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: System Account (r:3 w:2) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: VoterList ListNodes (r:3 w:3) + // Storage: VoterList ListBags (r:2 w:2) fn bond_extra_transfer() -> Weight { - // Proof Size summary in bytes: - // Measured: `3615` - // Estimated: `38583` - // Minimum execution time: 136_048 nanoseconds. - Weight::from_parts(136_767_000, 38583) - .saturating_add(RocksDbWeight::get().reads(14_u64)) - .saturating_add(RocksDbWeight::get().writes(12_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: System Account (r:3 w:3) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:3 w:3) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:2 w:2) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) + // Minimum execution time: 137_000 nanoseconds. + Weight::from_ref_time(142_000_000) + .saturating_add(RocksDbWeight::get().reads(14)) + .saturating_add(RocksDbWeight::get().writes(12)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: System Account (r:3 w:3) + // Storage: NominationPools GlobalMaxCommission (r:1 w:0) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: VoterList ListNodes (r:3 w:3) + // Storage: VoterList ListBags (r:2 w:2) fn bond_extra_reward() -> Weight { - // Proof Size summary in bytes: - // Measured: `3615` - // Estimated: `38583` - // Minimum execution time: 151_473 nanoseconds. - Weight::from_parts(152_375_000, 38583) - .saturating_add(RocksDbWeight::get().reads(14_u64)) - .saturating_add(RocksDbWeight::get().writes(13_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Minimum execution time: 166_000 nanoseconds. + Weight::from_ref_time(169_000_000) + .saturating_add(RocksDbWeight::get().reads(15)) + .saturating_add(RocksDbWeight::get().writes(13)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: NominationPools GlobalMaxCommission (r:1 w:0) fn claim_payout() -> Weight { - // Proof Size summary in bytes: - // Measured: `1189` - // Estimated: `10489` - // Minimum execution time: 51_146 nanoseconds. - Weight::from_parts(51_570_000, 10489) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(4_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Staking Nominators (r:1 w:0) - /// Proof: Staking Nominators (max_values: None, max_size: Some(558), added: 3033, mode: MaxEncodedLen) - /// Storage: Staking MinNominatorBond (r:1 w:0) - /// Proof: Staking MinNominatorBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:3 w:3) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:2 w:2) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) - /// Storage: NominationPools SubPoolsStorage (r:1 w:1) - /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) - /// Proof: NominationPools CounterForSubPoolsStorage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 64_000 nanoseconds. + Weight::from_ref_time(65_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(4)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: System Account (r:2 w:1) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: Staking Nominators (r:1 w:0) + // Storage: Staking MinNominatorBond (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) + // Storage: VoterList ListNodes (r:3 w:3) + // Storage: VoterList ListBags (r:2 w:2) + // Storage: NominationPools SubPoolsStorage (r:1 w:1) + // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) fn unbond() -> Weight { - // Proof Size summary in bytes: - // Measured: `3858` - // Estimated: `67379` - // Minimum execution time: 141_400 nanoseconds. - Weight::from_parts(141_822_000, 67379) - .saturating_add(RocksDbWeight::get().reads(18_u64)) - .saturating_add(RocksDbWeight::get().writes(13_u64)) - } - /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + // Minimum execution time: 143_000 nanoseconds. + Weight::from_ref_time(150_000_000) + .saturating_add(RocksDbWeight::get().reads(18)) + .saturating_add(RocksDbWeight::get().writes(13)) + } + // Storage: NominationPools BondedPools (r:1 w:0) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn pool_withdraw_unbonded(s: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1779` - // Estimated: `13025` - // Minimum execution time: 49_021 nanoseconds. - Weight::from_parts(49_954_282, 13025) - // Standard Error: 378 - .saturating_add(Weight::from_ref_time(5_165).saturating_mul(s.into())) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools SubPoolsStorage (r:1 w:1) - /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForPoolMembers (r:1 w:1) - /// Proof: NominationPools CounterForPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 52_000 nanoseconds. + Weight::from_ref_time(53_724_243) + // Standard Error: 1_649 + .saturating_add(Weight::from_ref_time(23_177).saturating_mul(s.into())) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(2)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools SubPoolsStorage (r:1 w:1) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: NominationPools CounterForPoolMembers (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_update(s: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `2303` - // Estimated: `45696` - // Minimum execution time: 92_473 nanoseconds. - Weight::from_parts(93_901_972, 45696) - // Standard Error: 618 - .saturating_add(Weight::from_ref_time(12_032).saturating_mul(s.into())) - .saturating_add(RocksDbWeight::get().reads(9_u64)) - .saturating_add(RocksDbWeight::get().writes(7_u64)) - } - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools SubPoolsStorage (r:1 w:1) - /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:1) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Staking SlashingSpans (r:1 w:0) - /// Proof Skipped: Staking SlashingSpans (max_values: None, max_size: None, mode: Measured) - /// Storage: Staking Validators (r:1 w:0) - /// Proof: Staking Validators (max_values: None, max_size: Some(45), added: 2520, mode: MaxEncodedLen) - /// Storage: Staking Nominators (r:1 w:0) - /// Proof: Staking Nominators (max_values: None, max_size: Some(558), added: 3033, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForPoolMembers (r:1 w:1) - /// Proof: NominationPools CounterForPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools ReversePoolIdLookup (r:1 w:1) - /// Proof: NominationPools ReversePoolIdLookup (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) - /// Proof: NominationPools CounterForReversePoolIdLookup (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForRewardPools (r:1 w:1) - /// Proof: NominationPools CounterForRewardPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) - /// Proof: NominationPools CounterForSubPoolsStorage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools Metadata (r:1 w:1) - /// Proof: NominationPools Metadata (max_values: None, max_size: Some(270), added: 2745, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForBondedPools (r:1 w:1) - /// Proof: NominationPools CounterForBondedPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Staking Payee (r:0 w:1) - /// Proof: Staking Payee (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + // Minimum execution time: 95_000 nanoseconds. + Weight::from_ref_time(99_545_463) + // Standard Error: 5_079 + .saturating_add(Weight::from_ref_time(31_957).saturating_mul(s.into())) + .saturating_add(RocksDbWeight::get().reads(9)) + .saturating_add(RocksDbWeight::get().writes(7)) + } + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: NominationPools SubPoolsStorage (r:1 w:1) + // Storage: Staking Bonded (r:1 w:1) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Staking SlashingSpans (r:1 w:0) + // Storage: Staking Validators (r:1 w:0) + // Storage: Staking Nominators (r:1 w:0) + // Storage: System Account (r:2 w:2) + // Storage: Balances Locks (r:1 w:1) + // Storage: NominationPools CounterForPoolMembers (r:1 w:1) + // Storage: NominationPools ReversePoolIdLookup (r:1 w:1) + // Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: NominationPools CounterForRewardPools (r:1 w:1) + // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) + // Storage: NominationPools Metadata (r:1 w:1) + // Storage: NominationPools CounterForBondedPools (r:1 w:1) + // Storage: Staking Payee (r:0 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `2690` - // Estimated: `68812` - // Minimum execution time: 150_063 nanoseconds. - Weight::from_parts(152_321_387, 68812) - .saturating_add(RocksDbWeight::get().reads(20_u64)) - .saturating_add(RocksDbWeight::get().writes(17_u64)) - } - /// Storage: NominationPools LastPoolId (r:1 w:1) - /// Proof: NominationPools LastPoolId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Staking MinNominatorBond (r:1 w:0) - /// Proof: Staking MinNominatorBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools MinCreateBond (r:1 w:0) - /// Proof: NominationPools MinCreateBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools MinJoinBond (r:1 w:0) - /// Proof: NominationPools MinJoinBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPools (r:1 w:0) - /// Proof: NominationPools MaxPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForBondedPools (r:1 w:1) - /// Proof: NominationPools CounterForBondedPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools PoolMembers (r:1 w:1) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) - /// Proof: NominationPools MaxPoolMembersPerPool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembers (r:1 w:0) - /// Proof: NominationPools MaxPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForPoolMembers (r:1 w:1) - /// Proof: NominationPools CounterForPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:1) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:1) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForRewardPools (r:1 w:1) - /// Proof: NominationPools CounterForRewardPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools ReversePoolIdLookup (r:1 w:1) - /// Proof: NominationPools ReversePoolIdLookup (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) - /// Proof: NominationPools CounterForReversePoolIdLookup (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Payee (r:0 w:1) - /// Proof: Staking Payee (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + // Minimum execution time: 148_000 nanoseconds. + Weight::from_ref_time(153_276_873) + .saturating_add(RocksDbWeight::get().reads(20)) + .saturating_add(RocksDbWeight::get().writes(17)) + } + // Storage: NominationPools LastPoolId (r:1 w:1) + // Storage: Staking MinNominatorBond (r:1 w:0) + // Storage: NominationPools MinCreateBond (r:1 w:0) + // Storage: NominationPools MinJoinBond (r:1 w:0) + // Storage: NominationPools MaxPools (r:1 w:0) + // Storage: NominationPools CounterForBondedPools (r:1 w:1) + // Storage: NominationPools PoolMembers (r:1 w:1) + // Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) + // Storage: NominationPools MaxPoolMembers (r:1 w:0) + // Storage: NominationPools CounterForPoolMembers (r:1 w:1) + // Storage: System Account (r:2 w:2) + // Storage: Staking Bonded (r:1 w:1) + // Storage: Staking Ledger (r:1 w:1) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) + // Storage: NominationPools RewardPools (r:1 w:1) + // Storage: NominationPools CounterForRewardPools (r:1 w:1) + // Storage: NominationPools ReversePoolIdLookup (r:1 w:1) + // Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: Staking Payee (r:0 w:1) fn create() -> Weight { - // Proof Size summary in bytes: - // Measured: `1321` - // Estimated: `31522` - // Minimum execution time: 131_430 nanoseconds. - Weight::from_parts(132_214_000, 31522) - .saturating_add(RocksDbWeight::get().reads(21_u64)) - .saturating_add(RocksDbWeight::get().writes(15_u64)) - } - /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:0) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Staking MinNominatorBond (r:1 w:0) - /// Proof: Staking MinNominatorBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: Staking Nominators (r:1 w:1) - /// Proof: Staking Nominators (max_values: None, max_size: Some(558), added: 3033, mode: MaxEncodedLen) - /// Storage: Staking MaxNominatorsCount (r:1 w:0) - /// Proof: Staking MaxNominatorsCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Staking Validators (r:17 w:0) - /// Proof: Staking Validators (max_values: None, max_size: Some(45), added: 2520, mode: MaxEncodedLen) - /// Storage: Staking CurrentEra (r:1 w:0) - /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:1 w:1) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:1 w:1) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) - /// Storage: VoterList CounterForListNodes (r:1 w:1) - /// Proof: VoterList CounterForListNodes (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Staking CounterForNominators (r:1 w:1) - /// Proof: Staking CounterForNominators (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 131_000 nanoseconds. + Weight::from_ref_time(132_000_000) + .saturating_add(RocksDbWeight::get().reads(21)) + .saturating_add(RocksDbWeight::get().writes(15)) + } + // Storage: NominationPools BondedPools (r:1 w:0) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:0) + // Storage: Staking MinNominatorBond (r:1 w:0) + // Storage: Staking Nominators (r:1 w:1) + // Storage: Staking MaxNominatorsCount (r:1 w:0) + // Storage: Staking Validators (r:2 w:0) + // Storage: Staking CurrentEra (r:1 w:0) + // Storage: VoterList ListNodes (r:1 w:1) + // Storage: VoterList ListBags (r:1 w:1) + // Storage: VoterList CounterForListNodes (r:1 w:1) + // Storage: Staking CounterForNominators (r:1 w:1) /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1909` - // Estimated: `21998 + n * (2520 ±0)` - // Minimum execution time: 61_798 nanoseconds. - Weight::from_parts(61_504_758, 21998) - // Standard Error: 4_046 - .saturating_add(Weight::from_ref_time(1_159_175).saturating_mul(n.into())) - .saturating_add(RocksDbWeight::get().reads(12_u64)) + // Minimum execution time: 59_000 nanoseconds. + Weight::from_ref_time(58_398_812) + // Standard Error: 7_443 + .saturating_add(Weight::from_ref_time(1_436_557).saturating_mul(n.into())) + .saturating_add(RocksDbWeight::get().reads(12)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into()))) - .saturating_add(RocksDbWeight::get().writes(5_u64)) - .saturating_add(Weight::from_proof_size(2520).saturating_mul(n.into())) - } - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:0) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) + .saturating_add(RocksDbWeight::get().writes(5)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:0) fn set_state() -> Weight { - // Proof Size summary in bytes: - // Measured: `1498` - // Estimated: `8752` - // Minimum execution time: 32_433 nanoseconds. - Weight::from_parts(32_894_000, 8752) - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: NominationPools Metadata (r:1 w:1) - /// Proof: NominationPools Metadata (max_values: None, max_size: Some(270), added: 2745, mode: MaxEncodedLen) - /// Storage: NominationPools CounterForMetadata (r:1 w:1) - /// Proof: NominationPools CounterForMetadata (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 34_000 nanoseconds. + Weight::from_ref_time(35_000_000) + .saturating_add(RocksDbWeight::get().reads(3)) + .saturating_add(RocksDbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:0) + // Storage: NominationPools Metadata (r:1 w:1) + // Storage: NominationPools CounterForMetadata (r:1 w:1) /// The range of component `n` is `[1, 256]`. fn set_metadata(n: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `559` - // Estimated: `5883` - // Minimum execution time: 13_608 nanoseconds. - Weight::from_parts(13_966_346, 5883) - // Standard Error: 44 - .saturating_add(Weight::from_ref_time(1_511).saturating_mul(n.into())) - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// Storage: NominationPools MinJoinBond (r:0 w:1) - /// Proof: NominationPools MinJoinBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembers (r:0 w:1) - /// Proof: NominationPools MaxPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPoolMembersPerPool (r:0 w:1) - /// Proof: NominationPools MaxPoolMembersPerPool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools MinCreateBond (r:0 w:1) - /// Proof: NominationPools MinCreateBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: NominationPools MaxPools (r:0 w:1) - /// Proof: NominationPools MaxPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 12_000 nanoseconds. + Weight::from_ref_time(13_360_093) + // Standard Error: 294 + .saturating_add(Weight::from_ref_time(514).saturating_mul(n.into())) + .saturating_add(RocksDbWeight::get().reads(3)) + .saturating_add(RocksDbWeight::get().writes(2)) + } + // Storage: NominationPools MinJoinBond (r:0 w:1) + // Storage: NominationPools MaxPoolMembers (r:0 w:1) + // Storage: NominationPools MaxPoolMembersPerPool (r:0 w:1) + // Storage: NominationPools MinCreateBond (r:0 w:1) + // Storage: NominationPools GlobalMaxCommission (r:0 w:1) + // Storage: NominationPools MaxPools (r:0 w:1) fn set_configs() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 5_832 nanoseconds. - Weight::from_ref_time(6_117_000) - .saturating_add(RocksDbWeight::get().writes(5_u64)) - } - /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + // Minimum execution time: 6_000 nanoseconds. + Weight::from_ref_time(7_000_000) + .saturating_add(RocksDbWeight::get().writes(6)) + } + // Storage: NominationPools BondedPools (r:1 w:1) fn update_roles() -> Weight { - // Proof Size summary in bytes: - // Measured: `559` - // Estimated: `2639` - // Minimum execution time: 18_160 nanoseconds. - Weight::from_parts(18_567_000, 2639) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) - /// Storage: Staking Bonded (r:1 w:0) - /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Staking Ledger (r:1 w:0) - /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) - /// Storage: Staking Validators (r:1 w:0) - /// Proof: Staking Validators (max_values: None, max_size: Some(45), added: 2520, mode: MaxEncodedLen) - /// Storage: Staking Nominators (r:1 w:1) - /// Proof: Staking Nominators (max_values: None, max_size: Some(558), added: 3033, mode: MaxEncodedLen) - /// Storage: Staking CounterForNominators (r:1 w:1) - /// Proof: Staking CounterForNominators (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: VoterList ListNodes (r:1 w:1) - /// Proof: VoterList ListNodes (max_values: None, max_size: Some(154), added: 2629, mode: MaxEncodedLen) - /// Storage: VoterList ListBags (r:1 w:1) - /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) - /// Storage: VoterList CounterForListNodes (r:1 w:1) - /// Proof: VoterList CounterForListNodes (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Minimum execution time: 22_000 nanoseconds. + Weight::from_ref_time(23_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:0) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:0) + // Storage: Staking Validators (r:1 w:0) + // Storage: Staking Nominators (r:1 w:1) + // Storage: Staking CounterForNominators (r:1 w:1) + // Storage: VoterList ListNodes (r:1 w:1) + // Storage: VoterList ListBags (r:1 w:1) + // Storage: VoterList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - // Proof Size summary in bytes: - // Measured: `2136` - // Estimated: `20489` - // Minimum execution time: 58_991 nanoseconds. - Weight::from_parts(59_528_000, 20489) - .saturating_add(RocksDbWeight::get().reads(9_u64)) - .saturating_add(RocksDbWeight::get().writes(5_u64)) + // Minimum execution time: 58_000 nanoseconds. + Weight::from_ref_time(60_000_000) + .saturating_add(RocksDbWeight::get().reads(9)) + .saturating_add(RocksDbWeight::get().writes(5)) } -} + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission() -> Weight { + // Minimum execution time: 24_000 nanoseconds. + Weight::from_ref_time(24_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission_max() -> Weight { + // Minimum execution time: 21_000 nanoseconds. + Weight::from_ref_time(22_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) + } + // Storage: NominationPools BondedPools (r:1 w:1) + fn set_commission_change_rate() -> Weight { + // Minimum execution time: 22_000 nanoseconds. + Weight::from_ref_time(23_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) + } +} \ No newline at end of file From c1a420731d823ef3bfadb170a0b85a355f1893ae Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sun, 19 Feb 2023 15:22:59 +0700 Subject: [PATCH 15/90] revert PalletError stuff --- frame/nomination-pools/src/lib.rs | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 3e9ffaca135f0..cc9049c6cbf5b 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -396,23 +396,6 @@ enum BondType { Later, } -#[derive(Debug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo, PalletError)] -pub enum CommissionError { - /// Commission change has been throttled. - CommissionChangeThrottled, - // Commission exceeds the pool's maximum commission. - CommissionExceedsMaximum, -} - -impl From for Error { - fn from(t: CommissionError) -> Self { - match t { - CommissionError::CommissionChangeThrottled => Error::::CommissionChangeThrottled, - CommissionError::CommissionExceedsMaximum => Error::::CommissionExceedsMaximum, - } - } -} - /// How to increase the bond of a member. #[derive(Encode, Decode, Clone, Copy, Debug, PartialEq, Eq, TypeInfo)] pub enum BondExtra { @@ -687,14 +670,14 @@ impl Commission { fn try_update_current( &mut self, current: &Option<(Perbill, T::AccountId)>, - ) -> Result<(), CommissionError> { + ) -> DispatchResult { self.current = match current { None => None, Some((commission, payee)) => { - ensure!(!self.throttling(&commission), CommissionError::CommissionChangeThrottled); + ensure!(!self.throttling(&commission), Error::::CommissionChangeThrottled); ensure!( self.max.map_or(true, |m| commission <= &m), - CommissionError::CommissionExceedsMaximum + Error::::CommissionExceedsMaximum ); if commission.is_zero() { None @@ -2407,11 +2390,7 @@ pub mod pallet { let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; ensure!(bonded_pool.can_set_commission(&who), Error::::DoesNotHavePermission); - bonded_pool - .commission - .try_update_current(&new_commission) - .map_err::, _>(Into::into) - .map_err::(Into::into)?; + bonded_pool.commission.try_update_current(&new_commission)?; bonded_pool.put(); Self::deposit_event(Event::::PoolCommissionUpdated { From 2d539e7f9c1ca70073a79cde35de9570abe7eb7d Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Sun, 19 Feb 2023 08:27:59 +0000 Subject: [PATCH 16/90] ".git/.scripts/commands/fmt/fmt.sh" --- frame/nomination-pools/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index cc9049c6cbf5b..0cc4d5f92088b 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -667,10 +667,7 @@ impl Commission { /// Update commission based on `current`. If a `None` is supplied, allow the commission to be /// removed without any change rate restrictions. Updates `throttle_from` to the current block. /// If the supplied commission is zero, `None` will be inserted and `payee` will be ignored. - fn try_update_current( - &mut self, - current: &Option<(Perbill, T::AccountId)>, - ) -> DispatchResult { + fn try_update_current(&mut self, current: &Option<(Perbill, T::AccountId)>) -> DispatchResult { self.current = match current { None => None, Some((commission, payee)) => { From f56227f09fd59cb1f0ccb47a0fd721a5d74c467b Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 20 Feb 2023 19:28:59 +0700 Subject: [PATCH 17/90] make pool_events_since_last_call more modular --- frame/nomination-pools/src/tests.rs | 188 ++++++++++++++++++---------- 1 file changed, 121 insertions(+), 67 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index ce5185f42d087..2a1e57c20217a 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5219,12 +5219,24 @@ mod commission { #[test] fn set_commission_works() { ExtBuilder::default().build_and_execute(|| { + // Set a commission for pool 1. assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), 1, Some((Perbill::from_percent(50), 900)) )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(50), 900)) + }, + ] + ); let commission_as_percent = BondedPool::::get(1) .unwrap() @@ -5241,6 +5253,15 @@ mod commission { 1, Some((Perbill::from_percent(25), 900)) )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(25), 900)) + }, + ] + ); // update payee only. assert_ok!(Pools::set_commission( @@ -5248,10 +5269,26 @@ mod commission { 1, Some((Perbill::from_percent(25), 901)) )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(25), 901)) + }, + ] + ); // remove the commission for pool 1. assert_ok!(Pools::set_commission(RuntimeOrigin::signed(900), 1, None)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PoolCommissionUpdated { pool_id: 1, current: None }, + ] + ); + // test whether supplying a 0% commission along with a payee results in a None `current` // being inserted. // @@ -5279,6 +5316,24 @@ mod commission { Some((Perbill::from_percent(0), 900)) )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(10), 900)) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(0), 900)) + }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(0), 900)) + }, + ] + ); + // test for updating payee only when commission = max commission // // set max commission to 10% @@ -5305,33 +5360,6 @@ mod commission { assert_eq!( pool_events_since_last_call(), vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(50), 900)) - }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(25), 900)) - }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(25), 901)) - }, - Event::PoolCommissionUpdated { pool_id: 1, current: None }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(10), 900)) - }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(0), 900)) - }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(0), 900)) - }, Event::PoolMaxCommissionUpdated { pool_id: 1, max_commission: Perbill::from_percent(10) @@ -5378,6 +5406,18 @@ mod commission { Some((Perbill::from_percent(5), 900)), )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(5), 900)) + }, + ] + ); + // Change rate test. // // Set a change rate to be a +1% commission increase every 2 blocks. @@ -5399,6 +5439,19 @@ mod commission { } ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 2 + } + }, + ] + ); + // Now try to increase commission to 10% (5% increase). This should be throttled. assert_noop!( Pools::set_commission( @@ -5431,6 +5484,15 @@ mod commission { throttle_from: Some(3_u64), } ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(6), 900)) + }, + ] + ); // Attempt to increase the commission an additional 1% (now 7%). this will fail as // `throttle_from` is now the current block. At least 2 blocks need to pass before we @@ -5453,6 +5515,15 @@ mod commission { 1, Some((Perbill::from_percent(7), 900)), )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(7), 900)) + }, + ] + ); // Run 2 blocks into the future, to block 5. run_blocks(2); @@ -5487,6 +5558,15 @@ mod commission { throttle_from: Some(7) } ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PoolMaxCommissionUpdated { + pool_id: 1, + max_commission: Perbill::from_percent(5) + } + ] + ); // Run 2 blocks into the future so we are eligible to update commission again. run_blocks(2); @@ -5502,37 +5582,6 @@ mod commission { ), Error::::CommissionExceedsMaximum ); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(5), 900)) - }, - Event::PoolCommissionChangeRateUpdated { - pool_id: 1, - change_rate: CommissionChangeRate { - max_increase: Perbill::from_percent(1), - min_delay: 2 - } - }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(6), 900)) - }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(7), 900)) - }, - Event::PoolMaxCommissionUpdated { - pool_id: 1, - max_commission: Perbill::from_percent(5) - } - ] - ); }); } @@ -5658,6 +5707,20 @@ mod commission { min_delay: 10_u64 }) ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(5), + min_delay: 10 + } + }, + ] + ); // We now try to half the min_delay - this will be disallowed. A greater delay between // commission changes is seen as more restrictive. @@ -5711,15 +5774,6 @@ mod commission { assert_eq!( pool_events_since_last_call(), vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PoolCommissionChangeRateUpdated { - pool_id: 1, - change_rate: CommissionChangeRate { - max_increase: Perbill::from_percent(5), - min_delay: 10 - } - }, Event::PoolCommissionChangeRateUpdated { pool_id: 1, change_rate: CommissionChangeRate { From 42af0fb5107470ac36969d80f5825f81bc58664c Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 20 Feb 2023 19:29:30 +0700 Subject: [PATCH 18/90] fmt --- frame/nomination-pools/src/tests.rs | 71 ++++++++++++----------------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 2a1e57c20217a..2ffa75e28df57 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5219,7 +5219,6 @@ mod commission { #[test] fn set_commission_works() { ExtBuilder::default().build_and_execute(|| { - // Set a commission for pool 1. assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), @@ -5255,12 +5254,10 @@ mod commission { )); assert_eq!( pool_events_since_last_call(), - vec![ - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(25), 900)) - }, - ] + vec![Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(25), 900)) + },] ); // update payee only. @@ -5271,12 +5268,10 @@ mod commission { )); assert_eq!( pool_events_since_last_call(), - vec![ - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(25), 901)) - }, - ] + vec![Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(25), 901)) + },] ); // remove the commission for pool 1. @@ -5284,9 +5279,7 @@ mod commission { assert_eq!( pool_events_since_last_call(), - vec![ - Event::PoolCommissionUpdated { pool_id: 1, current: None }, - ] + vec![Event::PoolCommissionUpdated { pool_id: 1, current: None },] ); // test whether supplying a 0% commission along with a payee results in a None `current` @@ -5441,15 +5434,13 @@ mod commission { assert_eq!( pool_events_since_last_call(), - vec![ - Event::PoolCommissionChangeRateUpdated { - pool_id: 1, - change_rate: CommissionChangeRate { - max_increase: Perbill::from_percent(1), - min_delay: 2 - } - }, - ] + vec![Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 2 + } + },] ); // Now try to increase commission to 10% (5% increase). This should be throttled. @@ -5486,12 +5477,10 @@ mod commission { ); assert_eq!( pool_events_since_last_call(), - vec![ - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(6), 900)) - }, - ] + vec![Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(6), 900)) + },] ); // Attempt to increase the commission an additional 1% (now 7%). this will fail as @@ -5517,12 +5506,10 @@ mod commission { )); assert_eq!( pool_events_since_last_call(), - vec![ - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(7), 900)) - }, - ] + vec![Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(7), 900)) + },] ); // Run 2 blocks into the future, to block 5. @@ -5560,12 +5547,10 @@ mod commission { ); assert_eq!( pool_events_since_last_call(), - vec![ - Event::PoolMaxCommissionUpdated { - pool_id: 1, - max_commission: Perbill::from_percent(5) - } - ] + vec![Event::PoolMaxCommissionUpdated { + pool_id: 1, + max_commission: Perbill::from_percent(5) + }] ); // Run 2 blocks into the future so we are eligible to update commission again. From 339f2c1c2de3df68846a1b533a69589e5aba76ba Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Thu, 23 Feb 2023 16:53:15 +0700 Subject: [PATCH 19/90] fix call indexes + test --- .../nomination-pools/benchmarking/src/lib.rs | 6 +- frame/nomination-pools/src/lib.rs | 128 +++++++++--------- frame/nomination-pools/src/tests.rs | 1 + 3 files changed, 68 insertions(+), 67 deletions(-) diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index 1dc048c436ba2..7ae178aeac647 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -31,9 +31,9 @@ use frame_support::{assert_ok, ensure, traits::Get}; use frame_system::RawOrigin as RuntimeOrigin; use pallet_nomination_pools::{ BalanceOf, BondExtra, BondedPoolInner, BondedPools, ClaimPermission, ClaimPermissions, - Commission, CommissionChangeRate, ConfigOp, GlobalMaxCommission, MaxPoolMembers, MaxPoolMembersPerPool, - MaxPools, Metadata, MinCreateBond, MinJoinBond, Pallet as Pools, PoolMembers, PoolRoles, PoolState, - RewardPools, SubPoolsStorage, + Commission, CommissionChangeRate, ConfigOp, GlobalMaxCommission, MaxPoolMembers, + MaxPoolMembersPerPool, MaxPools, Metadata, MinCreateBond, MinJoinBond, Pallet as Pools, + PoolMembers, PoolRoles, PoolState, RewardPools, SubPoolsStorage, }; use sp_staking::{EraIndex, StakingInterface}; // `frame_benchmarking::benchmarks!` macro needs this diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index bf5717b6a600c..b69c9718ae8da 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2387,6 +2387,67 @@ pub mod pallet { T::Staking::chill(&bonded_pool.bonded_account()) } + /// `origin` bonds funds from `extra` for some pool member `member` into their respective + /// pools. + /// + /// `origin` can bond extra funds from free balance or pending rewards when `origin == + /// other`. + /// + /// In the case of `origin != other`, `origin` can only bond extra pending rewards of + /// `other` members assuming set_claim_permission for the given member is + /// `PermissionlessAll` or `PermissionlessCompound`. + #[pallet::call_index(14)] + #[pallet::weight( + T::WeightInfo::bond_extra_transfer() + .max(T::WeightInfo::bond_extra_other()) + )] + pub fn bond_extra_other( + origin: OriginFor, + member: AccountIdLookupOf, + extra: BondExtra>, + ) -> DispatchResult { + let who = ensure_signed(origin)?; + Self::do_bond_extra(who, T::Lookup::lookup(member)?, extra) + } + + /// Allows a pool member to set a claim permission to allow or disallow permissionless + /// bonding and withdrawing. + /// + /// By default, this is `Permissioned`, which implies only the pool member themselves can + /// claim their pending rewards. If a pool member wishes so, they can set this to + /// `PermissionlessAll` to allow any account to claim their rewards and bond extra to the + /// pool. + /// + /// # Arguments + /// + /// * `origin` - Member of a pool. + /// * `actor` - Account to claim reward. // improve this + #[pallet::call_index(15)] + #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + pub fn set_claim_permission( + origin: OriginFor, + permission: ClaimPermission, + ) -> DispatchResult { + let who = ensure_signed(origin)?; + + ensure!(PoolMembers::::contains_key(&who), Error::::PoolMemberNotFound); + ClaimPermissions::::mutate(who, |source| { + *source = permission; + }); + Ok(()) + } + + /// `origin` can claim payouts on some pool member `other`'s behalf. + /// + /// Pool member `other` must have a `PermissionlessAll` or `PermissionlessWithdraw` in order + /// for this call to be successful. + #[pallet::call_index(16)] + #[pallet::weight(T::WeightInfo::claim_payout())] + pub fn claim_payout_other(origin: OriginFor, other: T::AccountId) -> DispatchResult { + let signer = ensure_signed(origin)?; + Self::do_claim_payout(signer, other) + } + /// Set the commission of a pool. /// /// The dispatch origin of this call must be signed by the `root` role of the pool. Both a @@ -2394,7 +2455,7 @@ pub mod pallet { /// Where a `current` of `None` is provided, any current commission will be removed. /// /// - If a `None` is supplied to `new_commission`, existing commission will be removed. - #[pallet::call_index(14)] + #[pallet::call_index(17)] #[pallet::weight(T::WeightInfo::set_commission())] pub fn set_commission( origin: OriginFor, @@ -2422,7 +2483,7 @@ pub mod pallet { /// - Initial max can be set to any `Perbill`, and only smaller values thereafter. /// - Current commission will be lowered in the event it is higher than a new max /// commission. - #[pallet::call_index(15)] + #[pallet::call_index(18)] #[pallet::weight(T::WeightInfo::set_commission_max())] pub fn set_commission_max( origin: OriginFor, @@ -2445,7 +2506,7 @@ pub mod pallet { /// The dispatch origin of this call must be signed by the `root` role of the pool. Initial /// change rate is not bounded, whereas subsequent updates can only be more restrictive than /// the current. - #[pallet::call_index(16)] + #[pallet::call_index(19)] #[pallet::weight(T::WeightInfo::set_commission_change_rate())] pub fn set_commission_change_rate( origin: OriginFor, @@ -2464,67 +2525,6 @@ pub mod pallet { change_rate, }); Ok(()) - } - - /// `origin` bonds funds from `extra` for some pool member `member` into their respective - /// pools. - /// - /// `origin` can bond extra funds from free balance or pending rewards when `origin == - /// other`. - /// - /// In the case of `origin != other`, `origin` can only bond extra pending rewards of - /// `other` members assuming set_claim_permission for the given member is - /// `PermissionlessAll` or `PermissionlessCompound`. - #[pallet::call_index(14)] - #[pallet::weight( - T::WeightInfo::bond_extra_transfer() - .max(T::WeightInfo::bond_extra_other()) - )] - pub fn bond_extra_other( - origin: OriginFor, - member: AccountIdLookupOf, - extra: BondExtra>, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - Self::do_bond_extra(who, T::Lookup::lookup(member)?, extra) - } - - /// Allows a pool member to set a claim permission to allow or disallow permissionless - /// bonding and withdrawing. - /// - /// By default, this is `Permissioned`, which implies only the pool member themselves can - /// claim their pending rewards. If a pool member wishes so, they can set this to - /// `PermissionlessAll` to allow any account to claim their rewards and bond extra to the - /// pool. - /// - /// # Arguments - /// - /// * `origin` - Member of a pool. - /// * `actor` - Account to claim reward. // improve this - #[pallet::call_index(15)] - #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] - pub fn set_claim_permission( - origin: OriginFor, - permission: ClaimPermission, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - - ensure!(PoolMembers::::contains_key(&who), Error::::PoolMemberNotFound); - ClaimPermissions::::mutate(who, |source| { - *source = permission; - }); - Ok(()) - } - - /// `origin` can claim payouts on some pool member `other`'s behalf. - /// - /// Pool member `other` must have a `PermissionlessAll` or `PermissionlessWithdraw` in order - /// for this call to be successful. - #[pallet::call_index(16)] - #[pallet::weight(T::WeightInfo::claim_payout())] - pub fn claim_payout_other(origin: OriginFor, other: T::AccountId) -> DispatchResult { - let signer = ensure_signed(origin)?; - Self::do_claim_payout(signer, other) } } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index b1b69c8759f3e..34409185d0295 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -4314,6 +4314,7 @@ mod create { nominator: Some(456), bouncer: Some(789) }, + state: PoolState::Open, } } ); From 3955de0afaacda97fc333c96f5f0398609c5907c Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Thu, 23 Feb 2023 17:05:39 +0700 Subject: [PATCH 20/90] add payout teste --- frame/nomination-pools/src/tests.rs | 82 ++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 20 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 34409185d0295..faee0a0d4ecf5 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5411,25 +5411,31 @@ mod commission { #[test] fn set_commission_works() { ExtBuilder::default().build_and_execute(|| { + let (mut member, bonded_pool, mut reward_pool) = + Pools::get_member_with_pools(&10).unwrap(); + + // top up commission payee account to existential deposit + let _ = Balances::deposit_creating(&900, 5); + // Set a commission for pool 1. assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - 1, + bonded_pool.id, Some((Perbill::from_percent(50), 900)) )); assert_eq!( pool_events_since_last_call(), vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Created { depositor: 10, pool_id: bonded_pool.id }, + Event::Bonded { member: 10, pool_id: bonded_pool.id, bonded: 10, joined: true }, Event::PoolCommissionUpdated { - pool_id: 1, + pool_id: bonded_pool.id, current: Some((Perbill::from_percent(50), 900)) }, ] ); - let commission_as_percent = BondedPool::::get(1) + let commission_as_percent = BondedPool::::get(bonded_pool.id) .unwrap() .commission .current @@ -5447,11 +5453,29 @@ mod commission { assert_eq!( pool_events_since_last_call(), vec![Event::PoolCommissionUpdated { - pool_id: 1, + pool_id: bonded_pool.id, current: Some((Perbill::from_percent(25), 900)) },] ); + // Pool earns 40 points, payout is triggered. + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 40)); + assert_ok!(Pools::do_reward_payout( + &10, + &mut member, + &mut BondedPool::::get(1).unwrap(), + &mut reward_pool + )); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { + member: 10, + pool_id: bonded_pool.id, + payout: 30, + commission: 10 + },] + ); + // update payee only. assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), @@ -5461,17 +5485,35 @@ mod commission { assert_eq!( pool_events_since_last_call(), vec![Event::PoolCommissionUpdated { - pool_id: 1, + pool_id: bonded_pool.id, current: Some((Perbill::from_percent(25), 901)) },] ); // remove the commission for pool 1. - assert_ok!(Pools::set_commission(RuntimeOrigin::signed(900), 1, None)); + assert_ok!(Pools::set_commission(RuntimeOrigin::signed(900), bonded_pool.id, None)); assert_eq!( pool_events_since_last_call(), - vec![Event::PoolCommissionUpdated { pool_id: 1, current: None },] + vec![Event::PoolCommissionUpdated { pool_id: bonded_pool.id, current: None },] + ); + + // Pool earns 100 points, payout is triggered. + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); + assert_ok!(Pools::do_reward_payout( + &10, + &mut member, + &mut BondedPool::::get(1).unwrap(), + &mut reward_pool + )); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { + member: 10, + pool_id: bonded_pool.id, + payout: 100, + commission: 0 + },] ); // test whether supplying a 0% commission along with a payee results in a None `current` @@ -5486,7 +5528,7 @@ mod commission { // set the commission to 0% assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - 1, + bonded_pool.id, Some((Perbill::from_percent(0), 900)) )); // commssion current should now be None, and `throttle_from` the current block. @@ -5497,7 +5539,7 @@ mod commission { // set the commission to 0% assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - 1, + bonded_pool.id, Some((Perbill::from_percent(0), 900)) )); @@ -5505,15 +5547,15 @@ mod commission { pool_events_since_last_call(), vec![ Event::PoolCommissionUpdated { - pool_id: 1, + pool_id: bonded_pool.id, current: Some((Perbill::from_percent(10), 900)) }, Event::PoolCommissionUpdated { - pool_id: 1, + pool_id: bonded_pool.id, current: Some((Perbill::from_percent(0), 900)) }, Event::PoolCommissionUpdated { - pool_id: 1, + pool_id: bonded_pool.id, current: Some((Perbill::from_percent(0), 900)) }, ] @@ -5524,21 +5566,21 @@ mod commission { // set max commission to 10% assert_ok!(Pools::set_commission_max( RuntimeOrigin::signed(900), - 1, + bonded_pool.id, Perbill::from_percent(10) )); // set commission to 10% assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - 1, + bonded_pool.id, Some((Perbill::from_percent(10), 900)) )); // update payee only and keep current commission assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - 1, + bonded_pool.id, Some((Perbill::from_percent(10), 901)) )); @@ -5546,15 +5588,15 @@ mod commission { pool_events_since_last_call(), vec![ Event::PoolMaxCommissionUpdated { - pool_id: 1, + pool_id: bonded_pool.id, max_commission: Perbill::from_percent(10) }, Event::PoolCommissionUpdated { - pool_id: 1, + pool_id: bonded_pool.id, current: Some((Perbill::from_percent(10), 900)) }, Event::PoolCommissionUpdated { - pool_id: 1, + pool_id: bonded_pool.id, current: Some((Perbill::from_percent(10), 901)) } ] From 29e5c751158792ba3d6d2dbce11dd36c21a60a33 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Thu, 23 Feb 2023 17:25:39 +0700 Subject: [PATCH 21/90] add event to max_commisson updating current --- frame/nomination-pools/src/lib.rs | 11 +++++++++-- frame/nomination-pools/src/tests.rs | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index b69c9718ae8da..a1e0d343a0d3c 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -735,7 +735,8 @@ impl Commission { /// /// If `current.0` is larger than the updated max commission value, `current.0` will also be /// updated to the new maximum. This will also register a `throttle_from` update. - fn try_update_max(&mut self, new_max: Perbill) -> DispatchResult { + /// A `PoolCommissionUpdated` event is triggered if `current.0` is updated. + fn try_update_max(&mut self, pool_id: PoolId, new_max: Perbill) -> DispatchResult { if let Some(old) = self.max.as_mut() { if new_max > *old { return Err(Error::::MaxCommissionRestricted.into()) @@ -755,6 +756,12 @@ impl Commission { .unwrap_or(false); if updated_current { + if let Some((_, payee)) = self.current.as_ref() { + Pallet::::deposit_event(Event::::PoolCommissionUpdated { + pool_id, + current: Some((new_max, payee.clone())), + }); + } self.register_update(); } Ok(()) @@ -2494,7 +2501,7 @@ pub mod pallet { let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; ensure!(bonded_pool.can_set_commission(&who), Error::::DoesNotHavePermission); - bonded_pool.commission.try_update_max(max_commission)?; + bonded_pool.commission.try_update_max(pool_id, max_commission)?; bonded_pool.put(); Self::deposit_event(Event::::PoolMaxCommissionUpdated { pool_id, max_commission }); diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index faee0a0d4ecf5..b7bfff8c6a778 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5781,10 +5781,16 @@ mod commission { ); assert_eq!( pool_events_since_last_call(), - vec![Event::PoolMaxCommissionUpdated { - pool_id: 1, - max_commission: Perbill::from_percent(5) - }] + vec![ + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(5), 900)) + }, + Event::PoolMaxCommissionUpdated { + pool_id: 1, + max_commission: Perbill::from_percent(5) + } + ] ); // Run 2 blocks into the future so we are eligible to update commission again. @@ -5876,6 +5882,10 @@ mod commission { pool_id: 1, current: Some((Perbill::from_percent(75), 900)) }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(50), 900)) + }, Event::PoolMaxCommissionUpdated { pool_id: 1, max_commission: Perbill::from_percent(50) From 9cbeee164f227a0dc83173c537c66e792c8af214 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Thu, 23 Feb 2023 19:06:02 +0700 Subject: [PATCH 22/90] begin refactor --- frame/nomination-pools/src/lib.rs | 124 +++++++++++++++++------- frame/nomination-pools/src/migration.rs | 2 + frame/nomination-pools/src/tests.rs | 30 +++--- 3 files changed, 106 insertions(+), 50 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index a1e0d343a0d3c..292a644fec0cf 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1232,6 +1232,10 @@ pub struct RewardPool { last_recorded_total_payouts: BalanceOf, /// Total amount that this pool has paid out so far to the members. total_rewards_claimed: BalanceOf, + /// The amount of commission pending to be claimed. + total_commission_pending: BalanceOf, + /// The amount of commission that has been claimed. + total_commission_claimed: BalanceOf, } impl RewardPool { @@ -1246,11 +1250,21 @@ impl RewardPool { } /// Update the recorded values of the pool. - fn update_records(&mut self, id: PoolId, bonded_points: BalanceOf) -> Result<(), Error> { + fn update_records( + &mut self, + id: PoolId, + bonded_points: BalanceOf, + commission: &Commission, + ) -> Result<(), Error> { let balance = Self::current_balance(id); - self.last_recorded_reward_counter = self.current_reward_counter(id, bonded_points)?; + let (current_reward_counter, newly_earned_commission) = + self.current_reward_counter(id, bonded_points, commission)?; + + self.last_recorded_reward_counter = current_reward_counter; + self.total_commission_pending += newly_earned_commission; + self.last_recorded_total_payouts = balance - .checked_add(&self.total_rewards_claimed) + .checked_add(&self.total_rewards_claimed.saturating_add(self.total_commission_claimed)) .ok_or(Error::::OverflowRisk)?; Ok(()) } @@ -1261,12 +1275,25 @@ impl RewardPool { &self, id: PoolId, bonded_points: BalanceOf, - ) -> Result> { + commission: &Commission, + ) -> Result<(T::RewardCounter, BalanceOf), Error> { let balance = Self::current_balance(id); let payouts_since_last_record = balance .saturating_add(self.total_rewards_claimed) + .saturating_add(self.total_commission_claimed) .saturating_sub(self.last_recorded_total_payouts); + // Split the `payouts_since_last_record` into regular rewards and commission according to + // the current commission rate. + let current = commission + .current + .as_ref() + .map_or(Perbill::zero(), |(c, _)| c.clone()) + .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())); + + let share_commission = current * payouts_since_last_record; + let share_rewards = payouts_since_last_record - share_commission; + // * accuracy notes regarding the multiplication in `checked_from_rational`: // `payouts_since_last_record` is a subset of the total_issuance at the very // worse. `bonded_points` are similarly, in a non-slashed pool, have the same granularity as @@ -1300,9 +1327,12 @@ impl RewardPool { // x = 100 // // which is basically 10^-8 DOTs. See `smallest_claimable_reward` for an example of this. - T::RewardCounter::checked_from_rational(payouts_since_last_record, bonded_points) - .and_then(|ref r| self.last_recorded_reward_counter.checked_add(r)) - .ok_or(Error::::OverflowRisk) + let current_reward_counter = + T::RewardCounter::checked_from_rational(share_rewards, bonded_points) + .and_then(|ref r| self.last_recorded_reward_counter.checked_add(r)) + .ok_or(Error::::OverflowRisk)?; + + Ok((current_reward_counter, share_commission)) } /// Current free balance of the reward pool. @@ -1827,7 +1857,7 @@ pub mod pallet { let mut reward_pool = RewardPools::::get(pool_id) .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; // IMPORTANT: reward pool records must be updated with the old points. - reward_pool.update_records(pool_id, bonded_pool.points)?; + reward_pool.update_records(pool_id, bonded_pool.points, &bonded_pool.commission)?; bonded_pool.try_inc_members()?; let points_issued = bonded_pool.try_bond_funds(&who, amount, BondType::Later)?; @@ -1940,7 +1970,11 @@ pub mod pallet { // Claim the the payout prior to unbonding. Once the user is unbonding their points no // longer exist in the bonded pool and thus they can no longer claim their payouts. It // is not strictly necessary to claim the rewards, but we do it here for UX. - let _ = reward_pool.update_records(bonded_pool.id, bonded_pool.points)?; + let _ = reward_pool.update_records( + bonded_pool.id, + bonded_pool.points, + &bonded_pool.commission, + )?; let _ = Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?; let current_era = T::Staking::current_era(); @@ -2473,8 +2507,13 @@ pub mod pallet { let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; ensure!(bonded_pool.can_set_commission(&who), Error::::DoesNotHavePermission); - bonded_pool.commission.try_update_current(&new_commission)?; + let mut reward_pool = RewardPools::::get(pool_id) + .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; + // IMPORTANT: make sure that everything up to this point is using the current commission + // before it updates. Note that `try_update_current` could still fail at this point. + reward_pool.update_records(pool_id, bonded_pool.points, &bonded_pool.commission)?; + bonded_pool.commission.try_update_current(&new_commission)?; bonded_pool.put(); Self::deposit_event(Event::::PoolCommissionUpdated { pool_id, @@ -2716,9 +2755,12 @@ impl Pallet { // a member who has no skin in the game anymore cannot claim any rewards. ensure!(!member.active_points().is_zero(), Error::::FullyUnbonding); - let current_reward_counter = - reward_pool.current_reward_counter(bonded_pool.id, bonded_pool.points)?; - let mut pending_rewards = member.pending_rewards(current_reward_counter)?; + let (current_reward_counter, _) = reward_pool.current_reward_counter( + bonded_pool.id, + bonded_pool.points, + &bonded_pool.commission, + )?; + let pending_rewards = member.pending_rewards(current_reward_counter)?; if pending_rewards.is_zero() { return Ok(pending_rewards) @@ -2728,24 +2770,27 @@ impl Pallet { member.last_recorded_reward_counter = current_reward_counter; reward_pool.register_claimed_reward(pending_rewards); + // TODO: Remove once new commission refactor is working as intended. + // Legacy code to split and payout commission upon reward payout. + // Gets the commission percentage and payee to be paid if commission has been set. // Otherwise, `None` is returned. - let maybe_commission = &bonded_pool.commission.maybe_commission_and_payee(&pending_rewards); - - if let Some((pool_commission, payee)) = maybe_commission { - // Deduct any outstanding commission from the reward being claimed. - pending_rewards = pending_rewards.saturating_sub(*pool_commission); - - // Send any non-zero `pool_commission` to the commission `payee`. - if pool_commission > &Zero::zero() { - T::Currency::transfer( - &bonded_pool.reward_account(), - &payee, - *pool_commission, - ExistenceRequirement::KeepAlive, - )?; - } - } + // let maybe_commission = + // &bonded_pool.commission.maybe_commission_and_payee(&pending_rewards); + // if let Some((pool_commission, payee)) = maybe_commission { + // // Deduct any outstanding commission from the reward being claimed. + // pending_rewards = pending_rewards.saturating_sub(*pool_commission); + + // // Send any non-zero `pool_commission` to the commission `payee`. + // if pool_commission > &Zero::zero() { + // T::Currency::transfer( + // &bonded_pool.reward_account(), + // &payee, + // *pool_commission, + // ExistenceRequirement::KeepAlive, + // )?; + // } + // } // Transfer remaining payout to the member. // @@ -2766,7 +2811,9 @@ impl Pallet { member: member_account.clone(), pool_id: member.pool_id, payout: pending_rewards, - commission: maybe_commission.as_ref().map(|(c, _)| *c).unwrap_or(Zero::zero()), + // TODO: Remove once new commission refactor is working as intended. + // commission: maybe_commission.as_ref().map(|(c, _)| *c).unwrap_or(Zero::zero()), + commission: Zero::zero(), }); Ok(pending_rewards) @@ -2825,6 +2872,8 @@ impl Pallet { last_recorded_reward_counter: Zero::zero(), last_recorded_total_payouts: Zero::zero(), total_rewards_claimed: Zero::zero(), + total_commission_claimed: Zero::zero(), + total_commission_pending: Zero::zero(), }, ); ReversePoolIdLookup::::insert(bonded_pool.bonded_account(), pool_id); @@ -2859,7 +2908,7 @@ impl Pallet { // payout related stuff: we must claim the payouts, and updated recorded payout data // before updating the bonded pool points, similar to that of `join` transaction. - reward_pool.update_records(bonded_pool.id, bonded_pool.points)?; + reward_pool.update_records(bonded_pool.id, bonded_pool.points, &bonded_pool.commission)?; let claimed = Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?; @@ -2977,8 +3026,9 @@ impl Pallet { let reward_pool = RewardPools::::get(d.pool_id).unwrap(); if !bonded_pool.points.is_zero() { - let current_rc = - reward_pool.current_reward_counter(d.pool_id, bonded_pool.points).unwrap(); + let (current_rc, _) = reward_pool + .current_reward_counter(d.pool_id, bonded_pool.points, &bonded_pool.commission) + .unwrap(); *pools_members_pending_rewards.entry(d.pool_id).or_default() += d.pending_rewards(current_rc).unwrap(); } // else this pool has been heavily slashed and cannot have any rewards anymore. @@ -3069,8 +3119,12 @@ impl Pallet { if let Some((reward_pool, bonded_pool)) = RewardPools::::get(pool_member.pool_id) .zip(BondedPools::::get(pool_member.pool_id)) { - let current_reward_counter = reward_pool - .current_reward_counter(pool_member.pool_id, bonded_pool.points) + let (current_reward_counter, _) = reward_pool + .current_reward_counter( + pool_member.pool_id, + bonded_pool.points, + &bonded_pool.commission, + ) .ok()?; return pool_member.pending_rewards(current_reward_counter).ok() } diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 5e02ad30b6df6..af5592992866d 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -311,6 +311,8 @@ pub mod v2 { last_recorded_reward_counter: Zero::zero(), last_recorded_total_payouts: Zero::zero(), total_rewards_claimed: Zero::zero(), + total_commission_claimed: Zero::zero(), + total_commission_pending: Zero::zero(), }) }, ); diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index b7bfff8c6a778..8fca2f562263e 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -68,7 +68,9 @@ fn test_setup_works() { RewardPool:: { last_recorded_reward_counter: Zero::zero(), last_recorded_total_payouts: 0, - total_rewards_claimed: 0 + total_rewards_claimed: 0, + total_commission_claimed: 0, + total_commission_pending: 0, } ); assert_eq!( @@ -729,6 +731,8 @@ mod claim_payout { last_recorded_reward_counter: last_recorded_reward_counter.into(), last_recorded_total_payouts, total_rewards_claimed, + total_commission_claimed: 0, + total_commission_pending: 0, } } @@ -982,7 +986,7 @@ mod claim_payout { // commission applied is 50%, not 75%. Has been bounded by `GlobalMaxCommission`. assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 5 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 },] ); }) } @@ -5059,10 +5063,12 @@ mod reward_counter_precision { } fn default_pool_reward_counter() -> FixedU128 { + let bonded_pool = BondedPools::::get(1).unwrap(); RewardPools::::get(1) .unwrap() - .current_reward_counter(1, BondedPools::::get(1).unwrap().points) + .current_reward_counter(1, bonded_pool.points, &bonded_pool.commission) .unwrap() + .0 } fn pending_rewards(of: AccountId) -> Option> { @@ -5472,7 +5478,7 @@ mod commission { member: 10, pool_id: bonded_pool.id, payout: 30, - commission: 10 + commission: 0 },] ); @@ -6287,7 +6293,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 7, commission: 3 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 7, commission: 0 },] ); // The pool earns 17 points @@ -6302,7 +6308,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 11, commission: 6 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 11, commission: 0 },] ); // The pool earns 50 points @@ -6317,7 +6323,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 34, commission: 16 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 34, commission: 0 },] ); // The pool earns 10439 points @@ -6332,7 +6338,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 6994, commission: 3445 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 6994, commission: 0 },] ); }) } @@ -6385,12 +6391,6 @@ mod commission { &mut BondedPool::::get(1).unwrap(), &mut reward_pool )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 0, commission: 10 },] - ); }) } @@ -6445,7 +6445,7 @@ mod commission { // of 10 points, reflecting the 90% global max commission. assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1, commission: 9 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1, commission: 0 },] ); }) } From f4db6b3c381b90954a2cbbcd68315c15bed84ae6 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Thu, 23 Feb 2023 21:04:58 +0700 Subject: [PATCH 23/90] some debugging --- frame/nomination-pools/src/lib.rs | 1 + frame/nomination-pools/src/tests.rs | 55 +++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 292a644fec0cf..38539adf4e8c0 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1280,6 +1280,7 @@ impl RewardPool { let balance = Self::current_balance(id); let payouts_since_last_record = balance .saturating_add(self.total_rewards_claimed) + .saturating_add(self.total_commission_pending) .saturating_add(self.total_commission_claimed) .saturating_sub(self.last_recorded_total_payouts); diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 8fca2f562263e..ff71b1bd5405e 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5466,6 +5466,12 @@ mod commission { // Pool earns 40 points, payout is triggered. assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 40)); + + assert_eq!( + PoolMembers::::get(10).unwrap(), + PoolMember:: { pool_id: bonded_pool.id, points: 10, ..Default::default() } + ); + assert_ok!(Pools::do_reward_payout( &10, &mut member, @@ -5479,15 +5485,34 @@ mod commission { pool_id: bonded_pool.id, payout: 30, commission: 0 - },] + }] ); + let (mut member, bonded_pool, mut reward_pool) = + Pools::get_member_with_pools(&10).unwrap(); + + let (current_reward_counter, _) = reward_pool + .current_reward_counter(bonded_pool.id, bonded_pool.points, &bonded_pool.commission) + .unwrap(); + + assert_eq!(current_reward_counter, Zero::zero()); + // update payee only. assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), 1, Some((Perbill::from_percent(25), 901)) )); + + let current = bonded_pool + .commission + .current + .as_ref() + .map_or(Perbill::zero(), |(c, _)| c.clone()) + .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())); + + assert_eq!(current, Perbill::from_percent(25)); + assert_eq!( pool_events_since_last_call(), vec![Event::PoolCommissionUpdated { @@ -5496,6 +5521,11 @@ mod commission { },] ); + assert_eq!(reward_pool.total_commission_pending, 10); + + // Pool earns 100 points, payout is triggered. + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); + // remove the commission for pool 1. assert_ok!(Pools::set_commission(RuntimeOrigin::signed(900), bonded_pool.id, None)); @@ -5504,8 +5534,27 @@ mod commission { vec![Event::PoolCommissionUpdated { pool_id: bonded_pool.id, current: None },] ); - // Pool earns 100 points, payout is triggered. - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); + assert_eq!( + BondedPools::::get(bonded_pool.id).unwrap(), + BondedPoolInner { + commission: Commission { + current: None, + max: None, + change_rate: None, + throttle_from: Some(1) + }, + member_counter: 1, + points: 10, + roles: PoolRoles { + depositor: 10, + root: Some(900), + nominator: Some(901), + bouncer: Some(902) + }, + state: PoolState::Open + } + ); + assert_ok!(Pools::do_reward_payout( &10, &mut member, From f3fdbb40012557f1418e7c7c2dca59f8126c9bfe Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Thu, 23 Feb 2023 23:27:05 +0700 Subject: [PATCH 24/90] update --- frame/nomination-pools/src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 38539adf4e8c0..82c32fe609c7c 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1257,11 +1257,14 @@ impl RewardPool { commission: &Commission, ) -> Result<(), Error> { let balance = Self::current_balance(id); - let (current_reward_counter, newly_earned_commission) = + + let (current_reward_counter, share_commission) = self.current_reward_counter(id, bonded_points, commission)?; self.last_recorded_reward_counter = current_reward_counter; - self.total_commission_pending += newly_earned_commission; + + self.total_commission_pending = + self.total_commission_pending.saturating_add(share_commission); self.last_recorded_total_payouts = balance .checked_add(&self.total_rewards_claimed.saturating_add(self.total_commission_claimed)) @@ -2873,8 +2876,8 @@ impl Pallet { last_recorded_reward_counter: Zero::zero(), last_recorded_total_payouts: Zero::zero(), total_rewards_claimed: Zero::zero(), - total_commission_claimed: Zero::zero(), total_commission_pending: Zero::zero(), + total_commission_claimed: Zero::zero(), }, ); ReversePoolIdLookup::::insert(bonded_pool.bonded_account(), pool_id); From 1537684ac356207d4f927a2cd92af7967120b93e Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Thu, 23 Feb 2023 23:27:14 +0700 Subject: [PATCH 25/90] more tests --- frame/nomination-pools/src/tests.rs | 80 ++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 12 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index ff71b1bd5405e..8b1bedfdf5b42 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5412,6 +5412,7 @@ mod reward_counter_precision { } mod commission { + use super::*; #[test] @@ -5464,14 +5465,31 @@ mod commission { },] ); + let current = BondedPools::::get(bonded_pool.id).unwrap() + .commission + .current + .as_ref() + .map_or(Perbill::zero(), |(c, _)| c.clone()) + .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())); + assert_eq!(current, Perbill::from_percent(25)); + // Pool earns 40 points, payout is triggered. assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 40)); - assert_eq!( PoolMembers::::get(10).unwrap(), PoolMember:: { pool_id: bonded_pool.id, points: 10, ..Default::default() } ); + let (current_reward_counter, share_commission) = reward_pool + .current_reward_counter(bonded_pool.id, bonded_pool.points, &BondedPools::::get(bonded_pool.id).unwrap().commission) + .unwrap(); + + let pending_rewards = PoolMembers::::get(10) + .unwrap() + .pending_rewards(current_reward_counter) + .unwrap(); + assert_eq!(pending_rewards, 30); + assert_ok!(Pools::do_reward_payout( &10, &mut member, @@ -5488,23 +5506,28 @@ mod commission { }] ); - let (mut member, bonded_pool, mut reward_pool) = - Pools::get_member_with_pools(&10).unwrap(); + assert_eq!(RewardPool::::current_balance(bonded_pool.id), 10); - let (current_reward_counter, _) = reward_pool - .current_reward_counter(bonded_pool.id, bonded_pool.points, &bonded_pool.commission) - .unwrap(); - - assert_eq!(current_reward_counter, Zero::zero()); + // uncomment to check reward_pool state + assert_eq!( + reward_pool, + RewardPool { + last_recorded_reward_counter: Zero::zero(), + last_recorded_total_payouts: 0, + total_rewards_claimed: 30, + total_commission_pending: 0, + total_commission_claimed: 0 + } + ); // update payee only. assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - 1, + bonded_pool.id, Some((Perbill::from_percent(25), 901)) )); - let current = bonded_pool + let current = BondedPools::::get(bonded_pool.id).unwrap() .commission .current .as_ref() @@ -5512,6 +5535,41 @@ mod commission { .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())); assert_eq!(current, Perbill::from_percent(25)); + let payouts_since_last_record = RewardPool::::current_balance(bonded_pool.id) + .saturating_add(reward_pool.total_rewards_claimed) + .saturating_add(reward_pool.total_commission_pending) + .saturating_add(reward_pool.total_commission_claimed) + .saturating_sub(reward_pool.last_recorded_total_payouts); + + let share_commission = current * payouts_since_last_record; + assert_eq!(payouts_since_last_record, 40); + assert_eq!(share_commission, 10); + + assert_eq!(RewardPool::::current_balance(bonded_pool.id), 10); + + assert_eq!( + reward_pool, + RewardPool { + last_recorded_reward_counter: Zero::zero(), + last_recorded_total_payouts: 0, + total_rewards_claimed: 30, + total_commission_pending: 0, + total_commission_claimed: 0 + } + ); + + + // let (current_reward_counter, share_commission) = reward_pool + // .current_reward_counter(bonded_pool.id, bonded_pool.points, &bonded_pool.commission) + // .unwrap(); + + // assert_eq!(share_commission, 10); + // let pending_rewards = member.pending_rewards(current_reward_counter).unwrap(); + + // assert_eq!(reward_pool, Default::default()); + assert_eq!(reward_pool.last_recorded_total_payouts, 30); + assert_eq!(reward_pool.total_rewards_claimed, 30); + assert_eq!(reward_pool.total_commission_pending, 10); assert_eq!( pool_events_since_last_call(), @@ -5521,8 +5579,6 @@ mod commission { },] ); - assert_eq!(reward_pool.total_commission_pending, 10); - // Pool earns 100 points, payout is triggered. assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); From 0b48dd123e94337d0f70db261b6c11f5a483b529 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Thu, 23 Feb 2023 23:32:35 +0700 Subject: [PATCH 26/90] rewardpol not working --- frame/nomination-pools/src/tests.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 8b1bedfdf5b42..00cb59c8f229d 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5510,7 +5510,7 @@ mod commission { // uncomment to check reward_pool state assert_eq!( - reward_pool, + RewardPools::::get(bonded_pool.id).unwrap(), RewardPool { last_recorded_reward_counter: Zero::zero(), last_recorded_total_payouts: 0, @@ -5527,6 +5527,17 @@ mod commission { Some((Perbill::from_percent(25), 901)) )); + assert_eq!( + RewardPools::::get(bonded_pool.id).unwrap(), + RewardPool { + last_recorded_reward_counter: Zero::zero(), + last_recorded_total_payouts: 30, + total_rewards_claimed: 30, + total_commission_pending: 10, + total_commission_claimed: 0 + } + ); + let current = BondedPools::::get(bonded_pool.id).unwrap() .commission .current From 91001fb394317f8b45a5b0979cfbb534c4b8a7d1 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 24 Feb 2023 21:01:18 +0700 Subject: [PATCH 27/90] commission refactor --- frame/nomination-pools/src/lib.rs | 83 +++++++----- frame/nomination-pools/src/tests.rs | 190 ++++++++++------------------ 2 files changed, 120 insertions(+), 153 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 82c32fe609c7c..3aa72597a840b 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -476,6 +476,7 @@ impl PoolMember { fn pending_rewards( &self, current_reward_counter: T::RewardCounter, + commission: Perbill, ) -> Result, Error> { // accuracy note: Reward counters are `FixedU128` with base of 10^18. This value is being // multiplied by a point. The worse case of a point is 10x the granularity of the balance @@ -494,9 +495,12 @@ impl PoolMember { // point is equal to balance (normally), and rewards are usually a proportion of the points // in the pool, the likelihood of rc reaching near u128::MAX is near impossible. - (current_reward_counter.defensive_saturating_sub(self.last_recorded_reward_counter)) - .checked_mul_int(self.active_points()) - .ok_or(Error::::OverflowRisk) + let pending_total = (current_reward_counter + .defensive_saturating_sub(self.last_recorded_reward_counter)) + .checked_mul_int(self.active_points()) + .ok_or(Error::::OverflowRisk)?; + + Ok(pending_total.saturating_sub(commission * pending_total)) } /// Active balance of the member. @@ -703,6 +707,15 @@ impl Commission { false } + /// Get's the pool's current commission, or returns Perbill::zero if none is set. + /// Bounded to global max if current is greater than GlobalMaxCommission. + fn current(&self) -> Perbill { + self.current + .as_ref() + .map_or(Perbill::zero(), |(c, _)| c.clone()) + .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())) + } + /// Set the pool's commission. /// /// Update commission based on `current`. If a `None` is supplied, allow the commission to be @@ -1254,17 +1267,17 @@ impl RewardPool { &mut self, id: PoolId, bonded_points: BalanceOf, - commission: &Commission, + commission: Perbill, ) -> Result<(), Error> { let balance = Self::current_balance(id); - let (current_reward_counter, share_commission) = + let (current_reward_counter, new_pending_commission) = self.current_reward_counter(id, bonded_points, commission)?; self.last_recorded_reward_counter = current_reward_counter; self.total_commission_pending = - self.total_commission_pending.saturating_add(share_commission); + self.total_commission_pending.saturating_add(new_pending_commission); self.last_recorded_total_payouts = balance .checked_add(&self.total_rewards_claimed.saturating_add(self.total_commission_claimed)) @@ -1278,7 +1291,7 @@ impl RewardPool { &self, id: PoolId, bonded_points: BalanceOf, - commission: &Commission, + commission: Perbill, ) -> Result<(T::RewardCounter, BalanceOf), Error> { let balance = Self::current_balance(id); let payouts_since_last_record = balance @@ -1289,14 +1302,7 @@ impl RewardPool { // Split the `payouts_since_last_record` into regular rewards and commission according to // the current commission rate. - let current = commission - .current - .as_ref() - .map_or(Perbill::zero(), |(c, _)| c.clone()) - .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())); - - let share_commission = current * payouts_since_last_record; - let share_rewards = payouts_since_last_record - share_commission; + let new_pending_commission = commission * payouts_since_last_record; // * accuracy notes regarding the multiplication in `checked_from_rational`: // `payouts_since_last_record` is a subset of the total_issuance at the very @@ -1332,11 +1338,11 @@ impl RewardPool { // // which is basically 10^-8 DOTs. See `smallest_claimable_reward` for an example of this. let current_reward_counter = - T::RewardCounter::checked_from_rational(share_rewards, bonded_points) + T::RewardCounter::checked_from_rational(payouts_since_last_record, bonded_points) .and_then(|ref r| self.last_recorded_reward_counter.checked_add(r)) .ok_or(Error::::OverflowRisk)?; - Ok((current_reward_counter, share_commission)) + Ok((current_reward_counter, new_pending_commission)) } /// Current free balance of the reward pool. @@ -1861,7 +1867,11 @@ pub mod pallet { let mut reward_pool = RewardPools::::get(pool_id) .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; // IMPORTANT: reward pool records must be updated with the old points. - reward_pool.update_records(pool_id, bonded_pool.points, &bonded_pool.commission)?; + reward_pool.update_records( + pool_id, + bonded_pool.points, + bonded_pool.commission.current(), + )?; bonded_pool.try_inc_members()?; let points_issued = bonded_pool.try_bond_funds(&who, amount, BondType::Later)?; @@ -1977,7 +1987,7 @@ pub mod pallet { let _ = reward_pool.update_records( bonded_pool.id, bonded_pool.points, - &bonded_pool.commission, + bonded_pool.commission.current(), )?; let _ = Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?; @@ -2515,7 +2525,11 @@ pub mod pallet { .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; // IMPORTANT: make sure that everything up to this point is using the current commission // before it updates. Note that `try_update_current` could still fail at this point. - reward_pool.update_records(pool_id, bonded_pool.points, &bonded_pool.commission)?; + reward_pool.update_records( + pool_id, + bonded_pool.points, + bonded_pool.commission.current(), + )?; bonded_pool.commission.try_update_current(&new_commission)?; bonded_pool.put(); @@ -2762,9 +2776,10 @@ impl Pallet { let (current_reward_counter, _) = reward_pool.current_reward_counter( bonded_pool.id, bonded_pool.points, - &bonded_pool.commission, + bonded_pool.commission.current(), )?; - let pending_rewards = member.pending_rewards(current_reward_counter)?; + let pending_rewards = + member.pending_rewards(current_reward_counter, bonded_pool.commission.current())?; if pending_rewards.is_zero() { return Ok(pending_rewards) @@ -2912,7 +2927,11 @@ impl Pallet { // payout related stuff: we must claim the payouts, and updated recorded payout data // before updating the bonded pool points, similar to that of `join` transaction. - reward_pool.update_records(bonded_pool.id, bonded_pool.points, &bonded_pool.commission)?; + reward_pool.update_records( + bonded_pool.id, + bonded_pool.points, + bonded_pool.commission.current(), + )?; let claimed = Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?; @@ -3030,11 +3049,16 @@ impl Pallet { let reward_pool = RewardPools::::get(d.pool_id).unwrap(); if !bonded_pool.points.is_zero() { + let commission = bonded_pool.commission.current(); let (current_rc, _) = reward_pool - .current_reward_counter(d.pool_id, bonded_pool.points, &bonded_pool.commission) + .current_reward_counter( + d.pool_id, + bonded_pool.points, + commission, + ) .unwrap(); *pools_members_pending_rewards.entry(d.pool_id).or_default() += - d.pending_rewards(current_rc).unwrap(); + d.pending_rewards(current_rc, commission).unwrap(); } // else this pool has been heavily slashed and cannot have any rewards anymore. }); @@ -3123,14 +3147,11 @@ impl Pallet { if let Some((reward_pool, bonded_pool)) = RewardPools::::get(pool_member.pool_id) .zip(BondedPools::::get(pool_member.pool_id)) { + let commission = bonded_pool.commission.current(); let (current_reward_counter, _) = reward_pool - .current_reward_counter( - pool_member.pool_id, - bonded_pool.points, - &bonded_pool.commission, - ) + .current_reward_counter(pool_member.pool_id, bonded_pool.points, commission) .ok()?; - return pool_member.pending_rewards(current_reward_counter).ok() + return pool_member.pending_rewards(current_reward_counter, commission).ok() } } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 00cb59c8f229d..a77ef6b9921d1 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -19,7 +19,7 @@ use super::*; use crate::{mock::*, Event}; use frame_support::{assert_err, assert_noop, assert_ok, assert_storage_noop, bounded_btree_map}; use pallet_balances::Event as BEvent; -use sp_runtime::traits::Dispatchable; +use sp_runtime::{traits::Dispatchable, FixedU128}; macro_rules! unbonding_pools_with_era { ($($k:expr => $v:expr),* $(,)?) => {{ @@ -5045,8 +5045,6 @@ mod update_roles { } mod reward_counter_precision { - use sp_runtime::FixedU128; - use super::*; const DOT: Balance = 10u128.pow(10u32); @@ -5066,16 +5064,17 @@ mod reward_counter_precision { let bonded_pool = BondedPools::::get(1).unwrap(); RewardPools::::get(1) .unwrap() - .current_reward_counter(1, bonded_pool.points, &bonded_pool.commission) + .current_reward_counter(1, bonded_pool.points, bonded_pool.commission.current()) .unwrap() .0 } fn pending_rewards(of: AccountId) -> Option> { let member = PoolMembers::::get(of).unwrap(); + let bonded_pool = BondedPools::::get(member.pool_id).unwrap(); assert_eq!(member.pool_id, 1); let rc = default_pool_reward_counter(); - member.pending_rewards(rc).ok() + member.pending_rewards(rc, bonded_pool.commission.current()).ok() } #[test] @@ -5412,14 +5411,12 @@ mod reward_counter_precision { } mod commission { - use super::*; #[test] fn set_commission_works() { ExtBuilder::default().build_and_execute(|| { - let (mut member, bonded_pool, mut reward_pool) = - Pools::get_member_with_pools(&10).unwrap(); + let pool_id = 1; // top up commission payee account to existential deposit let _ = Balances::deposit_creating(&900, 5); @@ -5427,22 +5424,22 @@ mod commission { // Set a commission for pool 1. assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - bonded_pool.id, + pool_id, Some((Perbill::from_percent(50), 900)) )); assert_eq!( pool_events_since_last_call(), vec![ - Event::Created { depositor: 10, pool_id: bonded_pool.id }, - Event::Bonded { member: 10, pool_id: bonded_pool.id, bonded: 10, joined: true }, + Event::Created { depositor: 10, pool_id }, + Event::Bonded { member: 10, pool_id, bonded: 10, joined: true }, Event::PoolCommissionUpdated { - pool_id: bonded_pool.id, + pool_id, current: Some((Perbill::from_percent(50), 900)) }, ] ); - let commission_as_percent = BondedPool::::get(bonded_pool.id) + let commission_as_percent = BondedPool::::get(pool_id) .unwrap() .commission .current @@ -5460,12 +5457,13 @@ mod commission { assert_eq!( pool_events_since_last_call(), vec![Event::PoolCommissionUpdated { - pool_id: bonded_pool.id, + pool_id, current: Some((Perbill::from_percent(25), 900)) },] ); - let current = BondedPools::::get(bonded_pool.id).unwrap() + let current = BondedPools::::get(pool_id) + .unwrap() .commission .current .as_ref() @@ -5477,40 +5475,20 @@ mod commission { assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 40)); assert_eq!( PoolMembers::::get(10).unwrap(), - PoolMember:: { pool_id: bonded_pool.id, points: 10, ..Default::default() } + PoolMember:: { pool_id, points: 10, ..Default::default() } ); - let (current_reward_counter, share_commission) = reward_pool - .current_reward_counter(bonded_pool.id, bonded_pool.points, &BondedPools::::get(bonded_pool.id).unwrap().commission) - .unwrap(); - - let pending_rewards = PoolMembers::::get(10) - .unwrap() - .pending_rewards(current_reward_counter) - .unwrap(); - assert_eq!(pending_rewards, 30); - - assert_ok!(Pools::do_reward_payout( - &10, - &mut member, - &mut BondedPool::::get(1).unwrap(), - &mut reward_pool - )); + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { - member: 10, - pool_id: bonded_pool.id, - payout: 30, - commission: 0 - }] + vec![Event::PaidOut { member: 10, pool_id, payout: 30, commission: 0 }] ); - assert_eq!(RewardPool::::current_balance(bonded_pool.id), 10); + assert_eq!(RewardPool::::current_balance(pool_id), 10); // uncomment to check reward_pool state assert_eq!( - RewardPools::::get(bonded_pool.id).unwrap(), + RewardPools::::get(pool_id).unwrap(), RewardPool { last_recorded_reward_counter: Zero::zero(), last_recorded_total_payouts: 0, @@ -5523,69 +5501,16 @@ mod commission { // update payee only. assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - bonded_pool.id, + pool_id, Some((Perbill::from_percent(25), 901)) )); - assert_eq!( - RewardPools::::get(bonded_pool.id).unwrap(), - RewardPool { - last_recorded_reward_counter: Zero::zero(), - last_recorded_total_payouts: 30, - total_rewards_claimed: 30, - total_commission_pending: 10, - total_commission_claimed: 0 - } - ); - - let current = BondedPools::::get(bonded_pool.id).unwrap() - .commission - .current - .as_ref() - .map_or(Perbill::zero(), |(c, _)| c.clone()) - .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())); - - assert_eq!(current, Perbill::from_percent(25)); - let payouts_since_last_record = RewardPool::::current_balance(bonded_pool.id) - .saturating_add(reward_pool.total_rewards_claimed) - .saturating_add(reward_pool.total_commission_pending) - .saturating_add(reward_pool.total_commission_claimed) - .saturating_sub(reward_pool.last_recorded_total_payouts); - - let share_commission = current * payouts_since_last_record; - assert_eq!(payouts_since_last_record, 40); - assert_eq!(share_commission, 10); - - assert_eq!(RewardPool::::current_balance(bonded_pool.id), 10); - - assert_eq!( - reward_pool, - RewardPool { - last_recorded_reward_counter: Zero::zero(), - last_recorded_total_payouts: 0, - total_rewards_claimed: 30, - total_commission_pending: 0, - total_commission_claimed: 0 - } - ); - - - // let (current_reward_counter, share_commission) = reward_pool - // .current_reward_counter(bonded_pool.id, bonded_pool.points, &bonded_pool.commission) - // .unwrap(); - - // assert_eq!(share_commission, 10); - // let pending_rewards = member.pending_rewards(current_reward_counter).unwrap(); - - // assert_eq!(reward_pool, Default::default()); - assert_eq!(reward_pool.last_recorded_total_payouts, 30); - assert_eq!(reward_pool.total_rewards_claimed, 30); - assert_eq!(reward_pool.total_commission_pending, 10); + assert_eq!(RewardPool::::current_balance(pool_id), 10); assert_eq!( pool_events_since_last_call(), vec![Event::PoolCommissionUpdated { - pool_id: bonded_pool.id, + pool_id, current: Some((Perbill::from_percent(25), 901)) },] ); @@ -5594,15 +5519,15 @@ mod commission { assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); // remove the commission for pool 1. - assert_ok!(Pools::set_commission(RuntimeOrigin::signed(900), bonded_pool.id, None)); + assert_ok!(Pools::set_commission(RuntimeOrigin::signed(900), pool_id, None)); assert_eq!( pool_events_since_last_call(), - vec![Event::PoolCommissionUpdated { pool_id: bonded_pool.id, current: None },] + vec![Event::PoolCommissionUpdated { pool_id, current: None },] ); assert_eq!( - BondedPools::::get(bonded_pool.id).unwrap(), + BondedPools::::get(pool_id).unwrap(), BondedPoolInner { commission: Commission { current: None, @@ -5622,20 +5547,10 @@ mod commission { } ); - assert_ok!(Pools::do_reward_payout( - &10, - &mut member, - &mut BondedPool::::get(1).unwrap(), - &mut reward_pool - )); + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { - member: 10, - pool_id: bonded_pool.id, - payout: 100, - commission: 0 - },] + vec![Event::PaidOut { member: 10, pool_id, payout: 100, commission: 0 },] ); // test whether supplying a 0% commission along with a payee results in a None `current` @@ -5650,7 +5565,7 @@ mod commission { // set the commission to 0% assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - bonded_pool.id, + pool_id, Some((Perbill::from_percent(0), 900)) )); // commssion current should now be None, and `throttle_from` the current block. @@ -5661,7 +5576,7 @@ mod commission { // set the commission to 0% assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - bonded_pool.id, + pool_id, Some((Perbill::from_percent(0), 900)) )); @@ -5669,15 +5584,15 @@ mod commission { pool_events_since_last_call(), vec![ Event::PoolCommissionUpdated { - pool_id: bonded_pool.id, + pool_id, current: Some((Perbill::from_percent(10), 900)) }, Event::PoolCommissionUpdated { - pool_id: bonded_pool.id, + pool_id, current: Some((Perbill::from_percent(0), 900)) }, Event::PoolCommissionUpdated { - pool_id: bonded_pool.id, + pool_id, current: Some((Perbill::from_percent(0), 900)) }, ] @@ -5688,21 +5603,21 @@ mod commission { // set max commission to 10% assert_ok!(Pools::set_commission_max( RuntimeOrigin::signed(900), - bonded_pool.id, + pool_id, Perbill::from_percent(10) )); // set commission to 10% assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - bonded_pool.id, + pool_id, Some((Perbill::from_percent(10), 900)) )); // update payee only and keep current commission assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - bonded_pool.id, + pool_id, Some((Perbill::from_percent(10), 901)) )); @@ -5710,15 +5625,15 @@ mod commission { pool_events_since_last_call(), vec![ Event::PoolMaxCommissionUpdated { - pool_id: bonded_pool.id, + pool_id, max_commission: Perbill::from_percent(10) }, Event::PoolCommissionUpdated { - pool_id: bonded_pool.id, + pool_id, current: Some((Perbill::from_percent(10), 900)) }, Event::PoolCommissionUpdated { - pool_id: bonded_pool.id, + pool_id, current: Some((Perbill::from_percent(10), 901)) } ] @@ -5726,6 +5641,37 @@ mod commission { }); } + #[test] + fn commission_reward_counter_works_one_member() { + ExtBuilder::default().build_and_execute(|| { + let pool_id = 1; + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(10), 900)), + )); + + // Pool earns 40 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 40)); + + assert_eq!( + PoolMembers::::get(10).unwrap(), + PoolMember:: { pool_id, points: 10, ..Default::default() } + ); + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); + + //10% balance (commission) should still be in the pool. + assert_eq!(RewardPool::::current_balance(pool_id), 4); + + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + 1, + Some((Perbill::from_percent(20), 900)), + )); + assert_eq!(Pools::api_pending_rewards(10).unwrap(), 0); + }) + } + #[test] fn set_commission_handles_errors() { ExtBuilder::default().build_and_execute(|| { From 36d647c7eafc84eebbbaa2172e07daeacc41d409 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 24 Feb 2023 21:12:18 +0700 Subject: [PATCH 28/90] pending rewards returns commission --- frame/nomination-pools/src/lib.rs | 60 ++++++----------------------- frame/nomination-pools/src/tests.rs | 31 +++++---------- 2 files changed, 20 insertions(+), 71 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 3aa72597a840b..1a89d56489072 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -477,7 +477,7 @@ impl PoolMember { &self, current_reward_counter: T::RewardCounter, commission: Perbill, - ) -> Result, Error> { + ) -> Result<(BalanceOf, BalanceOf), Error> { // accuracy note: Reward counters are `FixedU128` with base of 10^18. This value is being // multiplied by a point. The worse case of a point is 10x the granularity of the balance // (10x is the common configuration of `MaxPointsToBalance`). @@ -499,8 +499,10 @@ impl PoolMember { .defensive_saturating_sub(self.last_recorded_reward_counter)) .checked_mul_int(self.active_points()) .ok_or(Error::::OverflowRisk)?; - - Ok(pending_total.saturating_sub(commission * pending_total)) + + let pending_after_commission = pending_total.saturating_sub(commission * pending_total); + let commission_amount = pending_total.saturating_sub(pending_after_commission); + Ok((pending_after_commission, commission_amount)) } /// Active balance of the member. @@ -801,23 +803,6 @@ impl Commission { Ok(()) } - /// Gets the current commission (if any) and payee to be paid. - /// - /// `None` is returned if a commission has not been set. Commission is bounded to - /// `GlobalMaxCommission`. - fn maybe_commission_and_payee( - &self, - pending_rewards: &BalanceOf, - ) -> Option<(BalanceOf, T::AccountId)> { - self.current.as_ref().map(|(commission, payee)| { - ( - *commission.min(&GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())) * - *pending_rewards, - payee.clone(), - ) - }) - } - /// Updates a commission's `throttle_from` field to the current block. fn register_update(&mut self) { self.throttle_from = Some(>::block_number()); @@ -2778,7 +2763,7 @@ impl Pallet { bonded_pool.points, bonded_pool.commission.current(), )?; - let pending_rewards = + let (pending_rewards, commission) = member.pending_rewards(current_reward_counter, bonded_pool.commission.current())?; if pending_rewards.is_zero() { @@ -2789,28 +2774,6 @@ impl Pallet { member.last_recorded_reward_counter = current_reward_counter; reward_pool.register_claimed_reward(pending_rewards); - // TODO: Remove once new commission refactor is working as intended. - // Legacy code to split and payout commission upon reward payout. - - // Gets the commission percentage and payee to be paid if commission has been set. - // Otherwise, `None` is returned. - // let maybe_commission = - // &bonded_pool.commission.maybe_commission_and_payee(&pending_rewards); - // if let Some((pool_commission, payee)) = maybe_commission { - // // Deduct any outstanding commission from the reward being claimed. - // pending_rewards = pending_rewards.saturating_sub(*pool_commission); - - // // Send any non-zero `pool_commission` to the commission `payee`. - // if pool_commission > &Zero::zero() { - // T::Currency::transfer( - // &bonded_pool.reward_account(), - // &payee, - // *pool_commission, - // ExistenceRequirement::KeepAlive, - // )?; - // } - // } - // Transfer remaining payout to the member. // // In scenarios where commission is 100%, `pending_rewards` will be zero. We therefore check @@ -2830,9 +2793,7 @@ impl Pallet { member: member_account.clone(), pool_id: member.pool_id, payout: pending_rewards, - // TODO: Remove once new commission refactor is working as intended. - // commission: maybe_commission.as_ref().map(|(c, _)| *c).unwrap_or(Zero::zero()), - commission: Zero::zero(), + commission, }); Ok(pending_rewards) @@ -3057,8 +3018,8 @@ impl Pallet { commission, ) .unwrap(); - *pools_members_pending_rewards.entry(d.pool_id).or_default() += - d.pending_rewards(current_rc, commission).unwrap(); + let (pending_rewards, _) = d.pending_rewards(current_rc, commission).unwrap(); + *pools_members_pending_rewards.entry(d.pool_id).or_default() += pending_rewards; } // else this pool has been heavily slashed and cannot have any rewards anymore. }); @@ -3151,7 +3112,8 @@ impl Pallet { let (current_reward_counter, _) = reward_pool .current_reward_counter(pool_member.pool_id, bonded_pool.points, commission) .ok()?; - return pool_member.pending_rewards(current_reward_counter, commission).ok() + let (pending_rewards, _) = pool_member.pending_rewards(current_reward_counter, commission).ok()?; + return Some(pending_rewards); } } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index a77ef6b9921d1..67a2deac33c9c 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -986,7 +986,7 @@ mod claim_payout { // commission applied is 50%, not 75%. Has been bounded by `GlobalMaxCommission`. assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 5 },] ); }) } @@ -5074,7 +5074,8 @@ mod reward_counter_precision { let bonded_pool = BondedPools::::get(member.pool_id).unwrap(); assert_eq!(member.pool_id, 1); let rc = default_pool_reward_counter(); - member.pending_rewards(rc, bonded_pool.commission.current()).ok() + let (pending_after_commission, _) = member.pending_rewards(rc, bonded_pool.commission.current()).ok()?; + Some(pending_after_commission) } #[test] @@ -5481,7 +5482,7 @@ mod commission { assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id, payout: 30, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id, payout: 30, commission: 10 }] ); assert_eq!(RewardPool::::current_balance(pool_id), 10); @@ -6355,7 +6356,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 7, commission: 0 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 7, commission: 3 },] ); // The pool earns 17 points @@ -6370,7 +6371,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 11, commission: 0 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 11, commission: 6 },] ); // The pool earns 50 points @@ -6385,7 +6386,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 34, commission: 0 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 34, commission: 16 },] ); // The pool earns 10439 points @@ -6400,7 +6401,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 6994, commission: 0 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 6994, commission: 3445 },] ); }) } @@ -6439,13 +6440,6 @@ mod commission { // The pool earns 10 points assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10)); - // Ensure the commission equals the total amount of points. - let maybe_commission = &BondedPools::::get(1) - .unwrap() - .commission - .maybe_commission_and_payee(&10); - assert_eq!(*maybe_commission, Some((10_u128, 2_u128))); - // execute the payout assert_ok!(Pools::do_reward_payout( &10, @@ -6488,13 +6482,6 @@ mod commission { // The pool earns 10 points assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10)); - // Ensure the commission equals 90% of the total points. - let maybe_commission = &BondedPools::::get(1) - .unwrap() - .commission - .maybe_commission_and_payee(&10); - assert_eq!(*maybe_commission, Some((9_u128, 2_u128))); - // execute the payout assert_ok!(Pools::do_reward_payout( &10, @@ -6507,7 +6494,7 @@ mod commission { // of 10 points, reflecting the 90% global max commission. assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1, commission: 0 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1, commission: 9 },] ); }) } From 65e1480e7e4696202e41db91ab34baa20656080c Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 24 Feb 2023 21:12:37 +0700 Subject: [PATCH 29/90] fmt --- frame/nomination-pools/src/lib.rs | 13 +++++-------- frame/nomination-pools/src/tests.rs | 3 ++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 1a89d56489072..5778c03f7f8c5 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -499,7 +499,7 @@ impl PoolMember { .defensive_saturating_sub(self.last_recorded_reward_counter)) .checked_mul_int(self.active_points()) .ok_or(Error::::OverflowRisk)?; - + let pending_after_commission = pending_total.saturating_sub(commission * pending_total); let commission_amount = pending_total.saturating_sub(pending_after_commission); Ok((pending_after_commission, commission_amount)) @@ -3012,11 +3012,7 @@ impl Pallet { if !bonded_pool.points.is_zero() { let commission = bonded_pool.commission.current(); let (current_rc, _) = reward_pool - .current_reward_counter( - d.pool_id, - bonded_pool.points, - commission, - ) + .current_reward_counter(d.pool_id, bonded_pool.points, commission) .unwrap(); let (pending_rewards, _) = d.pending_rewards(current_rc, commission).unwrap(); *pools_members_pending_rewards.entry(d.pool_id).or_default() += pending_rewards; @@ -3112,8 +3108,9 @@ impl Pallet { let (current_reward_counter, _) = reward_pool .current_reward_counter(pool_member.pool_id, bonded_pool.points, commission) .ok()?; - let (pending_rewards, _) = pool_member.pending_rewards(current_reward_counter, commission).ok()?; - return Some(pending_rewards); + let (pending_rewards, _) = + pool_member.pending_rewards(current_reward_counter, commission).ok()?; + return Some(pending_rewards) } } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 67a2deac33c9c..aa9e982683e29 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5074,7 +5074,8 @@ mod reward_counter_precision { let bonded_pool = BondedPools::::get(member.pool_id).unwrap(); assert_eq!(member.pool_id, 1); let rc = default_pool_reward_counter(); - let (pending_after_commission, _) = member.pending_rewards(rc, bonded_pool.commission.current()).ok()?; + let (pending_after_commission, _) = + member.pending_rewards(rc, bonded_pool.commission.current()).ok()?; Some(pending_after_commission) } From f30585e343445f0f0dbb64872ffedb8568f192aa Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 24 Feb 2023 21:40:21 +0700 Subject: [PATCH 30/90] add claim_commission call --- frame/nomination-pools/src/lib.rs | 71 +++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 5778c03f7f8c5..5f1e3613ba73f 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1015,7 +1015,7 @@ impl BondedPool { self.is_root(who) || self.is_bouncer(who) } - fn can_set_commission(&self, who: &T::AccountId) -> bool { + fn can_manage_commission(&self, who: &T::AccountId) -> bool { self.is_root(who) } @@ -1729,6 +1729,8 @@ pub mod pallet { pool_id: PoolId, change_rate: CommissionChangeRate, }, + /// Pool commission has been claimed. + PoolCommissionClaimed { pool_id: PoolId, commission: BalanceOf }, } #[pallet::error] @@ -1792,6 +1794,10 @@ pub mod pallet { CommissionChangeThrottled, /// The submitted changes to commission change rate are not allowed. CommissionChangeRateNotAllowed, + /// There is no pending commission to claim. + NoPendingCommission, + /// No commission current has been set. + NoCommissionCurrentSet, /// Pool id currently in use. PoolIdInUse, /// Pool id provided is not correct/usable. @@ -2504,7 +2510,7 @@ pub mod pallet { ) -> DispatchResult { let who = ensure_signed(origin)?; let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; - ensure!(bonded_pool.can_set_commission(&who), Error::::DoesNotHavePermission); + ensure!(bonded_pool.can_manage_commission(&who), Error::::DoesNotHavePermission); let mut reward_pool = RewardPools::::get(pool_id) .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; @@ -2541,7 +2547,7 @@ pub mod pallet { ) -> DispatchResult { let who = ensure_signed(origin)?; let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; - ensure!(bonded_pool.can_set_commission(&who), Error::::DoesNotHavePermission); + ensure!(bonded_pool.can_manage_commission(&who), Error::::DoesNotHavePermission); bonded_pool.commission.try_update_max(pool_id, max_commission)?; bonded_pool.put(); @@ -2564,7 +2570,7 @@ pub mod pallet { ) -> DispatchResult { let who = ensure_signed(origin)?; let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; - ensure!(bonded_pool.can_set_commission(&who), Error::::DoesNotHavePermission); + ensure!(bonded_pool.can_manage_commission(&who), Error::::DoesNotHavePermission); bonded_pool.commission.try_update_change_rate(change_rate)?; bonded_pool.put(); @@ -2575,6 +2581,18 @@ pub mod pallet { }); Ok(()) } + + /// Claim pending commission. + /// + /// The dispatch origin of this call must be signed by the `root` role of the pool. Pending + /// commission is paid out and added to total claimed commission`. Total pending commission + /// is reset to zero. the current. + #[pallet::call_index(20)] + #[pallet::weight(T::WeightInfo::set_commission_change_rate())] + pub fn claim_commission(origin: OriginFor, pool_id: PoolId) -> DispatchResult { + let who = ensure_signed(origin)?; + Self::do_claim_commission(who, pool_id) + } } #[pallet::hooks] @@ -2918,6 +2936,51 @@ impl Pallet { Ok(()) } + fn do_claim_commission(who: T::AccountId, pool_id: PoolId) -> DispatchResult { + let bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; + ensure!(bonded_pool.can_manage_commission(&who), Error::::DoesNotHavePermission); + + let mut reward_pool = RewardPools::::get(pool_id) + .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; + + // IMPORTANT: make sure that any newly pending commission not yet processed is added to + // `total_commission_pending`. + reward_pool.update_records( + pool_id, + bonded_pool.points, + bonded_pool.commission.current(), + )?; + + ensure!(!reward_pool.total_commission_pending.is_zero(), Error::::NoPendingCommission); + + let payee = bonded_pool + .commission + .current + .as_ref() + .map(|(_, p)| p.clone()) + .ok_or(Error::::NoCommissionCurrentSet)?; + + // Payout claimed commission. + T::Currency::transfer( + &bonded_pool.reward_account(), + &payee, + reward_pool.total_commission_pending, + ExistenceRequirement::KeepAlive, + )?; + + reward_pool.total_commission_claimed = reward_pool + .total_commission_claimed + .saturating_add(reward_pool.total_commission_pending); + reward_pool.total_commission_pending = Zero::zero(); + + Self::deposit_event(Event::::PoolCommissionClaimed { + pool_id, + commission: Zero::zero(), + }); + + Ok(()) + } + fn do_claim_payout(signer: T::AccountId, who: T::AccountId) -> DispatchResult { if signer != who { ensure!( From bd192d391e2b5de72c6a8637bfcefdb093847532 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 24 Feb 2023 22:26:10 +0700 Subject: [PATCH 31/90] + claim_commission --- frame/nomination-pools/src/weights.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index 7e0ca3fdf8202..197776f763871 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -68,6 +68,7 @@ pub trait WeightInfo { fn set_commission() -> Weight; fn set_commission_max() -> Weight; fn set_commission_change_rate() -> Weight; + fn claim_commission() -> Weight; } /// Weights for pallet_nomination_pools using the Substrate node and recommended hardware. @@ -551,7 +552,10 @@ impl WeightInfo for SubstrateWeight { Weight::from_ref_time(23_000_000) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) - } + } + fn claim_commission() -> Weight { + Weight::zero() + } } // For backwards compatibility and tests @@ -1035,4 +1039,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(1)) } + fn claim_commission() -> Weight { + Weight::zero() + } } \ No newline at end of file From 1c803b720807d25ada9121b3cd8f80467cd2571a Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 24 Feb 2023 22:41:32 +0700 Subject: [PATCH 32/90] fix benchmarks --- frame/nomination-pools/benchmarking/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index 7ae178aeac647..8613727f905f3 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -36,6 +36,7 @@ use pallet_nomination_pools::{ PoolMembers, PoolRoles, PoolState, RewardPools, SubPoolsStorage, }; use sp_staking::{EraIndex, StakingInterface}; +use sp_runtime::{traits::{Bounded, StaticLookup, Zero}, Perbill}; // `frame_benchmarking::benchmarks!` macro needs this use pallet_nomination_pools::Call; @@ -86,7 +87,7 @@ fn create_pool_account( .unwrap(); if let Some(c) = commission { - let pool_id = LastPoolId::::get(); + let pool_id = pallet_nomination_pools::LastPoolId::::get(); Pools::::set_commission( RuntimeOrigin::Signed(pool_creator.clone()).into(), pool_id, @@ -749,7 +750,7 @@ frame_benchmarking::benchmarks! { set_claim_permission { // Create a pool let min_create_bond = Pools::::depositor_min_bond(); - let (depositor, pool_account) = create_pool_account::(0, min_create_bond); + let (depositor, pool_account) = create_pool_account::(0, min_create_bond, None); // Join pool let min_join_bond = MinJoinBond::::get().max(CurrencyOf::::minimum_balance()); From 3197e62fd615a984b7de233b0d0c49e42bdd1db7 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 24 Feb 2023 22:42:23 +0700 Subject: [PATCH 33/90] weight 0 for now --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 5f1e3613ba73f..cee5e2333abcf 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2588,7 +2588,7 @@ pub mod pallet { /// commission is paid out and added to total claimed commission`. Total pending commission /// is reset to zero. the current. #[pallet::call_index(20)] - #[pallet::weight(T::WeightInfo::set_commission_change_rate())] + #[pallet::weight(0)] pub fn claim_commission(origin: OriginFor, pool_id: PoolId) -> DispatchResult { let who = ensure_signed(origin)?; Self::do_claim_commission(who, pool_id) From d27f56f0889c1a6b8a7196bdd80025b935ab5d7b Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 24 Feb 2023 22:57:57 +0700 Subject: [PATCH 34/90] + claim_commission benchmark --- .../nomination-pools/benchmarking/src/lib.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index 8613727f905f3..149112dfd192f 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -769,6 +769,31 @@ frame_benchmarking::benchmarks! { assert_eq!(ClaimPermissions::::get(joiner), ClaimPermission::PermissionlessAll); } + claim_commission { + let claimer: T::AccountId = account("claimer_member", USER_SEED + 4, 0); + + let origin_weight = Pools::::depositor_min_bond() * 2u32.into(); + let ed = CurrencyOf::::minimum_balance(); + let (depositor, pool_account) = create_pool_account::(0, origin_weight, Some(Perbill::from_percent(50))); + let reward_account = Pools::::create_reward_account(1); + CurrencyOf::::make_free_balance_be(&reward_account, ed + origin_weight); + + // member claims a payout to make some commission available. + let _ = Pools::::claim_payout(RuntimeOrigin::Signed(claimer).into()); + + whitelist_account!(depositor); + }:_(RuntimeOrigin::Signed(depositor.clone()), 1u32.into()) + verify { + assert_eq!( + CurrencyOf::::free_balance(&depositor), + origin_weight * 1u32.into() + ); + assert_eq!( + CurrencyOf::::free_balance(&reward_account), + ed + Zero::zero() + ); + } + impl_benchmark_test_suite!( Pallet, crate::mock::new_test_ext(), From 50658b336555cdeb9124224de80083ac510161e8 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 24 Feb 2023 22:58:16 +0700 Subject: [PATCH 35/90] fmt --- frame/nomination-pools/benchmarking/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index 149112dfd192f..feddea965ecc3 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -35,8 +35,11 @@ use pallet_nomination_pools::{ MaxPoolMembersPerPool, MaxPools, Metadata, MinCreateBond, MinJoinBond, Pallet as Pools, PoolMembers, PoolRoles, PoolState, RewardPools, SubPoolsStorage, }; +use sp_runtime::{ + traits::{Bounded, StaticLookup, Zero}, + Perbill, +}; use sp_staking::{EraIndex, StakingInterface}; -use sp_runtime::{traits::{Bounded, StaticLookup, Zero}, Perbill}; // `frame_benchmarking::benchmarks!` macro needs this use pallet_nomination_pools::Call; From 9da0c584c39e886dd684cab2fe1be071bb88dec1 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Fri, 24 Feb 2023 23:43:50 +0700 Subject: [PATCH 36/90] apply commission to benchmarks --- frame/nomination-pools/benchmarking/src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index feddea965ecc3..92cafca21c8a4 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -299,10 +299,10 @@ frame_benchmarking::benchmarks! { claim_payout { let claimer: T::AccountId = account("claimer", USER_SEED + 4, 0); - + let commission = Perbill::from_percent(50); let origin_weight = Pools::::depositor_min_bond() * 2u32.into(); let ed = CurrencyOf::::minimum_balance(); - let (depositor, pool_account) = create_pool_account::(0, origin_weight, Some(Perbill::from_percent(50))); + let (depositor, pool_account) = create_pool_account::(0, origin_weight, Some(commission)); let reward_account = Pools::::create_reward_account(1); // Send funds to the reward account of the pool @@ -323,11 +323,11 @@ frame_benchmarking::benchmarks! { verify { assert_eq!( CurrencyOf::::free_balance(&depositor), - origin_weight * 2u32.into() + origin_weight + commission * origin_weight ); assert_eq!( CurrencyOf::::free_balance(&reward_account), - ed + Zero::zero() + ed + commission * origin_weight ); } @@ -774,10 +774,10 @@ frame_benchmarking::benchmarks! { claim_commission { let claimer: T::AccountId = account("claimer_member", USER_SEED + 4, 0); - + let commission = Perbill::from_percent(50); let origin_weight = Pools::::depositor_min_bond() * 2u32.into(); let ed = CurrencyOf::::minimum_balance(); - let (depositor, pool_account) = create_pool_account::(0, origin_weight, Some(Perbill::from_percent(50))); + let (depositor, pool_account) = create_pool_account::(0, origin_weight, Some(commission)); let reward_account = Pools::::create_reward_account(1); CurrencyOf::::make_free_balance_be(&reward_account, ed + origin_weight); @@ -789,11 +789,11 @@ frame_benchmarking::benchmarks! { verify { assert_eq!( CurrencyOf::::free_balance(&depositor), - origin_weight * 1u32.into() + origin_weight + commission * origin_weight ); assert_eq!( CurrencyOf::::free_balance(&reward_account), - ed + Zero::zero() + ed + commission * origin_weight ); } From b6ad6a6474b9d0d6efd5e8c014bdbcb816752f6d Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 24 Feb 2023 17:09:42 +0000 Subject: [PATCH 37/90] ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_nomination_pools --- frame/nomination-pools/src/weights.rs | 662 +++++++++++++++----------- 1 file changed, 381 insertions(+), 281 deletions(-) diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index 197776f763871..b4d2e89ead583 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -18,9 +18,9 @@ //! Autogenerated weights for pallet_nomination_pools //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-ehxwxxsd-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -33,7 +33,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --json-file=/builds/parity/mirrors/substrate/.git/.artifacts/bench.json +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/substrate/.git/.artifacts/bench.json // --pallet=pallet_nomination_pools // --chain=dev // --header=./HEADER-APACHE2 @@ -64,10 +64,10 @@ pub trait WeightInfo { fn set_configs() -> Weight; fn update_roles() -> Weight; fn chill() -> Weight; - fn set_claim_permission() -> Weight; fn set_commission() -> Weight; fn set_commission_max() -> Weight; fn set_commission_change_rate() -> Weight; + fn set_claim_permission() -> Weight; fn claim_commission() -> Weight; } @@ -79,13 +79,15 @@ impl WeightInfo for SubstrateWeight { /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:1) /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: System Account (r:2 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) @@ -102,20 +104,22 @@ impl WeightInfo for SubstrateWeight { /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) fn join() -> Weight { // Proof Size summary in bytes: - // Measured: `3573` - // Estimated: `37988` - // Minimum execution time: 169_857 nanoseconds. - Weight::from_ref_time(173_895_000) - .saturating_add(Weight::from_proof_size(37988)) - .saturating_add(T::DbWeight::get().reads(17_u64)) + // Measured: `3650` + // Estimated: `38575` + // Minimum execution time: 164_798 nanoseconds. + Weight::from_ref_time(166_299_000) + .saturating_add(Weight::from_proof_size(38575)) + .saturating_add(T::DbWeight::get().reads(18_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)) } /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: System Account (r:3 w:2) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) @@ -130,12 +134,12 @@ impl WeightInfo for SubstrateWeight { /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) fn bond_extra_transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `3615` - // Estimated: `38583` - // Minimum execution time: 167_372 nanoseconds. - Weight::from_ref_time(168_776_000) - .saturating_add(Weight::from_proof_size(38583)) - .saturating_add(T::DbWeight::get().reads(14_u64)) + // Measured: `3692` + // Estimated: `39170` + // Minimum execution time: 162_598 nanoseconds. + Weight::from_ref_time(163_420_000) + .saturating_add(Weight::from_proof_size(39170)) + .saturating_add(T::DbWeight::get().reads(15_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)) } /// Storage: NominationPools ClaimPermissions (r:1 w:0) @@ -143,9 +147,11 @@ impl WeightInfo for SubstrateWeight { /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: System Account (r:3 w:3) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) @@ -160,12 +166,12 @@ impl WeightInfo for SubstrateWeight { /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) fn bond_extra_other() -> Weight { // Proof Size summary in bytes: - // Measured: `3680` - // Estimated: `41099` - // Minimum execution time: 186_346 nanoseconds. - Weight::from_ref_time(191_308_000) - .saturating_add(Weight::from_proof_size(41099)) - .saturating_add(T::DbWeight::get().reads(15_u64)) + // Measured: `3757` + // Estimated: `41686` + // Minimum execution time: 181_848 nanoseconds. + Weight::from_ref_time(183_274_000) + .saturating_add(Weight::from_proof_size(41686)) + .saturating_add(T::DbWeight::get().reads(16_u64)) .saturating_add(T::DbWeight::get().writes(13_u64)) } /// Storage: NominationPools ClaimPermissions (r:1 w:0) @@ -173,31 +179,35 @@ impl WeightInfo for SubstrateWeight { /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: System Account (r:1 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn claim_payout() -> Weight { // Proof Size summary in bytes: - // Measured: `1254` - // Estimated: `13005` - // Minimum execution time: 61_423 nanoseconds. - Weight::from_ref_time(63_219_000) - .saturating_add(Weight::from_proof_size(13005)) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Measured: `1331` + // Estimated: `13592` + // Minimum execution time: 64_438 nanoseconds. + Weight::from_ref_time(65_232_000) + .saturating_add(Weight::from_proof_size(13592)) + .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:1) /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: System Account (r:2 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Staking CurrentEra (r:1 w:0) @@ -216,20 +226,18 @@ impl WeightInfo for SubstrateWeight { /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) /// Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) /// Proof: NominationPools CounterForSubPoolsStorage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools ClaimPermissions (r:0 w:1) - /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) fn unbond() -> Weight { // Proof Size summary in bytes: - // Measured: `3858` - // Estimated: `67379` - // Minimum execution time: 174_532 nanoseconds. - Weight::from_ref_time(180_032_000) - .saturating_add(Weight::from_proof_size(67379)) - .saturating_add(T::DbWeight::get().reads(18_u64)) - .saturating_add(T::DbWeight::get().writes(14_u64)) + // Measured: `3935` + // Estimated: `67966` + // Minimum execution time: 167_605 nanoseconds. + Weight::from_ref_time(168_608_000) + .saturating_add(Weight::from_proof_size(67966)) + .saturating_add(T::DbWeight::get().reads(19_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) } /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:1) @@ -241,13 +249,13 @@ impl WeightInfo for SubstrateWeight { /// The range of component `s` is `[0, 100]`. fn pool_withdraw_unbonded(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1779` - // Estimated: `13025` - // Minimum execution time: 55_327 nanoseconds. - Weight::from_ref_time(58_947_746) - .saturating_add(Weight::from_proof_size(13025)) - // Standard Error: 1_589 - .saturating_add(Weight::from_ref_time(40_696).saturating_mul(s.into())) + // Measured: `1783` + // Estimated: `13081` + // Minimum execution time: 55_844 nanoseconds. + Weight::from_ref_time(56_991_168) + .saturating_add(Weight::from_proof_size(13081)) + // Standard Error: 6_490 + .saturating_add(Weight::from_ref_time(25_031).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -256,7 +264,7 @@ impl WeightInfo for SubstrateWeight { /// Storage: Staking CurrentEra (r:1 w:0) /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools SubPoolsStorage (r:1 w:1) /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) @@ -269,25 +277,25 @@ impl WeightInfo for SubstrateWeight { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: NominationPools CounterForPoolMembers (r:1 w:1) /// Proof: NominationPools CounterForPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: NominationPools ClaimPermissions (r:0 w:1) + /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_update(s: u32, ) -> Weight { + fn withdraw_unbonded_update(_s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `2303` - // Estimated: `45696` - // Minimum execution time: 105_923 nanoseconds. - Weight::from_ref_time(110_572_476) - .saturating_add(Weight::from_proof_size(45696)) - // Standard Error: 2_438 - .saturating_add(Weight::from_ref_time(69_045).saturating_mul(s.into())) + // Measured: `2307` + // Estimated: `45752` + // Minimum execution time: 109_056 nanoseconds. + Weight::from_ref_time(112_339_953) + .saturating_add(Weight::from_proof_size(45752)) .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) } /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: Staking CurrentEra (r:1 w:0) /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools SubPoolsStorage (r:1 w:1) /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:1) @@ -311,7 +319,7 @@ impl WeightInfo for SubstrateWeight { /// Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) /// Proof: NominationPools CounterForReversePoolIdLookup (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) /// Storage: NominationPools CounterForRewardPools (r:1 w:1) /// Proof: NominationPools CounterForRewardPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) @@ -322,16 +330,20 @@ impl WeightInfo for SubstrateWeight { /// Proof: NominationPools CounterForBondedPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: Staking Payee (r:0 w:1) /// Proof: Staking Payee (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: NominationPools ClaimPermissions (r:0 w:1) + /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_kill(_s: u32, ) -> Weight { + fn withdraw_unbonded_kill(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `2690` - // Estimated: `68812` - // Minimum execution time: 169_700 nanoseconds. - Weight::from_ref_time(178_693_541) - .saturating_add(Weight::from_proof_size(68812)) + // Measured: `2694` + // Estimated: `68904` + // Minimum execution time: 173_492 nanoseconds. + Weight::from_ref_time(176_020_869) + .saturating_add(Weight::from_proof_size(68904)) + // Standard Error: 9_468 + .saturating_add(Weight::from_ref_time(18_840).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(20_u64)) - .saturating_add(T::DbWeight::get().writes(17_u64)) + .saturating_add(T::DbWeight::get().writes(18_u64)) } /// Storage: NominationPools LastPoolId (r:1 w:1) /// Proof: NominationPools LastPoolId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) @@ -364,7 +376,7 @@ impl WeightInfo for SubstrateWeight { /// Storage: Balances Locks (r:1 w:1) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) /// Storage: NominationPools CounterForRewardPools (r:1 w:1) /// Proof: NominationPools CounterForRewardPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools ReversePoolIdLookup (r:1 w:1) @@ -372,21 +384,21 @@ impl WeightInfo for SubstrateWeight { /// Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) /// Proof: NominationPools CounterForReversePoolIdLookup (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Payee (r:0 w:1) /// Proof: Staking Payee (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) fn create() -> Weight { // Proof Size summary in bytes: // Measured: `1321` - // Estimated: `31522` - // Minimum execution time: 145_976 nanoseconds. - Weight::from_ref_time(150_664_000) - .saturating_add(Weight::from_proof_size(31522)) + // Estimated: `31610` + // Minimum execution time: 150_941 nanoseconds. + Weight::from_ref_time(151_589_000) + .saturating_add(Weight::from_proof_size(31610)) .saturating_add(T::DbWeight::get().reads(21_u64)) .saturating_add(T::DbWeight::get().writes(15_u64)) } /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:0) @@ -412,36 +424,36 @@ impl WeightInfo for SubstrateWeight { /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1909` - // Estimated: `21998 + n * (2520 ±0)` - // Minimum execution time: 69_288 nanoseconds. - Weight::from_ref_time(71_075_293) - .saturating_add(Weight::from_proof_size(21998)) - // Standard Error: 10_508 - .saturating_add(Weight::from_ref_time(1_384_674).saturating_mul(n.into())) + // Measured: `1913` + // Estimated: `22054 + n * (2520 ±0)` + // Minimum execution time: 69_510 nanoseconds. + Weight::from_ref_time(69_738_016) + .saturating_add(Weight::from_proof_size(22054)) + // Standard Error: 5_538 + .saturating_add(Weight::from_ref_time(1_481_803).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(12_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(T::DbWeight::get().writes(5_u64)) .saturating_add(Weight::from_proof_size(2520).saturating_mul(n.into())) } /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:0) /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) fn set_state() -> Weight { // Proof Size summary in bytes: - // Measured: `1498` - // Estimated: `8752` - // Minimum execution time: 36_410 nanoseconds. - Weight::from_ref_time(37_585_000) - .saturating_add(Weight::from_proof_size(8752)) + // Measured: `1502` + // Estimated: `8808` + // Minimum execution time: 36_968 nanoseconds. + Weight::from_ref_time(37_288_000) + .saturating_add(Weight::from_proof_size(8808)) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools Metadata (r:1 w:1) /// Proof: NominationPools Metadata (max_values: None, max_size: Some(270), added: 2745, mode: MaxEncodedLen) /// Storage: NominationPools CounterForMetadata (r:1 w:1) @@ -449,13 +461,13 @@ impl WeightInfo for SubstrateWeight { /// The range of component `n` is `[1, 256]`. fn set_metadata(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `559` - // Estimated: `5883` - // Minimum execution time: 14_322 nanoseconds. - Weight::from_ref_time(15_328_204) - .saturating_add(Weight::from_proof_size(5883)) - // Standard Error: 161 - .saturating_add(Weight::from_ref_time(1_406).saturating_mul(n.into())) + // Measured: `563` + // Estimated: `5939` + // Minimum execution time: 15_112 nanoseconds. + Weight::from_ref_time(15_528_998) + .saturating_add(Weight::from_proof_size(5939)) + // Standard Error: 405 + .saturating_add(Weight::from_ref_time(3_157).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -467,31 +479,33 @@ impl WeightInfo for SubstrateWeight { /// Proof: NominationPools MaxPoolMembersPerPool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools MinCreateBond (r:0 w:1) /// Proof: NominationPools MinCreateBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:0 w:1) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools MaxPools (r:0 w:1) /// Proof: NominationPools MaxPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn set_configs() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_968 nanoseconds. - Weight::from_ref_time(6_245_000) + // Minimum execution time: 7_225 nanoseconds. + Weight::from_ref_time(7_502_000) .saturating_add(Weight::from_proof_size(0)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) fn update_roles() -> Weight { // Proof Size summary in bytes: - // Measured: `559` - // Estimated: `2639` - // Minimum execution time: 18_979 nanoseconds. - Weight::from_ref_time(19_795_000) - .saturating_add(Weight::from_proof_size(2639)) + // Measured: `563` + // Estimated: `2695` + // Minimum execution time: 20_777 nanoseconds. + Weight::from_ref_time(21_446_000) + .saturating_add(Weight::from_proof_size(2695)) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:0) @@ -510,14 +524,56 @@ impl WeightInfo for SubstrateWeight { /// Proof: VoterList CounterForListNodes (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn chill() -> Weight { // Proof Size summary in bytes: - // Measured: `2136` - // Estimated: `20489` - // Minimum execution time: 68_145 nanoseconds. - Weight::from_ref_time(70_444_000) - .saturating_add(Weight::from_proof_size(20489)) + // Measured: `2140` + // Estimated: `20545` + // Minimum execution time: 67_539 nanoseconds. + Weight::from_ref_time(68_114_000) + .saturating_add(Weight::from_proof_size(20545)) .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } + /// Storage: NominationPools BondedPools (r:1 w:1) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) + /// Storage: NominationPools RewardPools (r:1 w:0) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:0) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + fn set_commission() -> Weight { + // Proof Size summary in bytes: + // Measured: `866` + // Estimated: `8364` + // Minimum execution time: 31_945 nanoseconds. + Weight::from_ref_time(32_310_000) + .saturating_add(Weight::from_proof_size(8364)) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: NominationPools BondedPools (r:1 w:1) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) + fn set_commission_max() -> Weight { + // Proof Size summary in bytes: + // Measured: `603` + // Estimated: `2695` + // Minimum execution time: 19_907 nanoseconds. + Weight::from_ref_time(20_105_000) + .saturating_add(Weight::from_proof_size(2695)) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: NominationPools BondedPools (r:1 w:1) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) + fn set_commission_change_rate() -> Weight { + // Proof Size summary in bytes: + // Measured: `563` + // Estimated: `2695` + // Minimum execution time: 20_770 nanoseconds. + Weight::from_ref_time(21_017_000) + .saturating_add(Weight::from_proof_size(2695)) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } /// Storage: NominationPools PoolMembers (r:1 w:0) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools ClaimPermissions (r:1 w:1) @@ -526,36 +582,30 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `542` // Estimated: `5228` - // Minimum execution time: 15_112 nanoseconds. - Weight::from_ref_time(15_897_000) + // Minimum execution time: 15_312 nanoseconds. + Weight::from_ref_time(15_595_000) .saturating_add(Weight::from_proof_size(5228)) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: NominationPools BondedPools (r:1 w:1) - fn set_commission() -> Weight { - // Minimum execution time: 24_000 nanoseconds. - Weight::from_ref_time(24_000_000) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - // Storage: NominationPools BondedPools (r:1 w:1) - fn set_commission_max() -> Weight { - // Minimum execution time: 21_000 nanoseconds. - Weight::from_ref_time(22_000_000) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - // Storage: NominationPools BondedPools (r:1 w:1) - fn set_commission_change_rate() -> Weight { - // Minimum execution time: 22_000 nanoseconds. - Weight::from_ref_time(23_000_000) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - fn claim_commission() -> Weight { - Weight::zero() - } + /// Storage: NominationPools BondedPools (r:1 w:0) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) + /// Storage: NominationPools RewardPools (r:1 w:0) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + fn claim_commission() -> Weight { + // Proof Size summary in bytes: + // Measured: `1096` + // Estimated: `8364` + // Minimum execution time: 46_155 nanoseconds. + Weight::from_ref_time(46_918_000) + .saturating_add(Weight::from_proof_size(8364)) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } // For backwards compatibility and tests @@ -565,13 +615,15 @@ impl WeightInfo for () { /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:1) /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: System Account (r:2 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) @@ -588,20 +640,22 @@ impl WeightInfo for () { /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) fn join() -> Weight { // Proof Size summary in bytes: - // Measured: `3573` - // Estimated: `37988` - // Minimum execution time: 169_857 nanoseconds. - Weight::from_ref_time(173_895_000) - .saturating_add(Weight::from_proof_size(37988)) - .saturating_add(RocksDbWeight::get().reads(17_u64)) + // Measured: `3650` + // Estimated: `38575` + // Minimum execution time: 164_798 nanoseconds. + Weight::from_ref_time(166_299_000) + .saturating_add(Weight::from_proof_size(38575)) + .saturating_add(RocksDbWeight::get().reads(18_u64)) .saturating_add(RocksDbWeight::get().writes(12_u64)) } /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: System Account (r:3 w:2) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) @@ -616,12 +670,12 @@ impl WeightInfo for () { /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) fn bond_extra_transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `3615` - // Estimated: `38583` - // Minimum execution time: 167_372 nanoseconds. - Weight::from_ref_time(168_776_000) - .saturating_add(Weight::from_proof_size(38583)) - .saturating_add(RocksDbWeight::get().reads(14_u64)) + // Measured: `3692` + // Estimated: `39170` + // Minimum execution time: 162_598 nanoseconds. + Weight::from_ref_time(163_420_000) + .saturating_add(Weight::from_proof_size(39170)) + .saturating_add(RocksDbWeight::get().reads(15_u64)) .saturating_add(RocksDbWeight::get().writes(12_u64)) } /// Storage: NominationPools ClaimPermissions (r:1 w:0) @@ -629,9 +683,11 @@ impl WeightInfo for () { /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: System Account (r:3 w:3) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) @@ -646,12 +702,12 @@ impl WeightInfo for () { /// Proof: VoterList ListBags (max_values: None, max_size: Some(82), added: 2557, mode: MaxEncodedLen) fn bond_extra_other() -> Weight { // Proof Size summary in bytes: - // Measured: `3680` - // Estimated: `41099` - // Minimum execution time: 186_346 nanoseconds. - Weight::from_ref_time(191_308_000) - .saturating_add(Weight::from_proof_size(41099)) - .saturating_add(RocksDbWeight::get().reads(15_u64)) + // Measured: `3757` + // Estimated: `41686` + // Minimum execution time: 181_848 nanoseconds. + Weight::from_ref_time(183_274_000) + .saturating_add(Weight::from_proof_size(41686)) + .saturating_add(RocksDbWeight::get().reads(16_u64)) .saturating_add(RocksDbWeight::get().writes(13_u64)) } /// Storage: NominationPools ClaimPermissions (r:1 w:0) @@ -659,31 +715,35 @@ impl WeightInfo for () { /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: System Account (r:1 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn claim_payout() -> Weight { // Proof Size summary in bytes: - // Measured: `1254` - // Estimated: `13005` - // Minimum execution time: 61_423 nanoseconds. - Weight::from_ref_time(63_219_000) - .saturating_add(Weight::from_proof_size(13005)) - .saturating_add(RocksDbWeight::get().reads(5_u64)) + // Measured: `1331` + // Estimated: `13592` + // Minimum execution time: 64_438 nanoseconds. + Weight::from_ref_time(65_232_000) + .saturating_add(Weight::from_proof_size(13592)) + .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:1) /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: System Account (r:2 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Staking CurrentEra (r:1 w:0) @@ -702,20 +762,18 @@ impl WeightInfo for () { /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) /// Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) /// Proof: NominationPools CounterForSubPoolsStorage (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: NominationPools ClaimPermissions (r:0 w:1) - /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) fn unbond() -> Weight { // Proof Size summary in bytes: - // Measured: `3858` - // Estimated: `67379` - // Minimum execution time: 174_532 nanoseconds. - Weight::from_ref_time(180_032_000) - .saturating_add(Weight::from_proof_size(67379)) - .saturating_add(RocksDbWeight::get().reads(18_u64)) - .saturating_add(RocksDbWeight::get().writes(14_u64)) + // Measured: `3935` + // Estimated: `67966` + // Minimum execution time: 167_605 nanoseconds. + Weight::from_ref_time(168_608_000) + .saturating_add(Weight::from_proof_size(67966)) + .saturating_add(RocksDbWeight::get().reads(19_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) } /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:1) @@ -727,13 +785,13 @@ impl WeightInfo for () { /// The range of component `s` is `[0, 100]`. fn pool_withdraw_unbonded(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1779` - // Estimated: `13025` - // Minimum execution time: 55_327 nanoseconds. - Weight::from_ref_time(58_947_746) - .saturating_add(Weight::from_proof_size(13025)) - // Standard Error: 1_589 - .saturating_add(Weight::from_ref_time(40_696).saturating_mul(s.into())) + // Measured: `1783` + // Estimated: `13081` + // Minimum execution time: 55_844 nanoseconds. + Weight::from_ref_time(56_991_168) + .saturating_add(Weight::from_proof_size(13081)) + // Standard Error: 6_490 + .saturating_add(Weight::from_ref_time(25_031).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -742,7 +800,7 @@ impl WeightInfo for () { /// Storage: Staking CurrentEra (r:1 w:0) /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools SubPoolsStorage (r:1 w:1) /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) @@ -755,25 +813,25 @@ impl WeightInfo for () { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: NominationPools CounterForPoolMembers (r:1 w:1) /// Proof: NominationPools CounterForPoolMembers (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: NominationPools ClaimPermissions (r:0 w:1) + /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_update(s: u32, ) -> Weight { + fn withdraw_unbonded_update(_s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `2303` - // Estimated: `45696` - // Minimum execution time: 105_923 nanoseconds. - Weight::from_ref_time(110_572_476) - .saturating_add(Weight::from_proof_size(45696)) - // Standard Error: 2_438 - .saturating_add(Weight::from_ref_time(69_045).saturating_mul(s.into())) + // Measured: `2307` + // Estimated: `45752` + // Minimum execution time: 109_056 nanoseconds. + Weight::from_ref_time(112_339_953) + .saturating_add(Weight::from_proof_size(45752)) .saturating_add(RocksDbWeight::get().reads(9_u64)) - .saturating_add(RocksDbWeight::get().writes(7_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) } /// Storage: NominationPools PoolMembers (r:1 w:1) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: Staking CurrentEra (r:1 w:0) /// Proof: Staking CurrentEra (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools SubPoolsStorage (r:1 w:1) /// Proof: NominationPools SubPoolsStorage (max_values: None, max_size: Some(24382), added: 26857, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:1) @@ -797,7 +855,7 @@ impl WeightInfo for () { /// Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) /// Proof: NominationPools CounterForReversePoolIdLookup (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) /// Storage: NominationPools CounterForRewardPools (r:1 w:1) /// Proof: NominationPools CounterForRewardPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) @@ -808,16 +866,20 @@ impl WeightInfo for () { /// Proof: NominationPools CounterForBondedPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: Staking Payee (r:0 w:1) /// Proof: Staking Payee (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: NominationPools ClaimPermissions (r:0 w:1) + /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_kill(_s: u32, ) -> Weight { + fn withdraw_unbonded_kill(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `2690` - // Estimated: `68812` - // Minimum execution time: 169_700 nanoseconds. - Weight::from_ref_time(178_693_541) - .saturating_add(Weight::from_proof_size(68812)) + // Measured: `2694` + // Estimated: `68904` + // Minimum execution time: 173_492 nanoseconds. + Weight::from_ref_time(176_020_869) + .saturating_add(Weight::from_proof_size(68904)) + // Standard Error: 9_468 + .saturating_add(Weight::from_ref_time(18_840).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(20_u64)) - .saturating_add(RocksDbWeight::get().writes(17_u64)) + .saturating_add(RocksDbWeight::get().writes(18_u64)) } /// Storage: NominationPools LastPoolId (r:1 w:1) /// Proof: NominationPools LastPoolId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) @@ -850,7 +912,7 @@ impl WeightInfo for () { /// Storage: Balances Locks (r:1 w:1) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:1) - /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) /// Storage: NominationPools CounterForRewardPools (r:1 w:1) /// Proof: NominationPools CounterForRewardPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools ReversePoolIdLookup (r:1 w:1) @@ -858,21 +920,21 @@ impl WeightInfo for () { /// Storage: NominationPools CounterForReversePoolIdLookup (r:1 w:1) /// Proof: NominationPools CounterForReversePoolIdLookup (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Payee (r:0 w:1) /// Proof: Staking Payee (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) fn create() -> Weight { // Proof Size summary in bytes: // Measured: `1321` - // Estimated: `31522` - // Minimum execution time: 145_976 nanoseconds. - Weight::from_ref_time(150_664_000) - .saturating_add(Weight::from_proof_size(31522)) + // Estimated: `31610` + // Minimum execution time: 150_941 nanoseconds. + Weight::from_ref_time(151_589_000) + .saturating_add(Weight::from_proof_size(31610)) .saturating_add(RocksDbWeight::get().reads(21_u64)) .saturating_add(RocksDbWeight::get().writes(15_u64)) } /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:0) @@ -898,36 +960,36 @@ impl WeightInfo for () { /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1909` - // Estimated: `21998 + n * (2520 ±0)` - // Minimum execution time: 69_288 nanoseconds. - Weight::from_ref_time(71_075_293) - .saturating_add(Weight::from_proof_size(21998)) - // Standard Error: 10_508 - .saturating_add(Weight::from_ref_time(1_384_674).saturating_mul(n.into())) + // Measured: `1913` + // Estimated: `22054 + n * (2520 ±0)` + // Minimum execution time: 69_510 nanoseconds. + Weight::from_ref_time(69_738_016) + .saturating_add(Weight::from_proof_size(22054)) + // Standard Error: 5_538 + .saturating_add(Weight::from_ref_time(1_481_803).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(12_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(RocksDbWeight::get().writes(5_u64)) .saturating_add(Weight::from_proof_size(2520).saturating_mul(n.into())) } /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:0) /// Proof: Staking Ledger (max_values: None, max_size: Some(1091), added: 3566, mode: MaxEncodedLen) fn set_state() -> Weight { // Proof Size summary in bytes: - // Measured: `1498` - // Estimated: `8752` - // Minimum execution time: 36_410 nanoseconds. - Weight::from_ref_time(37_585_000) - .saturating_add(Weight::from_proof_size(8752)) + // Measured: `1502` + // Estimated: `8808` + // Minimum execution time: 36_968 nanoseconds. + Weight::from_ref_time(37_288_000) + .saturating_add(Weight::from_proof_size(8808)) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools Metadata (r:1 w:1) /// Proof: NominationPools Metadata (max_values: None, max_size: Some(270), added: 2745, mode: MaxEncodedLen) /// Storage: NominationPools CounterForMetadata (r:1 w:1) @@ -935,13 +997,13 @@ impl WeightInfo for () { /// The range of component `n` is `[1, 256]`. fn set_metadata(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `559` - // Estimated: `5883` - // Minimum execution time: 14_322 nanoseconds. - Weight::from_ref_time(15_328_204) - .saturating_add(Weight::from_proof_size(5883)) - // Standard Error: 161 - .saturating_add(Weight::from_ref_time(1_406).saturating_mul(n.into())) + // Measured: `563` + // Estimated: `5939` + // Minimum execution time: 15_112 nanoseconds. + Weight::from_ref_time(15_528_998) + .saturating_add(Weight::from_proof_size(5939)) + // Standard Error: 405 + .saturating_add(Weight::from_ref_time(3_157).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -953,31 +1015,33 @@ impl WeightInfo for () { /// Proof: NominationPools MaxPoolMembersPerPool (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools MinCreateBond (r:0 w:1) /// Proof: NominationPools MinCreateBond (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:0 w:1) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: NominationPools MaxPools (r:0 w:1) /// Proof: NominationPools MaxPools (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn set_configs() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_968 nanoseconds. - Weight::from_ref_time(6_245_000) + // Minimum execution time: 7_225 nanoseconds. + Weight::from_ref_time(7_502_000) .saturating_add(Weight::from_proof_size(0)) - .saturating_add(RocksDbWeight::get().writes(5_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } /// Storage: NominationPools BondedPools (r:1 w:1) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) fn update_roles() -> Weight { // Proof Size summary in bytes: - // Measured: `559` - // Estimated: `2639` - // Minimum execution time: 18_979 nanoseconds. - Weight::from_ref_time(19_795_000) - .saturating_add(Weight::from_proof_size(2639)) + // Measured: `563` + // Estimated: `2695` + // Minimum execution time: 20_777 nanoseconds. + Weight::from_ref_time(21_446_000) + .saturating_add(Weight::from_proof_size(2695)) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: NominationPools BondedPools (r:1 w:0) - /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(164), added: 2639, mode: MaxEncodedLen) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: Staking Bonded (r:1 w:0) /// Proof: Staking Bonded (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) /// Storage: Staking Ledger (r:1 w:0) @@ -996,14 +1060,56 @@ impl WeightInfo for () { /// Proof: VoterList CounterForListNodes (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn chill() -> Weight { // Proof Size summary in bytes: - // Measured: `2136` - // Estimated: `20489` - // Minimum execution time: 68_145 nanoseconds. - Weight::from_ref_time(70_444_000) - .saturating_add(Weight::from_proof_size(20489)) + // Measured: `2140` + // Estimated: `20545` + // Minimum execution time: 67_539 nanoseconds. + Weight::from_ref_time(68_114_000) + .saturating_add(Weight::from_proof_size(20545)) .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } + /// Storage: NominationPools BondedPools (r:1 w:1) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) + /// Storage: NominationPools RewardPools (r:1 w:0) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:0) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + fn set_commission() -> Weight { + // Proof Size summary in bytes: + // Measured: `866` + // Estimated: `8364` + // Minimum execution time: 31_945 nanoseconds. + Weight::from_ref_time(32_310_000) + .saturating_add(Weight::from_proof_size(8364)) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: NominationPools BondedPools (r:1 w:1) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) + fn set_commission_max() -> Weight { + // Proof Size summary in bytes: + // Measured: `603` + // Estimated: `2695` + // Minimum execution time: 19_907 nanoseconds. + Weight::from_ref_time(20_105_000) + .saturating_add(Weight::from_proof_size(2695)) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: NominationPools BondedPools (r:1 w:1) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) + fn set_commission_change_rate() -> Weight { + // Proof Size summary in bytes: + // Measured: `563` + // Estimated: `2695` + // Minimum execution time: 20_770 nanoseconds. + Weight::from_ref_time(21_017_000) + .saturating_add(Weight::from_proof_size(2695)) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } /// Storage: NominationPools PoolMembers (r:1 w:0) /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) /// Storage: NominationPools ClaimPermissions (r:1 w:1) @@ -1012,34 +1118,28 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `542` // Estimated: `5228` - // Minimum execution time: 15_112 nanoseconds. - Weight::from_ref_time(15_897_000) + // Minimum execution time: 15_312 nanoseconds. + Weight::from_ref_time(15_595_000) .saturating_add(Weight::from_proof_size(5228)) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: NominationPools BondedPools (r:1 w:1) - fn set_commission() -> Weight { - // Minimum execution time: 24_000 nanoseconds. - Weight::from_ref_time(24_000_000) - .saturating_add(RocksDbWeight::get().reads(1)) - .saturating_add(RocksDbWeight::get().writes(1)) - } - // Storage: NominationPools BondedPools (r:1 w:1) - fn set_commission_max() -> Weight { - // Minimum execution time: 21_000 nanoseconds. - Weight::from_ref_time(22_000_000) - .saturating_add(RocksDbWeight::get().reads(1)) - .saturating_add(RocksDbWeight::get().writes(1)) - } - // Storage: NominationPools BondedPools (r:1 w:1) - fn set_commission_change_rate() -> Weight { - // Minimum execution time: 22_000 nanoseconds. - Weight::from_ref_time(23_000_000) - .saturating_add(RocksDbWeight::get().reads(1)) - .saturating_add(RocksDbWeight::get().writes(1)) - } + /// Storage: NominationPools BondedPools (r:1 w:0) + /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) + /// Storage: NominationPools RewardPools (r:1 w:0) + /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) + /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) + /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn claim_commission() -> Weight { - Weight::zero() + // Proof Size summary in bytes: + // Measured: `1096` + // Estimated: `8364` + // Minimum execution time: 46_155 nanoseconds. + Weight::from_ref_time(46_918_000) + .saturating_add(Weight::from_proof_size(8364)) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } -} \ No newline at end of file +} From 26006375e199d0061c415a1070934eb0f00acb79 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 24 Feb 2023 17:14:16 +0000 Subject: [PATCH 38/90] ".git/.scripts/commands/fmt/fmt.sh" --- frame/nomination-pools/benchmarking/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index 92cafca21c8a4..d58bbaf3d117c 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -327,7 +327,7 @@ frame_benchmarking::benchmarks! { ); assert_eq!( CurrencyOf::::free_balance(&reward_account), - ed + commission * origin_weight + ed + commission * origin_weight ); } From ee5ec6dfd5107975ff2668858a423126091fe942 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 00:57:54 +0700 Subject: [PATCH 39/90] clippy --- frame/nomination-pools/src/lib.rs | 2 +- frame/nomination-pools/src/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index cee5e2333abcf..0affe6b44d556 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -714,7 +714,7 @@ impl Commission { fn current(&self) -> Perbill { self.current .as_ref() - .map_or(Perbill::zero(), |(c, _)| c.clone()) + .map_or(Perbill::zero(), |(c, _)| *c) .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())) } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index aa9e982683e29..f8f3c4f988a83 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5469,7 +5469,7 @@ mod commission { .commission .current .as_ref() - .map_or(Perbill::zero(), |(c, _)| c.clone()) + .map_or(Perbill::zero(), |(c, _)| *c) .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())); assert_eq!(current, Perbill::from_percent(25)); From 18f2df13849dad48d86fc021d9ad69b820410786 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 03:24:41 +0700 Subject: [PATCH 40/90] + pending --- frame/nomination-pools/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 0affe6b44d556..be11cdf514965 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1265,7 +1265,12 @@ impl RewardPool { self.total_commission_pending.saturating_add(new_pending_commission); self.last_recorded_total_payouts = balance - .checked_add(&self.total_rewards_claimed.saturating_add(self.total_commission_claimed)) + .checked_add( + &self + .total_rewards_claimed + .saturating_add(self.total_commission_pending) + .saturating_add(self.total_commission_claimed), + ) .ok_or(Error::::OverflowRisk)?; Ok(()) } From 6d4431cf7b303faac87531e1aacd2ec5c51417f4 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 03:33:32 +0700 Subject: [PATCH 41/90] add RewardPool.total_rewards_acounted --- frame/nomination-pools/src/lib.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index be11cdf514965..bc185269efff7 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1242,6 +1242,15 @@ impl RewardPool { self.last_recorded_reward_counter } + /// The total amount of pool balance that has been∑ accounted for. + /// + /// The combined total of claimed rewards and commission counters. + pub(crate) fn total_rewards_acounted(&self) -> BalanceOf { + self.total_rewards_claimed + .saturating_add(self.total_commission_pending) + .saturating_add(self.total_commission_claimed) + } + /// Register some rewards that are claimed from the pool by the members. fn register_claimed_reward(&mut self, reward: BalanceOf) { self.total_rewards_claimed = self.total_rewards_claimed.saturating_add(reward); @@ -1265,12 +1274,7 @@ impl RewardPool { self.total_commission_pending.saturating_add(new_pending_commission); self.last_recorded_total_payouts = balance - .checked_add( - &self - .total_rewards_claimed - .saturating_add(self.total_commission_pending) - .saturating_add(self.total_commission_claimed), - ) + .checked_add(&self.total_rewards_acounted()) .ok_or(Error::::OverflowRisk)?; Ok(()) } @@ -1285,9 +1289,7 @@ impl RewardPool { ) -> Result<(T::RewardCounter, BalanceOf), Error> { let balance = Self::current_balance(id); let payouts_since_last_record = balance - .saturating_add(self.total_rewards_claimed) - .saturating_add(self.total_commission_pending) - .saturating_add(self.total_commission_claimed) + .saturating_add(self.total_rewards_acounted()) .saturating_sub(self.last_recorded_total_payouts); // Split the `payouts_since_last_record` into regular rewards and commission according to From 84d8bf09ca2d509c1ca04bf0f2f9f7069cac6a3a Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 05:41:01 +0700 Subject: [PATCH 42/90] fixes --- frame/nomination-pools/src/lib.rs | 45 ++--- frame/nomination-pools/src/migration.rs | 1 - frame/nomination-pools/src/tests.rs | 225 ++++++++++-------------- 3 files changed, 111 insertions(+), 160 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index bc185269efff7..118c68aa16e64 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -477,7 +477,7 @@ impl PoolMember { &self, current_reward_counter: T::RewardCounter, commission: Perbill, - ) -> Result<(BalanceOf, BalanceOf), Error> { + ) -> Result, Error> { // accuracy note: Reward counters are `FixedU128` with base of 10^18. This value is being // multiplied by a point. The worse case of a point is 10x the granularity of the balance // (10x is the common configuration of `MaxPointsToBalance`). @@ -495,14 +495,10 @@ impl PoolMember { // point is equal to balance (normally), and rewards are usually a proportion of the points // in the pool, the likelihood of rc reaching near u128::MAX is near impossible. - let pending_total = (current_reward_counter + (current_reward_counter .defensive_saturating_sub(self.last_recorded_reward_counter)) .checked_mul_int(self.active_points()) - .ok_or(Error::::OverflowRisk)?; - - let pending_after_commission = pending_total.saturating_sub(commission * pending_total); - let commission_amount = pending_total.saturating_sub(pending_after_commission); - Ok((pending_after_commission, commission_amount)) + .ok_or(Error::::OverflowRisk) } /// Active balance of the member. @@ -1242,15 +1238,6 @@ impl RewardPool { self.last_recorded_reward_counter } - /// The total amount of pool balance that has been∑ accounted for. - /// - /// The combined total of claimed rewards and commission counters. - pub(crate) fn total_rewards_acounted(&self) -> BalanceOf { - self.total_rewards_claimed - .saturating_add(self.total_commission_pending) - .saturating_add(self.total_commission_claimed) - } - /// Register some rewards that are claimed from the pool by the members. fn register_claimed_reward(&mut self, reward: BalanceOf) { self.total_rewards_claimed = self.total_rewards_claimed.saturating_add(reward); @@ -1272,10 +1259,9 @@ impl RewardPool { self.total_commission_pending = self.total_commission_pending.saturating_add(new_pending_commission); - self.last_recorded_total_payouts = balance - .checked_add(&self.total_rewards_acounted()) - .ok_or(Error::::OverflowRisk)?; + .checked_add(&self.total_rewards_claimed) + .ok_or(Error::::OverflowRisk)?; Ok(()) } @@ -1289,12 +1275,14 @@ impl RewardPool { ) -> Result<(T::RewardCounter, BalanceOf), Error> { let balance = Self::current_balance(id); let payouts_since_last_record = balance - .saturating_add(self.total_rewards_acounted()) + .saturating_add(self.total_rewards_claimed) + .saturating_add(self.total_commission_claimed) .saturating_sub(self.last_recorded_total_payouts); // Split the `payouts_since_last_record` into regular rewards and commission according to // the current commission rate. let new_pending_commission = commission * payouts_since_last_record; + let payouts_deducting_commission = payouts_since_last_record.saturating_sub(new_pending_commission); // * accuracy notes regarding the multiplication in `checked_from_rational`: // `payouts_since_last_record` is a subset of the total_issuance at the very @@ -1330,7 +1318,7 @@ impl RewardPool { // // which is basically 10^-8 DOTs. See `smallest_claimable_reward` for an example of this. let current_reward_counter = - T::RewardCounter::checked_from_rational(payouts_since_last_record, bonded_points) + T::RewardCounter::checked_from_rational(payouts_deducting_commission, bonded_points) .and_then(|ref r| self.last_recorded_reward_counter.checked_add(r)) .ok_or(Error::::OverflowRisk)?; @@ -1675,8 +1663,7 @@ pub mod pallet { PaidOut { member: T::AccountId, pool_id: PoolId, - payout: BalanceOf, - commission: BalanceOf, + payout: BalanceOf }, /// A member has unbonded from their pool. /// @@ -2788,9 +2775,8 @@ impl Pallet { bonded_pool.points, bonded_pool.commission.current(), )?; - let (pending_rewards, commission) = + let pending_rewards = member.pending_rewards(current_reward_counter, bonded_pool.commission.current())?; - if pending_rewards.is_zero() { return Ok(pending_rewards) } @@ -2817,8 +2803,7 @@ impl Pallet { Self::deposit_event(Event::::PaidOut { member: member_account.clone(), pool_id: member.pool_id, - payout: pending_rewards, - commission, + payout: pending_rewards }); Ok(pending_rewards) @@ -3084,7 +3069,7 @@ impl Pallet { let (current_rc, _) = reward_pool .current_reward_counter(d.pool_id, bonded_pool.points, commission) .unwrap(); - let (pending_rewards, _) = d.pending_rewards(current_rc, commission).unwrap(); + let pending_rewards = d.pending_rewards(current_rc, commission).unwrap(); *pools_members_pending_rewards.entry(d.pool_id).or_default() += pending_rewards; } // else this pool has been heavily slashed and cannot have any rewards anymore. }); @@ -3178,9 +3163,7 @@ impl Pallet { let (current_reward_counter, _) = reward_pool .current_reward_counter(pool_member.pool_id, bonded_pool.points, commission) .ok()?; - let (pending_rewards, _) = - pool_member.pending_rewards(current_reward_counter, commission).ok()?; - return Some(pending_rewards) + return pool_member.pending_rewards(current_reward_counter, commission).ok() } } diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index af5592992866d..6221f5681941c 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -286,7 +286,6 @@ pub mod v2 { member: who.clone(), pool_id: id, payout: last_claim, - commission: Zero::zero(), }); }); diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index f8f3c4f988a83..297a2782f5453 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -759,7 +759,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 },] ); // last recorded reward counter at the time of this member's payout is 1 assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 1)); @@ -775,7 +775,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40, commission: 0 }] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40}] ); assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 1)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 50)); @@ -788,7 +788,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50, commission: 0 }] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50}] ); assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 1)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 100)); @@ -804,7 +804,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] ); assert_eq!(PoolMembers::::get(10).unwrap(), del_float(10, 1.5)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 105)); @@ -817,7 +817,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20, commission: 0 }] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20}] ); assert_eq!(PoolMembers::::get(40).unwrap(), del_float(40, 1.5)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 125)); @@ -834,7 +834,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50, commission: 0 }] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] ); assert_eq!(PoolMembers::::get(50).unwrap(), del_float(50, 2.0)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 175)); @@ -847,7 +847,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] ); assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 2)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 180)); @@ -864,7 +864,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] ); // We expect a payout of 40 @@ -883,7 +883,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] ); assert_eq!(PoolMembers::::get(10).unwrap(), del_float(10, 6.2)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 222)); @@ -896,7 +896,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188, commission: 0 }] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] ); assert_eq!(PoolMembers::::get(40).unwrap(), del_float(40, 6.2)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 410)); @@ -909,7 +909,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210, commission: 0 }] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] ); assert_eq!(PoolMembers::::get(50).unwrap(), del_float(50, 6.2)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 620)); @@ -986,7 +986,7 @@ mod claim_payout { // commission applied is 50%, not 75%. Has been bounded by `GlobalMaxCommission`. assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 5 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 },] ); }) } @@ -1023,7 +1023,7 @@ mod claim_payout { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 5 } ] ); assert_eq!(payout, 5); @@ -1041,7 +1041,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] ); assert_eq!(payout, 10); assert_eq!(reward_pool, rew(0, 0, 15)); @@ -1100,7 +1100,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] ); assert_eq!(payout, 10); assert_eq!(del_10, del(10, 1)); @@ -1114,7 +1114,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40, commission: 0 }] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] ); assert_eq!(payout, 40); assert_eq!(del_40, del(40, 1)); @@ -1128,7 +1128,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50, commission: 0 }] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] ); assert_eq!(payout, 50); assert_eq!(del_50, del(50, 1)); @@ -1145,7 +1145,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] ); assert_eq!(payout, 5); assert_eq!(del_10, del_float(10, 1.5)); @@ -1159,7 +1159,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20, commission: 0 }] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] ); assert_eq!(payout, 20); assert_eq!(del_40, del_float(40, 1.5)); @@ -1176,7 +1176,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50, commission: 0 }] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] ); assert_eq!(payout, 50); assert_eq!(del_50, del_float(50, 2.0)); @@ -1190,7 +1190,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] ); assert_eq!(payout, 5); assert_eq!(del_10, del_float(10, 2.0)); @@ -1207,7 +1207,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] ); assert_eq!(payout, 40); assert_eq!(del_10, del_float(10, 6.0)); @@ -1270,8 +1270,8 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 20, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, ] ); @@ -1284,8 +1284,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, ] ); }); @@ -1313,8 +1313,8 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 3 + 3, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 3, commission: 0 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 3 + 3 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, ] ); @@ -1327,8 +1327,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 4, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 4, commission: 0 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 4, }, + Event::PaidOut { member: 20, pool_id: 1, payout: 4, }, ] ); @@ -1341,8 +1341,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 3, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 3, commission: 0 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 3, }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3, }, ] ); }); @@ -1381,15 +1381,13 @@ mod claim_payout { member: 10, pool_id: 1, payout: 30 + 100 / 2 + 60 / 3, - commission: 0 }, Event::PaidOut { member: 20, pool_id: 1, payout: 100 / 2 + 60 / 3, - commission: 0 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 60 / 3, commission: 0 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 60 / 3 }, ] ); @@ -1403,9 +1401,9 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10, commission: 0 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 10 }, ] ); }); @@ -1488,9 +1486,9 @@ mod claim_payout { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 20, commission: 0 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 10, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 10, }, + Event::PaidOut { member: 20, pool_id: 1 , payout: 20, }, + Event::PaidOut { member: 30, pool_id: 1, payout: 10 } ] ); @@ -1508,9 +1506,9 @@ mod claim_payout { pool_events_since_last_call(), vec![ Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: false }, - Event::PaidOut { member: 10, pool_id: 1, payout: 20, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 40, commission: 0 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 40, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 40, } ] ); }); @@ -1536,8 +1534,8 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 20, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20 } ] ); @@ -1554,8 +1552,8 @@ mod claim_payout { pool_events_since_last_call(), vec![ Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10, era: 3 }, - Event::PaidOut { member: 10, pool_id: 1, payout: 50, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 50, commission: 0 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 50 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 50 }, ] ); }); @@ -1585,8 +1583,8 @@ mod claim_payout { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 20, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20 } ] ); @@ -1600,8 +1598,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 20, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 40, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40 } ] ); @@ -1615,8 +1613,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 20, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 40, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40 } ] ); @@ -1629,7 +1627,6 @@ mod claim_payout { member: 30, pool_id: 1, payout: 10 + 20 + 20, - commission: 0 }] ); }); @@ -1655,7 +1652,7 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 10 } ] ); @@ -1673,9 +1670,9 @@ mod claim_payout { pool_events_since_last_call(), vec![ // 20 + 40, which means the extra amount they bonded did not impact us. - Event::PaidOut { member: 20, pool_id: 1, payout: 60, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 60 }, Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: false }, - Event::PaidOut { member: 10, pool_id: 1, payout: 20, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 20 } ] ); @@ -1689,8 +1686,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 15, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 45, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 15 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 45 } ] ); }); @@ -1757,7 +1754,7 @@ mod claim_payout { Event::Bonded { member: 20, pool_id: 2, bonded: 10, joined: true }, Event::Created { depositor: 30, pool_id: 3 }, Event::Bonded { member: 30, pool_id: 3, bonded: 10, joined: true }, - Event::PaidOut { member: 30, pool_id: 3, payout: 10, commission: 0 } + Event::PaidOut { member: 30, pool_id: 3, payout: 10 } ] ); }) @@ -1904,9 +1901,9 @@ mod claim_payout { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false }, - Event::PaidOut { member: 10, pool_id: 1, payout: 15, commission: 0 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 15 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false }, - Event::PaidOut { member: 20, pool_id: 1, payout: 15, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 15 }, Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: false } ] ); @@ -1936,7 +1933,7 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] ); } @@ -1953,7 +1950,7 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 20, pool_id: 1, payout: 20, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20 }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: false } ] ); @@ -2050,12 +2047,12 @@ mod claim_payout { Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, Event::Bonded { member: 30, pool_id: 1, bonded: 20, joined: true }, Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10, era: 3 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 15, commission: 0 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 15 }, Event::Unbonded { member: 30, pool_id: 1, balance: 10, points: 10, era: 3 }, Event::Unbonded { member: 30, pool_id: 1, balance: 5, points: 5, era: 3 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 7, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 7 }, Event::Unbonded { member: 20, pool_id: 1, balance: 5, points: 5, era: 3 }, - Event::PaidOut { member: 10, pool_id: 1, payout: 7, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 7 } ] ); }) @@ -2086,8 +2083,8 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 13, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 26, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 13 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 26 } ] ); @@ -2172,10 +2169,10 @@ mod claim_payout { bonded: 5000000000000000, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 100000000, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 150000000, commission: 0 }, - Event::PaidOut { member: 21, pool_id: 1, payout: 250000000, commission: 0 }, - Event::PaidOut { member: 22, pool_id: 1, payout: 500000000, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 100000000 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 150000000 }, + Event::PaidOut { member: 21, pool_id: 1, payout: 250000000 }, + Event::PaidOut { member: 22, pool_id: 1, payout: 500000000 } ] ); }) @@ -2568,7 +2565,7 @@ mod unbond { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, - Event::PaidOut { member: 40, pool_id: 1, payout: 40, commission: 0 }, + Event::PaidOut { member: 40, pool_id: 1, payout: 40 }, Event::Unbonded { member: 40, pool_id: 1, points: 6, balance: 6, era: 3 } ] ); @@ -2611,7 +2608,7 @@ mod unbond { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 550, pool_id: 1, payout: 550, commission: 0 }, + Event::PaidOut { member: 550, pool_id: 1, payout: 550 }, Event::Unbonded { member: 550, pool_id: 1, @@ -2656,7 +2653,7 @@ mod unbond { Event::MemberRemoved { pool_id: 1, member: 40 }, Event::Withdrawn { member: 550, pool_id: 1, points: 92, balance: 92 }, Event::MemberRemoved { pool_id: 1, member: 550 }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2, era: 6 } ] ); @@ -3194,7 +3191,7 @@ mod unbond { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, Event::Unbonded { member: 20, pool_id: 1, balance: 2, points: 2, era: 3 } ] ); @@ -3210,7 +3207,7 @@ mod unbond { pool_events_since_last_call(), vec![ // 2/3 of ed, which is 20's share. - Event::PaidOut { member: 20, pool_id: 1, payout: 6, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 6 }, Event::Unbonded { member: 20, pool_id: 1, points: 3, balance: 3, era: 4 } ] ); @@ -3225,7 +3222,7 @@ mod unbond { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 20, pool_id: 1, payout: 3, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, Event::Unbonded { member: 20, pool_id: 1, points: 5, balance: 5, era: 5 } ] ); @@ -4778,7 +4775,6 @@ mod bond_extra { member: 10, pool_id: 1, payout: claimable_reward, - commission: 0 }, Event::Bonded { member: 10, @@ -4835,9 +4831,9 @@ mod bond_extra { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 1, commission: 0 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 1, joined: false }, - Event::PaidOut { member: 20, pool_id: 1, payout: 2, commission: 0 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 2 }, Event::Bonded { member: 20, pool_id: 1, bonded: 2, joined: false } ] ); @@ -5074,9 +5070,7 @@ mod reward_counter_precision { let bonded_pool = BondedPools::::get(member.pool_id).unwrap(); assert_eq!(member.pool_id, 1); let rc = default_pool_reward_counter(); - let (pending_after_commission, _) = - member.pending_rewards(rc, bonded_pool.commission.current()).ok()?; - Some(pending_after_commission) + member.pending_rewards(rc, bonded_pool.commission.current()).ok() } #[test] @@ -5116,7 +5110,7 @@ mod reward_counter_precision { assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1173, commission: 0 }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1173 }] ); }) } @@ -5153,13 +5147,11 @@ mod reward_counter_precision { member: 10, pool_id: 1, payout: 7333333333333333333, - commission: 0 }, Event::PaidOut { member: 20, pool_id: 1, payout: 3666666666666666666, - commission: 0 } ] ); @@ -5215,7 +5207,6 @@ mod reward_counter_precision { member: 10, pool_id: 1, payout: 15937424600999999996, - commission: 0 }] ); @@ -5232,7 +5223,7 @@ mod reward_counter_precision { vec![ Event::Bonded { member: 30, pool_id: 1, bonded: 100000000000, joined: true }, // quite small, but working fine. - Event::PaidOut { member: 30, pool_id: 1, payout: 38, commission: 0 } + Event::PaidOut { member: 30, pool_id: 1, payout: 38 } ] ); }) @@ -5312,7 +5303,7 @@ mod reward_counter_precision { bonded: 100000000000, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 9999997, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 9999997 } ] ); @@ -5329,7 +5320,6 @@ mod reward_counter_precision { member: 10, pool_id: 1, payout: 10000000, - commission: 0 }] ); @@ -5343,8 +5333,8 @@ mod reward_counter_precision { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 10000000, commission: 0 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 1, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 10000000 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 1 } ] ); }); @@ -5393,7 +5383,7 @@ mod reward_counter_precision { bonded: 100000000000, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 9999997, commission: 0 } + Event::PaidOut { member: 10, pool_id: 1, payout: 9999997 } ] ); @@ -5474,7 +5464,7 @@ mod commission { assert_eq!(current, Perbill::from_percent(25)); // Pool earns 40 points, payout is triggered. - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 40)); + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 80)); assert_eq!( PoolMembers::::get(10).unwrap(), PoolMember:: { pool_id, points: 10, ..Default::default() } @@ -5483,10 +5473,10 @@ mod commission { assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id, payout: 30, commission: 10 }] + vec![Event::PaidOut { member: 10, pool_id, payout: 60 }] ); - assert_eq!(RewardPool::::current_balance(pool_id), 10); + assert_eq!(RewardPool::::current_balance(pool_id), 20); // uncomment to check reward_pool state assert_eq!( @@ -5494,7 +5484,7 @@ mod commission { RewardPool { last_recorded_reward_counter: Zero::zero(), last_recorded_total_payouts: 0, - total_rewards_claimed: 30, + total_rewards_claimed: 60, total_commission_pending: 0, total_commission_claimed: 0 } @@ -5507,7 +5497,7 @@ mod commission { Some((Perbill::from_percent(25), 901)) )); - assert_eq!(RewardPool::::current_balance(pool_id), 10); + assert_eq!(RewardPool::::current_balance(pool_id), 20); assert_eq!( pool_events_since_last_call(), @@ -5528,31 +5518,10 @@ mod commission { vec![Event::PoolCommissionUpdated { pool_id, current: None },] ); - assert_eq!( - BondedPools::::get(pool_id).unwrap(), - BondedPoolInner { - commission: Commission { - current: None, - max: None, - change_rate: None, - throttle_from: Some(1) - }, - member_counter: 1, - points: 10, - roles: PoolRoles { - depositor: 10, - root: Some(900), - nominator: Some(901), - bouncer: Some(902) - }, - state: PoolState::Open - } - ); - assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id, payout: 100, commission: 0 },] + vec![Event::PaidOut { member: 10, pool_id, payout: 100 },] ); // test whether supplying a 0% commission along with a payee results in a None `current` @@ -6357,7 +6326,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 7, commission: 3 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 7 },] ); // The pool earns 17 points @@ -6372,7 +6341,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 11, commission: 6 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 11 },] ); // The pool earns 50 points @@ -6387,7 +6356,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 34, commission: 16 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 34 },] ); // The pool earns 10439 points @@ -6402,7 +6371,7 @@ mod commission { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 6994, commission: 3445 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 6994 },] ); }) } @@ -6495,7 +6464,7 @@ mod commission { // of 10 points, reflecting the 90% global max commission. assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1, commission: 9 },] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1 },] ); }) } From 20d9af8f45b733a696f18752c0bf5ee9dfe98527 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 13:11:37 +0700 Subject: [PATCH 43/90] println --- frame/nomination-pools/src/lib.rs | 66 ++++++++++++++++----- frame/nomination-pools/src/tests.rs | 91 +++++++++++++---------------- 2 files changed, 93 insertions(+), 64 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 118c68aa16e64..0f1ce120e5ae6 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -495,10 +495,11 @@ impl PoolMember { // point is equal to balance (normally), and rewards are usually a proportion of the points // in the pool, the likelihood of rc reaching near u128::MAX is near impossible. - (current_reward_counter - .defensive_saturating_sub(self.last_recorded_reward_counter)) - .checked_mul_int(self.active_points()) - .ok_or(Error::::OverflowRisk) + println!("current reward counter pending rewards: {:?}", current_reward_counter); + + (current_reward_counter.defensive_saturating_sub(self.last_recorded_reward_counter)) + .checked_mul_int(self.active_points()) + .ok_or(Error::::OverflowRisk) } /// Active balance of the member. @@ -1255,13 +1256,26 @@ impl RewardPool { let (current_reward_counter, new_pending_commission) = self.current_reward_counter(id, bonded_points, commission)?; + println!("rc in update_records: {:?}", current_reward_counter); self.last_recorded_reward_counter = current_reward_counter; self.total_commission_pending = self.total_commission_pending.saturating_add(new_pending_commission); + + println!( + "updating LRTP: {:?} + {:?} + {:?}", + balance, self.total_rewards_claimed, self.total_commission_claimed + ); + self.last_recorded_total_payouts = balance - .checked_add(&self.total_rewards_claimed) - .ok_or(Error::::OverflowRisk)?; + .checked_add(&self.total_rewards_claimed.saturating_add(self.total_commission_claimed)) + .ok_or(Error::::OverflowRisk)?; + + println!("rc end of update_records: {:?}", current_reward_counter); + println!("last recorded total payouts: {:?}", self.last_recorded_total_payouts); + + println!("RP: {:?}", self); + Ok(()) } @@ -1279,10 +1293,20 @@ impl RewardPool { .saturating_add(self.total_commission_claimed) .saturating_sub(self.last_recorded_total_payouts); + println!( + "{:?} + {:?} + {:?} - {:?}", + balance, + self.total_rewards_claimed, + self.total_commission_claimed, + self.last_recorded_total_payouts + ); + // Split the `payouts_since_last_record` into regular rewards and commission according to // the current commission rate. let new_pending_commission = commission * payouts_since_last_record; - let payouts_deducting_commission = payouts_since_last_record.saturating_sub(new_pending_commission); + println!("new pending commission: {:?}", new_pending_commission); + let payouts_deducting_commission = + payouts_since_last_record.saturating_sub(new_pending_commission); // * accuracy notes regarding the multiplication in `checked_from_rational`: // `payouts_since_last_record` is a subset of the total_issuance at the very @@ -1660,11 +1684,7 @@ pub mod pallet { /// A member has became bonded in a pool. Bonded { member: T::AccountId, pool_id: PoolId, bonded: BalanceOf, joined: bool }, /// A payout has been made to a member. - PaidOut { - member: T::AccountId, - pool_id: PoolId, - payout: BalanceOf - }, + PaidOut { member: T::AccountId, pool_id: PoolId, payout: BalanceOf }, /// A member has unbonded from their pool. /// /// - `balance` is the corresponding balance of the number of points that has been @@ -2522,6 +2542,7 @@ pub mod pallet { pool_id, current: new_commission, }); + println!("end call"); Ok(()) } @@ -2770,11 +2791,19 @@ impl Pallet { // a member who has no skin in the game anymore cannot claim any rewards. ensure!(!member.active_points().is_zero(), Error::::FullyUnbonding); + println!( + "rc with {:?}, {:?} and {:?}", + bonded_pool.id, + bonded_pool.points, + bonded_pool.commission.current() + ); let (current_reward_counter, _) = reward_pool.current_reward_counter( bonded_pool.id, bonded_pool.points, bonded_pool.commission.current(), )?; + println!("current reward counter before pending rewards: {:?}", current_reward_counter); + let pending_rewards = member.pending_rewards(current_reward_counter, bonded_pool.commission.current())?; if pending_rewards.is_zero() { @@ -2803,7 +2832,7 @@ impl Pallet { Self::deposit_event(Event::::PaidOut { member: member_account.clone(), pool_id: member.pool_id, - payout: pending_rewards + payout: pending_rewards, }); Ok(pending_rewards) @@ -3066,6 +3095,12 @@ impl Pallet { let reward_pool = RewardPools::::get(d.pool_id).unwrap(); if !bonded_pool.points.is_zero() { let commission = bonded_pool.commission.current(); + + println!( + "do try state: {:?} + {:?} + {:?}", + d.pool_id, bonded_pool.points, commission + ); + println!("{:?}", reward_pool); let (current_rc, _) = reward_pool .current_reward_counter(d.pool_id, bonded_pool.points, commission) .unwrap(); @@ -3160,9 +3195,14 @@ impl Pallet { .zip(BondedPools::::get(pool_member.pool_id)) { let commission = bonded_pool.commission.current(); + println!( + "rc with {:?}, {:?} and {:?}", + pool_member.pool_id, bonded_pool.points, commission + ); let (current_reward_counter, _) = reward_pool .current_reward_counter(pool_member.pool_id, bonded_pool.points, commission) .ok()?; + println!("rc in api_pending_rewards: {:?}", current_reward_counter); return pool_member.pending_rewards(current_reward_counter, commission).ok() } } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 297a2782f5453..f60dfdbe13963 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -775,7 +775,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40}] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] ); assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 1)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 50)); @@ -788,7 +788,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50}] + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] ); assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 1)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 100)); @@ -817,7 +817,7 @@ mod claim_payout { // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20}] + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] ); assert_eq!(PoolMembers::::get(40).unwrap(), del_float(40, 1.5)); assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 125)); @@ -1327,8 +1327,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 4, }, - Event::PaidOut { member: 20, pool_id: 1, payout: 4, }, + Event::PaidOut { member: 10, pool_id: 1, payout: 4 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 4 }, ] ); @@ -1341,8 +1341,8 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 3, }, - Event::PaidOut { member: 20, pool_id: 1, payout: 3, }, + Event::PaidOut { member: 10, pool_id: 1, payout: 3 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, ] ); }); @@ -1377,16 +1377,8 @@ mod claim_payout { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { - member: 10, - pool_id: 1, - payout: 30 + 100 / 2 + 60 / 3, - }, - Event::PaidOut { - member: 20, - pool_id: 1, - payout: 100 / 2 + 60 / 3, - }, + Event::PaidOut { member: 10, pool_id: 1, payout: 30 + 100 / 2 + 60 / 3 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 100 / 2 + 60 / 3 }, Event::PaidOut { member: 30, pool_id: 1, payout: 60 / 3 }, ] ); @@ -1486,8 +1478,8 @@ mod claim_payout { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10, }, - Event::PaidOut { member: 20, pool_id: 1 , payout: 20, }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20 }, Event::PaidOut { member: 30, pool_id: 1, payout: 10 } ] ); @@ -1508,7 +1500,7 @@ mod claim_payout { Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: false }, Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, Event::PaidOut { member: 20, pool_id: 1, payout: 40 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 40, } + Event::PaidOut { member: 30, pool_id: 1, payout: 40 } ] ); }); @@ -1623,11 +1615,7 @@ mod claim_payout { assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { - member: 30, - pool_id: 1, - payout: 10 + 20 + 20, - }] + vec![Event::PaidOut { member: 30, pool_id: 1, payout: 10 + 20 + 20 }] ); }); } @@ -4771,11 +4759,7 @@ mod bond_extra { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { - member: 10, - pool_id: 1, - payout: claimable_reward, - }, + Event::PaidOut { member: 10, pool_id: 1, payout: claimable_reward }, Event::Bonded { member: 10, pool_id: 1, @@ -5143,16 +5127,8 @@ mod reward_counter_precision { pool_events_since_last_call(), vec![ Event::Bonded { member: 20, pool_id: 1, bonded: 5000000000000, joined: true }, - Event::PaidOut { - member: 10, - pool_id: 1, - payout: 7333333333333333333, - }, - Event::PaidOut { - member: 20, - pool_id: 1, - payout: 3666666666666666666, - } + Event::PaidOut { member: 10, pool_id: 1, payout: 7333333333333333333 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3666666666666666666 } ] ); }) @@ -5203,11 +5179,7 @@ mod reward_counter_precision { assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { - member: 10, - pool_id: 1, - payout: 15937424600999999996, - }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 15937424600999999996 }] ); // now let a small member join with 10 DOTs. @@ -5316,11 +5288,7 @@ mod reward_counter_precision { assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { - member: 10, - pool_id: 1, - payout: 10000000, - }] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10000000 }] ); // earn some more rewards, this time 20 can also claim. @@ -5616,6 +5584,7 @@ mod commission { fn commission_reward_counter_works_one_member() { ExtBuilder::default().build_and_execute(|| { let pool_id = 1; + println!("SET COMMISSION 1"); assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), 1, @@ -5629,17 +5598,37 @@ mod commission { PoolMembers::::get(10).unwrap(), PoolMember:: { pool_id, points: 10, ..Default::default() } ); + println!("CLAIM PAYOUT 1"); assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); //10% balance (commission) should still be in the pool. assert_eq!(RewardPool::::current_balance(pool_id), 4); + println!("SET COMMISSION 2"); assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), 1, Some((Perbill::from_percent(20), 900)), )); - assert_eq!(Pools::api_pending_rewards(10).unwrap(), 0); + println!("PENDING REWARDS"); + println!("{:?}", RewardPools::::get(pool_id).unwrap()); + + let (current_reward_counter, _) = RewardPools::::get(pool_id) + .unwrap() + .current_reward_counter( + pool_id, + BondedPools::::get(pool_id).unwrap().points, + Perbill::from_percent(20), + ) + .unwrap(); + + assert_eq!( + PoolMembers::::get(10) + .unwrap() + .pending_rewards(current_reward_counter, Perbill::from_percent(20)) + .unwrap(), + 0 + ); }) } From 26d5f77aab90bdec5bc575393d0a88dafa701df0 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 14:54:02 +0700 Subject: [PATCH 44/90] more logs --- frame/nomination-pools/src/lib.rs | 11 ++++++----- frame/nomination-pools/src/tests.rs | 3 +-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 0f1ce120e5ae6..93a194d790add 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1274,7 +1274,7 @@ impl RewardPool { println!("rc end of update_records: {:?}", current_reward_counter); println!("last recorded total payouts: {:?}", self.last_recorded_total_payouts); - println!("RP: {:?}", self); + println!("RP id {:?}: {:?}", id, self); Ok(()) } @@ -1872,7 +1872,7 @@ pub mod pallet { let mut reward_pool = RewardPools::::get(pool_id) .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; // IMPORTANT: reward pool records must be updated with the old points. - reward_pool.update_records( + let _ = reward_pool.update_records( pool_id, bonded_pool.points, bonded_pool.commission.current(), @@ -2530,7 +2530,7 @@ pub mod pallet { .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; // IMPORTANT: make sure that everything up to this point is using the current commission // before it updates. Note that `try_update_current` could still fail at this point. - reward_pool.update_records( + let _ = reward_pool.update_records( pool_id, bonded_pool.points, bonded_pool.commission.current(), @@ -2543,6 +2543,7 @@ pub mod pallet { current: new_commission, }); println!("end call"); + println!("reward pool: {:?}", reward_pool); Ok(()) } @@ -2927,7 +2928,7 @@ impl Pallet { // payout related stuff: we must claim the payouts, and updated recorded payout data // before updating the bonded pool points, similar to that of `join` transaction. - reward_pool.update_records( + let _ = reward_pool.update_records( bonded_pool.id, bonded_pool.points, bonded_pool.commission.current(), @@ -2966,7 +2967,7 @@ impl Pallet { // IMPORTANT: make sure that any newly pending commission not yet processed is added to // `total_commission_pending`. - reward_pool.update_records( + let _ = reward_pool.update_records( pool_id, bonded_pool.points, bonded_pool.commission.current(), diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index f60dfdbe13963..b118a32a090eb 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5611,7 +5611,7 @@ mod commission { Some((Perbill::from_percent(20), 900)), )); println!("PENDING REWARDS"); - println!("{:?}", RewardPools::::get(pool_id).unwrap()); + println!("reward pool {:?}: {:?}", pool_id, RewardPools::::get(pool_id).unwrap()); let (current_reward_counter, _) = RewardPools::::get(pool_id) .unwrap() @@ -5621,7 +5621,6 @@ mod commission { Perbill::from_percent(20), ) .unwrap(); - assert_eq!( PoolMembers::::get(10) .unwrap() From 5addf17e3435e61cbd4032a5ada7ae64ad91d280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Sat, 25 Feb 2023 09:34:17 +0100 Subject: [PATCH 45/90] Fix plus cleanups --- frame/nomination-pools/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 93a194d790add..a56877262fb20 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -907,7 +907,7 @@ impl BondedPool { /// Consume self and put into storage. fn put(self) { - BondedPools::::insert(self.id, BondedPoolInner { ..self.inner }); + BondedPools::::insert(self.id, self.inner); } /// Consume self and remove from storage. @@ -2530,11 +2530,13 @@ pub mod pallet { .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; // IMPORTANT: make sure that everything up to this point is using the current commission // before it updates. Note that `try_update_current` could still fail at this point. - let _ = reward_pool.update_records( + reward_pool.update_records( pool_id, bonded_pool.points, bonded_pool.commission.current(), )?; + println!("reward pool: {:?}", reward_pool); + RewardPools::insert(pool_id, reward_pool); bonded_pool.commission.try_update_current(&new_commission)?; bonded_pool.put(); From 5006164cec7139f5a15f8af4be39052e9d96351f Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 15:43:34 +0700 Subject: [PATCH 46/90] fix assert --- frame/nomination-pools/src/lib.rs | 1 - frame/nomination-pools/src/tests.rs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index a56877262fb20..89c6e76f3d20a 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2545,7 +2545,6 @@ pub mod pallet { current: new_commission, }); println!("end call"); - println!("reward pool: {:?}", reward_pool); Ok(()) } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index b118a32a090eb..94049e713b1bf 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5621,6 +5621,18 @@ mod commission { Perbill::from_percent(20), ) .unwrap(); + + assert_eq!( + RewardPools::::get(pool_id).unwrap(), + RewardPool { + last_recorded_reward_counter: FixedU128::from_float(3.6), + last_recorded_total_payouts: 40, + total_rewards_claimed: 36, + total_commission_pending: 4, + total_commission_claimed: 0 + } + ); + assert_eq!( PoolMembers::::get(10) .unwrap() From d4e3a690fd7b6c5ca5f248e17ee29b87e737dc16 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 16:07:43 +0700 Subject: [PATCH 47/90] tidy up --- frame/nomination-pools/src/lib.rs | 50 ++--------------------------- frame/nomination-pools/src/tests.rs | 38 ++++++++++++++-------- 2 files changed, 27 insertions(+), 61 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 89c6e76f3d20a..a0ab44be25785 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -476,7 +476,6 @@ impl PoolMember { fn pending_rewards( &self, current_reward_counter: T::RewardCounter, - commission: Perbill, ) -> Result, Error> { // accuracy note: Reward counters are `FixedU128` with base of 10^18. This value is being // multiplied by a point. The worse case of a point is 10x the granularity of the balance @@ -495,8 +494,6 @@ impl PoolMember { // point is equal to balance (normally), and rewards are usually a proportion of the points // in the pool, the likelihood of rc reaching near u128::MAX is near impossible. - println!("current reward counter pending rewards: {:?}", current_reward_counter); - (current_reward_counter.defensive_saturating_sub(self.last_recorded_reward_counter)) .checked_mul_int(self.active_points()) .ok_or(Error::::OverflowRisk) @@ -1256,26 +1253,15 @@ impl RewardPool { let (current_reward_counter, new_pending_commission) = self.current_reward_counter(id, bonded_points, commission)?; - println!("rc in update_records: {:?}", current_reward_counter); self.last_recorded_reward_counter = current_reward_counter; self.total_commission_pending = self.total_commission_pending.saturating_add(new_pending_commission); - println!( - "updating LRTP: {:?} + {:?} + {:?}", - balance, self.total_rewards_claimed, self.total_commission_claimed - ); - self.last_recorded_total_payouts = balance .checked_add(&self.total_rewards_claimed.saturating_add(self.total_commission_claimed)) .ok_or(Error::::OverflowRisk)?; - println!("rc end of update_records: {:?}", current_reward_counter); - println!("last recorded total payouts: {:?}", self.last_recorded_total_payouts); - - println!("RP id {:?}: {:?}", id, self); - Ok(()) } @@ -1293,18 +1279,9 @@ impl RewardPool { .saturating_add(self.total_commission_claimed) .saturating_sub(self.last_recorded_total_payouts); - println!( - "{:?} + {:?} + {:?} - {:?}", - balance, - self.total_rewards_claimed, - self.total_commission_claimed, - self.last_recorded_total_payouts - ); - // Split the `payouts_since_last_record` into regular rewards and commission according to // the current commission rate. let new_pending_commission = commission * payouts_since_last_record; - println!("new pending commission: {:?}", new_pending_commission); let payouts_deducting_commission = payouts_since_last_record.saturating_sub(new_pending_commission); @@ -2535,7 +2512,6 @@ pub mod pallet { bonded_pool.points, bonded_pool.commission.current(), )?; - println!("reward pool: {:?}", reward_pool); RewardPools::insert(pool_id, reward_pool); bonded_pool.commission.try_update_current(&new_commission)?; @@ -2544,7 +2520,6 @@ pub mod pallet { pool_id, current: new_commission, }); - println!("end call"); Ok(()) } @@ -2793,21 +2768,13 @@ impl Pallet { // a member who has no skin in the game anymore cannot claim any rewards. ensure!(!member.active_points().is_zero(), Error::::FullyUnbonding); - println!( - "rc with {:?}, {:?} and {:?}", - bonded_pool.id, - bonded_pool.points, - bonded_pool.commission.current() - ); let (current_reward_counter, _) = reward_pool.current_reward_counter( bonded_pool.id, bonded_pool.points, bonded_pool.commission.current(), )?; - println!("current reward counter before pending rewards: {:?}", current_reward_counter); - let pending_rewards = - member.pending_rewards(current_reward_counter, bonded_pool.commission.current())?; + let pending_rewards = member.pending_rewards(current_reward_counter)?; if pending_rewards.is_zero() { return Ok(pending_rewards) } @@ -3097,16 +3064,10 @@ impl Pallet { let reward_pool = RewardPools::::get(d.pool_id).unwrap(); if !bonded_pool.points.is_zero() { let commission = bonded_pool.commission.current(); - - println!( - "do try state: {:?} + {:?} + {:?}", - d.pool_id, bonded_pool.points, commission - ); - println!("{:?}", reward_pool); let (current_rc, _) = reward_pool .current_reward_counter(d.pool_id, bonded_pool.points, commission) .unwrap(); - let pending_rewards = d.pending_rewards(current_rc, commission).unwrap(); + let pending_rewards = d.pending_rewards(current_rc).unwrap(); *pools_members_pending_rewards.entry(d.pool_id).or_default() += pending_rewards; } // else this pool has been heavily slashed and cannot have any rewards anymore. }); @@ -3197,15 +3158,10 @@ impl Pallet { .zip(BondedPools::::get(pool_member.pool_id)) { let commission = bonded_pool.commission.current(); - println!( - "rc with {:?}, {:?} and {:?}", - pool_member.pool_id, bonded_pool.points, commission - ); let (current_reward_counter, _) = reward_pool .current_reward_counter(pool_member.pool_id, bonded_pool.points, commission) .ok()?; - println!("rc in api_pending_rewards: {:?}", current_reward_counter); - return pool_member.pending_rewards(current_reward_counter, commission).ok() + return pool_member.pending_rewards(current_reward_counter).ok() } } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 94049e713b1bf..e6b011884e49a 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5054,7 +5054,7 @@ mod reward_counter_precision { let bonded_pool = BondedPools::::get(member.pool_id).unwrap(); assert_eq!(member.pool_id, 1); let rc = default_pool_reward_counter(); - member.pending_rewards(rc, bonded_pool.commission.current()).ok() + member.pending_rewards(rc).ok() } #[test] @@ -5431,7 +5431,7 @@ mod commission { .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())); assert_eq!(current, Perbill::from_percent(25)); - // Pool earns 40 points, payout is triggered. + // Pool earns 80 points, payout is triggered. assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 80)); assert_eq!( PoolMembers::::get(10).unwrap(), @@ -5486,7 +5486,13 @@ mod commission { vec![Event::PoolCommissionUpdated { pool_id, current: None },] ); + println!("{:?}", Balances::free_balance(&default_reward_account())); + println!("REWARD POOL CHECK: {:?}", RewardPools::::get(pool_id).unwrap()); + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); + + println!("REWARD POOL CHECK: {:?}", RewardPools::::get(pool_id).unwrap()); + assert_eq!( pool_events_since_last_call(), vec![Event::PaidOut { member: 10, pool_id, payout: 100 },] @@ -5611,7 +5617,11 @@ mod commission { Some((Perbill::from_percent(20), 900)), )); println!("PENDING REWARDS"); - println!("reward pool {:?}: {:?}", pool_id, RewardPools::::get(pool_id).unwrap()); + println!( + "reward pool {:?}: {:?}", + pool_id, + RewardPools::::get(pool_id).unwrap() + ); let (current_reward_counter, _) = RewardPools::::get(pool_id) .unwrap() @@ -5622,21 +5632,21 @@ mod commission { ) .unwrap(); - assert_eq!( - RewardPools::::get(pool_id).unwrap(), - RewardPool { - last_recorded_reward_counter: FixedU128::from_float(3.6), - last_recorded_total_payouts: 40, - total_rewards_claimed: 36, - total_commission_pending: 4, - total_commission_claimed: 0 - } - ); + assert_eq!( + RewardPools::::get(pool_id).unwrap(), + RewardPool { + last_recorded_reward_counter: FixedU128::from_float(3.6), + last_recorded_total_payouts: 40, + total_rewards_claimed: 36, + total_commission_pending: 4, + total_commission_claimed: 0 + } + ); assert_eq!( PoolMembers::::get(10) .unwrap() - .pending_rewards(current_reward_counter, Perbill::from_percent(20)) + .pending_rewards(current_reward_counter) .unwrap(), 0 ); From 61e3d75d22ba54d7f23d338f446b4e633b728d7b Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 16:31:09 +0700 Subject: [PATCH 48/90] tests work + tidy up --- frame/nomination-pools/src/tests.rs | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index e6b011884e49a..fe4325d02f680 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5475,24 +5475,19 @@ mod commission { },] ); - // Pool earns 100 points, payout is triggered. - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); - + // remove the commission for pool 1. assert_ok!(Pools::set_commission(RuntimeOrigin::signed(900), pool_id, None)); - + assert_eq!( pool_events_since_last_call(), vec![Event::PoolCommissionUpdated { pool_id, current: None },] ); - - println!("{:?}", Balances::free_balance(&default_reward_account())); - println!("REWARD POOL CHECK: {:?}", RewardPools::::get(pool_id).unwrap()); - + + // Pool earns 100 points, payout is triggered. + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); - println!("REWARD POOL CHECK: {:?}", RewardPools::::get(pool_id).unwrap()); - assert_eq!( pool_events_since_last_call(), vec![Event::PaidOut { member: 10, pool_id, payout: 100 },] @@ -5590,7 +5585,6 @@ mod commission { fn commission_reward_counter_works_one_member() { ExtBuilder::default().build_and_execute(|| { let pool_id = 1; - println!("SET COMMISSION 1"); assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), 1, @@ -5604,24 +5598,16 @@ mod commission { PoolMembers::::get(10).unwrap(), PoolMember:: { pool_id, points: 10, ..Default::default() } ); - println!("CLAIM PAYOUT 1"); assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); //10% balance (commission) should still be in the pool. assert_eq!(RewardPool::::current_balance(pool_id), 4); - println!("SET COMMISSION 2"); assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), 1, Some((Perbill::from_percent(20), 900)), )); - println!("PENDING REWARDS"); - println!( - "reward pool {:?}: {:?}", - pool_id, - RewardPools::::get(pool_id).unwrap() - ); let (current_reward_counter, _) = RewardPools::::get(pool_id) .unwrap() From 501f65fd9b9fc03991b338b1dffb2b36890c5b89 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 16:31:54 +0700 Subject: [PATCH 49/90] rm unused --- frame/nomination-pools/src/tests.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index fe4325d02f680..1a40d0be59791 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5051,7 +5051,6 @@ mod reward_counter_precision { fn pending_rewards(of: AccountId) -> Option> { let member = PoolMembers::::get(of).unwrap(); - let bonded_pool = BondedPools::::get(member.pool_id).unwrap(); assert_eq!(member.pool_id, 1); let rc = default_pool_reward_counter(); member.pending_rewards(rc).ok() @@ -5475,15 +5474,14 @@ mod commission { },] ); - // remove the commission for pool 1. assert_ok!(Pools::set_commission(RuntimeOrigin::signed(900), pool_id, None)); - + assert_eq!( pool_events_since_last_call(), vec![Event::PoolCommissionUpdated { pool_id, current: None },] ); - + // Pool earns 100 points, payout is triggered. assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); From 87e3f50005f1dcf05241b5a5e99371a172e63178 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 16:36:45 +0700 Subject: [PATCH 50/90] clippy fix --- frame/nomination-pools/src/lib.rs | 55 ++++++++---------- frame/nomination-pools/src/migration.rs | 8 +-- frame/nomination-pools/src/mock.rs | 8 +-- frame/nomination-pools/src/tests.rs | 76 ++++++++++++------------- 4 files changed, 71 insertions(+), 76 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index a0ab44be25785..c73a59d4d351a 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -347,7 +347,7 @@ use sp_staking::{EraIndex, OnStakerSlash, StakingInterface}; use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, ops::Div, vec::Vec}; /// The log target of this pallet. -pub const LOG_TARGET: &'static str = "runtime::nomination-pools"; +pub const LOG_TARGET: &str = "runtime::nomination-pools"; // syntactic sugar for logging. #[macro_export] @@ -690,12 +690,12 @@ impl Commission { |f| { // if `min_delay` is zero (no delay), not throttling. if t.min_delay == Zero::zero() { - return false + false } else { // throttling if blocks passed is less than `min_delay`. let blocks_surpassed = >::block_number().saturating_sub(f); - return blocks_surpassed < t.min_delay + blocks_surpassed < t.min_delay } }, ) @@ -721,7 +721,7 @@ impl Commission { self.current = match current { None => None, Some((commission, payee)) => { - ensure!(!self.throttling(&commission), Error::::CommissionChangeThrottled); + ensure!(!self.throttling(commission), Error::::CommissionChangeThrottled); ensure!( self.max.map_or(true, |m| commission <= &m), Error::::CommissionExceedsMaximum @@ -733,7 +733,7 @@ impl Commission { } }, }; - let _ = self.register_update(); + self.register_update(); Ok(()) } @@ -1165,7 +1165,7 @@ impl BondedPool { // Cache the value let bonded_account = self.bonded_account(); T::Currency::transfer( - &who, + who, &bonded_account, amount, match ty { @@ -1849,7 +1849,7 @@ pub mod pallet { let mut reward_pool = RewardPools::::get(pool_id) .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; // IMPORTANT: reward pool records must be updated with the old points. - let _ = reward_pool.update_records( + reward_pool.update_records( pool_id, bonded_pool.points, bonded_pool.commission.current(), @@ -1966,7 +1966,7 @@ pub mod pallet { // Claim the the payout prior to unbonding. Once the user is unbonding their points no // longer exist in the bonded pool and thus they can no longer claim their payouts. It // is not strictly necessary to claim the rewards, but we do it here for UX. - let _ = reward_pool.update_records( + reward_pool.update_records( bonded_pool.id, bonded_pool.points, bonded_pool.commission.current(), @@ -2017,7 +2017,7 @@ pub mod pallet { }); // Now that we know everything has worked write the items to storage. - SubPoolsStorage::insert(&member.pool_id, sub_pools); + SubPoolsStorage::insert(member.pool_id, sub_pools); Self::put_member_with_pools(&member_account, member, bonded_pool, reward_pool); Ok(()) } @@ -2106,10 +2106,10 @@ pub mod pallet { .iter() .fold(BalanceOf::::zero(), |accumulator, (era, unlocked_points)| { sum_unlocked_points = sum_unlocked_points.saturating_add(*unlocked_points); - if let Some(era_pool) = sub_pools.with_era.get_mut(&era) { + if let Some(era_pool) = sub_pools.with_era.get_mut(era) { let balance_to_unbond = era_pool.dissolve(*unlocked_points); if era_pool.points.is_zero() { - sub_pools.with_era.remove(&era); + sub_pools.with_era.remove(era); } accumulator.saturating_add(balance_to_unbond) } else { @@ -2158,12 +2158,12 @@ pub mod pallet { None } else { bonded_pool.dec_members().put(); - SubPoolsStorage::::insert(&member.pool_id, sub_pools); + SubPoolsStorage::::insert(member.pool_id, sub_pools); Some(T::WeightInfo::withdraw_unbonded_update(num_slashing_spans)) } } else { // we certainly don't need to delete any pools, because no one is being removed. - SubPoolsStorage::::insert(&member.pool_id, sub_pools); + SubPoolsStorage::::insert(member.pool_id, sub_pools); PoolMembers::::insert(&member_account, member); Some(T::WeightInfo::withdraw_unbonded_update(num_slashing_spans)) }; @@ -2685,7 +2685,7 @@ impl Pallet { fn get_member_with_pools( who: &T::AccountId, ) -> Result<(PoolMember, BondedPool, RewardPool), Error> { - let member = PoolMembers::::get(&who).ok_or(Error::::PoolMemberNotFound)?; + let member = PoolMembers::::get(who).ok_or(Error::::PoolMemberNotFound)?; let bonded_pool = BondedPool::::get(member.pool_id).defensive_ok_or(DefensiveError::PoolNotFound)?; let reward_pool = @@ -2713,8 +2713,8 @@ impl Pallet { current_points: BalanceOf, new_funds: BalanceOf, ) -> BalanceOf { - let u256 = |x| T::BalanceToU256::convert(x); - let balance = |x| T::U256ToBalance::convert(x); + let u256 = T::BalanceToU256::convert; + let balance = T::U256ToBalance::convert; match (current_balance.is_zero(), current_points.is_zero()) { (_, true) => new_funds.saturating_mul(POINTS_TO_BALANCE_INIT_RATIO.into()), (true, false) => { @@ -2741,8 +2741,8 @@ impl Pallet { current_points: BalanceOf, points: BalanceOf, ) -> BalanceOf { - let u256 = |x| T::BalanceToU256::convert(x); - let balance = |x| T::U256ToBalance::convert(x); + let u256 = T::BalanceToU256::convert; + let balance = T::U256ToBalance::convert; if current_balance.is_zero() || current_points.is_zero() || points.is_zero() { // There is nothing to unbond return Zero::zero() @@ -2790,7 +2790,7 @@ impl Pallet { if pending_rewards > Zero::zero() { T::Currency::transfer( &bonded_pool.reward_account(), - &member_account, + member_account, pending_rewards, // defensive: the depositor has put existential deposit into the pool and it stays // untouched, reward account shall not die. @@ -2896,7 +2896,7 @@ impl Pallet { // payout related stuff: we must claim the payouts, and updated recorded payout data // before updating the bonded pool points, similar to that of `join` transaction. - let _ = reward_pool.update_records( + reward_pool.update_records( bonded_pool.id, bonded_pool.points, bonded_pool.commission.current(), @@ -2935,7 +2935,7 @@ impl Pallet { // IMPORTANT: make sure that any newly pending commission not yet processed is added to // `total_commission_pending`. - let _ = reward_pool.update_records( + reward_pool.update_records( pool_id, bonded_pool.points, bonded_pool.commission.current(), @@ -3057,7 +3057,7 @@ impl Pallet { let mut all_members = 0u32; PoolMembers::::iter().for_each(|(_, d)| { let bonded_pool = BondedPools::::get(d.pool_id).unwrap(); - assert!(!d.total_points().is_zero(), "no member should have zero points: {:?}", d); + assert!(!d.total_points().is_zero(), "no member should have zero points: {d:?}"); *pools_members.entry(d.pool_id).or_default() += 1; all_members += 1; @@ -3084,14 +3084,14 @@ impl Pallet { ); assert!( RewardPool::::current_balance(id) >= - pools_members_pending_rewards.get(&id).map(|x| *x).unwrap_or_default() + pools_members_pending_rewards.get(&id).copied().unwrap_or_default() ) }); BondedPools::::iter().for_each(|(id, inner)| { let bonded_pool = BondedPool { id, inner }; assert_eq!( - pools_members.get(&id).map(|x| *x).unwrap_or_default(), + pools_members.get(&id).copied().unwrap_or_default(), bonded_pool.member_counter ); assert!(MaxPoolMembersPerPool::::get() @@ -3121,12 +3121,7 @@ impl Pallet { assert!( total_balance >= bonded_balance + sum_unbonding_balance, - "faulty pool: {:?} / {:?}, total_balance {:?} >= bonded_balance {:?} + sum_unbonding_balance {:?}", - pool_id, - _pool, - total_balance, - bonded_balance, - sum_unbonding_balance + "faulty pool: {pool_id:?} / {_pool:?}, total_balance {total_balance:?} >= bonded_balance {bonded_balance:?} + sum_unbonding_balance {sum_unbonding_balance:?}" ); } diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 6221f5681941c..636e5aec74352 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -238,7 +238,7 @@ pub mod v2 { let mut sum_paid_out = BalanceOf::::zero(); members - .into_iter() + .iter() .filter_map(|(who, points)| { let bonded_pool = match BondedPool::::get(id) { Some(x) => x, @@ -271,7 +271,7 @@ pub mod v2 { .for_each(|(who, last_claim)| { let outcome = T::Currency::transfer( &reward_account, - &who, + who, last_claim, ExistenceRequirement::KeepAlive, ); @@ -414,13 +414,13 @@ pub mod v3 { Metadata::::iter_keys() .filter(|id| { metadata_iterated += 1; - !BondedPools::::contains_key(&id) + !BondedPools::::contains_key(id) }) .collect::>() .into_iter() .for_each(|id| { metadata_removed += 1; - Metadata::::remove(&id); + Metadata::::remove(id); }); current.put::>(); // metadata iterated + bonded pools read + a storage version read diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index e779cae67814c..3d587745c8102 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -118,8 +118,8 @@ impl sp_staking::StakingInterface for StakingMock { fn stake(who: &Self::AccountId) -> Result, DispatchError> { match ( - UnbondingBalanceMap::get().get(who).map(|v| *v), - BondedBalanceMap::get().get(who).map(|v| *v), + UnbondingBalanceMap::get().get(who).copied(), + BondedBalanceMap::get().get(who).copied(), ) { (None, None) => Err(DispatchError::Other("balance not found")), (Some(v), None) => Ok(Stake { total: v, active: 0, stash: *who }), @@ -344,7 +344,7 @@ impl ExtBuilder { ext } - pub fn build_and_execute(self, test: impl FnOnce() -> ()) { + pub fn build_and_execute(self, test: impl FnOnce()) { self.build().execute_with(|| { test(); Pools::do_try_state(CheckLevel::get()).unwrap(); @@ -409,7 +409,7 @@ pub fn balances_events_since_last_call() -> Vec> /// Same as `fully_unbond`, in permissioned setting. pub fn fully_unbond_permissioned(member: AccountId) -> DispatchResult { - let points = PoolMembers::::get(&member) + let points = PoolMembers::::get(member) .map(|d| d.active_points()) .unwrap_or_default(); Pools::unbond(RuntimeOrigin::signed(member), member, points) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 1a40d0be59791..4386f0ddd610e 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -264,7 +264,7 @@ mod bonded_pool { // Simulate a slashed pool at `MaxPointsToBalance` + 1 slashed pool StakingMock::set_bonded_balance( pool.bonded_account(), - max_points_to_balance.saturating_add(1).into(), + max_points_to_balance.saturating_add(1), ); assert_ok!(pool.ok_to_join()); @@ -486,7 +486,7 @@ mod join { ExtBuilder::default().with_check(0).build_and_execute(|| { // Given Balances::make_free_balance_be(&11, ExistentialDeposit::get() + 2); - assert!(!PoolMembers::::contains_key(&11)); + assert!(!PoolMembers::::contains_key(11)); // When assert_ok!(Pools::join(RuntimeOrigin::signed(11), 2, 1)); @@ -503,7 +503,7 @@ mod join { ); assert_eq!( - PoolMembers::::get(&11).unwrap(), + PoolMembers::::get(11).unwrap(), PoolMember:: { pool_id: 1, points: 2, ..Default::default() } ); assert_eq!(BondedPool::::get(1).unwrap(), bonded(12, 2)); @@ -514,7 +514,7 @@ mod join { // And Balances::make_free_balance_be(&12, ExistentialDeposit::get() + 12); - assert!(!PoolMembers::::contains_key(&12)); + assert!(!PoolMembers::::contains_key(12)); // When assert_ok!(Pools::join(RuntimeOrigin::signed(12), 12, 1)); @@ -526,7 +526,7 @@ mod join { ); assert_eq!( - PoolMembers::::get(&12).unwrap(), + PoolMembers::::get(12).unwrap(), PoolMember:: { pool_id: 1, points: 24, ..Default::default() } ); assert_eq!(BondedPool::::get(1).unwrap(), bonded(12 + 24, 3)); @@ -537,7 +537,7 @@ mod join { fn join_errors_correctly() { ExtBuilder::default().with_check(0).build_and_execute(|| { // 10 is already part of the default pool created. - assert_eq!(PoolMembers::::get(&10).unwrap().pool_id, 1); + assert_eq!(PoolMembers::::get(10).unwrap().pool_id, 1); assert_noop!( Pools::join(RuntimeOrigin::signed(10), 420, 123), @@ -765,7 +765,7 @@ mod claim_payout { assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 1)); // pool's 'last_recorded_reward_counter' and 'last_recorded_total_payouts' don't // really change unless if someone bonds/unbonds. - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 10)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 10)); assert_eq!(Balances::free_balance(&10), 10); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 90); @@ -778,7 +778,7 @@ mod claim_payout { vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] ); assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 1)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 50)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 50)); assert_eq!(Balances::free_balance(&40), 40); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 50); @@ -791,9 +791,9 @@ mod claim_payout { vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] ); assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 1)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 100)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 100)); assert_eq!(Balances::free_balance(&50), 50); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); + assert_eq!(Balances::free_balance(&default_reward_account()), ed); // Given the reward pool has some new rewards assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); @@ -807,7 +807,7 @@ mod claim_payout { vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] ); assert_eq!(PoolMembers::::get(10).unwrap(), del_float(10, 1.5)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 105)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 105)); assert_eq!(Balances::free_balance(&10), 10 + 5); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 45); @@ -820,7 +820,7 @@ mod claim_payout { vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] ); assert_eq!(PoolMembers::::get(40).unwrap(), del_float(40, 1.5)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 125)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 125)); assert_eq!(Balances::free_balance(&40), 40 + 20); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); @@ -837,7 +837,7 @@ mod claim_payout { vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] ); assert_eq!(PoolMembers::::get(50).unwrap(), del_float(50, 2.0)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 175)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 175)); assert_eq!(Balances::free_balance(&50), 50 + 50); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); @@ -850,7 +850,7 @@ mod claim_payout { vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] ); assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 2)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 180)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 180)); assert_eq!(Balances::free_balance(&10), 15 + 5); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); @@ -869,7 +869,7 @@ mod claim_payout { // We expect a payout of 40 assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 6)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 220)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 220)); assert_eq!(Balances::free_balance(&10), 20 + 40); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380); @@ -886,7 +886,7 @@ mod claim_payout { vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] ); assert_eq!(PoolMembers::::get(10).unwrap(), del_float(10, 6.2)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 222)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 222)); assert_eq!(Balances::free_balance(&10), 60 + 2); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 398); @@ -899,7 +899,7 @@ mod claim_payout { vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] ); assert_eq!(PoolMembers::::get(40).unwrap(), del_float(40, 6.2)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 410)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 410)); assert_eq!(Balances::free_balance(&40), 60 + 188); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 210); @@ -912,9 +912,9 @@ mod claim_payout { vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] ); assert_eq!(PoolMembers::::get(50).unwrap(), del_float(50, 6.2)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 620)); + assert_eq!(RewardPools::::get(1).unwrap(), rew(0, 0, 620)); assert_eq!(Balances::free_balance(&50), 100 + 210); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); + assert_eq!(Balances::free_balance(&default_reward_account()), ed); }); } @@ -1048,7 +1048,7 @@ mod claim_payout { assert_eq!(member, del(1.5)); // Given the pool has earned no new rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 0); + Balances::make_free_balance_be(&default_reward_account(), ed); // When let payout = @@ -2493,7 +2493,7 @@ mod unbond { assert_eq!( SubPoolsStorage::::get(1).unwrap().with_era, - unbonding_pools_with_era! { 0 + 3 => UnbondPool:: { points: 10, balance: 10 }} + unbonding_pools_with_era! { 3 => UnbondPool:: { points: 10, balance: 10 }} ); assert_eq!( @@ -2531,7 +2531,7 @@ mod unbond { // Then assert_eq!( SubPoolsStorage::::get(1).unwrap().with_era, - unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 6, balance: 6 }} + unbonding_pools_with_era! { 3 => UnbondPool { points: 6, balance: 6 }} ); assert_eq!( BondedPool::::get(1).unwrap(), @@ -2561,7 +2561,7 @@ mod unbond { assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 94); assert_eq!( PoolMembers::::get(40).unwrap().unbonding_eras, - member_unbonding_eras!(0 + 3 => 6) + member_unbonding_eras!(3 => 6) ); assert_eq!(Balances::free_balance(&40), 40 + 40); // We claim rewards when unbonding @@ -2571,8 +2571,8 @@ mod unbond { // Then assert_eq!( - SubPoolsStorage::::get(&1).unwrap().with_era, - unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 98, balance: 98 }} + SubPoolsStorage::::get(1).unwrap().with_era, + unbonding_pools_with_era! { 3 => UnbondPool { points: 98, balance: 98 }} ); assert_eq!( BondedPool::::get(1).unwrap(), @@ -2590,7 +2590,7 @@ mod unbond { assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 2); assert_eq!( PoolMembers::::get(550).unwrap().unbonding_eras, - member_unbonding_eras!(0 + 3 => 92) + member_unbonding_eras!(3 => 92) ); assert_eq!(Balances::free_balance(&550), 550 + 550); assert_eq!( @@ -2658,7 +2658,7 @@ mod unbond { SubPools { no_era: Default::default(), with_era: unbonding_pools_with_era! { - 0 + 3 => UnbondPool { balance: 10, points: 100 }, + 3 => UnbondPool { balance: 10, points: 100 }, 1 + 3 => UnbondPool { balance: 20, points: 20 }, 2 + 3 => UnbondPool { balance: 101, points: 101} }, @@ -2766,7 +2766,7 @@ mod unbond { SubPools { no_era: Default::default(), with_era: unbonding_pools_with_era! { - 0 + 3 => UnbondPool { points: 100 + 200, balance: 100 + 200 } + 3 => UnbondPool { points: 100 + 200, balance: 100 + 200 } }, } ); @@ -3423,7 +3423,7 @@ mod withdraw_unbonded { assert_ok!(fully_unbond_permissioned(550)); assert_eq!( - SubPoolsStorage::::get(&1).unwrap().with_era, + SubPoolsStorage::::get(1).unwrap().with_era, unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2 + 40 / 2, balance: 550 / 2 + 40 / 2 }} ); @@ -3473,7 +3473,7 @@ mod withdraw_unbonded { ); assert_eq!( - SubPoolsStorage::::get(&1).unwrap().with_era, + SubPoolsStorage::::get(1).unwrap().with_era, unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2, balance: 550 / 2 }} ); @@ -3492,7 +3492,7 @@ mod withdraw_unbonded { Event::MemberRemoved { pool_id: 1, member: 550 } ] ); - assert!(SubPoolsStorage::::get(&1).unwrap().with_era.is_empty()); + assert!(SubPoolsStorage::::get(1).unwrap().with_era.is_empty()); // now, finally, the depositor can take out its share. unsafe_set_state(1, PoolState::Destroying); @@ -3500,7 +3500,7 @@ mod withdraw_unbonded { // because everyone else has left, the points assert_eq!( - SubPoolsStorage::::get(&1).unwrap().with_era, + SubPoolsStorage::::get(1).unwrap().with_era, unbonding_pools_with_era! { 6 => UnbondPool { points: 5, balance: 5 }} ); @@ -3554,10 +3554,10 @@ mod withdraw_unbonded { assert_eq!( SubPoolsStorage::::get(1).unwrap().with_era, //------------------------------balance decrease is not account for - unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 10 } } + unbonding_pools_with_era! { 3 => UnbondPool { points: 10, balance: 10 } } ); - CurrentEra::set(0 + 3); + CurrentEra::set(3); // When assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(10), 10, 0)); @@ -3574,7 +3574,7 @@ mod withdraw_unbonded { // Insert the sub-pool let sub_pools = SubPools { no_era: Default::default(), - with_era: unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 10 }}, + with_era: unbonding_pools_with_era! { 3 => UnbondPool { points: 10, balance: 10 }}, }; SubPoolsStorage::::insert(1, sub_pools.clone()); @@ -3587,7 +3587,7 @@ mod withdraw_unbonded { PoolMembers::::insert(11, member.clone()); // Simulate calling `unbond` - member.unbonding_eras = member_unbonding_eras!(3 + 0 => 10); + member.unbonding_eras = member_unbonding_eras!(3 => 10); PoolMembers::::insert(11, member.clone()); // We are still in the bonding duration @@ -3597,7 +3597,7 @@ mod withdraw_unbonded { ); // If we error the member does not get removed - assert_eq!(PoolMembers::::get(&11), Some(member)); + assert_eq!(PoolMembers::::get(11), Some(member)); // and the sub pools do not get updated. assert_eq!(SubPoolsStorage::::get(1).unwrap(), sub_pools) }); @@ -4440,7 +4440,7 @@ fn set_claimable_actor_works() { ExtBuilder::default().build_and_execute(|| { // Given Balances::make_free_balance_be(&11, ExistentialDeposit::get() + 2); - assert!(!PoolMembers::::contains_key(&11)); + assert!(!PoolMembers::::contains_key(11)); // When assert_ok!(Pools::join(RuntimeOrigin::signed(11), 2, 1)); From 0f560f0548c5fe123a3ee5e39ebf6e79e984ba7d Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 19:28:33 +0700 Subject: [PATCH 51/90] persist reward_pool update --- frame/nomination-pools/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index c73a59d4d351a..dc96856973480 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2963,11 +2963,12 @@ impl Pallet { .saturating_add(reward_pool.total_commission_pending); reward_pool.total_commission_pending = Zero::zero(); + RewardPools::::insert(pool_id, reward_pool); + Self::deposit_event(Event::::PoolCommissionClaimed { pool_id, commission: Zero::zero(), }); - Ok(()) } From 990d38d9996c8935a40f4c229b468e477e3fb532 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 19:47:01 +0700 Subject: [PATCH 52/90] claim_commission_works tests --- frame/nomination-pools/src/tests.rs | 91 ++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 16 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 4386f0ddd610e..d5677f87a55b2 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5445,18 +5445,6 @@ mod commission { assert_eq!(RewardPool::::current_balance(pool_id), 20); - // uncomment to check reward_pool state - assert_eq!( - RewardPools::::get(pool_id).unwrap(), - RewardPool { - last_recorded_reward_counter: Zero::zero(), - last_recorded_total_payouts: 0, - total_rewards_claimed: 60, - total_commission_pending: 0, - total_commission_claimed: 0 - } - ); - // update payee only. assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), @@ -5466,12 +5454,18 @@ mod commission { assert_eq!(RewardPool::::current_balance(pool_id), 20); + // Pending commission is claimed. + assert_ok!(Pools::claim_commission(RuntimeOrigin::signed(900), pool_id)); + assert_eq!( pool_events_since_last_call(), - vec![Event::PoolCommissionUpdated { - pool_id, - current: Some((Perbill::from_percent(25), 901)) - },] + vec![ + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(25), 901)) + }, + Event::PoolCommissionClaimed { pool_id: 1, commission: 0 } + ] ); // remove the commission for pool 1. @@ -6462,4 +6456,69 @@ mod commission { ); }) } + + #[test] + fn claim_commission_works() { + ExtBuilder::default().build_and_execute(|| { + let pool_id = 1; + + let _ = Balances::deposit_creating(&900, 5); + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + pool_id, + Some((Perbill::from_percent(50), 900)) + )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id }, + Event::Bonded { member: 10, pool_id, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id, + current: Some((Perbill::from_percent(50), 900)) + }, + ] + ); + + // Pool earns 80 points, payout is triggered. + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 80)); + assert_eq!( + PoolMembers::::get(10).unwrap(), + PoolMember:: { pool_id, points: 10, ..Default::default() } + ); + + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id, payout: 40 }] + ); + + // Given: + assert_eq!(RewardPool::::current_balance(pool_id), 40); + + // Pool does not exist + assert_noop!( + Pools::claim_commission(RuntimeOrigin::signed(900), 9999,), + Error::::PoolNotFound + ); + + // Does not have permission. + assert_noop!( + Pools::claim_commission(RuntimeOrigin::signed(10), pool_id,), + Error::::DoesNotHavePermission + ); + + // When: + assert_ok!(Pools::claim_commission(RuntimeOrigin::signed(900), pool_id)); + + // Then: + assert_eq!(RewardPool::::current_balance(pool_id), 0); + + // No more pending commission. + assert_noop!( + Pools::claim_commission(RuntimeOrigin::signed(900), pool_id,), + Error::::NoPendingCommission + ); + }) + } } From f4395ea1608a3a2314a6d01c13be84c93a1b5bba Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 20:26:38 +0700 Subject: [PATCH 53/90] . --- frame/nomination-pools/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index d5677f87a55b2..975f11883ffe0 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5454,7 +5454,7 @@ mod commission { assert_eq!(RewardPool::::current_balance(pool_id), 20); - // Pending commission is claimed. + // Pending commission is claimed assert_ok!(Pools::claim_commission(RuntimeOrigin::signed(900), pool_id)); assert_eq!( From 08429963aedc5886ab63bd2716ce6ba5dbc16411 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 25 Feb 2023 23:00:45 +0700 Subject: [PATCH 54/90] some test formatting --- frame/nomination-pools/src/tests.rs | 370 +++++++++++++++++----------- 1 file changed, 222 insertions(+), 148 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 975f11883ffe0..f883e7e50349c 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5376,16 +5376,18 @@ mod commission { fn set_commission_works() { ExtBuilder::default().build_and_execute(|| { let pool_id = 1; + let root = 900; - // top up commission payee account to existential deposit - let _ = Balances::deposit_creating(&900, 5); + // Commission can be set by the `root` role. - // Set a commission for pool 1. + // When: assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), + RuntimeOrigin::signed(root), pool_id, - Some((Perbill::from_percent(50), 900)) + Some((Perbill::from_percent(50), root)) )); + + // Then: assert_eq!( pool_events_since_last_call(), vec![ @@ -5393,166 +5395,199 @@ mod commission { Event::Bonded { member: 10, pool_id, bonded: 10, joined: true }, Event::PoolCommissionUpdated { pool_id, - current: Some((Perbill::from_percent(50), 900)) + current: Some((Perbill::from_percent(50), root)) }, ] ); - let commission_as_percent = BondedPool::::get(pool_id) - .unwrap() - .commission - .current - .as_ref() - .map(|(x, _)| *x) - .unwrap_or(Perbill::zero()); - assert_eq!(commission_as_percent, Perbill::from_percent(50)); - - // update commission only. + // Commission can be updated only, while keeping the same payee. + + // When: assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), + RuntimeOrigin::signed(root), 1, - Some((Perbill::from_percent(25), 900)) + Some((Perbill::from_percent(25), root)) )); + + // Then: assert_eq!( pool_events_since_last_call(), vec![Event::PoolCommissionUpdated { pool_id, - current: Some((Perbill::from_percent(25), 900)) + current: Some((Perbill::from_percent(25), root)) },] ); - let current = BondedPools::::get(pool_id) - .unwrap() - .commission - .current - .as_ref() - .map_or(Perbill::zero(), |(c, _)| *c) - .min(GlobalMaxCommission::::get().unwrap_or(Bounded::max_value())); - assert_eq!(current, Perbill::from_percent(25)); + // Payee can be updated only, while keeping the same commission. - // Pool earns 80 points, payout is triggered. + // Given: + let payee = 901; + + // When: + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(root), + pool_id, + Some((Perbill::from_percent(25), payee)) + )); + + // Then: + assert_eq!( + pool_events_since_last_call(), + vec![Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(25), payee)) + },] + ); + + // Pool earns 80 points and a payout is triggered. + + // Given: assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 80)); assert_eq!( PoolMembers::::get(10).unwrap(), PoolMember:: { pool_id, points: 10, ..Default::default() } ); + // When: assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); + + // Then: assert_eq!( pool_events_since_last_call(), vec![Event::PaidOut { member: 10, pool_id, payout: 60 }] ); - assert_eq!(RewardPool::::current_balance(pool_id), 20); - // update payee only. - assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), - pool_id, - Some((Perbill::from_percent(25), 901)) - )); - - assert_eq!(RewardPool::::current_balance(pool_id), 20); + // Pending pool commission can be claimed by the root role. - // Pending commission is claimed - assert_ok!(Pools::claim_commission(RuntimeOrigin::signed(900), pool_id)); + // When: + assert_ok!(Pools::claim_commission(RuntimeOrigin::signed(root), pool_id)); + // Then: + assert_eq!(RewardPool::::current_balance(pool_id), 0); assert_eq!( pool_events_since_last_call(), - vec![ - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(25), 901)) - }, - Event::PoolCommissionClaimed { pool_id: 1, commission: 0 } - ] + vec![Event::PoolCommissionClaimed { pool_id: 1, commission: 0 }] ); - // remove the commission for pool 1. - assert_ok!(Pools::set_commission(RuntimeOrigin::signed(900), pool_id, None)); + // Commission can be removed from the pool completely. + + // When: + assert_ok!(Pools::set_commission(RuntimeOrigin::signed(root), pool_id, None)); + // Then: assert_eq!( pool_events_since_last_call(), vec![Event::PoolCommissionUpdated { pool_id, current: None },] ); - // Pool earns 100 points, payout is triggered. + // Given a pool now has a reward counter history, additional rewards and payouts can be + // made while maintaining a correct ledger of the reward pool. Pool earns 100 points, + // payout is triggered. + // + // Note that the `total_commission_pending` will not be updated until `update_records` + // is next called, which is not done in this test segment.. + + // Given: assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); + + // When: assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); + // Then: assert_eq!( pool_events_since_last_call(), vec![Event::PaidOut { member: 10, pool_id, payout: 100 },] ); + assert_eq!( + RewardPools::::get(pool_id).unwrap(), + RewardPool { + last_recorded_reward_counter: FixedU128::from_float(6.0), + last_recorded_total_payouts: 80, + total_rewards_claimed: 160, + total_commission_pending: 0, + total_commission_claimed: 20 + } + ); - // test whether supplying a 0% commission along with a payee results in a None `current` - // being inserted. + // When set commission is called again, update_records is called and + // total_commission_pending is updated, based on the current reward counter and pool + // balance. // - // set an initial commission of 10% + // Note that commission is now 0%, so it should not come into play with subsequent + // payouts. + + // When: assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), + RuntimeOrigin::signed(root), 1, - Some((Perbill::from_percent(10), 900)) + Some((Perbill::from_percent(10), root)) )); - // set the commission to 0% + + // Then: + assert_eq!( + pool_events_since_last_call(), + vec![Event::PoolCommissionUpdated { + pool_id, + current: Some((Perbill::from_percent(10), root)) + },] + ); + assert_eq!( + RewardPools::::get(pool_id).unwrap(), + RewardPool { + last_recorded_reward_counter: FixedU128::from_float(16.0), + last_recorded_total_payouts: 180, + total_rewards_claimed: 160, + total_commission_pending: 0, + total_commission_claimed: 20 + } + ); + + // Supplying a 0% commission along with a payee results in a `None` current value. + + // When: assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), + RuntimeOrigin::signed(root), pool_id, - Some((Perbill::from_percent(0), 900)) + Some((Perbill::from_percent(0), root)) )); - // commssion current should now be None, and `throttle_from` the current block. + + // Then: assert_eq!( BondedPool::::get(1).unwrap().commission, Commission { current: None, max: None, change_rate: None, throttle_from: Some(1) } ); - // set the commission to 0% - assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), - pool_id, - Some((Perbill::from_percent(0), 900)) - )); - assert_eq!( pool_events_since_last_call(), - vec![ - Event::PoolCommissionUpdated { - pool_id, - current: Some((Perbill::from_percent(10), 900)) - }, - Event::PoolCommissionUpdated { - pool_id, - current: Some((Perbill::from_percent(0), 900)) - }, - Event::PoolCommissionUpdated { - pool_id, - current: Some((Perbill::from_percent(0), 900)) - }, - ] + vec![Event::PoolCommissionUpdated { + pool_id, + current: Some((Perbill::from_percent(0), root)) + },] ); - // test for updating payee only when commission = max commission - // - // set max commission to 10% + // The payee can be updated even when commission has reached maximum commission. Both + // commission and max commission are set to 10% to test this. + + // Given: assert_ok!(Pools::set_commission_max( - RuntimeOrigin::signed(900), + RuntimeOrigin::signed(root), pool_id, Perbill::from_percent(10) )); - - // set commission to 10% assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), + RuntimeOrigin::signed(root), pool_id, - Some((Perbill::from_percent(10), 900)) + Some((Perbill::from_percent(10), root)) )); - // update payee only and keep current commission + // When: assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), + RuntimeOrigin::signed(root), pool_id, - Some((Perbill::from_percent(10), 901)) + Some((Perbill::from_percent(10), payee)) )); + // Then: assert_eq!( pool_events_since_last_call(), vec![ @@ -5562,11 +5597,11 @@ mod commission { }, Event::PoolCommissionUpdated { pool_id, - current: Some((Perbill::from_percent(10), 900)) + current: Some((Perbill::from_percent(10), root)) }, Event::PoolCommissionUpdated { pool_id, - current: Some((Perbill::from_percent(10), 901)) + current: Some((Perbill::from_percent(10), payee)) } ] ); @@ -5577,39 +5612,37 @@ mod commission { fn commission_reward_counter_works_one_member() { ExtBuilder::default().build_and_execute(|| { let pool_id = 1; + let root = 900; + let member = 10; + + // Set the pool commission to 10% to test commission shares. Pool is topped up 40 points + // and `member` immediately claims their pending rewards. Reward pooll should still have + // 10% share. + + // Given: assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), + RuntimeOrigin::signed(root), 1, - Some((Perbill::from_percent(10), 900)), + Some((Perbill::from_percent(10), root)), )); - - // Pool earns 40 points assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 40)); - assert_eq!( - PoolMembers::::get(10).unwrap(), - PoolMember:: { pool_id, points: 10, ..Default::default() } - ); + // When: assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); - //10% balance (commission) should still be in the pool. + // Then: assert_eq!(RewardPool::::current_balance(pool_id), 4); + // Set pool commission to 20% and repeat the same process. + + // When: assert_ok!(Pools::set_commission( - RuntimeOrigin::signed(900), + RuntimeOrigin::signed(root), 1, - Some((Perbill::from_percent(20), 900)), + Some((Perbill::from_percent(20), root)), )); - let (current_reward_counter, _) = RewardPools::::get(pool_id) - .unwrap() - .current_reward_counter( - pool_id, - BondedPools::::get(pool_id).unwrap().points, - Perbill::from_percent(20), - ) - .unwrap(); - + // Then: assert_eq!( RewardPools::::get(pool_id).unwrap(), RewardPool { @@ -5621,20 +5654,58 @@ mod commission { } ); + // The current reward counter should yield the correct pending rewards of zero. + + // Given: + let (current_reward_counter, _) = RewardPools::::get(pool_id) + .unwrap() + .current_reward_counter( + pool_id, + BondedPools::::get(pool_id).unwrap().points, + Perbill::from_percent(20), + ) + .unwrap(); + + // Then: assert_eq!( - PoolMembers::::get(10) + PoolMembers::::get(member) .unwrap() .pending_rewards(current_reward_counter) .unwrap(), 0 ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(10), 900)) + }, + Event::PaidOut { member: 10, pool_id: 1, payout: 36 }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(20), 900)) + } + ] + ); }) } #[test] fn set_commission_handles_errors() { ExtBuilder::default().build_and_execute(|| { - // Provided pool does not exist + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + ] + ); + + // Provided pool does not exist. assert_noop!( Pools::set_commission( RuntimeOrigin::signed(900), @@ -5643,7 +5714,8 @@ mod commission { ), Error::::PoolNotFound ); - // Sender does not have permission to set commission + + // Sender does not have permission to set commission. assert_noop!( Pools::set_commission( RuntimeOrigin::signed(1), @@ -5653,28 +5725,16 @@ mod commission { Error::::DoesNotHavePermission ); - // Set the initial commission to 5%. + // Commission increases will be throttled if outside of change_rate allowance. + // Commission is set to 5%. + // Change rate is set to 1% max increase, 2 block delay. + + // When: assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), 1, Some((Perbill::from_percent(5), 900)), )); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PoolCommissionUpdated { - pool_id: 1, - current: Some((Perbill::from_percent(5), 900)) - }, - ] - ); - - // Change rate test. - // - // Set a change rate to be a +1% commission increase every 2 blocks. assert_ok!(Pools::set_commission_change_rate( RuntimeOrigin::signed(900), 1, @@ -5692,19 +5752,25 @@ mod commission { throttle_from: Some(1_u64), } ); - assert_eq!( pool_events_since_last_call(), - vec![Event::PoolCommissionChangeRateUpdated { - pool_id: 1, - change_rate: CommissionChangeRate { - max_increase: Perbill::from_percent(1), - min_delay: 2 + vec![ + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(5), 900)) + }, + Event::PoolCommissionChangeRateUpdated { + pool_id: 1, + change_rate: CommissionChangeRate { + max_increase: Perbill::from_percent(1), + min_delay: 2 + } } - },] + ] ); // Now try to increase commission to 10% (5% increase). This should be throttled. + // Then: assert_noop!( Pools::set_commission( RuntimeOrigin::signed(900), @@ -5714,11 +5780,12 @@ mod commission { Error::::CommissionChangeThrottled ); - // Run to block 3 run_blocks(2); - // Now try to increase commission by 1% and provide an initial payee. This should - // succeed and set the `throttle_from` field. + // Increase commission by 1% and provide an initial payee. This should succeed and set + // the `throttle_from` field. + + // When: assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), 1, @@ -5744,9 +5811,11 @@ mod commission { },] ); - // Attempt to increase the commission an additional 1% (now 7%). this will fail as + // Attempt to increase the commission an additional 1% (now 7%). This will fail as // `throttle_from` is now the current block. At least 2 blocks need to pass before we // can set commission again. + + // Then: assert_noop!( Pools::set_commission( RuntimeOrigin::signed(900), @@ -5756,10 +5825,11 @@ mod commission { Error::::CommissionChangeThrottled ); - // Run 2 blocks into the future, to block 3. run_blocks(2); // Can now successfully increase the commission again, to 7%. + + // When: assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), 1, @@ -5773,11 +5843,12 @@ mod commission { },] ); - // Run 2 blocks into the future, to block 5. run_blocks(2); // Now surpassed the `min_delay` threshold, but the `max_increase` threshold is // still at play. An attempted commission change now to 8% (+2% increase) should fail. + + // Then: assert_noop!( Pools::set_commission( RuntimeOrigin::signed(900), @@ -5789,6 +5860,8 @@ mod commission { // Now set a max commission to the current 5%. This will also update the current // commission to 5%. + + // When: assert_ok!(Pools::set_commission_max( RuntimeOrigin::signed(900), 1, @@ -5823,9 +5896,10 @@ mod commission { // Run 2 blocks into the future so we are eligible to update commission again. run_blocks(2); - // Now attempt again to increase the commission by 1%, to 6%. This is within the - // change rate allowance, but `max_commission` will now prevent us from going any - // higher. + // Now attempt again to increase the commission by 1%, to 6%. This is within the change + // rate allowance, but `max_commission` will now prevent us from going any higher. + + // Then: assert_noop!( Pools::set_commission( RuntimeOrigin::signed(900), From 2a9d39f9e80341c91c4c30a600ed91af8dced776 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sun, 26 Feb 2023 12:37:53 +0700 Subject: [PATCH 55/90] add high level docs --- frame/nomination-pools/src/lib.rs | 80 ++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index dc96856973480..a3a55b919922a 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -50,6 +50,11 @@ //! not nominating proper validators. //! * reward account: A similar key-less account, that is set as the `Payee` account for the bonded //! account for all staking rewards. +//! * change rate: The rate at which pool commission can be changed. A change rate consists of a +//! `max_increase` and `min_delay`, dictating the maximum percentage increase that can be applied +//! to the commission per number of blocks. +//! * throttle: An attempted commission increase is throttled if the attempted change falls outside +//! the change rate bounds. //! //! ## Usage //! @@ -125,8 +130,30 @@ //! other members have left. Once they fully withdraw their funds, the pool is destroyed. //! * Nominator: can select which validators the pool nominates. //! * Bouncer: can change the pools state and kick members if the pool is blocked. -//! * Root: can change the nominator, bouncer, or itself and can perform any of the actions the -//! nominator or bouncer can. +//! * Root: can change the nominator, bouncer, or itself, manage and claim commission, and can +//! perform any of the actions the nominator or bouncer can. +//! +//! ## Commission +//! +//! A pool can optionally have a commission configuration, via the `root` role, set with +//! [`Call::set_commission`]. A payee account must be supplied with the desired commission +//! percentage. Beyond the commission itself, a pool can have a maximum commission and a change rate +//! - the maximum commission and the rate at which the commission can be changed respectively. +//! +//! Importantly, both max commission and change rate can not be removed once set, and can only be +//! set to more restrictive values (i.e. a lower max commission or a slower change rate) in +//! subsequent updates. +//! +//! All commissions are bound to [`GlobalMaxCommission`] when they are applied to rewards, a storage +//! value intended to be updated via governance. +//! +//! When a pool is dissolved, any outstanding pending commission that has not been claimed will be +//! transferred to the depositor. +//! +//! Implementation note: Commission is applied to rewards based on the current commission in effect +//! at the time the reward was transferred to the reward pool. This is to prevent the malicious +//! behaviour of changing the commission rate to a very high value after rewards are accumulated, +//! and thus claim an unexpectedly high chunk of the reward. //! //! ### Dismantling //! @@ -236,7 +263,8 @@ //! destination. //! //! The reward pool is not really a pool anymore, as it does not track points anymore. Instead, it -//! tracks, a virtual value called `reward_counter`, among a few other values. +//! tracks, a virtual value called `reward_counter`, among a few other values including commission +//! counters. //! //! See [this link](https://hackmd.io/PFGn6wI5TbCmBYoEA_f2Uw) for an in-depth explanation of the //! reward pool mechanism. @@ -247,13 +275,12 @@ //! //! ### Unbonding sub pools //! -//! When a member unbonds, it's balance is unbonded in the bonded pool's account and tracked in -//! an unbonding pool associated with the active era. If no such pool exists, one is created. To -//! track which unbonding sub pool a member belongs too, a member tracks it's -//! `unbonding_era`. +//! When a member unbonds, it's balance is unbonded in the bonded pool's account and tracked in an +//! unbonding pool associated with the active era. If no such pool exists, one is created. To track +//! which unbonding sub pool a member belongs too, a member tracks it's `unbonding_era`. //! -//! When a member initiates unbonding it's claim on the bonded pool -//! (`balance_to_unbond`) is computed as: +//! When a member initiates unbonding it's claim on the bonded pool (`balance_to_unbond`) is +//! computed as: //! //! ```text //! balance_to_unbond = (bonded_pool.balance / bonded_pool.points) * member.points; @@ -262,8 +289,8 @@ //! If this is the first transfer into an unbonding pool arbitrary amount of points can be issued //! per balance. In this implementation unbonding pools are initialized with a 1 point to 1 balance //! ratio (see [`POINTS_TO_BALANCE_INIT_RATIO`]). Otherwise, the unbonding pools hold the same -//! points to balance ratio properties as the bonded pool, so member points in the -//! unbonding pool are issued based on +//! points to balance ratio properties as the bonded pool, so member points in the unbonding pool +//! are issued based on //! //! ```text //! new_points_issued = (points_before_transfer / balance_before_transfer) * balance_to_unbond; @@ -296,14 +323,14 @@ //! `pallet_staking::StakingLedger::slash`, which passes the information to this pallet via //! [`sp_staking::OnStakerSlash::on_slash`]. //! -//! Unbonding pools need to be slashed to ensure all nominators whom where in the bonded pool -//! while it was backing a validator that equivocated are punished. Without these measures a -//! member could unbond right after a validator equivocated with no consequences. +//! Unbonding pools need to be slashed to ensure all nominators whom where in the bonded pool while +//! it was backing a validator that equivocated are punished. Without these measures a member could +//! unbond right after a validator equivocated with no consequences. //! -//! This strategy is unfair to members who joined after the slash, because they get slashed as -//! well, but spares members who unbond. The latter is much more important for security: if a -//! pool's validators are attacking the network, their members need to unbond fast! Avoiding -//! slashes gives them an incentive to do that if validators get repeatedly slashed. +//! This strategy is unfair to members who joined after the slash, because they get slashed as well, +//! but spares members who unbond. The latter is much more important for security: if a pool's +//! validators are attacking the network, their members need to unbond fast! Avoiding slashes gives +//! them an incentive to do that if validators get repeatedly slashed. //! //! To be fair to joiners, this implementation also need joining pools, which are actively staking, //! in addition to the unbonding pools. For maintenance simplicity these are not implemented. @@ -2486,10 +2513,9 @@ pub mod pallet { } /// Set the commission of a pool. - /// - /// The dispatch origin of this call must be signed by the `root` role of the pool. Both a - /// commission percentage and a commission payee must be provided in the `current` tuple. - /// Where a `current` of `None` is provided, any current commission will be removed. + // + /// Both a commission percentage and a commission payee must be provided in the `current` + /// tuple. Where a `current` of `None` is provided, any current commission will be removed. /// /// - If a `None` is supplied to `new_commission`, existing commission will be removed. #[pallet::call_index(17)] @@ -2525,8 +2551,6 @@ pub mod pallet { /// Set the maximum commission of a pool. /// - /// The dispatch origin of this call must be signed by the `root` role of the pool. - /// /// - Initial max can be set to any `Perbill`, and only smaller values thereafter. /// - Current commission will be lowered in the event it is higher than a new max /// commission. @@ -2550,9 +2574,8 @@ pub mod pallet { /// Set the commission change rate for a pool. /// - /// The dispatch origin of this call must be signed by the `root` role of the pool. Initial - /// change rate is not bounded, whereas subsequent updates can only be more restrictive than - /// the current. + /// Initial change rate is not bounded, whereas subsequent updates can only be more + /// restrictive than the current. #[pallet::call_index(19)] #[pallet::weight(T::WeightInfo::set_commission_change_rate())] pub fn set_commission_change_rate( @@ -2649,7 +2672,8 @@ impl Pallet { Zero::zero() ); - // This shouldn't fail, but if it does we don't really care + // This shouldn't fail, but if it does we don't really care. Remaining balance can consist + // of unclaimed pending commission, errorneous transfers to the reward account, etc. let reward_pool_remaining = T::Currency::free_balance(&reward_account); let _ = T::Currency::transfer( &reward_account, From 7de3ec249f4a9bc32cdaf26eef3769b097e61c56 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sun, 26 Feb 2023 12:44:00 +0700 Subject: [PATCH 56/90] add calls --- frame/nomination-pools/src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index a3a55b919922a..29aab7425b129 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -136,13 +136,14 @@ //! ## Commission //! //! A pool can optionally have a commission configuration, via the `root` role, set with -//! [`Call::set_commission`]. A payee account must be supplied with the desired commission -//! percentage. Beyond the commission itself, a pool can have a maximum commission and a change rate +//! [`Call::set_commission`] and claimed with [`Call::claim_commission`]. A payee account must be +//! supplied with the desired commission percentage. Beyond the commission itself, a pool can have a +//! maximum commission and a change rate //! - the maximum commission and the rate at which the commission can be changed respectively. //! -//! Importantly, both max commission and change rate can not be removed once set, and can only be -//! set to more restrictive values (i.e. a lower max commission or a slower change rate) in -//! subsequent updates. +//! Importantly, both max commission [`Call::set_commission_max`] and change rate +//! [`Call::set_commission_change_rate`] can not be removed once set, and can only be set to more +//! restrictive values (i.e. a lower max commission or a slower change rate) in subsequent updates. //! //! All commissions are bound to [`GlobalMaxCommission`] when they are applied to rewards, a storage //! value intended to be updated via governance. From 8f773a103af5807bccff8cdb56b9827c03257860 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sun, 26 Feb 2023 12:46:06 +0700 Subject: [PATCH 57/90] docs --- frame/nomination-pools/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 29aab7425b129..ad3e46e9163de 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -145,8 +145,8 @@ //! [`Call::set_commission_change_rate`] can not be removed once set, and can only be set to more //! restrictive values (i.e. a lower max commission or a slower change rate) in subsequent updates. //! -//! All commissions are bound to [`GlobalMaxCommission`] when they are applied to rewards, a storage -//! value intended to be updated via governance. +//! If set, a pool's commission is bound to [`GlobalMaxCommission`] at the time it is applied to +//! pending rewards. [`GlobalMaxCommission`] is intended to be updated only via governance. //! //! When a pool is dissolved, any outstanding pending commission that has not been claimed will be //! transferred to the depositor. From 5df778ff638a4901fadbcc970f2ebfa8a0c28f11 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 27 Feb 2023 12:05:41 +0700 Subject: [PATCH 58/90] rename --- frame/nomination-pools/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index ad3e46e9163de..5114641e362cd 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1310,7 +1310,7 @@ impl RewardPool { // Split the `payouts_since_last_record` into regular rewards and commission according to // the current commission rate. let new_pending_commission = commission * payouts_since_last_record; - let payouts_deducting_commission = + let payouts_minus_commission = payouts_since_last_record.saturating_sub(new_pending_commission); // * accuracy notes regarding the multiplication in `checked_from_rational`: @@ -1347,7 +1347,7 @@ impl RewardPool { // // which is basically 10^-8 DOTs. See `smallest_claimable_reward` for an example of this. let current_reward_counter = - T::RewardCounter::checked_from_rational(payouts_deducting_commission, bonded_points) + T::RewardCounter::checked_from_rational(payouts_minus_commission, bonded_points) .and_then(|ref r| self.last_recorded_reward_counter.checked_add(r)) .ok_or(Error::::OverflowRisk)?; From 76393720166cdb7623d01fd581fe33d368550cf4 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 27 Feb 2023 12:12:02 +0700 Subject: [PATCH 59/90] rename --- frame/nomination-pools/src/lib.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 5114641e362cd..5f7bc2036d557 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1302,20 +1302,20 @@ impl RewardPool { commission: Perbill, ) -> Result<(T::RewardCounter, BalanceOf), Error> { let balance = Self::current_balance(id); - let payouts_since_last_record = balance + let current_payout_balance = balance .saturating_add(self.total_rewards_claimed) .saturating_add(self.total_commission_claimed) .saturating_sub(self.last_recorded_total_payouts); - // Split the `payouts_since_last_record` into regular rewards and commission according to + // Split the `current_payout_balance` into regular rewards and commission according to // the current commission rate. - let new_pending_commission = commission * payouts_since_last_record; + let new_pending_commission = commission * current_payout_balance; let payouts_minus_commission = - payouts_since_last_record.saturating_sub(new_pending_commission); + current_payout_balance.saturating_sub(new_pending_commission); // * accuracy notes regarding the multiplication in `checked_from_rational`: - // `payouts_since_last_record` is a subset of the total_issuance at the very - // worse. `bonded_points` are similarly, in a non-slashed pool, have the same granularity as + // `current_payout_balance` is a subset of the total_issuance at the very worse. + // `bonded_points` are similarly, in a non-slashed pool, have the same granularity as // balance, and are thus below within the range of total_issuance. In the worse case // scenario, for `saturating_from_rational`, we have: // @@ -1333,13 +1333,14 @@ impl RewardPool { // represented as `FixedU128`, which means it is less than `total_issuance * 10^18`. // // * accuracy notes regarding `checked_from_rational` collapsing to zero, meaning that no - // reward can be claimed: + // reward + // can be claimed: // - // largest `bonded_points`, such that the reward counter is non-zero, with `FixedU128` - // will be when the payout is being computed. This essentially means `payout/bonded_points` - // needs to be more than 1/1^18. Thus, assuming that `bonded_points` will always be less - // than `10 * dot_total_issuance`, if the reward_counter is the smallest possible value, - // the value of the reward being calculated is: + // largest `bonded_points`, such that the reward counter is non-zero, with `FixedU128` will + // be when the payout is being computed. This essentially means `payout/bonded_points` needs + // to be more than 1/1^18. Thus, assuming that `bonded_points` will always be less than `10 + // * dot_total_issuance`, if the reward_counter is the smallest possible value, the value of + // the reward being calculated is: // // x / 10^20 = 1/ 10^18 // From 7f2ab90c33040e09d20d20bb93ebcb79e6ebb602 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 27 Feb 2023 12:37:30 +0700 Subject: [PATCH 60/90] docs --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 5f7bc2036d557..b22f4a180666e 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -152,7 +152,7 @@ //! transferred to the depositor. //! //! Implementation note: Commission is applied to rewards based on the current commission in effect -//! at the time the reward was transferred to the reward pool. This is to prevent the malicious +//! at the time rewards are transferred into the reward pool. This is to prevent the malicious //! behaviour of changing the commission rate to a very high value after rewards are accumulated, //! and thus claim an unexpectedly high chunk of the reward. //! From 6022d07c710f107f3606977b7f1e89ba01958a32 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 27 Feb 2023 12:54:12 +0700 Subject: [PATCH 61/90] rename --- frame/nomination-pools/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index b22f4a180666e..d4ec91e7c3c5d 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1310,7 +1310,7 @@ impl RewardPool { // Split the `current_payout_balance` into regular rewards and commission according to // the current commission rate. let new_pending_commission = commission * current_payout_balance; - let payouts_minus_commission = + let new_pending_rewards = current_payout_balance.saturating_sub(new_pending_commission); // * accuracy notes regarding the multiplication in `checked_from_rational`: @@ -1348,7 +1348,7 @@ impl RewardPool { // // which is basically 10^-8 DOTs. See `smallest_claimable_reward` for an example of this. let current_reward_counter = - T::RewardCounter::checked_from_rational(payouts_minus_commission, bonded_points) + T::RewardCounter::checked_from_rational(new_pending_rewards, bonded_points) .and_then(|ref r| self.last_recorded_reward_counter.checked_add(r)) .ok_or(Error::::OverflowRisk)?; From d1d2695e94d668fd0bbd74e31193b312c4d89103 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 27 Feb 2023 12:55:02 +0700 Subject: [PATCH 62/90] fmt --- frame/nomination-pools/src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index d4ec91e7c3c5d..51b722f8fb75f 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1310,8 +1310,7 @@ impl RewardPool { // Split the `current_payout_balance` into regular rewards and commission according to // the current commission rate. let new_pending_commission = commission * current_payout_balance; - let new_pending_rewards = - current_payout_balance.saturating_sub(new_pending_commission); + let new_pending_rewards = current_payout_balance.saturating_sub(new_pending_commission); // * accuracy notes regarding the multiplication in `checked_from_rational`: // `current_payout_balance` is a subset of the total_issuance at the very worse. @@ -1333,14 +1332,14 @@ impl RewardPool { // represented as `FixedU128`, which means it is less than `total_issuance * 10^18`. // // * accuracy notes regarding `checked_from_rational` collapsing to zero, meaning that no - // reward - // can be claimed: + // reward can be claimed: // // largest `bonded_points`, such that the reward counter is non-zero, with `FixedU128` will // be when the payout is being computed. This essentially means `payout/bonded_points` needs // to be more than 1/1^18. Thus, assuming that `bonded_points` will always be less than `10 // * dot_total_issuance`, if the reward_counter is the smallest possible value, the value of - // the reward being calculated is: + // the + // reward being calculated is: // // x / 10^20 = 1/ 10^18 // From b2d9197ca387c188606a7ef55229b3cfe48e1af0 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 27 Feb 2023 13:40:40 +0700 Subject: [PATCH 63/90] use matches! --- frame/nomination-pools/src/lib.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 51b722f8fb75f..e8fbe060df82f 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -459,19 +459,11 @@ pub enum ClaimPermission { impl ClaimPermission { fn can_bond_extra(&self) -> bool { - match self { - ClaimPermission::PermissionlessAll => true, - ClaimPermission::PermissionlessCompound => true, - _ => false, - } + matches!(self, ClaimPermission::PermissionlessAll | ClaimPermission::PermissionlessCompound) } fn can_claim_payout(&self) -> bool { - match self { - ClaimPermission::PermissionlessAll => true, - ClaimPermission::PermissionlessWithdraw => true, - _ => false, - } + matches!(self, ClaimPermission::PermissionlessAll | ClaimPermission::PermissionlessWithdraw) } } From b9526b6a829781ac2bcbace5fedb5b5ebc3a00e2 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Wed, 1 Mar 2023 06:26:29 +0000 Subject: [PATCH 64/90] Update frame/nomination-pools/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gonçalo Pestana --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index e8fbe060df82f..4fd9c3f33137d 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -724,7 +724,7 @@ impl Commission { } /// Get's the pool's current commission, or returns Perbill::zero if none is set. - /// Bounded to global max if current is greater than GlobalMaxCommission. + /// Bounded to global max if current is greater than `GlobalMaxCommission`. fn current(&self) -> Perbill { self.current .as_ref() From 20c53cf5ee4d05751f177bda7c88bb118c09d9d5 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Wed, 1 Mar 2023 06:26:39 +0000 Subject: [PATCH 65/90] Update frame/nomination-pools/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gonçalo Pestana --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 4fd9c3f33137d..d68b602fc48f7 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1578,7 +1578,7 @@ pub mod pallet { pub type MaxPoolMembersPerPool = StorageValue<_, u32, OptionQuery>; /// The maximum commission that can be charged by a pool. Used on commission payouts to bound - /// pool commissions that are > GlobalMaxCommission, necessary if a future `GlobalMaxCommission` + /// pool commissions that are > `GlobalMaxCommission`, necessary if a future `GlobalMaxCommission` /// is lower than some current pool commissions. #[pallet::storage] pub type GlobalMaxCommission = StorageValue<_, Perbill, OptionQuery>; From 700904ceb5387215ad0a2ee4b2a60855a31ddf26 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Wed, 1 Mar 2023 06:29:08 +0000 Subject: [PATCH 66/90] Update frame/nomination-pools/src/tests.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gonçalo Pestana --- frame/nomination-pools/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index f883e7e50349c..8de776f44e823 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5511,7 +5511,7 @@ mod commission { ); // When set commission is called again, update_records is called and - // total_commission_pending is updated, based on the current reward counter and pool + // `total_commission_pending` is updated, based on the current reward counter and pool // balance. // // Note that commission is now 0%, so it should not come into play with subsequent From c766ffa8085ed47a7eb587ee491baf581d157190 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Wed, 1 Mar 2023 13:30:26 +0700 Subject: [PATCH 67/90] comment --- frame/nomination-pools/src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index d68b602fc48f7..1fb21995123c3 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -138,8 +138,7 @@ //! A pool can optionally have a commission configuration, via the `root` role, set with //! [`Call::set_commission`] and claimed with [`Call::claim_commission`]. A payee account must be //! supplied with the desired commission percentage. Beyond the commission itself, a pool can have a -//! maximum commission and a change rate -//! - the maximum commission and the rate at which the commission can be changed respectively. +//! maximum commission and a change rate. //! //! Importantly, both max commission [`Call::set_commission_max`] and change rate //! [`Call::set_commission_change_rate`] can not be removed once set, and can only be set to more @@ -1578,8 +1577,8 @@ pub mod pallet { pub type MaxPoolMembersPerPool = StorageValue<_, u32, OptionQuery>; /// The maximum commission that can be charged by a pool. Used on commission payouts to bound - /// pool commissions that are > `GlobalMaxCommission`, necessary if a future `GlobalMaxCommission` - /// is lower than some current pool commissions. + /// pool commissions that are > `GlobalMaxCommission`, necessary if a future + /// `GlobalMaxCommission` is lower than some current pool commissions. #[pallet::storage] pub type GlobalMaxCommission = StorageValue<_, Perbill, OptionQuery>; From 99b741ca260d8697e4e5240422287d086847b66d Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Wed, 1 Mar 2023 06:30:53 +0000 Subject: [PATCH 68/90] Update frame/nomination-pools/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gonçalo Pestana --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 1fb21995123c3..ddd9a55597e62 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -722,7 +722,7 @@ impl Commission { false } - /// Get's the pool's current commission, or returns Perbill::zero if none is set. + /// Gets the pool's current commission, or returns Perbill::zero if none is set. /// Bounded to global max if current is greater than `GlobalMaxCommission`. fn current(&self) -> Perbill { self.current From 049b3990515b808cb96712f01ad7ae6e3df96b1c Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Wed, 1 Mar 2023 13:56:09 +0700 Subject: [PATCH 69/90] . --- frame/nomination-pools/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index ddd9a55597e62..51cb3a6ab5415 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2307,8 +2307,8 @@ pub mod pallet { /// Set a new metadata for the pool. /// - /// The dispatch origin of this call must be signed by the bouncer, or the root role - /// of the pool. + /// The dispatch origin of this call must be signed by the bouncer, or the root role of the + /// pool. #[pallet::call_index(10)] #[pallet::weight(T::WeightInfo::set_metadata(metadata.len() as u32))] pub fn set_metadata( From 1b0e6eb866907f27504dbc9c7cae91c0f4d12cb6 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Wed, 1 Mar 2023 15:49:44 +0700 Subject: [PATCH 70/90] weights order --- frame/nomination-pools/src/weights.rs | 58 +++++++++++++-------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index b4d2e89ead583..cb0e3b1a1b35d 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -64,10 +64,10 @@ pub trait WeightInfo { fn set_configs() -> Weight; fn update_roles() -> Weight; fn chill() -> Weight; + fn set_claim_permission() -> Weight; fn set_commission() -> Weight; fn set_commission_max() -> Weight; fn set_commission_change_rate() -> Weight; - fn set_claim_permission() -> Weight; fn claim_commission() -> Weight; } @@ -532,6 +532,20 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } + /// Storage: NominationPools PoolMembers (r:1 w:0) + /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) + /// Storage: NominationPools ClaimPermissions (r:1 w:1) + /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) + fn set_claim_permission() -> Weight { + // Proof Size summary in bytes: + // Measured: `542` + // Estimated: `5228` + // Minimum execution time: 15_312 nanoseconds. + Weight::from_ref_time(15_595_000) + .saturating_add(Weight::from_proof_size(5228)) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } /// Storage: NominationPools BondedPools (r:1 w:1) /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:0) @@ -574,20 +588,6 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: NominationPools PoolMembers (r:1 w:0) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools ClaimPermissions (r:1 w:1) - /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) - fn set_claim_permission() -> Weight { - // Proof Size summary in bytes: - // Measured: `542` - // Estimated: `5228` - // Minimum execution time: 15_312 nanoseconds. - Weight::from_ref_time(15_595_000) - .saturating_add(Weight::from_proof_size(5228)) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } /// Storage: NominationPools BondedPools (r:1 w:0) /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:0) @@ -1068,6 +1068,20 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } + /// Storage: NominationPools PoolMembers (r:1 w:0) + /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) + /// Storage: NominationPools ClaimPermissions (r:1 w:1) + /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) + fn set_claim_permission() -> Weight { + // Proof Size summary in bytes: + // Measured: `542` + // Estimated: `5228` + // Minimum execution time: 15_312 nanoseconds. + Weight::from_ref_time(15_595_000) + .saturating_add(Weight::from_proof_size(5228)) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } /// Storage: NominationPools BondedPools (r:1 w:1) /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:0) @@ -1110,20 +1124,6 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: NominationPools PoolMembers (r:1 w:0) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools ClaimPermissions (r:1 w:1) - /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) - fn set_claim_permission() -> Weight { - // Proof Size summary in bytes: - // Measured: `542` - // Estimated: `5228` - // Minimum execution time: 15_312 nanoseconds. - Weight::from_ref_time(15_595_000) - .saturating_add(Weight::from_proof_size(5228)) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } /// Storage: NominationPools BondedPools (r:1 w:0) /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) /// Storage: NominationPools RewardPools (r:1 w:0) From 8fd1038bdc2293fceec3c5d364f8e14c8dc11b54 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 1 Mar 2023 09:42:58 +0000 Subject: [PATCH 71/90] ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_nomination_pools --- frame/nomination-pools/src/weights.rs | 404 +++++++++++++------------- 1 file changed, 200 insertions(+), 204 deletions(-) diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index cb0e3b1a1b35d..b88172d9bcd6d 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_nomination_pools //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 @@ -64,10 +64,10 @@ pub trait WeightInfo { fn set_configs() -> Weight; fn update_roles() -> Weight; fn chill() -> Weight; - fn set_claim_permission() -> Weight; fn set_commission() -> Weight; fn set_commission_max() -> Weight; fn set_commission_change_rate() -> Weight; + fn set_claim_permission() -> Weight; fn claim_commission() -> Weight; } @@ -105,10 +105,10 @@ impl WeightInfo for SubstrateWeight { fn join() -> Weight { // Proof Size summary in bytes: // Measured: `3650` - // Estimated: `38575` - // Minimum execution time: 164_798 nanoseconds. - Weight::from_ref_time(166_299_000) - .saturating_add(Weight::from_proof_size(38575)) + // Estimated: `52435` + // Minimum execution time: 162_803 nanoseconds. + Weight::from_ref_time(163_826_000) + .saturating_add(Weight::from_proof_size(52435)) .saturating_add(T::DbWeight::get().reads(18_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)) } @@ -135,10 +135,10 @@ impl WeightInfo for SubstrateWeight { fn bond_extra_transfer() -> Weight { // Proof Size summary in bytes: // Measured: `3692` - // Estimated: `39170` - // Minimum execution time: 162_598 nanoseconds. - Weight::from_ref_time(163_420_000) - .saturating_add(Weight::from_proof_size(39170)) + // Estimated: `49070` + // Minimum execution time: 158_990 nanoseconds. + Weight::from_ref_time(160_063_000) + .saturating_add(Weight::from_proof_size(49070)) .saturating_add(T::DbWeight::get().reads(15_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)) } @@ -167,10 +167,10 @@ impl WeightInfo for SubstrateWeight { fn bond_extra_other() -> Weight { // Proof Size summary in bytes: // Measured: `3757` - // Estimated: `41686` - // Minimum execution time: 181_848 nanoseconds. - Weight::from_ref_time(183_274_000) - .saturating_add(Weight::from_proof_size(41686)) + // Estimated: `52576` + // Minimum execution time: 178_597 nanoseconds. + Weight::from_ref_time(179_922_000) + .saturating_add(Weight::from_proof_size(52576)) .saturating_add(T::DbWeight::get().reads(16_u64)) .saturating_add(T::DbWeight::get().writes(13_u64)) } @@ -189,10 +189,10 @@ impl WeightInfo for SubstrateWeight { fn claim_payout() -> Weight { // Proof Size summary in bytes: // Measured: `1331` - // Estimated: `13592` - // Minimum execution time: 64_438 nanoseconds. - Weight::from_ref_time(65_232_000) - .saturating_add(Weight::from_proof_size(13592)) + // Estimated: `19532` + // Minimum execution time: 62_735 nanoseconds. + Weight::from_ref_time(63_448_000) + .saturating_add(Weight::from_proof_size(19532)) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -229,10 +229,10 @@ impl WeightInfo for SubstrateWeight { fn unbond() -> Weight { // Proof Size summary in bytes: // Measured: `3935` - // Estimated: `67966` - // Minimum execution time: 167_605 nanoseconds. - Weight::from_ref_time(168_608_000) - .saturating_add(Weight::from_proof_size(67966)) + // Estimated: `82816` + // Minimum execution time: 164_570 nanoseconds. + Weight::from_ref_time(166_034_000) + .saturating_add(Weight::from_proof_size(82816)) .saturating_add(T::DbWeight::get().reads(19_u64)) .saturating_add(T::DbWeight::get().writes(13_u64)) } @@ -250,12 +250,12 @@ impl WeightInfo for SubstrateWeight { fn pool_withdraw_unbonded(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `1783` - // Estimated: `13081` - // Minimum execution time: 55_844 nanoseconds. - Weight::from_ref_time(56_991_168) - .saturating_add(Weight::from_proof_size(13081)) - // Standard Error: 6_490 - .saturating_add(Weight::from_ref_time(25_031).saturating_mul(s.into())) + // Estimated: `18031` + // Minimum execution time: 55_830 nanoseconds. + Weight::from_ref_time(57_099_319) + .saturating_add(Weight::from_proof_size(18031)) + // Standard Error: 697 + .saturating_add(Weight::from_ref_time(5_710).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -283,10 +283,10 @@ impl WeightInfo for SubstrateWeight { fn withdraw_unbonded_update(_s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `2307` - // Estimated: `45752` - // Minimum execution time: 109_056 nanoseconds. - Weight::from_ref_time(112_339_953) - .saturating_add(Weight::from_proof_size(45752)) + // Estimated: `54662` + // Minimum execution time: 108_207 nanoseconds. + Weight::from_ref_time(110_862_821) + .saturating_add(Weight::from_proof_size(54662)) .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } @@ -333,15 +333,13 @@ impl WeightInfo for SubstrateWeight { /// Storage: NominationPools ClaimPermissions (r:0 w:1) /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_kill(s: u32, ) -> Weight { + fn withdraw_unbonded_kill(_s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `2694` - // Estimated: `68904` - // Minimum execution time: 173_492 nanoseconds. - Weight::from_ref_time(176_020_869) - .saturating_add(Weight::from_proof_size(68904)) - // Standard Error: 9_468 - .saturating_add(Weight::from_ref_time(18_840).saturating_mul(s.into())) + // Estimated: `87714` + // Minimum execution time: 172_141 nanoseconds. + Weight::from_ref_time(176_082_851) + .saturating_add(Weight::from_proof_size(87714)) .saturating_add(T::DbWeight::get().reads(20_u64)) .saturating_add(T::DbWeight::get().writes(18_u64)) } @@ -390,10 +388,10 @@ impl WeightInfo for SubstrateWeight { fn create() -> Weight { // Proof Size summary in bytes: // Measured: `1321` - // Estimated: `31610` - // Minimum execution time: 150_941 nanoseconds. - Weight::from_ref_time(151_589_000) - .saturating_add(Weight::from_proof_size(31610)) + // Estimated: `51410` + // Minimum execution time: 149_802 nanoseconds. + Weight::from_ref_time(150_736_000) + .saturating_add(Weight::from_proof_size(51410)) .saturating_add(T::DbWeight::get().reads(21_u64)) .saturating_add(T::DbWeight::get().writes(15_u64)) } @@ -425,12 +423,12 @@ impl WeightInfo for SubstrateWeight { fn nominate(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `1913` - // Estimated: `22054 + n * (2520 ±0)` - // Minimum execution time: 69_510 nanoseconds. - Weight::from_ref_time(69_738_016) - .saturating_add(Weight::from_proof_size(22054)) - // Standard Error: 5_538 - .saturating_add(Weight::from_ref_time(1_481_803).saturating_mul(n.into())) + // Estimated: `33934 + n * (2520 ±0)` + // Minimum execution time: 70_145 nanoseconds. + Weight::from_ref_time(70_129_523) + .saturating_add(Weight::from_proof_size(33934)) + // Standard Error: 6_775 + .saturating_add(Weight::from_ref_time(1_506_411).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(12_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(T::DbWeight::get().writes(5_u64)) @@ -445,10 +443,10 @@ impl WeightInfo for SubstrateWeight { fn set_state() -> Weight { // Proof Size summary in bytes: // Measured: `1502` - // Estimated: `8808` - // Minimum execution time: 36_968 nanoseconds. - Weight::from_ref_time(37_288_000) - .saturating_add(Weight::from_proof_size(8808)) + // Estimated: `11778` + // Minimum execution time: 36_847 nanoseconds. + Weight::from_ref_time(37_462_000) + .saturating_add(Weight::from_proof_size(11778)) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -462,12 +460,12 @@ impl WeightInfo for SubstrateWeight { fn set_metadata(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `563` - // Estimated: `5939` - // Minimum execution time: 15_112 nanoseconds. - Weight::from_ref_time(15_528_998) - .saturating_add(Weight::from_proof_size(5939)) - // Standard Error: 405 - .saturating_add(Weight::from_ref_time(3_157).saturating_mul(n.into())) + // Estimated: `8909` + // Minimum execution time: 15_181 nanoseconds. + Weight::from_ref_time(15_743_624) + .saturating_add(Weight::from_proof_size(8909)) + // Standard Error: 79 + .saturating_add(Weight::from_ref_time(687).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -487,8 +485,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 7_225 nanoseconds. - Weight::from_ref_time(7_502_000) + // Minimum execution time: 7_434 nanoseconds. + Weight::from_ref_time(7_643_000) .saturating_add(Weight::from_proof_size(0)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -497,10 +495,10 @@ impl WeightInfo for SubstrateWeight { fn update_roles() -> Weight { // Proof Size summary in bytes: // Measured: `563` - // Estimated: `2695` - // Minimum execution time: 20_777 nanoseconds. - Weight::from_ref_time(21_446_000) - .saturating_add(Weight::from_proof_size(2695)) + // Estimated: `3685` + // Minimum execution time: 20_567 nanoseconds. + Weight::from_ref_time(20_872_000) + .saturating_add(Weight::from_proof_size(3685)) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -525,30 +523,16 @@ impl WeightInfo for SubstrateWeight { fn chill() -> Weight { // Proof Size summary in bytes: // Measured: `2140` - // Estimated: `20545` - // Minimum execution time: 67_539 nanoseconds. - Weight::from_ref_time(68_114_000) - .saturating_add(Weight::from_proof_size(20545)) + // Estimated: `29455` + // Minimum execution time: 67_795 nanoseconds. + Weight::from_ref_time(68_417_000) + .saturating_add(Weight::from_proof_size(29455)) .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } - /// Storage: NominationPools PoolMembers (r:1 w:0) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools ClaimPermissions (r:1 w:1) - /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) - fn set_claim_permission() -> Weight { - // Proof Size summary in bytes: - // Measured: `542` - // Estimated: `5228` - // Minimum execution time: 15_312 nanoseconds. - Weight::from_ref_time(15_595_000) - .saturating_add(Weight::from_proof_size(5228)) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } /// Storage: NominationPools BondedPools (r:1 w:1) /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:0) + /// Storage: NominationPools RewardPools (r:1 w:1) /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) @@ -557,22 +541,22 @@ impl WeightInfo for SubstrateWeight { fn set_commission() -> Weight { // Proof Size summary in bytes: // Measured: `866` - // Estimated: `8364` - // Minimum execution time: 31_945 nanoseconds. - Weight::from_ref_time(32_310_000) - .saturating_add(Weight::from_proof_size(8364)) + // Estimated: `12324` + // Minimum execution time: 34_664 nanoseconds. + Weight::from_ref_time(35_281_000) + .saturating_add(Weight::from_proof_size(12324)) .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: NominationPools BondedPools (r:1 w:1) /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) fn set_commission_max() -> Weight { // Proof Size summary in bytes: // Measured: `603` - // Estimated: `2695` - // Minimum execution time: 19_907 nanoseconds. - Weight::from_ref_time(20_105_000) - .saturating_add(Weight::from_proof_size(2695)) + // Estimated: `3685` + // Minimum execution time: 19_775 nanoseconds. + Weight::from_ref_time(20_170_000) + .saturating_add(Weight::from_proof_size(3685)) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -581,16 +565,30 @@ impl WeightInfo for SubstrateWeight { fn set_commission_change_rate() -> Weight { // Proof Size summary in bytes: // Measured: `563` - // Estimated: `2695` - // Minimum execution time: 20_770 nanoseconds. - Weight::from_ref_time(21_017_000) - .saturating_add(Weight::from_proof_size(2695)) + // Estimated: `3685` + // Minimum execution time: 20_794 nanoseconds. + Weight::from_ref_time(21_279_000) + .saturating_add(Weight::from_proof_size(3685)) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// Storage: NominationPools PoolMembers (r:1 w:0) + /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) + /// Storage: NominationPools ClaimPermissions (r:1 w:1) + /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) + fn set_claim_permission() -> Weight { + // Proof Size summary in bytes: + // Measured: `542` + // Estimated: `7208` + // Minimum execution time: 15_620 nanoseconds. + Weight::from_ref_time(15_867_000) + .saturating_add(Weight::from_proof_size(7208)) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } /// Storage: NominationPools BondedPools (r:1 w:0) /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:0) + /// Storage: NominationPools RewardPools (r:1 w:1) /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) @@ -599,12 +597,12 @@ impl WeightInfo for SubstrateWeight { fn claim_commission() -> Weight { // Proof Size summary in bytes: // Measured: `1096` - // Estimated: `8364` - // Minimum execution time: 46_155 nanoseconds. - Weight::from_ref_time(46_918_000) - .saturating_add(Weight::from_proof_size(8364)) + // Estimated: `12324` + // Minimum execution time: 49_068 nanoseconds. + Weight::from_ref_time(49_847_000) + .saturating_add(Weight::from_proof_size(12324)) .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } } @@ -641,10 +639,10 @@ impl WeightInfo for () { fn join() -> Weight { // Proof Size summary in bytes: // Measured: `3650` - // Estimated: `38575` - // Minimum execution time: 164_798 nanoseconds. - Weight::from_ref_time(166_299_000) - .saturating_add(Weight::from_proof_size(38575)) + // Estimated: `52435` + // Minimum execution time: 162_803 nanoseconds. + Weight::from_ref_time(163_826_000) + .saturating_add(Weight::from_proof_size(52435)) .saturating_add(RocksDbWeight::get().reads(18_u64)) .saturating_add(RocksDbWeight::get().writes(12_u64)) } @@ -671,10 +669,10 @@ impl WeightInfo for () { fn bond_extra_transfer() -> Weight { // Proof Size summary in bytes: // Measured: `3692` - // Estimated: `39170` - // Minimum execution time: 162_598 nanoseconds. - Weight::from_ref_time(163_420_000) - .saturating_add(Weight::from_proof_size(39170)) + // Estimated: `49070` + // Minimum execution time: 158_990 nanoseconds. + Weight::from_ref_time(160_063_000) + .saturating_add(Weight::from_proof_size(49070)) .saturating_add(RocksDbWeight::get().reads(15_u64)) .saturating_add(RocksDbWeight::get().writes(12_u64)) } @@ -703,10 +701,10 @@ impl WeightInfo for () { fn bond_extra_other() -> Weight { // Proof Size summary in bytes: // Measured: `3757` - // Estimated: `41686` - // Minimum execution time: 181_848 nanoseconds. - Weight::from_ref_time(183_274_000) - .saturating_add(Weight::from_proof_size(41686)) + // Estimated: `52576` + // Minimum execution time: 178_597 nanoseconds. + Weight::from_ref_time(179_922_000) + .saturating_add(Weight::from_proof_size(52576)) .saturating_add(RocksDbWeight::get().reads(16_u64)) .saturating_add(RocksDbWeight::get().writes(13_u64)) } @@ -725,10 +723,10 @@ impl WeightInfo for () { fn claim_payout() -> Weight { // Proof Size summary in bytes: // Measured: `1331` - // Estimated: `13592` - // Minimum execution time: 64_438 nanoseconds. - Weight::from_ref_time(65_232_000) - .saturating_add(Weight::from_proof_size(13592)) + // Estimated: `19532` + // Minimum execution time: 62_735 nanoseconds. + Weight::from_ref_time(63_448_000) + .saturating_add(Weight::from_proof_size(19532)) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -765,10 +763,10 @@ impl WeightInfo for () { fn unbond() -> Weight { // Proof Size summary in bytes: // Measured: `3935` - // Estimated: `67966` - // Minimum execution time: 167_605 nanoseconds. - Weight::from_ref_time(168_608_000) - .saturating_add(Weight::from_proof_size(67966)) + // Estimated: `82816` + // Minimum execution time: 164_570 nanoseconds. + Weight::from_ref_time(166_034_000) + .saturating_add(Weight::from_proof_size(82816)) .saturating_add(RocksDbWeight::get().reads(19_u64)) .saturating_add(RocksDbWeight::get().writes(13_u64)) } @@ -786,12 +784,12 @@ impl WeightInfo for () { fn pool_withdraw_unbonded(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `1783` - // Estimated: `13081` - // Minimum execution time: 55_844 nanoseconds. - Weight::from_ref_time(56_991_168) - .saturating_add(Weight::from_proof_size(13081)) - // Standard Error: 6_490 - .saturating_add(Weight::from_ref_time(25_031).saturating_mul(s.into())) + // Estimated: `18031` + // Minimum execution time: 55_830 nanoseconds. + Weight::from_ref_time(57_099_319) + .saturating_add(Weight::from_proof_size(18031)) + // Standard Error: 697 + .saturating_add(Weight::from_ref_time(5_710).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -819,10 +817,10 @@ impl WeightInfo for () { fn withdraw_unbonded_update(_s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `2307` - // Estimated: `45752` - // Minimum execution time: 109_056 nanoseconds. - Weight::from_ref_time(112_339_953) - .saturating_add(Weight::from_proof_size(45752)) + // Estimated: `54662` + // Minimum execution time: 108_207 nanoseconds. + Weight::from_ref_time(110_862_821) + .saturating_add(Weight::from_proof_size(54662)) .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(8_u64)) } @@ -869,15 +867,13 @@ impl WeightInfo for () { /// Storage: NominationPools ClaimPermissions (r:0 w:1) /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_kill(s: u32, ) -> Weight { + fn withdraw_unbonded_kill(_s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `2694` - // Estimated: `68904` - // Minimum execution time: 173_492 nanoseconds. - Weight::from_ref_time(176_020_869) - .saturating_add(Weight::from_proof_size(68904)) - // Standard Error: 9_468 - .saturating_add(Weight::from_ref_time(18_840).saturating_mul(s.into())) + // Estimated: `87714` + // Minimum execution time: 172_141 nanoseconds. + Weight::from_ref_time(176_082_851) + .saturating_add(Weight::from_proof_size(87714)) .saturating_add(RocksDbWeight::get().reads(20_u64)) .saturating_add(RocksDbWeight::get().writes(18_u64)) } @@ -926,10 +922,10 @@ impl WeightInfo for () { fn create() -> Weight { // Proof Size summary in bytes: // Measured: `1321` - // Estimated: `31610` - // Minimum execution time: 150_941 nanoseconds. - Weight::from_ref_time(151_589_000) - .saturating_add(Weight::from_proof_size(31610)) + // Estimated: `51410` + // Minimum execution time: 149_802 nanoseconds. + Weight::from_ref_time(150_736_000) + .saturating_add(Weight::from_proof_size(51410)) .saturating_add(RocksDbWeight::get().reads(21_u64)) .saturating_add(RocksDbWeight::get().writes(15_u64)) } @@ -961,12 +957,12 @@ impl WeightInfo for () { fn nominate(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `1913` - // Estimated: `22054 + n * (2520 ±0)` - // Minimum execution time: 69_510 nanoseconds. - Weight::from_ref_time(69_738_016) - .saturating_add(Weight::from_proof_size(22054)) - // Standard Error: 5_538 - .saturating_add(Weight::from_ref_time(1_481_803).saturating_mul(n.into())) + // Estimated: `33934 + n * (2520 ±0)` + // Minimum execution time: 70_145 nanoseconds. + Weight::from_ref_time(70_129_523) + .saturating_add(Weight::from_proof_size(33934)) + // Standard Error: 6_775 + .saturating_add(Weight::from_ref_time(1_506_411).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(12_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(RocksDbWeight::get().writes(5_u64)) @@ -981,10 +977,10 @@ impl WeightInfo for () { fn set_state() -> Weight { // Proof Size summary in bytes: // Measured: `1502` - // Estimated: `8808` - // Minimum execution time: 36_968 nanoseconds. - Weight::from_ref_time(37_288_000) - .saturating_add(Weight::from_proof_size(8808)) + // Estimated: `11778` + // Minimum execution time: 36_847 nanoseconds. + Weight::from_ref_time(37_462_000) + .saturating_add(Weight::from_proof_size(11778)) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -998,12 +994,12 @@ impl WeightInfo for () { fn set_metadata(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `563` - // Estimated: `5939` - // Minimum execution time: 15_112 nanoseconds. - Weight::from_ref_time(15_528_998) - .saturating_add(Weight::from_proof_size(5939)) - // Standard Error: 405 - .saturating_add(Weight::from_ref_time(3_157).saturating_mul(n.into())) + // Estimated: `8909` + // Minimum execution time: 15_181 nanoseconds. + Weight::from_ref_time(15_743_624) + .saturating_add(Weight::from_proof_size(8909)) + // Standard Error: 79 + .saturating_add(Weight::from_ref_time(687).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -1023,8 +1019,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 7_225 nanoseconds. - Weight::from_ref_time(7_502_000) + // Minimum execution time: 7_434 nanoseconds. + Weight::from_ref_time(7_643_000) .saturating_add(Weight::from_proof_size(0)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } @@ -1033,10 +1029,10 @@ impl WeightInfo for () { fn update_roles() -> Weight { // Proof Size summary in bytes: // Measured: `563` - // Estimated: `2695` - // Minimum execution time: 20_777 nanoseconds. - Weight::from_ref_time(21_446_000) - .saturating_add(Weight::from_proof_size(2695)) + // Estimated: `3685` + // Minimum execution time: 20_567 nanoseconds. + Weight::from_ref_time(20_872_000) + .saturating_add(Weight::from_proof_size(3685)) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1061,30 +1057,16 @@ impl WeightInfo for () { fn chill() -> Weight { // Proof Size summary in bytes: // Measured: `2140` - // Estimated: `20545` - // Minimum execution time: 67_539 nanoseconds. - Weight::from_ref_time(68_114_000) - .saturating_add(Weight::from_proof_size(20545)) + // Estimated: `29455` + // Minimum execution time: 67_795 nanoseconds. + Weight::from_ref_time(68_417_000) + .saturating_add(Weight::from_proof_size(29455)) .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } - /// Storage: NominationPools PoolMembers (r:1 w:0) - /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) - /// Storage: NominationPools ClaimPermissions (r:1 w:1) - /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) - fn set_claim_permission() -> Weight { - // Proof Size summary in bytes: - // Measured: `542` - // Estimated: `5228` - // Minimum execution time: 15_312 nanoseconds. - Weight::from_ref_time(15_595_000) - .saturating_add(Weight::from_proof_size(5228)) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } /// Storage: NominationPools BondedPools (r:1 w:1) /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:0) + /// Storage: NominationPools RewardPools (r:1 w:1) /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) @@ -1093,22 +1075,22 @@ impl WeightInfo for () { fn set_commission() -> Weight { // Proof Size summary in bytes: // Measured: `866` - // Estimated: `8364` - // Minimum execution time: 31_945 nanoseconds. - Weight::from_ref_time(32_310_000) - .saturating_add(Weight::from_proof_size(8364)) + // Estimated: `12324` + // Minimum execution time: 34_664 nanoseconds. + Weight::from_ref_time(35_281_000) + .saturating_add(Weight::from_proof_size(12324)) .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: NominationPools BondedPools (r:1 w:1) /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) fn set_commission_max() -> Weight { // Proof Size summary in bytes: // Measured: `603` - // Estimated: `2695` - // Minimum execution time: 19_907 nanoseconds. - Weight::from_ref_time(20_105_000) - .saturating_add(Weight::from_proof_size(2695)) + // Estimated: `3685` + // Minimum execution time: 19_775 nanoseconds. + Weight::from_ref_time(20_170_000) + .saturating_add(Weight::from_proof_size(3685)) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1117,16 +1099,30 @@ impl WeightInfo for () { fn set_commission_change_rate() -> Weight { // Proof Size summary in bytes: // Measured: `563` - // Estimated: `2695` - // Minimum execution time: 20_770 nanoseconds. - Weight::from_ref_time(21_017_000) - .saturating_add(Weight::from_proof_size(2695)) + // Estimated: `3685` + // Minimum execution time: 20_794 nanoseconds. + Weight::from_ref_time(21_279_000) + .saturating_add(Weight::from_proof_size(3685)) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + /// Storage: NominationPools PoolMembers (r:1 w:0) + /// Proof: NominationPools PoolMembers (max_values: None, max_size: Some(237), added: 2712, mode: MaxEncodedLen) + /// Storage: NominationPools ClaimPermissions (r:1 w:1) + /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) + fn set_claim_permission() -> Weight { + // Proof Size summary in bytes: + // Measured: `542` + // Estimated: `7208` + // Minimum execution time: 15_620 nanoseconds. + Weight::from_ref_time(15_867_000) + .saturating_add(Weight::from_proof_size(7208)) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } /// Storage: NominationPools BondedPools (r:1 w:0) /// Proof: NominationPools BondedPools (max_values: None, max_size: Some(220), added: 2695, mode: MaxEncodedLen) - /// Storage: NominationPools RewardPools (r:1 w:0) + /// Storage: NominationPools RewardPools (r:1 w:1) /// Proof: NominationPools RewardPools (max_values: None, max_size: Some(92), added: 2567, mode: MaxEncodedLen) /// Storage: NominationPools GlobalMaxCommission (r:1 w:0) /// Proof: NominationPools GlobalMaxCommission (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) @@ -1135,11 +1131,11 @@ impl WeightInfo for () { fn claim_commission() -> Weight { // Proof Size summary in bytes: // Measured: `1096` - // Estimated: `8364` - // Minimum execution time: 46_155 nanoseconds. - Weight::from_ref_time(46_918_000) - .saturating_add(Weight::from_proof_size(8364)) + // Estimated: `12324` + // Minimum execution time: 49_068 nanoseconds. + Weight::from_ref_time(49_847_000) + .saturating_add(Weight::from_proof_size(12324)) .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } } From e3d5b53a365aa05527352d65f1cf4c7edd67c9a5 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Sat, 4 Mar 2023 23:02:08 +0700 Subject: [PATCH 72/90] use from_parts --- frame/nomination-pools/src/weights.rs | 293 +++++++++++--------------- 1 file changed, 123 insertions(+), 170 deletions(-) diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index 8a9e0b2891e52..fa6e4e0e00656 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -1,44 +1,33 @@ -// This file is part of Substrate. - -// Copyright (C) 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. //! Autogenerated weights for pallet_nomination_pools //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! HOSTNAME: `Ross-MacBook-Pro-2.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// target/production/substrate +// target/release/substrate // benchmark // pallet -// --steps=50 -// --repeat=20 -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/substrate/.git/.artifacts/bench.json -// --pallet=pallet_nomination_pools -// --chain=dev -// --header=./HEADER-APACHE2 -// --output=./frame/nomination-pools/src/weights.rs -// --template=./.maintain/frame-weight-template.hbs +// --execution +// wasm +// --wasm-execution +// compiled +// --dev +// --pallet +// pallet-nomination-pools +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --output +// frame/nomination-pools/src/weights.rs +// --template +// .maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -106,9 +95,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3650` // Estimated: `52435` - // Minimum execution time: 162_803 nanoseconds. - Weight::from_ref_time(163_826_000) - .saturating_add(Weight::from_proof_size(52435)) + // Minimum execution time: 179_000_000 picoseconds. + Weight::from_parts(184_000_000, 52435) .saturating_add(T::DbWeight::get().reads(18_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)) } @@ -136,9 +124,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3692` // Estimated: `49070` - // Minimum execution time: 158_990 nanoseconds. - Weight::from_ref_time(160_063_000) - .saturating_add(Weight::from_proof_size(49070)) + // Minimum execution time: 175_000_000 picoseconds. + Weight::from_parts(180_000_000, 49070) .saturating_add(T::DbWeight::get().reads(15_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)) } @@ -168,9 +155,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3757` // Estimated: `52576` - // Minimum execution time: 178_597 nanoseconds. - Weight::from_ref_time(179_922_000) - .saturating_add(Weight::from_proof_size(52576)) + // Minimum execution time: 201_000_000 picoseconds. + Weight::from_parts(206_000_000, 52576) .saturating_add(T::DbWeight::get().reads(16_u64)) .saturating_add(T::DbWeight::get().writes(13_u64)) } @@ -190,9 +176,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1331` // Estimated: `19532` - // Minimum execution time: 62_735 nanoseconds. - Weight::from_ref_time(63_448_000) - .saturating_add(Weight::from_proof_size(19532)) + // Minimum execution time: 66_000_000 picoseconds. + Weight::from_parts(68_000_000, 19532) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -230,9 +215,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3935` // Estimated: `82816` - // Minimum execution time: 164_570 nanoseconds. - Weight::from_ref_time(166_034_000) - .saturating_add(Weight::from_proof_size(82816)) + // Minimum execution time: 182_000_000 picoseconds. + Weight::from_parts(185_000_000, 82816) .saturating_add(T::DbWeight::get().reads(19_u64)) .saturating_add(T::DbWeight::get().writes(13_u64)) } @@ -251,11 +235,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1783` // Estimated: `18031` - // Minimum execution time: 55_830 nanoseconds. - Weight::from_ref_time(57_099_319) - .saturating_add(Weight::from_proof_size(18031)) - // Standard Error: 697 - .saturating_add(Weight::from_ref_time(5_710).saturating_mul(s.into())) + // Minimum execution time: 55_000_000 picoseconds. + Weight::from_parts(57_002_753, 18031) + // Standard Error: 1_793 + .saturating_add(Weight::from_parts(16_018, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -280,13 +263,14 @@ impl WeightInfo for SubstrateWeight { /// Storage: NominationPools ClaimPermissions (r:0 w:1) /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_update(_s: u32, ) -> Weight { + fn withdraw_unbonded_update(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `2307` // Estimated: `54662` - // Minimum execution time: 108_207 nanoseconds. - Weight::from_ref_time(110_862_821) - .saturating_add(Weight::from_proof_size(54662)) + // Minimum execution time: 115_000_000 picoseconds. + Weight::from_parts(120_237_544, 54662) + // Standard Error: 1_910 + .saturating_add(Weight::from_parts(7_036, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } @@ -333,13 +317,14 @@ impl WeightInfo for SubstrateWeight { /// Storage: NominationPools ClaimPermissions (r:0 w:1) /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_kill(_s: u32, ) -> Weight { + fn withdraw_unbonded_kill(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `2694` // Estimated: `87714` - // Minimum execution time: 172_141 nanoseconds. - Weight::from_ref_time(176_082_851) - .saturating_add(Weight::from_proof_size(87714)) + // Minimum execution time: 193_000_000 picoseconds. + Weight::from_parts(198_945_137, 87714) + // Standard Error: 3_367 + .saturating_add(Weight::from_parts(38_991, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(20_u64)) .saturating_add(T::DbWeight::get().writes(18_u64)) } @@ -389,9 +374,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1321` // Estimated: `51410` - // Minimum execution time: 149_802 nanoseconds. - Weight::from_ref_time(150_736_000) - .saturating_add(Weight::from_proof_size(51410)) + // Minimum execution time: 169_000_000 picoseconds. + Weight::from_parts(175_000_000, 51410) .saturating_add(T::DbWeight::get().reads(21_u64)) .saturating_add(T::DbWeight::get().writes(15_u64)) } @@ -424,11 +408,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1913` // Estimated: `33934 + n * (2520 ±0)` - // Minimum execution time: 70_145 nanoseconds. - Weight::from_ref_time(70_129_523) - .saturating_add(Weight::from_proof_size(33934)) - // Standard Error: 6_775 - .saturating_add(Weight::from_ref_time(1_506_411).saturating_mul(n.into())) + // Minimum execution time: 72_000_000 picoseconds. + Weight::from_parts(72_507_807, 33934) + // Standard Error: 9_754 + .saturating_add(Weight::from_parts(1_834_936, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(12_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(T::DbWeight::get().writes(5_u64)) @@ -444,9 +427,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1502` // Estimated: `11778` - // Minimum execution time: 36_847 nanoseconds. - Weight::from_ref_time(37_462_000) - .saturating_add(Weight::from_proof_size(11778)) + // Minimum execution time: 36_000_000 picoseconds. + Weight::from_parts(37_000_000, 11778) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -457,15 +439,12 @@ impl WeightInfo for SubstrateWeight { /// Storage: NominationPools CounterForMetadata (r:1 w:1) /// Proof: NominationPools CounterForMetadata (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// The range of component `n` is `[1, 256]`. - fn set_metadata(n: u32, ) -> Weight { + fn set_metadata(_n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `563` // Estimated: `8909` - // Minimum execution time: 15_181 nanoseconds. - Weight::from_ref_time(15_743_624) - .saturating_add(Weight::from_proof_size(8909)) - // Standard Error: 79 - .saturating_add(Weight::from_ref_time(687).saturating_mul(n.into())) + // Minimum execution time: 14_000_000 picoseconds. + Weight::from_parts(15_348_240, 8909) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -485,9 +464,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 7_434 nanoseconds. - Weight::from_ref_time(7_643_000) - .saturating_add(Weight::from_proof_size(0)) + // Minimum execution time: 7_000_000 picoseconds. + Weight::from_parts(8_000_000, 0) .saturating_add(T::DbWeight::get().writes(6_u64)) } /// Storage: NominationPools BondedPools (r:1 w:1) @@ -496,9 +474,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `563` // Estimated: `3685` - // Minimum execution time: 20_567 nanoseconds. - Weight::from_ref_time(20_872_000) - .saturating_add(Weight::from_proof_size(3685)) + // Minimum execution time: 19_000_000 picoseconds. + Weight::from_parts(20_000_000, 3685) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -524,9 +501,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `2140` // Estimated: `29455` - // Minimum execution time: 67_795 nanoseconds. - Weight::from_ref_time(68_417_000) - .saturating_add(Weight::from_proof_size(29455)) + // Minimum execution time: 65_000_000 picoseconds. + Weight::from_parts(68_000_000, 29455) .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -542,9 +518,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `866` // Estimated: `12324` - // Minimum execution time: 34_664 nanoseconds. - Weight::from_ref_time(35_281_000) - .saturating_add(Weight::from_proof_size(12324)) + // Minimum execution time: 35_000_000 picoseconds. + Weight::from_parts(37_000_000, 12324) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -554,9 +529,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `603` // Estimated: `3685` - // Minimum execution time: 19_775 nanoseconds. - Weight::from_ref_time(20_170_000) - .saturating_add(Weight::from_proof_size(3685)) + // Minimum execution time: 19_000_000 picoseconds. + Weight::from_parts(20_000_000, 3685) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -566,9 +540,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `563` // Estimated: `3685` - // Minimum execution time: 20_794 nanoseconds. - Weight::from_ref_time(21_279_000) - .saturating_add(Weight::from_proof_size(3685)) + // Minimum execution time: 20_000_000 picoseconds. + Weight::from_parts(20_000_000, 3685) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -580,9 +553,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `542` // Estimated: `7208` - // Minimum execution time: 15_620 nanoseconds. - Weight::from_ref_time(15_867_000) - .saturating_add(Weight::from_proof_size(7208)) + // Minimum execution time: 14_000_000 picoseconds. + Weight::from_parts(15_000_000, 7208) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -598,9 +570,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1096` // Estimated: `12324` - // Minimum execution time: 49_068 nanoseconds. - Weight::from_ref_time(49_847_000) - .saturating_add(Weight::from_proof_size(12324)) + // Minimum execution time: 51_000_000 picoseconds. + Weight::from_parts(53_000_000, 12324) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -640,9 +611,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3650` // Estimated: `52435` - // Minimum execution time: 162_803 nanoseconds. - Weight::from_ref_time(163_826_000) - .saturating_add(Weight::from_proof_size(52435)) + // Minimum execution time: 179_000_000 picoseconds. + Weight::from_parts(184_000_000, 52435) .saturating_add(RocksDbWeight::get().reads(18_u64)) .saturating_add(RocksDbWeight::get().writes(12_u64)) } @@ -670,9 +640,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3692` // Estimated: `49070` - // Minimum execution time: 158_990 nanoseconds. - Weight::from_ref_time(160_063_000) - .saturating_add(Weight::from_proof_size(49070)) + // Minimum execution time: 175_000_000 picoseconds. + Weight::from_parts(180_000_000, 49070) .saturating_add(RocksDbWeight::get().reads(15_u64)) .saturating_add(RocksDbWeight::get().writes(12_u64)) } @@ -702,9 +671,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3757` // Estimated: `52576` - // Minimum execution time: 178_597 nanoseconds. - Weight::from_ref_time(179_922_000) - .saturating_add(Weight::from_proof_size(52576)) + // Minimum execution time: 201_000_000 picoseconds. + Weight::from_parts(206_000_000, 52576) .saturating_add(RocksDbWeight::get().reads(16_u64)) .saturating_add(RocksDbWeight::get().writes(13_u64)) } @@ -724,9 +692,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1331` // Estimated: `19532` - // Minimum execution time: 62_735 nanoseconds. - Weight::from_ref_time(63_448_000) - .saturating_add(Weight::from_proof_size(19532)) + // Minimum execution time: 66_000_000 picoseconds. + Weight::from_parts(68_000_000, 19532) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -764,9 +731,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3935` // Estimated: `82816` - // Minimum execution time: 164_570 nanoseconds. - Weight::from_ref_time(166_034_000) - .saturating_add(Weight::from_proof_size(82816)) + // Minimum execution time: 182_000_000 picoseconds. + Weight::from_parts(185_000_000, 82816) .saturating_add(RocksDbWeight::get().reads(19_u64)) .saturating_add(RocksDbWeight::get().writes(13_u64)) } @@ -785,11 +751,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1783` // Estimated: `18031` - // Minimum execution time: 55_830 nanoseconds. - Weight::from_ref_time(57_099_319) - .saturating_add(Weight::from_proof_size(18031)) - // Standard Error: 697 - .saturating_add(Weight::from_ref_time(5_710).saturating_mul(s.into())) + // Minimum execution time: 55_000_000 picoseconds. + Weight::from_parts(57_002_753, 18031) + // Standard Error: 1_793 + .saturating_add(Weight::from_parts(16_018, 0).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -814,13 +779,14 @@ impl WeightInfo for () { /// Storage: NominationPools ClaimPermissions (r:0 w:1) /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_update(_s: u32, ) -> Weight { + fn withdraw_unbonded_update(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `2307` // Estimated: `54662` - // Minimum execution time: 108_207 nanoseconds. - Weight::from_ref_time(110_862_821) - .saturating_add(Weight::from_proof_size(54662)) + // Minimum execution time: 115_000_000 picoseconds. + Weight::from_parts(120_237_544, 54662) + // Standard Error: 1_910 + .saturating_add(Weight::from_parts(7_036, 0).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(8_u64)) } @@ -867,13 +833,14 @@ impl WeightInfo for () { /// Storage: NominationPools ClaimPermissions (r:0 w:1) /// Proof: NominationPools ClaimPermissions (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) /// The range of component `s` is `[0, 100]`. - fn withdraw_unbonded_kill(_s: u32, ) -> Weight { + fn withdraw_unbonded_kill(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `2694` // Estimated: `87714` - // Minimum execution time: 172_141 nanoseconds. - Weight::from_ref_time(176_082_851) - .saturating_add(Weight::from_proof_size(87714)) + // Minimum execution time: 193_000_000 picoseconds. + Weight::from_parts(198_945_137, 87714) + // Standard Error: 3_367 + .saturating_add(Weight::from_parts(38_991, 0).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(20_u64)) .saturating_add(RocksDbWeight::get().writes(18_u64)) } @@ -923,9 +890,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1321` // Estimated: `51410` - // Minimum execution time: 149_802 nanoseconds. - Weight::from_ref_time(150_736_000) - .saturating_add(Weight::from_proof_size(51410)) + // Minimum execution time: 169_000_000 picoseconds. + Weight::from_parts(175_000_000, 51410) .saturating_add(RocksDbWeight::get().reads(21_u64)) .saturating_add(RocksDbWeight::get().writes(15_u64)) } @@ -958,11 +924,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1913` // Estimated: `33934 + n * (2520 ±0)` - // Minimum execution time: 70_145 nanoseconds. - Weight::from_ref_time(70_129_523) - .saturating_add(Weight::from_proof_size(33934)) - // Standard Error: 6_775 - .saturating_add(Weight::from_ref_time(1_506_411).saturating_mul(n.into())) + // Minimum execution time: 72_000_000 picoseconds. + Weight::from_parts(72_507_807, 33934) + // Standard Error: 9_754 + .saturating_add(Weight::from_parts(1_834_936, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(12_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(RocksDbWeight::get().writes(5_u64)) @@ -978,9 +943,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1502` // Estimated: `11778` - // Minimum execution time: 36_847 nanoseconds. - Weight::from_ref_time(37_462_000) - .saturating_add(Weight::from_proof_size(11778)) + // Minimum execution time: 36_000_000 picoseconds. + Weight::from_parts(37_000_000, 11778) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -991,15 +955,12 @@ impl WeightInfo for () { /// Storage: NominationPools CounterForMetadata (r:1 w:1) /// Proof: NominationPools CounterForMetadata (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// The range of component `n` is `[1, 256]`. - fn set_metadata(n: u32, ) -> Weight { + fn set_metadata(_n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `563` // Estimated: `8909` - // Minimum execution time: 15_181 nanoseconds. - Weight::from_ref_time(15_743_624) - .saturating_add(Weight::from_proof_size(8909)) - // Standard Error: 79 - .saturating_add(Weight::from_ref_time(687).saturating_mul(n.into())) + // Minimum execution time: 14_000_000 picoseconds. + Weight::from_parts(15_348_240, 8909) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -1019,9 +980,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 7_434 nanoseconds. - Weight::from_ref_time(7_643_000) - .saturating_add(Weight::from_proof_size(0)) + // Minimum execution time: 7_000_000 picoseconds. + Weight::from_parts(8_000_000, 0) .saturating_add(RocksDbWeight::get().writes(6_u64)) } /// Storage: NominationPools BondedPools (r:1 w:1) @@ -1030,9 +990,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `563` // Estimated: `3685` - // Minimum execution time: 20_567 nanoseconds. - Weight::from_ref_time(20_872_000) - .saturating_add(Weight::from_proof_size(3685)) + // Minimum execution time: 19_000_000 picoseconds. + Weight::from_parts(20_000_000, 3685) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1058,9 +1017,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `2140` // Estimated: `29455` - // Minimum execution time: 67_795 nanoseconds. - Weight::from_ref_time(68_417_000) - .saturating_add(Weight::from_proof_size(29455)) + // Minimum execution time: 65_000_000 picoseconds. + Weight::from_parts(68_000_000, 29455) .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -1076,9 +1034,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `866` // Estimated: `12324` - // Minimum execution time: 34_664 nanoseconds. - Weight::from_ref_time(35_281_000) - .saturating_add(Weight::from_proof_size(12324)) + // Minimum execution time: 35_000_000 picoseconds. + Weight::from_parts(37_000_000, 12324) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -1088,9 +1045,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `603` // Estimated: `3685` - // Minimum execution time: 19_775 nanoseconds. - Weight::from_ref_time(20_170_000) - .saturating_add(Weight::from_proof_size(3685)) + // Minimum execution time: 19_000_000 picoseconds. + Weight::from_parts(20_000_000, 3685) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1100,9 +1056,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `563` // Estimated: `3685` - // Minimum execution time: 20_794 nanoseconds. - Weight::from_ref_time(21_279_000) - .saturating_add(Weight::from_proof_size(3685)) + // Minimum execution time: 20_000_000 picoseconds. + Weight::from_parts(20_000_000, 3685) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1114,9 +1069,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `542` // Estimated: `7208` - // Minimum execution time: 15_620 nanoseconds. - Weight::from_ref_time(15_867_000) - .saturating_add(Weight::from_proof_size(7208)) + // Minimum execution time: 14_000_000 picoseconds. + Weight::from_parts(15_000_000, 7208) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1132,9 +1086,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1096` // Estimated: `12324` - // Minimum execution time: 49_068 nanoseconds. - Weight::from_ref_time(49_847_000) - .saturating_add(Weight::from_proof_size(12324)) + // Minimum execution time: 51_000_000 picoseconds. + Weight::from_parts(53_000_000, 12324) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } From eb819daa68ba4758917ba49d2fa33c98c9d2dc01 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 6 Mar 2023 20:04:36 +0700 Subject: [PATCH 73/90] comment --- frame/nomination-pools/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 51cb3a6ab5415..3e3dedff3c78b 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2376,11 +2376,11 @@ pub mod pallet { /// Update the roles of the pool. /// - /// The root is the only entity that can change any of the roles, including itself, - /// excluding the depositor, who can never change. + /// The root is the only entity that can change any of the roles, including itself, excluding + /// the depositor, who can never change. /// - /// It emits an event, notifying UIs of the role change. This event is quite relevant to - /// most pool members and they should be informed of changes to pool roles. + /// It emits an event, notifying UIs of the role change. This event is quite relevant to most + /// pool members and they should be informed of changes to pool roles. #[pallet::call_index(12)] #[pallet::weight(T::WeightInfo::update_roles())] pub fn update_roles( From 68f6706c5d34192f07d6b7f0122f4c285d25b9d2 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 6 Mar 2023 14:49:30 +0000 Subject: [PATCH 74/90] ".git/.scripts/commands/fmt/fmt.sh" --- frame/nomination-pools/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 3e3dedff3c78b..51cb3a6ab5415 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2376,11 +2376,11 @@ pub mod pallet { /// Update the roles of the pool. /// - /// The root is the only entity that can change any of the roles, including itself, excluding - /// the depositor, who can never change. + /// The root is the only entity that can change any of the roles, including itself, + /// excluding the depositor, who can never change. /// - /// It emits an event, notifying UIs of the role change. This event is quite relevant to most - /// pool members and they should be informed of changes to pool roles. + /// It emits an event, notifying UIs of the role change. This event is quite relevant to + /// most pool members and they should be informed of changes to pool roles. #[pallet::call_index(12)] #[pallet::weight(T::WeightInfo::update_roles())] pub fn update_roles( From 41b8278f3f9db502a5536d62bb4ccbe442298b1e Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Wed, 8 Mar 2023 11:59:07 +0700 Subject: [PATCH 75/90] revert clippy suggestions on old migrations --- frame/nomination-pools/src/migration.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 636e5aec74352..6221f5681941c 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -238,7 +238,7 @@ pub mod v2 { let mut sum_paid_out = BalanceOf::::zero(); members - .iter() + .into_iter() .filter_map(|(who, points)| { let bonded_pool = match BondedPool::::get(id) { Some(x) => x, @@ -271,7 +271,7 @@ pub mod v2 { .for_each(|(who, last_claim)| { let outcome = T::Currency::transfer( &reward_account, - who, + &who, last_claim, ExistenceRequirement::KeepAlive, ); @@ -414,13 +414,13 @@ pub mod v3 { Metadata::::iter_keys() .filter(|id| { metadata_iterated += 1; - !BondedPools::::contains_key(id) + !BondedPools::::contains_key(&id) }) .collect::>() .into_iter() .for_each(|id| { metadata_removed += 1; - Metadata::::remove(id); + Metadata::::remove(&id); }); current.put::>(); // metadata iterated + bonded pools read + a storage version read From 5969769d9c19bdc764634d8e9d28120b4f2fbfd6 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 8 Mar 2023 17:24:52 +0000 Subject: [PATCH 76/90] ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_nomination_pools --- frame/nomination-pools/src/weights.rs | 253 ++++++++++++++------------ 1 file changed, 134 insertions(+), 119 deletions(-) diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index fa6e4e0e00656..cf0048fa48dd9 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -1,33 +1,44 @@ +// This file is part of Substrate. + +// Copyright (C) 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. //! Autogenerated weights for pallet_nomination_pools //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-08, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Ross-MacBook-Pro-2.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: -// target/release/substrate +// target/production/substrate // benchmark // pallet -// --execution -// wasm -// --wasm-execution -// compiled -// --dev -// --pallet -// pallet-nomination-pools -// --extrinsic -// * -// --steps -// 50 -// --repeat -// 20 -// --output -// frame/nomination-pools/src/weights.rs -// --template -// .maintain/frame-weight-template.hbs +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/substrate/.git/.artifacts/bench.json +// --pallet=pallet_nomination_pools +// --chain=dev +// --header=./HEADER-APACHE2 +// --output=./frame/nomination-pools/src/weights.rs +// --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -95,8 +106,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3650` // Estimated: `52435` - // Minimum execution time: 179_000_000 picoseconds. - Weight::from_parts(184_000_000, 52435) + // Minimum execution time: 160_401_000 picoseconds. + Weight::from_parts(161_798_000, 52435) .saturating_add(T::DbWeight::get().reads(18_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)) } @@ -124,8 +135,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3692` // Estimated: `49070` - // Minimum execution time: 175_000_000 picoseconds. - Weight::from_parts(180_000_000, 49070) + // Minimum execution time: 157_668_000 picoseconds. + Weight::from_parts(161_129_000, 49070) .saturating_add(T::DbWeight::get().reads(15_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)) } @@ -155,8 +166,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3757` // Estimated: `52576` - // Minimum execution time: 201_000_000 picoseconds. - Weight::from_parts(206_000_000, 52576) + // Minimum execution time: 176_034_000 picoseconds. + Weight::from_parts(176_956_000, 52576) .saturating_add(T::DbWeight::get().reads(16_u64)) .saturating_add(T::DbWeight::get().writes(13_u64)) } @@ -176,8 +187,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1331` // Estimated: `19532` - // Minimum execution time: 66_000_000 picoseconds. - Weight::from_parts(68_000_000, 19532) + // Minimum execution time: 61_551_000 picoseconds. + Weight::from_parts(62_201_000, 19532) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -215,8 +226,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `3935` // Estimated: `82816` - // Minimum execution time: 182_000_000 picoseconds. - Weight::from_parts(185_000_000, 82816) + // Minimum execution time: 162_755_000 picoseconds. + Weight::from_parts(163_518_000, 82816) .saturating_add(T::DbWeight::get().reads(19_u64)) .saturating_add(T::DbWeight::get().writes(13_u64)) } @@ -235,10 +246,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1783` // Estimated: `18031` - // Minimum execution time: 55_000_000 picoseconds. - Weight::from_parts(57_002_753, 18031) - // Standard Error: 1_793 - .saturating_add(Weight::from_parts(16_018, 0).saturating_mul(s.into())) + // Minimum execution time: 54_752_000 picoseconds. + Weight::from_parts(56_248_171, 18031) + // Standard Error: 1_891 + .saturating_add(Weight::from_parts(4_767, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -267,10 +278,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `2307` // Estimated: `54662` - // Minimum execution time: 115_000_000 picoseconds. - Weight::from_parts(120_237_544, 54662) - // Standard Error: 1_910 - .saturating_add(Weight::from_parts(7_036, 0).saturating_mul(s.into())) + // Minimum execution time: 106_166_000 picoseconds. + Weight::from_parts(107_806_373, 54662) + // Standard Error: 6_985 + .saturating_add(Weight::from_parts(18_449, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } @@ -321,10 +332,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `2694` // Estimated: `87714` - // Minimum execution time: 193_000_000 picoseconds. - Weight::from_parts(198_945_137, 87714) - // Standard Error: 3_367 - .saturating_add(Weight::from_parts(38_991, 0).saturating_mul(s.into())) + // Minimum execution time: 170_047_000 picoseconds. + Weight::from_parts(172_125_770, 87714) + // Standard Error: 2_599 + .saturating_add(Weight::from_parts(9_964, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(20_u64)) .saturating_add(T::DbWeight::get().writes(18_u64)) } @@ -374,8 +385,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1321` // Estimated: `51410` - // Minimum execution time: 169_000_000 picoseconds. - Weight::from_parts(175_000_000, 51410) + // Minimum execution time: 149_672_000 picoseconds. + Weight::from_parts(153_613_000, 51410) .saturating_add(T::DbWeight::get().reads(21_u64)) .saturating_add(T::DbWeight::get().writes(15_u64)) } @@ -408,10 +419,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1913` // Estimated: `33934 + n * (2520 ±0)` - // Minimum execution time: 72_000_000 picoseconds. - Weight::from_parts(72_507_807, 33934) - // Standard Error: 9_754 - .saturating_add(Weight::from_parts(1_834_936, 0).saturating_mul(n.into())) + // Minimum execution time: 68_892_000 picoseconds. + Weight::from_parts(69_062_946, 33934) + // Standard Error: 6_448 + .saturating_add(Weight::from_parts(1_422_774, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(12_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(T::DbWeight::get().writes(5_u64)) @@ -427,8 +438,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1502` // Estimated: `11778` - // Minimum execution time: 36_000_000 picoseconds. - Weight::from_parts(37_000_000, 11778) + // Minimum execution time: 36_447_000 picoseconds. + Weight::from_parts(36_837_000, 11778) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -439,12 +450,14 @@ impl WeightInfo for SubstrateWeight { /// Storage: NominationPools CounterForMetadata (r:1 w:1) /// Proof: NominationPools CounterForMetadata (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// The range of component `n` is `[1, 256]`. - fn set_metadata(_n: u32, ) -> Weight { + fn set_metadata(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `563` // Estimated: `8909` - // Minimum execution time: 14_000_000 picoseconds. - Weight::from_parts(15_348_240, 8909) + // Minimum execution time: 15_221_000 picoseconds. + Weight::from_parts(15_632_286, 8909) + // Standard Error: 343 + .saturating_add(Weight::from_parts(2_299, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -464,8 +477,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(8_000_000, 0) + // Minimum execution time: 7_409_000 picoseconds. + Weight::from_parts(7_702_000, 0) .saturating_add(T::DbWeight::get().writes(6_u64)) } /// Storage: NominationPools BondedPools (r:1 w:1) @@ -474,8 +487,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `563` // Estimated: `3685` - // Minimum execution time: 19_000_000 picoseconds. - Weight::from_parts(20_000_000, 3685) + // Minimum execution time: 20_451_000 picoseconds. + Weight::from_parts(20_703_000, 3685) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -501,8 +514,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `2140` // Estimated: `29455` - // Minimum execution time: 65_000_000 picoseconds. - Weight::from_parts(68_000_000, 29455) + // Minimum execution time: 66_001_000 picoseconds. + Weight::from_parts(66_894_000, 29455) .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -518,8 +531,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `866` // Estimated: `12324` - // Minimum execution time: 35_000_000 picoseconds. - Weight::from_parts(37_000_000, 12324) + // Minimum execution time: 34_011_000 picoseconds. + Weight::from_parts(34_521_000, 12324) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -529,8 +542,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `603` // Estimated: `3685` - // Minimum execution time: 19_000_000 picoseconds. - Weight::from_parts(20_000_000, 3685) + // Minimum execution time: 19_524_000 picoseconds. + Weight::from_parts(19_855_000, 3685) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -540,8 +553,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `563` // Estimated: `3685` - // Minimum execution time: 20_000_000 picoseconds. - Weight::from_parts(20_000_000, 3685) + // Minimum execution time: 20_457_000 picoseconds. + Weight::from_parts(20_698_000, 3685) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -553,8 +566,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `542` // Estimated: `7208` - // Minimum execution time: 14_000_000 picoseconds. - Weight::from_parts(15_000_000, 7208) + // Minimum execution time: 15_183_000 picoseconds. + Weight::from_parts(15_597_000, 7208) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -570,8 +583,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1096` // Estimated: `12324` - // Minimum execution time: 51_000_000 picoseconds. - Weight::from_parts(53_000_000, 12324) + // Minimum execution time: 48_957_000 picoseconds. + Weight::from_parts(50_207_000, 12324) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -611,8 +624,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3650` // Estimated: `52435` - // Minimum execution time: 179_000_000 picoseconds. - Weight::from_parts(184_000_000, 52435) + // Minimum execution time: 160_401_000 picoseconds. + Weight::from_parts(161_798_000, 52435) .saturating_add(RocksDbWeight::get().reads(18_u64)) .saturating_add(RocksDbWeight::get().writes(12_u64)) } @@ -640,8 +653,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3692` // Estimated: `49070` - // Minimum execution time: 175_000_000 picoseconds. - Weight::from_parts(180_000_000, 49070) + // Minimum execution time: 157_668_000 picoseconds. + Weight::from_parts(161_129_000, 49070) .saturating_add(RocksDbWeight::get().reads(15_u64)) .saturating_add(RocksDbWeight::get().writes(12_u64)) } @@ -671,8 +684,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3757` // Estimated: `52576` - // Minimum execution time: 201_000_000 picoseconds. - Weight::from_parts(206_000_000, 52576) + // Minimum execution time: 176_034_000 picoseconds. + Weight::from_parts(176_956_000, 52576) .saturating_add(RocksDbWeight::get().reads(16_u64)) .saturating_add(RocksDbWeight::get().writes(13_u64)) } @@ -692,8 +705,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1331` // Estimated: `19532` - // Minimum execution time: 66_000_000 picoseconds. - Weight::from_parts(68_000_000, 19532) + // Minimum execution time: 61_551_000 picoseconds. + Weight::from_parts(62_201_000, 19532) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -731,8 +744,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3935` // Estimated: `82816` - // Minimum execution time: 182_000_000 picoseconds. - Weight::from_parts(185_000_000, 82816) + // Minimum execution time: 162_755_000 picoseconds. + Weight::from_parts(163_518_000, 82816) .saturating_add(RocksDbWeight::get().reads(19_u64)) .saturating_add(RocksDbWeight::get().writes(13_u64)) } @@ -751,10 +764,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1783` // Estimated: `18031` - // Minimum execution time: 55_000_000 picoseconds. - Weight::from_parts(57_002_753, 18031) - // Standard Error: 1_793 - .saturating_add(Weight::from_parts(16_018, 0).saturating_mul(s.into())) + // Minimum execution time: 54_752_000 picoseconds. + Weight::from_parts(56_248_171, 18031) + // Standard Error: 1_891 + .saturating_add(Weight::from_parts(4_767, 0).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -783,10 +796,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `2307` // Estimated: `54662` - // Minimum execution time: 115_000_000 picoseconds. - Weight::from_parts(120_237_544, 54662) - // Standard Error: 1_910 - .saturating_add(Weight::from_parts(7_036, 0).saturating_mul(s.into())) + // Minimum execution time: 106_166_000 picoseconds. + Weight::from_parts(107_806_373, 54662) + // Standard Error: 6_985 + .saturating_add(Weight::from_parts(18_449, 0).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(8_u64)) } @@ -837,10 +850,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `2694` // Estimated: `87714` - // Minimum execution time: 193_000_000 picoseconds. - Weight::from_parts(198_945_137, 87714) - // Standard Error: 3_367 - .saturating_add(Weight::from_parts(38_991, 0).saturating_mul(s.into())) + // Minimum execution time: 170_047_000 picoseconds. + Weight::from_parts(172_125_770, 87714) + // Standard Error: 2_599 + .saturating_add(Weight::from_parts(9_964, 0).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(20_u64)) .saturating_add(RocksDbWeight::get().writes(18_u64)) } @@ -890,8 +903,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1321` // Estimated: `51410` - // Minimum execution time: 169_000_000 picoseconds. - Weight::from_parts(175_000_000, 51410) + // Minimum execution time: 149_672_000 picoseconds. + Weight::from_parts(153_613_000, 51410) .saturating_add(RocksDbWeight::get().reads(21_u64)) .saturating_add(RocksDbWeight::get().writes(15_u64)) } @@ -924,10 +937,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1913` // Estimated: `33934 + n * (2520 ±0)` - // Minimum execution time: 72_000_000 picoseconds. - Weight::from_parts(72_507_807, 33934) - // Standard Error: 9_754 - .saturating_add(Weight::from_parts(1_834_936, 0).saturating_mul(n.into())) + // Minimum execution time: 68_892_000 picoseconds. + Weight::from_parts(69_062_946, 33934) + // Standard Error: 6_448 + .saturating_add(Weight::from_parts(1_422_774, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(12_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(RocksDbWeight::get().writes(5_u64)) @@ -943,8 +956,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1502` // Estimated: `11778` - // Minimum execution time: 36_000_000 picoseconds. - Weight::from_parts(37_000_000, 11778) + // Minimum execution time: 36_447_000 picoseconds. + Weight::from_parts(36_837_000, 11778) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -955,12 +968,14 @@ impl WeightInfo for () { /// Storage: NominationPools CounterForMetadata (r:1 w:1) /// Proof: NominationPools CounterForMetadata (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// The range of component `n` is `[1, 256]`. - fn set_metadata(_n: u32, ) -> Weight { + fn set_metadata(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `563` // Estimated: `8909` - // Minimum execution time: 14_000_000 picoseconds. - Weight::from_parts(15_348_240, 8909) + // Minimum execution time: 15_221_000 picoseconds. + Weight::from_parts(15_632_286, 8909) + // Standard Error: 343 + .saturating_add(Weight::from_parts(2_299, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -980,8 +995,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(8_000_000, 0) + // Minimum execution time: 7_409_000 picoseconds. + Weight::from_parts(7_702_000, 0) .saturating_add(RocksDbWeight::get().writes(6_u64)) } /// Storage: NominationPools BondedPools (r:1 w:1) @@ -990,8 +1005,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `563` // Estimated: `3685` - // Minimum execution time: 19_000_000 picoseconds. - Weight::from_parts(20_000_000, 3685) + // Minimum execution time: 20_451_000 picoseconds. + Weight::from_parts(20_703_000, 3685) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1017,8 +1032,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `2140` // Estimated: `29455` - // Minimum execution time: 65_000_000 picoseconds. - Weight::from_parts(68_000_000, 29455) + // Minimum execution time: 66_001_000 picoseconds. + Weight::from_parts(66_894_000, 29455) .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -1034,8 +1049,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `866` // Estimated: `12324` - // Minimum execution time: 35_000_000 picoseconds. - Weight::from_parts(37_000_000, 12324) + // Minimum execution time: 34_011_000 picoseconds. + Weight::from_parts(34_521_000, 12324) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -1045,8 +1060,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `603` // Estimated: `3685` - // Minimum execution time: 19_000_000 picoseconds. - Weight::from_parts(20_000_000, 3685) + // Minimum execution time: 19_524_000 picoseconds. + Weight::from_parts(19_855_000, 3685) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1056,8 +1071,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `563` // Estimated: `3685` - // Minimum execution time: 20_000_000 picoseconds. - Weight::from_parts(20_000_000, 3685) + // Minimum execution time: 20_457_000 picoseconds. + Weight::from_parts(20_698_000, 3685) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1069,8 +1084,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `542` // Estimated: `7208` - // Minimum execution time: 14_000_000 picoseconds. - Weight::from_parts(15_000_000, 7208) + // Minimum execution time: 15_183_000 picoseconds. + Weight::from_parts(15_597_000, 7208) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1086,8 +1101,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1096` // Estimated: `12324` - // Minimum execution time: 51_000_000 picoseconds. - Weight::from_parts(53_000_000, 12324) + // Minimum execution time: 48_957_000 picoseconds. + Weight::from_parts(50_207_000, 12324) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } From 14519c309866c25975223fafe9b5730260f04717 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 13 Mar 2023 13:57:05 +0700 Subject: [PATCH 77/90] add InitialGlobalMaxCommission --- bin/node/runtime/src/lib.rs | 2 ++ client/executor/wasmtime/README.md | 2 +- .../nomination-pools/benchmarking/src/mock.rs | 2 ++ frame/nomination-pools/src/lib.rs | 28 +++++++++++-------- frame/nomination-pools/src/migration.rs | 3 +- frame/nomination-pools/src/mock.rs | 2 ++ .../nomination-pools/test-staking/src/mock.rs | 2 ++ 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 614dbc4d958c8..e1fb10fc2c849 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -765,6 +765,7 @@ parameter_types! { pub const PostUnbondPoolsWindow: u32 = 4; pub const NominationPoolsPalletId: PalletId = PalletId(*b"py/nopls"); pub const MaxPointsToBalance: u8 = 10; + pub const InitialGlobalMaxCommission: Perbill = Perbill::zero(); } use sp_runtime::traits::Convert; @@ -794,6 +795,7 @@ impl pallet_nomination_pools::Config for Runtime { type MaxUnbonding = ConstU32<8>; type PalletId = NominationPoolsPalletId; type MaxPointsToBalance = MaxPointsToBalance; + type InitialGlobalMaxCommission = InitialGlobalMaxCommission; } parameter_types! { diff --git a/client/executor/wasmtime/README.md b/client/executor/wasmtime/README.md index 3e9ac0bddbdc1..399b72e39c477 100644 --- a/client/executor/wasmtime/README.md +++ b/client/executor/wasmtime/README.md @@ -1 +1 @@ -License: GPL-3.0-or-later WITH Classpath-exception-2.0 \ No newline at end of file +mcoLicense: GPL-3.0-or-later WITH Classpath-exception-2.0 \ No newline at end of file diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index 4a1a52868e367..0ddba4f72ccd2 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -151,6 +151,7 @@ parameter_types! { pub static PostUnbondingPoolsWindow: u32 = 10; pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls"); pub const MaxPointsToBalance: u8 = 10; + pub const InitialGlobalMaxCommission: Perbill = Perbill::zero(); } impl pallet_nomination_pools::Config for Runtime { @@ -166,6 +167,7 @@ impl pallet_nomination_pools::Config for Runtime { type MaxUnbonding = ConstU32<8>; type PalletId = PoolsPalletId; type MaxPointsToBalance = MaxPointsToBalance; + type InitialGlobalMaxCommission = InitialGlobalMaxCommission; } impl crate::Config for Runtime {} diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 51cb3a6ab5415..20bd1172504c3 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1545,6 +1545,9 @@ pub mod pallet { /// The maximum number of simultaneous unbonding chunks that can exist per member. type MaxUnbonding: Get; + + /// The initial value for global maximum commission. Used in pool migration to v4. + type InitialGlobalMaxCommission: Get; } /// Minimum amount to bond to join a pool. @@ -2803,16 +2806,14 @@ impl Pallet { // // In scenarios where commission is 100%, `pending_rewards` will be zero. We therefore check // if there is a non-zero payout to be transferred. - if pending_rewards > Zero::zero() { - T::Currency::transfer( - &bonded_pool.reward_account(), - member_account, - pending_rewards, - // defensive: the depositor has put existential deposit into the pool and it stays - // untouched, reward account shall not die. - ExistenceRequirement::KeepAlive, - )?; - } + T::Currency::transfer( + &bonded_pool.reward_account(), + member_account, + pending_rewards, + // defensive: the depositor has put existential deposit into the pool and it stays + // untouched, reward account shall not die. + ExistenceRequirement::KeepAlive, + )?; Self::deposit_event(Event::::PaidOut { member: member_account.clone(), @@ -3138,7 +3139,12 @@ impl Pallet { assert!( total_balance >= bonded_balance + sum_unbonding_balance, - "faulty pool: {pool_id:?} / {_pool:?}, total_balance {total_balance:?} >= bonded_balance {bonded_balance:?} + sum_unbonding_balance {sum_unbonding_balance:?}" + "faulty pool: {:?} / {:?}, total_balance {:?} >= bonded_balance {:?} + sum_unbonding_balance {:?}", + pool_id, + _pool, + total_balance, + bonded_balance, + sum_unbonding_balance ); } diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 6221f5681941c..87daa4242a63b 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -494,7 +494,7 @@ pub mod v4 { ); if current == 4 && onchain == 3 { - GlobalMaxCommission::::set(Some(Zero::zero())); + GlobalMaxCommission::::set(Some(T::InitialGlobalMaxCommission::get())); log!(info, "Set initial global max commission to 0%"); let mut translated = 0u64; @@ -534,6 +534,7 @@ pub mod v4 { inner.commission.throttle_from.is_none()), "a commission value has been incorrectly set" ); + ensure!(GlobalMaxCommission::::get(), InitialGlobalMaxCommission::::get()); ensure!(Pallet::::on_chain_storage_version() == 4, "wrong storage version"); Ok(()) } diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index c6b094f0aa0f1..2bff188afd46d 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -217,6 +217,7 @@ parameter_types! { pub static MaxMetadataLen: u32 = 2; pub static CheckLevel: u8 = 255; pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls"); + pub const InitialGlobalMaxCommission: Perbill = Perbill::zero(); } impl pools::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -231,6 +232,7 @@ impl pools::Config for Runtime { type MaxMetadataLen = MaxMetadataLen; type MaxUnbonding = MaxUnbonding; type MaxPointsToBalance = frame_support::traits::ConstU8<10>; + type InitialGlobalMaxCommission = InitialGlobalMaxCommission; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index 0550c8e0ca708..0648b2a6115c8 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -165,6 +165,7 @@ impl Convert for U256ToBalance { parameter_types! { pub const PostUnbondingPoolsWindow: u32 = 10; pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls"); + pub const InitialGlobalMaxCommission: Perbill = Perbill::zero(); } impl pallet_nomination_pools::Config for Runtime { @@ -180,6 +181,7 @@ impl pallet_nomination_pools::Config for Runtime { type MaxUnbonding = ConstU32<8>; type MaxPointsToBalance = ConstU8<10>; type PalletId = PoolsPalletId; + type InitialGlobalMaxCommission = InitialGlobalMaxCommission; } type Block = frame_system::mocking::MockBlock; From d30b5a1849bb08f649e8e9cf423129db3d892450 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 13 Mar 2023 14:08:00 +0700 Subject: [PATCH 78/90] fix migration --- frame/nomination-pools/src/migration.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 87daa4242a63b..60c56056c28db 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -534,7 +534,10 @@ pub mod v4 { inner.commission.throttle_from.is_none()), "a commission value has been incorrectly set" ); - ensure!(GlobalMaxCommission::::get(), InitialGlobalMaxCommission::::get()); + ensure!( + GlobalMaxCommission::::get() == Some(T::InitialGlobalMaxCommission::get()), + "global maximum commission error" + ); ensure!(Pallet::::on_chain_storage_version() == 4, "wrong storage version"); Ok(()) } From 8dcca041d28b21cf4adf5fed11fa5e54f9739a15 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 13 Mar 2023 20:14:05 +0700 Subject: [PATCH 79/90] reward counter comments & explanations --- frame/nomination-pools/src/lib.rs | 39 +++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 20bd1172504c3..90b6845c58020 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -259,12 +259,14 @@ //! //! ### Reward pool //! -//! When a pool is first bonded it sets up an deterministic, inaccessible account as its reward -//! destination. -//! -//! The reward pool is not really a pool anymore, as it does not track points anymore. Instead, it -//! tracks, a virtual value called `reward_counter`, among a few other values including commission -//! counters. +//! When a pool is first bonded it sets up a deterministic, inaccessible account as its reward +//! destination. This reward account combined with `RewardPool` compose a reward pool. +//! +//! Reward pools are completely separate entities to bonded pools. Along with its account, a reward +//! pool also tracks its outstanding and claimed rewards as counters, in addition to pending and +//! claimed commission. These counters are updated with `RewardPool::update_records`. The current +//! reward counter of the pool (the total outstanding rewards, in points) is also callable with the +//! `RewardPool::current_reward_counter` method. //! //! See [this link](https://hackmd.io/PFGn6wI5TbCmBYoEA_f2Uw) for an in-depth explanation of the //! reward pool mechanism. @@ -1260,7 +1262,12 @@ impl RewardPool { self.total_rewards_claimed = self.total_rewards_claimed.saturating_add(reward); } - /// Update the recorded values of the pool. + /// Update the recorded values of the reward pool. + /// + /// This function MUST be called whenever the points in the bonded pool change, AND whenever the + /// the pools commission is updated. The reason for the former is that a change in pool points + /// will alter the share of the reward balance among pool members, and the reason for the latter + /// is that a change in commission will alter the share of the reward balance among the pool. fn update_records( &mut self, id: PoolId, @@ -1271,12 +1278,19 @@ impl RewardPool { let (current_reward_counter, new_pending_commission) = self.current_reward_counter(id, bonded_points, commission)?; - + + // Store the reward counter at the time of this update. This is used in subsequent calls to + // `current_reward_counter`, whereby newly pending rewards (in points) are added to this value. self.last_recorded_reward_counter = current_reward_counter; + // Add any new pending commission that has been calculated from `current_reward_counter` to + // determine the total pending commission at the time of this update. self.total_commission_pending = self.total_commission_pending.saturating_add(new_pending_commission); + // Store the total payouts at the time of this update. Total payouts are essentially the entire + // historical balance of the reward pool, equating to the current balance + the total rewards + // that have left the pool + the total commission that has left the pool. self.last_recorded_total_payouts = balance .checked_add(&self.total_rewards_claimed.saturating_add(self.total_commission_claimed)) .ok_or(Error::::OverflowRisk)?; @@ -1293,13 +1307,18 @@ impl RewardPool { commission: Perbill, ) -> Result<(T::RewardCounter, BalanceOf), Error> { let balance = Self::current_balance(id); + + // Calculate the current payout balance. The first 3 values of this calculation added together + // represent what the balance would be if no payouts were made. The + // `last_recorded_total_payouts` is then subtracted from this value to cancel out previously + // recorded payouts, leaving only the remaining payouts that have not been claimed. let current_payout_balance = balance .saturating_add(self.total_rewards_claimed) .saturating_add(self.total_commission_claimed) .saturating_sub(self.last_recorded_total_payouts); - // Split the `current_payout_balance` into regular rewards and commission according to - // the current commission rate. + // Split the `current_payout_balance` into claimable rewards and claimable commission according + // to the current commission rate. let new_pending_commission = commission * current_payout_balance; let new_pending_rewards = current_payout_balance.saturating_sub(new_pending_commission); From d0c47681aca738d6c605ac6c05ba882b11ac3547 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 13 Mar 2023 20:14:32 +0700 Subject: [PATCH 80/90] format --- frame/nomination-pools/src/lib.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 90b6845c58020..6c5bd3c5a581c 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -261,7 +261,7 @@ //! //! When a pool is first bonded it sets up a deterministic, inaccessible account as its reward //! destination. This reward account combined with `RewardPool` compose a reward pool. -//! +//! //! Reward pools are completely separate entities to bonded pools. Along with its account, a reward //! pool also tracks its outstanding and claimed rewards as counters, in addition to pending and //! claimed commission. These counters are updated with `RewardPool::update_records`. The current @@ -1263,11 +1263,11 @@ impl RewardPool { } /// Update the recorded values of the reward pool. - /// + /// /// This function MUST be called whenever the points in the bonded pool change, AND whenever the /// the pools commission is updated. The reason for the former is that a change in pool points /// will alter the share of the reward balance among pool members, and the reason for the latter - /// is that a change in commission will alter the share of the reward balance among the pool. + /// is that a change in commission will alter the share of the reward balance among the pool. fn update_records( &mut self, id: PoolId, @@ -1278,9 +1278,10 @@ impl RewardPool { let (current_reward_counter, new_pending_commission) = self.current_reward_counter(id, bonded_points, commission)?; - + // Store the reward counter at the time of this update. This is used in subsequent calls to - // `current_reward_counter`, whereby newly pending rewards (in points) are added to this value. + // `current_reward_counter`, whereby newly pending rewards (in points) are added to this + // value. self.last_recorded_reward_counter = current_reward_counter; // Add any new pending commission that has been calculated from `current_reward_counter` to @@ -1288,9 +1289,9 @@ impl RewardPool { self.total_commission_pending = self.total_commission_pending.saturating_add(new_pending_commission); - // Store the total payouts at the time of this update. Total payouts are essentially the entire - // historical balance of the reward pool, equating to the current balance + the total rewards - // that have left the pool + the total commission that has left the pool. + // Store the total payouts at the time of this update. Total payouts are essentially the + // entire historical balance of the reward pool, equating to the current balance + the total + // rewards that have left the pool + the total commission that has left the pool. self.last_recorded_total_payouts = balance .checked_add(&self.total_rewards_claimed.saturating_add(self.total_commission_claimed)) .ok_or(Error::::OverflowRisk)?; @@ -1308,8 +1309,8 @@ impl RewardPool { ) -> Result<(T::RewardCounter, BalanceOf), Error> { let balance = Self::current_balance(id); - // Calculate the current payout balance. The first 3 values of this calculation added together - // represent what the balance would be if no payouts were made. The + // Calculate the current payout balance. The first 3 values of this calculation added + // together represent what the balance would be if no payouts were made. The // `last_recorded_total_payouts` is then subtracted from this value to cancel out previously // recorded payouts, leaving only the remaining payouts that have not been claimed. let current_payout_balance = balance @@ -1317,8 +1318,8 @@ impl RewardPool { .saturating_add(self.total_commission_claimed) .saturating_sub(self.last_recorded_total_payouts); - // Split the `current_payout_balance` into claimable rewards and claimable commission according - // to the current commission rate. + // Split the `current_payout_balance` into claimable rewards and claimable commission + // according to the current commission rate. let new_pending_commission = commission * current_payout_balance; let new_pending_rewards = current_payout_balance.saturating_sub(new_pending_commission); From 0a5924580b456e694958780654e391f941506d33 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 13 Mar 2023 20:21:57 +0700 Subject: [PATCH 81/90] add commission implementation note --- frame/nomination-pools/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 6c5bd3c5a581c..d0c3227b41e48 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -150,10 +150,13 @@ //! When a pool is dissolved, any outstanding pending commission that has not been claimed will be //! transferred to the depositor. //! -//! Implementation note: Commission is applied to rewards based on the current commission in effect -//! at the time rewards are transferred into the reward pool. This is to prevent the malicious -//! behaviour of changing the commission rate to a very high value after rewards are accumulated, -//! and thus claim an unexpectedly high chunk of the reward. +//! Implementation note: Commission is analogous to a separate member account of the pool, with its +//! own reward counter in the form of `current_pending_commission`. +//! +//! Crucially, commission is applied to rewards based on the current commission in effect at the +//! time rewards are transferred into the reward pool. This is to prevent the malicious behaviour of +//! changing the commission rate to a very high value after rewards are accumulated, and thus claim +//! an unexpectedly high chunk of the reward. //! //! ### Dismantling //! From ca3261e212ca4efc9f12eb8df5ff8e0a48d2b64e Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 13 Mar 2023 20:56:46 +0700 Subject: [PATCH 82/90] fmt --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index d0c3227b41e48..35a706d77d7ba 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -152,7 +152,7 @@ //! //! Implementation note: Commission is analogous to a separate member account of the pool, with its //! own reward counter in the form of `current_pending_commission`. -//! +//! //! Crucially, commission is applied to rewards based on the current commission in effect at the //! time rewards are transferred into the reward pool. This is to prevent the malicious behaviour of //! changing the commission rate to a very high value after rewards are accumulated, and thus claim From c8968c9363dee0c5d8d554185487a43c4cbda2ac Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 13 Mar 2023 21:14:38 +0700 Subject: [PATCH 83/90] revert InitialGlobalMaxCommission --- bin/node/runtime/src/lib.rs | 2 -- frame/nomination-pools/benchmarking/src/mock.rs | 2 -- frame/nomination-pools/src/lib.rs | 3 --- frame/nomination-pools/src/migration.rs | 6 +----- frame/nomination-pools/src/mock.rs | 2 -- frame/nomination-pools/test-staking/src/mock.rs | 2 -- 6 files changed, 1 insertion(+), 16 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index e1fb10fc2c849..614dbc4d958c8 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -765,7 +765,6 @@ parameter_types! { pub const PostUnbondPoolsWindow: u32 = 4; pub const NominationPoolsPalletId: PalletId = PalletId(*b"py/nopls"); pub const MaxPointsToBalance: u8 = 10; - pub const InitialGlobalMaxCommission: Perbill = Perbill::zero(); } use sp_runtime::traits::Convert; @@ -795,7 +794,6 @@ impl pallet_nomination_pools::Config for Runtime { type MaxUnbonding = ConstU32<8>; type PalletId = NominationPoolsPalletId; type MaxPointsToBalance = MaxPointsToBalance; - type InitialGlobalMaxCommission = InitialGlobalMaxCommission; } parameter_types! { diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index 0ddba4f72ccd2..4a1a52868e367 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -151,7 +151,6 @@ parameter_types! { pub static PostUnbondingPoolsWindow: u32 = 10; pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls"); pub const MaxPointsToBalance: u8 = 10; - pub const InitialGlobalMaxCommission: Perbill = Perbill::zero(); } impl pallet_nomination_pools::Config for Runtime { @@ -167,7 +166,6 @@ impl pallet_nomination_pools::Config for Runtime { type MaxUnbonding = ConstU32<8>; type PalletId = PoolsPalletId; type MaxPointsToBalance = MaxPointsToBalance; - type InitialGlobalMaxCommission = InitialGlobalMaxCommission; } impl crate::Config for Runtime {} diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 35a706d77d7ba..6f23ce0bb3d4a 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1568,9 +1568,6 @@ pub mod pallet { /// The maximum number of simultaneous unbonding chunks that can exist per member. type MaxUnbonding: Get; - - /// The initial value for global maximum commission. Used in pool migration to v4. - type InitialGlobalMaxCommission: Get; } /// Minimum amount to bond to join a pool. diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 60c56056c28db..e3e8e55df03eb 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -494,7 +494,7 @@ pub mod v4 { ); if current == 4 && onchain == 3 { - GlobalMaxCommission::::set(Some(T::InitialGlobalMaxCommission::get())); + GlobalMaxCommission::::set(Some(Perbill::zero())); log!(info, "Set initial global max commission to 0%"); let mut translated = 0u64; @@ -534,10 +534,6 @@ pub mod v4 { inner.commission.throttle_from.is_none()), "a commission value has been incorrectly set" ); - ensure!( - GlobalMaxCommission::::get() == Some(T::InitialGlobalMaxCommission::get()), - "global maximum commission error" - ); ensure!(Pallet::::on_chain_storage_version() == 4, "wrong storage version"); Ok(()) } diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 2bff188afd46d..c6b094f0aa0f1 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -217,7 +217,6 @@ parameter_types! { pub static MaxMetadataLen: u32 = 2; pub static CheckLevel: u8 = 255; pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls"); - pub const InitialGlobalMaxCommission: Perbill = Perbill::zero(); } impl pools::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -232,7 +231,6 @@ impl pools::Config for Runtime { type MaxMetadataLen = MaxMetadataLen; type MaxUnbonding = MaxUnbonding; type MaxPointsToBalance = frame_support::traits::ConstU8<10>; - type InitialGlobalMaxCommission = InitialGlobalMaxCommission; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index 0648b2a6115c8..0550c8e0ca708 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -165,7 +165,6 @@ impl Convert for U256ToBalance { parameter_types! { pub const PostUnbondingPoolsWindow: u32 = 10; pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls"); - pub const InitialGlobalMaxCommission: Perbill = Perbill::zero(); } impl pallet_nomination_pools::Config for Runtime { @@ -181,7 +180,6 @@ impl pallet_nomination_pools::Config for Runtime { type MaxUnbonding = ConstU32<8>; type MaxPointsToBalance = ConstU8<10>; type PalletId = PoolsPalletId; - type InitialGlobalMaxCommission = InitialGlobalMaxCommission; } type Block = frame_system::mocking::MockBlock; From 669c3c8aa2e723ddc1e2fdfb33f80e515daca505 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 13 Mar 2023 22:57:21 +0700 Subject: [PATCH 84/90] global max commission migration generic --- frame/nomination-pools/src/migration.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index e3e8e55df03eb..f6f166d7f5de2 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -480,8 +480,8 @@ pub mod v4 { /// This migration adds a `commission` field to every `BondedPoolInner`, if /// any. - pub struct MigrateToV4(sp_std::marker::PhantomData); - impl OnRuntimeUpgrade for MigrateToV4 { + pub struct MigrateToV4(sp_std::marker::PhantomData<(T, U)>); + impl> OnRuntimeUpgrade for MigrateToV4 { fn on_runtime_upgrade() -> Weight { let current = Pallet::::current_storage_version(); let onchain = Pallet::::on_chain_storage_version(); @@ -494,8 +494,13 @@ pub mod v4 { ); if current == 4 && onchain == 3 { - GlobalMaxCommission::::set(Some(Perbill::zero())); - log!(info, "Set initial global max commission to 0%"); + let initial_global_max_commission = U::get(); + GlobalMaxCommission::::set(Some(initial_global_max_commission)); + log!( + info, + "Set initial global max commission to {:?}.", + initial_global_max_commission + ); let mut translated = 0u64; BondedPools::::translate::, _>(|_key, old_value| { @@ -534,6 +539,10 @@ pub mod v4 { inner.commission.throttle_from.is_none()), "a commission value has been incorrectly set" ); + ensure!( + GlobalMaxCommission::::get() == Some(U::get()), + "global maximum commission error" + ); ensure!(Pallet::::on_chain_storage_version() == 4, "wrong storage version"); Ok(()) } From 0a7e368b69ec077a0d540fc5edb43726949dfe74 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Tue, 14 Mar 2023 00:03:29 +0700 Subject: [PATCH 85/90] text --- client/executor/wasmtime/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/executor/wasmtime/README.md b/client/executor/wasmtime/README.md index 399b72e39c477..3e9ac0bddbdc1 100644 --- a/client/executor/wasmtime/README.md +++ b/client/executor/wasmtime/README.md @@ -1 +1 @@ -mcoLicense: GPL-3.0-or-later WITH Classpath-exception-2.0 \ No newline at end of file +License: GPL-3.0-or-later WITH Classpath-exception-2.0 \ No newline at end of file From ecab0c0b6106213967fb8a74f2f1868a91712ba9 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Tue, 14 Mar 2023 11:20:32 +0700 Subject: [PATCH 86/90] 100% commission no payout test --- frame/nomination-pools/src/lib.rs | 6 +-- frame/nomination-pools/src/tests.rs | 73 +++++++++++++++-------------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 513744a841b72..44cb1cb04b3e1 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2812,6 +2812,8 @@ impl Pallet { bonded_pool.commission.current(), )?; + // Determine the pending rewards. In scenarios where commission is 100%, `pending_rewards` + // will be zero. let pending_rewards = member.pending_rewards(current_reward_counter)?; if pending_rewards.is_zero() { return Ok(pending_rewards) @@ -2821,10 +2823,6 @@ impl Pallet { member.last_recorded_reward_counter = current_reward_counter; reward_pool.register_claimed_reward(pending_rewards); - // Transfer remaining payout to the member. - // - // In scenarios where commission is 100%, `pending_rewards` will be zero. We therefore check - // if there is a non-zero payout to be transferred. T::Currency::transfer( &bonded_pool.reward_account(), member_account, diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 8de776f44e823..faee10f446ce2 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5042,7 +5042,7 @@ mod reward_counter_precision { fn default_pool_reward_counter() -> FixedU128 { let bonded_pool = BondedPools::::get(1).unwrap(); - RewardPools::::get(1) + RewardPools::::get(1) .unwrap() .current_reward_counter(1, bonded_pool.points, bonded_pool.commission.current()) .unwrap() @@ -5500,7 +5500,7 @@ mod commission { vec![Event::PaidOut { member: 10, pool_id, payout: 100 },] ); assert_eq!( - RewardPools::::get(pool_id).unwrap(), + RewardPools::::get(pool_id).unwrap(), RewardPool { last_recorded_reward_counter: FixedU128::from_float(6.0), last_recorded_total_payouts: 80, @@ -5533,7 +5533,7 @@ mod commission { },] ); assert_eq!( - RewardPools::::get(pool_id).unwrap(), + RewardPools::::get(pool_id).unwrap(), RewardPool { last_recorded_reward_counter: FixedU128::from_float(16.0), last_recorded_total_payouts: 180, @@ -6351,8 +6351,9 @@ mod commission { #[test] fn do_reward_payout_with_various_commissions() { ExtBuilder::default().build_and_execute(|| { - let (mut member, bonded_pool, mut reward_pool) = - Pools::get_member_with_pools(&10).unwrap(); + // turn off GlobalMaxCommission for this test. + GlobalMaxCommission::::set(None); + let pool_id = 1; // top up commission payee account to existential deposit let _ = Balances::deposit_creating(&2, 5); @@ -6360,7 +6361,7 @@ mod commission { // Set a commission pool 1 to 33%, with a payee set to `2` assert_ok!(Pools::set_commission( RuntimeOrigin::signed(900), - bonded_pool.id, + pool_id, Some((Perbill::from_percent(33), 2)), )); assert_eq!( @@ -6377,15 +6378,9 @@ mod commission { // The pool earns 10 points assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10)); + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); - assert_ok!(Pools::do_reward_payout( - &10, - &mut member, - &mut BondedPool::::get(1).unwrap(), - &mut reward_pool - )); - - // Then + // Then: assert_eq!( pool_events_since_last_call(), vec![Event::PaidOut { member: 10, pool_id: 1, payout: 7 },] @@ -6393,14 +6388,9 @@ mod commission { // The pool earns 17 points assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 17)); - assert_ok!(Pools::do_reward_payout( - &10, - &mut member, - &mut BondedPool::::get(1).unwrap(), - &mut reward_pool - )); + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); - // Then + // Then: assert_eq!( pool_events_since_last_call(), vec![Event::PaidOut { member: 10, pool_id: 1, payout: 11 },] @@ -6408,14 +6398,9 @@ mod commission { // The pool earns 50 points assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); - assert_ok!(Pools::do_reward_payout( - &10, - &mut member, - &mut BondedPool::::get(1).unwrap(), - &mut reward_pool - )); + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); - // Then + // Then: assert_eq!( pool_events_since_last_call(), vec![Event::PaidOut { member: 10, pool_id: 1, payout: 34 },] @@ -6423,18 +6408,36 @@ mod commission { // The pool earns 10439 points assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10439)); - assert_ok!(Pools::do_reward_payout( - &10, - &mut member, - &mut BondedPool::::get(1).unwrap(), - &mut reward_pool - )); + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); - // Then + // Then: assert_eq!( pool_events_since_last_call(), vec![Event::PaidOut { member: 10, pool_id: 1, payout: 6994 },] ); + + // Set the commission to 100% and ensure the following payout to the pool member will + // not happen. + + // When: + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + pool_id, + Some((Perbill::from_percent(100), 2)), + )); + + // Given: + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 200)); + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); + + // Then: + assert_eq!( + pool_events_since_last_call(), + vec![Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(100), 2)) + },] + ); }) } From 566a78e2dc5ae0a1ed9b6ecb4483d1b28a09495d Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Tue, 14 Mar 2023 11:33:37 +0700 Subject: [PATCH 87/90] add commission_accumulates_on_multiple_rewards --- frame/nomination-pools/src/tests.rs | 58 +++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index faee10f446ce2..0902f69c599b4 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -6441,6 +6441,64 @@ mod commission { }) } + #[test] + fn commission_accumulates_on_multiple_rewards() { + ExtBuilder::default().build_and_execute(|| { + let pool_id = 1; + + // Given: + + // Set initial commission of pool 1 to 10%. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + pool_id, + Some((Perbill::from_percent(10), 2)), + )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(10), 2)) + }, + ] + ); + + // When: + + // The pool earns 100 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); + + // Change commission to 20% + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + pool_id, + Some((Perbill::from_percent(20), 2)), + )); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(20), 2)) + },] + ); + + // The pool earns 100 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); + + // Claim payout: + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); + + // Then: + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 90 + 80 }] + ); + }) + } + #[test] fn do_reward_payout_with_100_percent_commission() { ExtBuilder::default().build_and_execute(|| { From 64801080fcca0d87af41c7b895defb562c35237b Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Tue, 14 Mar 2023 11:37:24 +0700 Subject: [PATCH 88/90] non-zero fuzzer GlobalMaxCommission --- frame/nomination-pools/fuzzer/src/call.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/fuzzer/src/call.rs b/frame/nomination-pools/fuzzer/src/call.rs index 0a3d951c188c6..027fb2b69138c 100644 --- a/frame/nomination-pools/fuzzer/src/call.rs +++ b/frame/nomination-pools/fuzzer/src/call.rs @@ -224,7 +224,7 @@ fn main() { MaxPoolMembers::::set(Some(10_000)); MaxPoolMembersPerPool::::set(Some(1000)); MaxPools::::set(Some(1_000)); - GlobalMaxCommission::::set(Some(Perbill::zero())); + GlobalMaxCommission::::set(Some(Perbill::from_percent(25))); MinCreateBond::::set(10 * ExistentialDeposit::get()); MinJoinBond::::set(5 * ExistentialDeposit::get()); From bbea2d2647272f1327cfc414d87d9cbb5b202109 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Tue, 14 Mar 2023 12:23:04 +0700 Subject: [PATCH 89/90] add last_recorded_total_payouts_needs_commission --- frame/nomination-pools/src/tests.rs | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 0902f69c599b4..f2bbe2592d31e 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -6499,6 +6499,59 @@ mod commission { }) } + #[test] + fn last_recorded_total_payouts_needs_commission() { + ExtBuilder::default().build_and_execute(|| { + let pool_id = 1; + + // Given: + + // Set initial commission of pool 1 to 10%. + assert_ok!(Pools::set_commission( + RuntimeOrigin::signed(900), + pool_id, + Some((Perbill::from_percent(10), 2)), + )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PoolCommissionUpdated { + pool_id: 1, + current: Some((Perbill::from_percent(10), 2)) + }, + ] + ); + + // When: + + // The pool earns 100 points + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); + + // Claim payout: + assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); + + // Claim commission: + assert_ok!(Pools::claim_commission(RuntimeOrigin::signed(900), pool_id)); + + // Then: + + assert_eq!( + RewardPools::::get(1).unwrap().last_recorded_total_payouts, + 90 + 10 + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 90 }, + Event::PoolCommissionClaimed { pool_id: 1, commission: 0 } + ] + ); + }) + } + #[test] fn do_reward_payout_with_100_percent_commission() { ExtBuilder::default().build_and_execute(|| { From 70f7769747adb98ad4f876d4115957735adbca06 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Tue, 14 Mar 2023 15:35:09 +0700 Subject: [PATCH 90/90] commission event fix + claim commission test --- frame/nomination-pools/src/lib.rs | 19 +++++++++---------- frame/nomination-pools/src/tests.rs | 14 +++++++++++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 44cb1cb04b3e1..e73d4b4173ecf 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2975,7 +2975,8 @@ impl Pallet { bonded_pool.commission.current(), )?; - ensure!(!reward_pool.total_commission_pending.is_zero(), Error::::NoPendingCommission); + let commission = reward_pool.total_commission_pending; + ensure!(!commission.is_zero(), Error::::NoPendingCommission); let payee = bonded_pool .commission @@ -2988,21 +2989,19 @@ impl Pallet { T::Currency::transfer( &bonded_pool.reward_account(), &payee, - reward_pool.total_commission_pending, + commission, ExistenceRequirement::KeepAlive, )?; - reward_pool.total_commission_claimed = reward_pool - .total_commission_claimed - .saturating_add(reward_pool.total_commission_pending); + // Add pending commission to total claimed counter. + reward_pool.total_commission_claimed = + reward_pool.total_commission_claimed.saturating_add(commission); + // Reset total pending commission counter to zero. reward_pool.total_commission_pending = Zero::zero(); - + // Commit reward pool updates RewardPools::::insert(pool_id, reward_pool); - Self::deposit_event(Event::::PoolCommissionClaimed { - pool_id, - commission: Zero::zero(), - }); + Self::deposit_event(Event::::PoolCommissionClaimed { pool_id, commission }); Ok(()) } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index f2bbe2592d31e..a4fda2e5d91b3 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -5467,7 +5467,7 @@ mod commission { assert_eq!(RewardPool::::current_balance(pool_id), 0); assert_eq!( pool_events_since_last_call(), - vec![Event::PoolCommissionClaimed { pool_id: 1, commission: 0 }] + vec![Event::PoolCommissionClaimed { pool_id: 1, commission: 20 }] ); // Commission can be removed from the pool completely. @@ -6488,13 +6488,21 @@ mod commission { // The pool earns 100 points assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); + // Then: + // Claim payout: assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10))); + // Claim commission: + assert_ok!(Pools::claim_commission(RuntimeOrigin::signed(900), pool_id)); + // Then: assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 90 + 80 }] + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 90 + 80 }, + Event::PoolCommissionClaimed { pool_id: 1, commission: 30 } + ] ); }) } @@ -6546,7 +6554,7 @@ mod commission { pool_events_since_last_call(), vec![ Event::PaidOut { member: 10, pool_id: 1, payout: 90 }, - Event::PoolCommissionClaimed { pool_id: 1, commission: 0 } + Event::PoolCommissionClaimed { pool_id: 1, commission: 10 } ] ); })