mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 13:31:10 +00:00
fix a few more things with nomination pools (#11373)
* fix a few more things with nomination pools * add bench * use weight fn * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- 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 --template=./.maintain/frame-weight-template.hbs * allow real root to also set roles * Update frame/nomination-pools/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/nomination-pools/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * move out of the closure * fix a few more things Co-authored-by: Parity Bot <admin@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -631,6 +631,28 @@ frame_benchmarking::benchmarks! {
|
||||
assert_eq!(MaxPoolMembersPerPool::<T>::get(), Some(u32::MAX));
|
||||
}
|
||||
|
||||
update_roles {
|
||||
let first_id = pallet_nomination_pools::LastPoolId::<T>::get() + 1;
|
||||
let (root, _) = create_pool_account::<T>(0, CurrencyOf::<T>::minimum_balance() * 2u32.into());
|
||||
let random: T::AccountId = account("but is anything really random in computers..?", 0, USER_SEED);
|
||||
}:_(
|
||||
Origin::Signed(root.clone()),
|
||||
first_id,
|
||||
Some(random.clone()),
|
||||
Some(random.clone()),
|
||||
Some(random.clone())
|
||||
) verify {
|
||||
assert_eq!(
|
||||
pallet_nomination_pools::BondedPools::<T>::get(first_id).unwrap().roles,
|
||||
pallet_nomination_pools::PoolRoles {
|
||||
depositor: root,
|
||||
nominator: random.clone(),
|
||||
state_toggler: random.clone(),
|
||||
root: random,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Pallet,
|
||||
crate::mock::new_test_ext(),
|
||||
|
||||
@@ -348,7 +348,7 @@ pub const POINTS_TO_BALANCE_INIT_RATIO: u32 = 1;
|
||||
|
||||
/// Possible operations on the configuration values of this pallet.
|
||||
#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebugNoBound, PartialEq, Clone)]
|
||||
pub enum ConfigOp<T: Default + Codec + Debug> {
|
||||
pub enum ConfigOp<T: Codec + Debug> {
|
||||
/// Don't change.
|
||||
Noop,
|
||||
/// Set the given value.
|
||||
@@ -505,11 +505,11 @@ pub enum PoolState {
|
||||
/// Pool adminstration roles.
|
||||
#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Debug, PartialEq, Clone)]
|
||||
pub struct PoolRoles<AccountId> {
|
||||
/// Creates the pool and is the initial member. They can only leave the pool once all
|
||||
/// other members have left. Once they fully leave, the pool is destroyed.
|
||||
/// Creates the pool and is the initial member. They can only leave the pool once all other
|
||||
/// members have left. Once they fully leave, the pool is destroyed.
|
||||
pub depositor: AccountId,
|
||||
/// Can change the nominator, state-toggler, or itself and can perform any of the actions
|
||||
/// the nominator or state-toggler can.
|
||||
/// Can change the nominator, state-toggler, or itself and can perform any of the actions the
|
||||
/// nominator or state-toggler can.
|
||||
pub root: AccountId,
|
||||
/// Can select which validators the pool nominates.
|
||||
pub nominator: AccountId,
|
||||
@@ -665,6 +665,10 @@ impl<T: Config> BondedPool<T> {
|
||||
.saturating_sub(T::StakingInterface::active_stake(&account).unwrap_or_default())
|
||||
}
|
||||
|
||||
fn can_update_roles(&self, who: &T::AccountId) -> bool {
|
||||
*who == self.roles.root
|
||||
}
|
||||
|
||||
fn can_nominate(&self, who: &T::AccountId) -> bool {
|
||||
*who == self.roles.root || *who == self.roles.nominator
|
||||
}
|
||||
@@ -1141,9 +1145,14 @@ pub mod pallet {
|
||||
pub type Metadata<T: Config> =
|
||||
CountedStorageMap<_, Twox64Concat, PoolId, BoundedVec<u8, T::MaxMetadataLen>, ValueQuery>;
|
||||
|
||||
/// Ever increasing number of all pools created so far.
|
||||
#[pallet::storage]
|
||||
pub type LastPoolId<T: Config> = StorageValue<_, u32, ValueQuery>;
|
||||
|
||||
/// A reverse lookup from the pool's account id to its id.
|
||||
///
|
||||
/// This is only used for slashing. In all other instances, the pool id is used, and the
|
||||
/// accounts are deterministically derived from it.
|
||||
#[pallet::storage]
|
||||
pub type ReversePoolIdLookup<T: Config> =
|
||||
CountedStorageMap<_, Twox64Concat, T::AccountId, PoolId, OptionQuery>;
|
||||
@@ -1209,6 +1218,8 @@ pub mod pallet {
|
||||
///
|
||||
/// The removal can be voluntary (withdrawn all unbonded funds) or involuntary (kicked).
|
||||
MemberRemoved { pool_id: PoolId, member: T::AccountId },
|
||||
/// The roles of a pool have been updated to the given new roles.
|
||||
RolesUpdated { root: T::AccountId, state_toggler: T::AccountId, nominator: T::AccountId },
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
@@ -1436,9 +1447,9 @@ pub mod pallet {
|
||||
|
||||
bonded_pool.ok_to_unbond_with(&caller, &member_account, &member, unbonding_points)?;
|
||||
|
||||
// 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.
|
||||
// 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.
|
||||
Self::do_reward_payout(
|
||||
&member_account,
|
||||
&mut member,
|
||||
@@ -1827,6 +1838,60 @@ pub mod pallet {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// 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::weight(T::WeightInfo::update_roles())]
|
||||
pub fn update_roles(
|
||||
origin: OriginFor<T>,
|
||||
pool_id: PoolId,
|
||||
root: Option<T::AccountId>,
|
||||
nominator: Option<T::AccountId>,
|
||||
state_toggler: Option<T::AccountId>,
|
||||
) -> DispatchResult {
|
||||
let o1 = origin;
|
||||
let o2 = o1.clone();
|
||||
|
||||
let mut bonded_pool = BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?;
|
||||
let is_pool_root = || -> Result<(), sp_runtime::DispatchError> {
|
||||
let who = ensure_signed(o1)?;
|
||||
ensure!(bonded_pool.can_update_roles(&who), Error::<T>::DoesNotHavePermission);
|
||||
Ok(())
|
||||
};
|
||||
let is_root = || -> Result<(), sp_runtime::DispatchError> {
|
||||
ensure_root(o2)?;
|
||||
Ok(())
|
||||
};
|
||||
|
||||
let _ = is_root().or_else(|_| is_pool_root())?;
|
||||
|
||||
match root {
|
||||
None => (),
|
||||
Some(v) => bonded_pool.roles.root = v,
|
||||
};
|
||||
match nominator {
|
||||
None => (),
|
||||
Some(v) => bonded_pool.roles.nominator = v,
|
||||
};
|
||||
match state_toggler {
|
||||
None => (),
|
||||
Some(v) => bonded_pool.roles.state_toggler = v,
|
||||
};
|
||||
|
||||
Self::deposit_event(Event::<T>::RolesUpdated {
|
||||
root: bonded_pool.roles.root.clone(),
|
||||
nominator: bonded_pool.roles.nominator.clone(),
|
||||
state_toggler: bonded_pool.roles.state_toggler.clone(),
|
||||
});
|
||||
|
||||
bonded_pool.put();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
|
||||
@@ -69,7 +69,20 @@ fn test_setup_works() {
|
||||
assert_eq!(
|
||||
PoolMembers::<Runtime>::get(10).unwrap(),
|
||||
PoolMember::<Runtime> { pool_id: last_pool, points: 10, ..Default::default() }
|
||||
)
|
||||
);
|
||||
|
||||
let bonded_account = Pools::create_bonded_account(last_pool);
|
||||
let reward_account = Pools::create_reward_account(last_pool);
|
||||
|
||||
// the bonded_account should be bonded by the depositor's funds.
|
||||
assert_eq!(StakingMock::active_stake(&bonded_account).unwrap(), 10);
|
||||
assert_eq!(StakingMock::total_stake(&bonded_account).unwrap(), 10);
|
||||
|
||||
// but not nominating yet.
|
||||
assert!(Nominations::get().is_empty());
|
||||
|
||||
// reward account should have an initial ED in it.
|
||||
assert_eq!(Balances::free_balance(&reward_account), Balances::minimum_balance());
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2082,7 +2095,7 @@ mod unbond {
|
||||
// depositor can unbond inly up to `MinCreateBond`.
|
||||
#[test]
|
||||
fn depositor_permissioned_partial_unbond() {
|
||||
ExtBuilder::default().ed(1).add_members(vec![(100, 100)]).build_and_execute(|| {
|
||||
ExtBuilder::default().ed(1).build_and_execute(|| {
|
||||
// given
|
||||
assert_eq!(MinCreateBond::<Runtime>::get(), 2);
|
||||
assert_eq!(PoolMembers::<Runtime>::get(10).unwrap().active_points(), 10);
|
||||
@@ -2098,12 +2111,12 @@ mod unbond {
|
||||
Pools::unbond(Origin::signed(10), 10, 6),
|
||||
Error::<Runtime>::NotOnlyPoolMember
|
||||
);
|
||||
|
||||
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::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true },
|
||||
Event::Unbonded { member: 10, pool_id: 1, amount: 3 }
|
||||
]
|
||||
);
|
||||
@@ -2113,7 +2126,7 @@ mod unbond {
|
||||
// same as above, but the pool is slashed and therefore the depositor cannot partially unbond.
|
||||
#[test]
|
||||
fn depositor_permissioned_partial_unbond_slashed() {
|
||||
ExtBuilder::default().ed(1).add_members(vec![(100, 100)]).build_and_execute(|| {
|
||||
ExtBuilder::default().ed(1).build_and_execute(|| {
|
||||
// given
|
||||
assert_eq!(MinCreateBond::<Runtime>::get(), 2);
|
||||
assert_eq!(PoolMembers::<Runtime>::get(10).unwrap().active_points(), 10);
|
||||
@@ -2132,11 +2145,75 @@ mod unbond {
|
||||
vec![
|
||||
Event::Created { depositor: 10, pool_id: 1 },
|
||||
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
|
||||
Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_unbonding_triggers_payout() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let initial_reward_account = Balances::free_balance(Pools::create_reward_account(1));
|
||||
assert_eq!(initial_reward_account, Balances::minimum_balance());
|
||||
assert_eq!(initial_reward_account, 5);
|
||||
|
||||
// set the pool to destroying so that depositor can leave.
|
||||
unsafe_set_state(1, PoolState::Destroying).unwrap();
|
||||
|
||||
Balances::make_free_balance_be(
|
||||
&Pools::create_reward_account(1),
|
||||
2 * Balances::minimum_balance(),
|
||||
);
|
||||
|
||||
assert_ok!(Pools::unbond(Origin::signed(10), 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 },
|
||||
// exactly equal to ed, all that can be claimed.
|
||||
Event::PaidOut { member: 10, pool_id: 1, payout: 5 },
|
||||
Event::Unbonded { member: 10, pool_id: 1, amount: 2 }
|
||||
]
|
||||
);
|
||||
|
||||
CurrentEra::set(1);
|
||||
Balances::make_free_balance_be(
|
||||
&Pools::create_reward_account(1),
|
||||
2 * Balances::minimum_balance(),
|
||||
);
|
||||
|
||||
assert_ok!(Pools::unbond(Origin::signed(10), 10, 3));
|
||||
assert_eq!(
|
||||
pool_events_since_last_call(),
|
||||
vec![
|
||||
// exactly equal to ed, all that can be claimed.
|
||||
Event::PaidOut { member: 10, pool_id: 1, payout: 5 },
|
||||
Event::Unbonded { member: 10, pool_id: 1, amount: 3 }
|
||||
]
|
||||
);
|
||||
|
||||
CurrentEra::set(2);
|
||||
Balances::make_free_balance_be(
|
||||
&Pools::create_reward_account(1),
|
||||
2 * Balances::minimum_balance(),
|
||||
);
|
||||
|
||||
assert_ok!(Pools::unbond(Origin::signed(10), 10, 5));
|
||||
assert_eq!(
|
||||
pool_events_since_last_call(),
|
||||
vec![
|
||||
Event::PaidOut { member: 10, pool_id: 1, payout: 5 },
|
||||
Event::Unbonded { member: 10, pool_id: 1, amount: 5 }
|
||||
]
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
PoolMembers::<Runtime>::get(10).unwrap().unbonding_eras,
|
||||
member_unbonding_eras!(3 => 2, 4 => 3, 5 => 5)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
mod pool_withdraw_unbonded {
|
||||
@@ -3504,3 +3581,81 @@ mod bond_extra {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
mod update_roles {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn update_roles_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(
|
||||
BondedPools::<Runtime>::get(1).unwrap().roles,
|
||||
PoolRoles { depositor: 10, root: 900, nominator: 901, state_toggler: 902 },
|
||||
);
|
||||
|
||||
// non-existent pools
|
||||
assert_noop!(
|
||||
Pools::update_roles(Origin::signed(1), 2, Some(5), Some(6), Some(7)),
|
||||
Error::<Runtime>::PoolNotFound,
|
||||
);
|
||||
|
||||
// depositor cannot change roles.
|
||||
assert_noop!(
|
||||
Pools::update_roles(Origin::signed(1), 1, Some(5), Some(6), Some(7)),
|
||||
Error::<Runtime>::DoesNotHavePermission,
|
||||
);
|
||||
|
||||
// nominator cannot change roles.
|
||||
assert_noop!(
|
||||
Pools::update_roles(Origin::signed(901), 1, Some(5), Some(6), Some(7)),
|
||||
Error::<Runtime>::DoesNotHavePermission,
|
||||
);
|
||||
// state-toggler
|
||||
assert_noop!(
|
||||
Pools::update_roles(Origin::signed(902), 1, Some(5), Some(6), Some(7)),
|
||||
Error::<Runtime>::DoesNotHavePermission,
|
||||
);
|
||||
|
||||
// but root can
|
||||
assert_ok!(Pools::update_roles(Origin::signed(900), 1, Some(5), Some(6), Some(7)));
|
||||
|
||||
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::RolesUpdated { root: 5, state_toggler: 7, nominator: 6 }
|
||||
]
|
||||
);
|
||||
assert_eq!(
|
||||
BondedPools::<Runtime>::get(1).unwrap().roles,
|
||||
PoolRoles { depositor: 10, root: 5, nominator: 6, state_toggler: 7 },
|
||||
);
|
||||
|
||||
// also root origin can
|
||||
assert_ok!(Pools::update_roles(Origin::root(), 1, Some(1), Some(2), Some(3)));
|
||||
|
||||
assert_eq!(
|
||||
pool_events_since_last_call(),
|
||||
vec![Event::RolesUpdated { root: 1, state_toggler: 3, nominator: 2 }]
|
||||
);
|
||||
assert_eq!(
|
||||
BondedPools::<Runtime>::get(1).unwrap().roles,
|
||||
PoolRoles { depositor: 10, root: 1, nominator: 2, state_toggler: 3 },
|
||||
);
|
||||
|
||||
// None is a noop
|
||||
assert_ok!(Pools::update_roles(Origin::root(), 1, Some(11), None, None));
|
||||
|
||||
assert_eq!(
|
||||
pool_events_since_last_call(),
|
||||
vec![Event::RolesUpdated { root: 11, state_toggler: 3, nominator: 2 }]
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
BondedPools::<Runtime>::get(1).unwrap().roles,
|
||||
PoolRoles { depositor: 10, root: 11, nominator: 2, state_toggler: 3 },
|
||||
);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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: 2022-04-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! DATE: 2022-05-10, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
|
||||
|
||||
// Executed Command:
|
||||
@@ -58,6 +58,7 @@ pub trait WeightInfo {
|
||||
fn set_state() -> Weight;
|
||||
fn set_metadata(n: u32, ) -> Weight;
|
||||
fn set_configs() -> Weight;
|
||||
fn update_roles() -> Weight;
|
||||
}
|
||||
|
||||
/// Weights for pallet_nomination_pools using the Substrate node and recommended hardware.
|
||||
@@ -78,7 +79,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: BagsList ListNodes (r:3 w:3)
|
||||
// Storage: BagsList ListBags (r:2 w:2)
|
||||
fn join() -> Weight {
|
||||
(117_870_000 as Weight)
|
||||
(119_253_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(18 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(12 as Weight))
|
||||
}
|
||||
@@ -93,7 +94,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: BagsList ListNodes (r:3 w:3)
|
||||
// Storage: BagsList ListBags (r:2 w:2)
|
||||
fn bond_extra_transfer() -> Weight {
|
||||
(110_176_000 as Weight)
|
||||
(110_157_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(14 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(13 as Weight))
|
||||
}
|
||||
@@ -108,7 +109,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: BagsList ListNodes (r:2 w:2)
|
||||
// Storage: BagsList ListBags (r:2 w:2)
|
||||
fn bond_extra_reward() -> Weight {
|
||||
(122_829_000 as Weight)
|
||||
(124_003_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(14 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(13 as Weight))
|
||||
}
|
||||
@@ -118,7 +119,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: NominationPools RewardPools (r:1 w:1)
|
||||
// Storage: System Account (r:1 w:1)
|
||||
fn claim_payout() -> Weight {
|
||||
(50_094_000 as Weight)
|
||||
(51_767_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(5 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(5 as Weight))
|
||||
}
|
||||
@@ -138,7 +139,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: NominationPools SubPoolsStorage (r:1 w:1)
|
||||
// Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1)
|
||||
fn unbond() -> Weight {
|
||||
(119_288_000 as Weight)
|
||||
(116_959_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(19 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(14 as Weight))
|
||||
}
|
||||
@@ -148,9 +149,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: Staking CurrentEra (r:1 w:0)
|
||||
// Storage: Balances Locks (r:1 w:1)
|
||||
fn pool_withdraw_unbonded(s: u32, ) -> Weight {
|
||||
(39_986_000 as Weight)
|
||||
(41_124_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((50_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add((52_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(5 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||
}
|
||||
@@ -164,9 +165,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: System Account (r:1 w:1)
|
||||
// Storage: NominationPools CounterForPoolMembers (r:1 w:1)
|
||||
fn withdraw_unbonded_update(s: u32, ) -> Weight {
|
||||
(76_897_000 as Weight)
|
||||
(80_654_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((48_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add((50_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(9 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(8 as Weight))
|
||||
}
|
||||
@@ -191,7 +192,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: NominationPools CounterForBondedPools (r:1 w:1)
|
||||
// Storage: Staking Payee (r:0 w:1)
|
||||
fn withdraw_unbonded_kill(_s: u32, ) -> Weight {
|
||||
(135_837_000 as Weight)
|
||||
(140_296_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(20 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(17 as Weight))
|
||||
}
|
||||
@@ -219,7 +220,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: NominationPools BondedPools (r:1 w:1)
|
||||
// Storage: Staking Payee (r:0 w:1)
|
||||
fn create() -> Weight {
|
||||
(129_265_000 as Weight)
|
||||
(130_543_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(23 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(16 as Weight))
|
||||
}
|
||||
@@ -236,9 +237,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: BagsList CounterForListNodes (r:1 w:1)
|
||||
// Storage: Staking CounterForNominators (r:1 w:1)
|
||||
fn nominate(n: u32, ) -> Weight {
|
||||
(45_546_000 as Weight)
|
||||
// Standard Error: 11_000
|
||||
.saturating_add((2_075_000 as Weight).saturating_mul(n as Weight))
|
||||
(46_152_000 as Weight)
|
||||
// Standard Error: 15_000
|
||||
.saturating_add((2_114_000 as Weight).saturating_mul(n as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(12 as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(n as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes(5 as Weight))
|
||||
@@ -246,7 +247,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: NominationPools BondedPools (r:1 w:1)
|
||||
// Storage: Staking Ledger (r:1 w:0)
|
||||
fn set_state() -> Weight {
|
||||
(23_256_000 as Weight)
|
||||
(23_544_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
@@ -254,7 +255,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: NominationPools Metadata (r:1 w:1)
|
||||
// Storage: NominationPools CounterForMetadata (r:1 w:1)
|
||||
fn set_metadata(n: u32, ) -> Weight {
|
||||
(10_893_000 as Weight)
|
||||
(11_032_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((1_000 as Weight).saturating_mul(n as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||
@@ -266,9 +267,15 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: NominationPools MinCreateBond (r:0 w:1)
|
||||
// Storage: NominationPools MaxPools (r:0 w:1)
|
||||
fn set_configs() -> Weight {
|
||||
(2_793_000 as Weight)
|
||||
(2_910_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().writes(5 as Weight))
|
||||
}
|
||||
// Storage: NominationPools BondedPools (r:1 w:1)
|
||||
fn update_roles() -> Weight {
|
||||
(18_608_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility and tests
|
||||
@@ -288,7 +295,7 @@ impl WeightInfo for () {
|
||||
// Storage: BagsList ListNodes (r:3 w:3)
|
||||
// Storage: BagsList ListBags (r:2 w:2)
|
||||
fn join() -> Weight {
|
||||
(117_870_000 as Weight)
|
||||
(119_253_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(18 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(12 as Weight))
|
||||
}
|
||||
@@ -303,7 +310,7 @@ impl WeightInfo for () {
|
||||
// Storage: BagsList ListNodes (r:3 w:3)
|
||||
// Storage: BagsList ListBags (r:2 w:2)
|
||||
fn bond_extra_transfer() -> Weight {
|
||||
(110_176_000 as Weight)
|
||||
(110_157_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(14 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(13 as Weight))
|
||||
}
|
||||
@@ -318,7 +325,7 @@ impl WeightInfo for () {
|
||||
// Storage: BagsList ListNodes (r:2 w:2)
|
||||
// Storage: BagsList ListBags (r:2 w:2)
|
||||
fn bond_extra_reward() -> Weight {
|
||||
(122_829_000 as Weight)
|
||||
(124_003_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(14 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(13 as Weight))
|
||||
}
|
||||
@@ -328,7 +335,7 @@ impl WeightInfo for () {
|
||||
// Storage: NominationPools RewardPools (r:1 w:1)
|
||||
// Storage: System Account (r:1 w:1)
|
||||
fn claim_payout() -> Weight {
|
||||
(50_094_000 as Weight)
|
||||
(51_767_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(5 as Weight))
|
||||
}
|
||||
@@ -348,7 +355,7 @@ impl WeightInfo for () {
|
||||
// Storage: NominationPools SubPoolsStorage (r:1 w:1)
|
||||
// Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1)
|
||||
fn unbond() -> Weight {
|
||||
(119_288_000 as Weight)
|
||||
(116_959_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(19 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(14 as Weight))
|
||||
}
|
||||
@@ -358,9 +365,9 @@ impl WeightInfo for () {
|
||||
// Storage: Staking CurrentEra (r:1 w:0)
|
||||
// Storage: Balances Locks (r:1 w:1)
|
||||
fn pool_withdraw_unbonded(s: u32, ) -> Weight {
|
||||
(39_986_000 as Weight)
|
||||
(41_124_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((50_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add((52_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
||||
}
|
||||
@@ -374,9 +381,9 @@ impl WeightInfo for () {
|
||||
// Storage: System Account (r:1 w:1)
|
||||
// Storage: NominationPools CounterForPoolMembers (r:1 w:1)
|
||||
fn withdraw_unbonded_update(s: u32, ) -> Weight {
|
||||
(76_897_000 as Weight)
|
||||
(80_654_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((48_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add((50_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(9 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(8 as Weight))
|
||||
}
|
||||
@@ -401,7 +408,7 @@ impl WeightInfo for () {
|
||||
// Storage: NominationPools CounterForBondedPools (r:1 w:1)
|
||||
// Storage: Staking Payee (r:0 w:1)
|
||||
fn withdraw_unbonded_kill(_s: u32, ) -> Weight {
|
||||
(135_837_000 as Weight)
|
||||
(140_296_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(20 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(17 as Weight))
|
||||
}
|
||||
@@ -429,7 +436,7 @@ impl WeightInfo for () {
|
||||
// Storage: NominationPools BondedPools (r:1 w:1)
|
||||
// Storage: Staking Payee (r:0 w:1)
|
||||
fn create() -> Weight {
|
||||
(129_265_000 as Weight)
|
||||
(130_543_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(23 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(16 as Weight))
|
||||
}
|
||||
@@ -446,9 +453,9 @@ impl WeightInfo for () {
|
||||
// Storage: BagsList CounterForListNodes (r:1 w:1)
|
||||
// Storage: Staking CounterForNominators (r:1 w:1)
|
||||
fn nominate(n: u32, ) -> Weight {
|
||||
(45_546_000 as Weight)
|
||||
// Standard Error: 11_000
|
||||
.saturating_add((2_075_000 as Weight).saturating_mul(n as Weight))
|
||||
(46_152_000 as Weight)
|
||||
// Standard Error: 15_000
|
||||
.saturating_add((2_114_000 as Weight).saturating_mul(n as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(12 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(n as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes(5 as Weight))
|
||||
@@ -456,7 +463,7 @@ impl WeightInfo for () {
|
||||
// Storage: NominationPools BondedPools (r:1 w:1)
|
||||
// Storage: Staking Ledger (r:1 w:0)
|
||||
fn set_state() -> Weight {
|
||||
(23_256_000 as Weight)
|
||||
(23_544_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
@@ -464,7 +471,7 @@ impl WeightInfo for () {
|
||||
// Storage: NominationPools Metadata (r:1 w:1)
|
||||
// Storage: NominationPools CounterForMetadata (r:1 w:1)
|
||||
fn set_metadata(n: u32, ) -> Weight {
|
||||
(10_893_000 as Weight)
|
||||
(11_032_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((1_000 as Weight).saturating_mul(n as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
||||
@@ -476,7 +483,13 @@ impl WeightInfo for () {
|
||||
// Storage: NominationPools MinCreateBond (r:0 w:1)
|
||||
// Storage: NominationPools MaxPools (r:0 w:1)
|
||||
fn set_configs() -> Weight {
|
||||
(2_793_000 as Weight)
|
||||
(2_910_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().writes(5 as Weight))
|
||||
}
|
||||
// Storage: NominationPools BondedPools (r:1 w:1)
|
||||
fn update_roles() -> Weight {
|
||||
(18_608_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,10 +80,10 @@ pub trait StakingInterface {
|
||||
/// This should be the latest planned era that the staking system knows about.
|
||||
fn current_era() -> EraIndex;
|
||||
|
||||
/// The amount of active stake that `controller` has in the staking system.
|
||||
fn active_stake(controller: &Self::AccountId) -> Option<Self::Balance>;
|
||||
/// The amount of active stake that `stash` has in the staking system.
|
||||
fn active_stake(stash: &Self::AccountId) -> Option<Self::Balance>;
|
||||
|
||||
/// The total stake that `controller` has in the staking system. This includes the
|
||||
/// The total stake that `stash` has in the staking system. This includes the
|
||||
/// [`Self::active_stake`], and any funds currently in the process of unbonding via
|
||||
/// [`Self::unbond`].
|
||||
///
|
||||
@@ -91,7 +91,7 @@ pub trait StakingInterface {
|
||||
///
|
||||
/// This is only guaranteed to reflect the amount locked by the staking system. If there are
|
||||
/// non-staking locks on the bonded pair's balance this may not be accurate.
|
||||
fn total_stake(controller: &Self::AccountId) -> Option<Self::Balance>;
|
||||
fn total_stake(stash: &Self::AccountId) -> Option<Self::Balance>;
|
||||
|
||||
/// Bond (lock) `value` of `stash`'s balance. `controller` will be set as the account
|
||||
/// controlling `stash`. This creates what is referred to as "bonded pair".
|
||||
@@ -111,7 +111,7 @@ pub trait StakingInterface {
|
||||
/// Bond some extra amount in the _Stash_'s free balance against the active bonded balance of
|
||||
/// the account. The amount extra actually bonded will never be more than the _Stash_'s free
|
||||
/// balance.
|
||||
fn bond_extra(controller: Self::AccountId, extra: Self::Balance) -> DispatchResult;
|
||||
fn bond_extra(stash: Self::AccountId, extra: Self::Balance) -> DispatchResult;
|
||||
|
||||
/// Schedule a portion of the active bonded balance to be unlocked at era
|
||||
/// [Self::current_era] + [`Self::bonding_duration`].
|
||||
@@ -122,11 +122,11 @@ pub trait StakingInterface {
|
||||
/// The amount of times this can be successfully called is limited based on how many distinct
|
||||
/// eras funds are schedule to unlock in. Calling [`Self::withdraw_unbonded`] after some unlock
|
||||
/// schedules have reached their unlocking era should allow more calls to this function.
|
||||
fn unbond(controller: Self::AccountId, value: Self::Balance) -> DispatchResult;
|
||||
fn unbond(stash: Self::AccountId, value: Self::Balance) -> DispatchResult;
|
||||
|
||||
/// Unlock any funds schedule to unlock before or at the current era.
|
||||
fn withdraw_unbonded(
|
||||
controller: Self::AccountId,
|
||||
stash: Self::AccountId,
|
||||
num_slashing_spans: u32,
|
||||
) -> Result<u64, DispatchError>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user