Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3a11e89
[Enhancement] Convert fast-unstake to use StakingInterface, decouplin…
ruseinov Oct 5, 2022
4f39589
Update primitives/staking/src/lib.rs
ruseinov Oct 6, 2022
9b8e123
Update primitives/staking/src/lib.rs
ruseinov Oct 6, 2022
25520d6
fix validator comment
ruseinov Oct 6, 2022
ad90903
remove todo
ruseinov Oct 10, 2022
89b32b5
ideas from Kian (#12474)
ruseinov Oct 11, 2022
f51c073
Merge remote-tracking branch 'origin/master' into ru/feature/fast-uns…
Oct 11, 2022
41d04ad
Rename StakingInterface -> Staking for nomination-pools
ruseinov Oct 12, 2022
7fc52f8
Staking fixes
ruseinov Oct 12, 2022
d3958ba
StakingInterface changes
ruseinov Oct 12, 2022
2ff689c
fix fast-unstake
ruseinov Oct 12, 2022
1fc6510
fix nomination-pools
ruseinov Oct 12, 2022
28d15d7
Merge remote-tracking branch 'origin/master' into ru/feature/fast-uns…
Oct 18, 2022
0705029
Fix fast-unstake tests
ruseinov Oct 18, 2022
39cf580
Fix benches for fast-unstake
ruseinov Oct 18, 2022
8093567
fix is_unbonding
ruseinov Oct 18, 2022
30a5882
fix nomination pools
ruseinov Oct 18, 2022
37107ef
fix node code
ruseinov Oct 19, 2022
097a9d1
add mock comments
ruseinov Oct 19, 2022
613a701
fix imports
ruseinov Oct 19, 2022
e785dd5
remove todo
ruseinov Oct 19, 2022
03586d7
more fixes
ruseinov Oct 19, 2022
20a4f29
more fixes
ruseinov Oct 19, 2022
9807cf2
bench fixes
ruseinov Oct 19, 2022
3639af8
more fixes
ruseinov Oct 19, 2022
b7827d5
more fixes
ruseinov Oct 20, 2022
5232b99
import fix
ruseinov Oct 20, 2022
f881456
more fixes
ruseinov Oct 20, 2022
c3cee71
more bench fix
ruseinov Oct 20, 2022
068c565
refix
ruseinov Oct 20, 2022
ff36f90
refix
ruseinov Oct 20, 2022
6f862e4
Update primitives/staking/src/lib.rs
ruseinov Oct 25, 2022
bff58a4
is_unbonding returns a result
ruseinov Oct 20, 2022
bdb525e
fix
ruseinov Oct 25, 2022
4bd57b1
review fixes
ruseinov Oct 25, 2022
f6040ec
more review fixes
ruseinov Oct 25, 2022
8c5604d
more fixes
ruseinov Oct 25, 2022
731fab2
more fixes
ruseinov Oct 25, 2022
b90082a
Update frame/fast-unstake/src/benchmarking.rs
ruseinov Oct 26, 2022
1eee8a5
remove redundant CurrencyBalance from nom-pools
ruseinov Oct 26, 2022
1f4fad2
remove CB
ruseinov Oct 26, 2022
27530dc
Merge remote-tracking branch 'origin/master' into ru/feature/fast-uns…
Oct 26, 2022
90cec9f
rephrase
ruseinov Oct 26, 2022
b1560aa
Apply suggestions from code review
kianenigma Oct 27, 2022
75a36bb
Update frame/nomination-pools/src/tests.rs
kianenigma Oct 27, 2022
b3e843e
finish damn renamed
kianenigma Oct 27, 2022
963837b
clippy fix
ruseinov Oct 27, 2022
cbed2f9
fix
ruseinov Oct 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename StakingInterface -> Staking for nomination-pools
  • Loading branch information
ruseinov committed Oct 12, 2022
commit 41d04ade20b3560428b5e718b6f765653807e23a
43 changes: 20 additions & 23 deletions frame/nomination-pools/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ impl<T: Config> ListScenario<T> {

// Create accounts with the origin weight
let (pool_creator1, pool_origin1) = create_pool_account::<T>(USER_SEED + 1, origin_weight);
T::StakingInterface::nominate(
T::Staking::nominate(
pool_origin1.clone(),
// NOTE: these don't really need to be validators.
vec![account("random_validator", 0, USER_SEED)],
)?;

let (_, pool_origin2) = create_pool_account::<T>(USER_SEED + 2, origin_weight);
T::StakingInterface::nominate(
T::Staking::nominate(
pool_origin2.clone(),
vec![account("random_validator", 0, USER_SEED)].clone(),
)?;
Expand All @@ -156,10 +156,7 @@ impl<T: Config> ListScenario<T> {

// Create an account with the worst case destination weight
let (_, pool_dest1) = create_pool_account::<T>(USER_SEED + 3, dest_weight);
T::StakingInterface::nominate(
pool_dest1.clone(),
vec![account("random_validator", 0, USER_SEED)],
)?;
T::Staking::nominate(pool_dest1.clone(), vec![account("random_validator", 0, USER_SEED)])?;

let weight_of = pallet_staking::Pallet::<T>::weight_of_fn();
assert_eq!(vote_to_balance::<T>(weight_of(&pool_origin1)).unwrap(), origin_weight);
Expand All @@ -185,11 +182,11 @@ impl<T: Config> ListScenario<T> {
self.origin1_member = Some(joiner.clone());
CurrencyOf::<T>::make_free_balance_be(&joiner, amount * 2u32.into());

let original_bonded = T::StakingInterface::active_stake(&self.origin1).unwrap();
let original_bonded = T::Staking::active_stake(&self.origin1).unwrap();

// Unbond `amount` from the underlying pool account so when the member joins
// we will maintain `current_bonded`.
T::StakingInterface::unbond(self.origin1.clone(), amount)
T::Staking::unbond(self.origin1.clone(), amount)
.expect("the pool was created in `Self::new`.");

// Account pool points for the unbonded balance.
Expand Down Expand Up @@ -219,7 +216,7 @@ frame_benchmarking::benchmarks! {
// setup the worst case list scenario.
let scenario = ListScenario::<T>::new(origin_weight, true)?;
assert_eq!(
T::StakingInterface::active_stake(&scenario.origin1).unwrap(),
T::Staking::active_stake(&scenario.origin1).unwrap(),
origin_weight
);

Expand All @@ -234,7 +231,7 @@ frame_benchmarking::benchmarks! {
verify {
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), joiner_free - max_additional);
assert_eq!(
T::StakingInterface::active_stake(&scenario.origin1).unwrap(),
T::Staking::active_stake(&scenario.origin1).unwrap(),
scenario.dest_weight
);
}
Expand All @@ -249,7 +246,7 @@ frame_benchmarking::benchmarks! {
}: bond_extra(RuntimeOrigin::Signed(scenario.creator1.clone()), BondExtra::FreeBalance(extra))
verify {
assert!(
T::StakingInterface::active_stake(&scenario.origin1).unwrap() >=
T::Staking::active_stake(&scenario.origin1).unwrap() >=
scenario.dest_weight
);
}
Expand All @@ -267,7 +264,7 @@ frame_benchmarking::benchmarks! {
}: bond_extra(RuntimeOrigin::Signed(scenario.creator1.clone()), BondExtra::Rewards)
verify {
assert!(
T::StakingInterface::active_stake(&scenario.origin1).unwrap() >=
T::Staking::active_stake(&scenario.origin1).unwrap() >=
scenario.dest_weight
);
}
Expand Down Expand Up @@ -314,7 +311,7 @@ frame_benchmarking::benchmarks! {
whitelist_account!(member_id);
}: _(RuntimeOrigin::Signed(member_id.clone()), member_id_lookup, all_points)
verify {
let bonded_after = T::StakingInterface::active_stake(&scenario.origin1).unwrap();
let bonded_after = T::Staking::active_stake(&scenario.origin1).unwrap();
// We at least went down to the destination bag
assert!(bonded_after <= scenario.dest_weight);
let member = PoolMembers::<T>::get(
Expand All @@ -323,7 +320,7 @@ frame_benchmarking::benchmarks! {
.unwrap();
assert_eq!(
member.unbonding_eras.keys().cloned().collect::<Vec<_>>(),
vec![0 + T::StakingInterface::bonding_duration()]
vec![0 + T::Staking::bonding_duration()]
);
assert_eq!(
member.unbonding_eras.values().cloned().collect::<Vec<_>>(),
Expand All @@ -345,7 +342,7 @@ frame_benchmarking::benchmarks! {

// Sanity check join worked
assert_eq!(
T::StakingInterface::active_stake(&pool_account).unwrap(),
T::Staking::active_stake(&pool_account).unwrap(),
min_create_bond + min_join_bond
);
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), min_join_bond);
Expand All @@ -355,7 +352,7 @@ frame_benchmarking::benchmarks! {

// Sanity check that unbond worked
assert_eq!(
T::StakingInterface::active_stake(&pool_account).unwrap(),
T::Staking::active_stake(&pool_account).unwrap(),
min_create_bond
);
assert_eq!(pallet_staking::Ledger::<T>::get(&pool_account).unwrap().unlocking.len(), 1);
Expand Down Expand Up @@ -388,7 +385,7 @@ frame_benchmarking::benchmarks! {

// Sanity check join worked
assert_eq!(
T::StakingInterface::active_stake(&pool_account).unwrap(),
T::Staking::active_stake(&pool_account).unwrap(),
min_create_bond + min_join_bond
);
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), min_join_bond);
Expand All @@ -399,7 +396,7 @@ frame_benchmarking::benchmarks! {

// Sanity check that unbond worked
assert_eq!(
T::StakingInterface::active_stake(&pool_account).unwrap(),
T::Staking::active_stake(&pool_account).unwrap(),
min_create_bond
);
assert_eq!(pallet_staking::Ledger::<T>::get(&pool_account).unwrap().unlocking.len(), 1);
Expand Down Expand Up @@ -446,7 +443,7 @@ frame_benchmarking::benchmarks! {

// Sanity check that unbond worked
assert_eq!(
T::StakingInterface::active_stake(&pool_account).unwrap(),
T::Staking::active_stake(&pool_account).unwrap(),
Zero::zero()
);
assert_eq!(
Expand Down Expand Up @@ -525,7 +522,7 @@ frame_benchmarking::benchmarks! {
}
);
assert_eq!(
T::StakingInterface::active_stake(&Pools::<T>::create_bonded_account(1)),
T::Staking::active_stake(&Pools::<T>::create_bonded_account(1)),
Some(min_create_bond)
);
}
Expand Down Expand Up @@ -564,7 +561,7 @@ frame_benchmarking::benchmarks! {
}
);
assert_eq!(
T::StakingInterface::active_stake(&Pools::<T>::create_bonded_account(1)),
T::Staking::active_stake(&Pools::<T>::create_bonded_account(1)),
Some(min_create_bond)
);
}
Expand Down Expand Up @@ -648,12 +645,12 @@ frame_benchmarking::benchmarks! {
.collect();

assert_ok!(Pools::<T>::nominate(RuntimeOrigin::Signed(depositor.clone()).into(), 1, validators));
assert!(T::StakingInterface::nominations(Pools::<T>::create_bonded_account(1)).is_some());
assert!(T::Staking::nominations(Pools::<T>::create_bonded_account(1)).is_some());

whitelist_account!(depositor);
}:_(RuntimeOrigin::Signed(depositor.clone()), 1)
verify {
assert!(T::StakingInterface::nominations(Pools::<T>::create_bonded_account(1)).is_none());
assert!(T::Staking::nominations(Pools::<T>::create_bonded_account(1)).is_none());
}

impl_benchmark_test_suite!(
Expand Down
2 changes: 1 addition & 1 deletion frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl pallet_nomination_pools::Config for Runtime {
type RewardCounter = FixedU128;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
type StakingInterface = Staking;
type Staking = Staking;
type PostUnbondingPoolsWindow = PostUnbondingPoolsWindow;
type MaxMetadataLen = ConstU32<256>;
type MaxUnbonding = ConstU32<8>;
Expand Down
52 changes: 23 additions & 29 deletions frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ impl<T: Config> BondedPool<T> {
/// This is often used for bonding and issuing new funds into the pool.
fn balance_to_point(&self, new_funds: BalanceOf<T>) -> BalanceOf<T> {
let bonded_balance =
T::StakingInterface::active_stake(&self.bonded_account()).unwrap_or(Zero::zero());
T::Staking::active_stake(&self.bonded_account()).unwrap_or(Zero::zero());
Pallet::<T>::balance_to_point(bonded_balance, self.points, new_funds)
}

Expand All @@ -632,7 +632,7 @@ impl<T: Config> BondedPool<T> {
/// This is often used for unbonding.
fn points_to_balance(&self, points: BalanceOf<T>) -> BalanceOf<T> {
let bonded_balance =
T::StakingInterface::active_stake(&self.bonded_account()).unwrap_or(Zero::zero());
T::Staking::active_stake(&self.bonded_account()).unwrap_or(Zero::zero());
Pallet::<T>::point_to_balance(bonded_balance, self.points, points)
}

Expand Down Expand Up @@ -683,7 +683,7 @@ impl<T: Config> BondedPool<T> {
fn transferrable_balance(&self) -> BalanceOf<T> {
let account = self.bonded_account();
T::Currency::free_balance(&account)
.saturating_sub(T::StakingInterface::active_stake(&account).unwrap_or_default())
.saturating_sub(T::Staking::active_stake(&account).unwrap_or_default())
}

fn is_root(&self, who: &T::AccountId) -> bool {
Expand Down Expand Up @@ -738,7 +738,7 @@ impl<T: Config> BondedPool<T> {
ensure!(!self.is_destroying(), Error::<T>::CanNotChangeState);

let bonded_balance =
T::StakingInterface::active_stake(&self.bonded_account()).unwrap_or(Zero::zero());
T::Staking::active_stake(&self.bonded_account()).unwrap_or(Zero::zero());
ensure!(!bonded_balance.is_zero(), Error::<T>::OverflowRisk);

let points_to_balance_ratio_floor = self
Expand Down Expand Up @@ -862,8 +862,8 @@ impl<T: Config> BondedPool<T> {

/// Bond exactly `amount` from `who`'s funds into this pool.
///
/// If the bond type is `Create`, `StakingInterface::bond` is called, and `who`
/// is allowed to be killed. Otherwise, `StakingInterface::bond_extra` is called and `who`
/// If the bond type is `Create`, `Staking::bond` is called, and `who`
/// is allowed to be killed. Otherwise, `Staking::bond_extra` is called and `who`
/// cannot be killed.
///
/// Returns `Ok(points_issues)`, `Err` otherwise.
Expand All @@ -889,7 +889,7 @@ impl<T: Config> BondedPool<T> {
let points_issued = self.issue(amount);

match ty {
BondType::Create => T::StakingInterface::bond(
BondType::Create => T::Staking::bond(
bonded_account.clone(),
bonded_account,
amount,
Expand All @@ -898,7 +898,7 @@ impl<T: Config> BondedPool<T> {
// The pool should always be created in such a way its in a state to bond extra, but if
// the active balance is slashed below the minimum bonded or the account cannot be
// found, we exit early.
BondType::Later => T::StakingInterface::bond_extra(bonded_account, amount)?,
BondType::Later => T::Staking::bond_extra(bonded_account, amount)?,
}

Ok(points_issued)
Expand Down Expand Up @@ -1129,7 +1129,7 @@ impl<T: Config> Get<u32> for TotalUnbondingPools<T> {
// NOTE: this may be dangerous in the scenario bonding_duration gets decreased because
// we would no longer be able to decode `UnbondingPoolsWithEra`, which uses
// `TotalUnbondingPools` as the bound
T::StakingInterface::bonding_duration() + T::PostUnbondingPoolsWindow::get()
T::Staking::bonding_duration() + T::PostUnbondingPoolsWindow::get()
}
}

Expand Down Expand Up @@ -1212,10 +1212,7 @@ pub mod pallet {
type U256ToBalance: Convert<U256, BalanceOf<Self>>;

/// The interface for nominating.
type StakingInterface: StakingInterface<
Balance = BalanceOf<Self>,
AccountId = Self::AccountId,
>;
type Staking: StakingInterface<Balance = BalanceOf<Self>, AccountId = Self::AccountId>;

/// The amount of eras a `SubPools::with_era` pool can exist before it gets merged into the
/// `SubPools::no_era` pool. In other words, this is the amount of eras a member will be
Expand Down Expand Up @@ -1650,12 +1647,12 @@ pub mod pallet {
let _ = reward_pool.update_records(bonded_pool.id, bonded_pool.points)?;
let _ = Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?;

let current_era = T::StakingInterface::current_era();
let unbond_era = T::StakingInterface::bonding_duration().saturating_add(current_era);
let current_era = T::Staking::current_era();
let unbond_era = T::Staking::bonding_duration().saturating_add(current_era);

// Unbond in the actual underlying nominator.
let unbonding_balance = bonded_pool.dissolve(unbonding_points);
T::StakingInterface::unbond(bonded_pool.bonded_account(), unbonding_balance)?;
T::Staking::unbond(bonded_pool.bonded_account(), unbonding_balance)?;

// Note that we lazily create the unbonding pools here if they don't already exist
let mut sub_pools = SubPoolsStorage::<T>::get(member.pool_id)
Expand Down Expand Up @@ -1718,7 +1715,7 @@ pub mod pallet {
// For now we only allow a pool to withdraw unbonded if its not destroying. If the pool
// is destroying then `withdraw_unbonded` can be used.
ensure!(pool.state != PoolState::Destroying, Error::<T>::NotDestroying);
T::StakingInterface::withdraw_unbonded(pool.bonded_account(), num_slashing_spans)?;
T::Staking::withdraw_unbonded(pool.bonded_account(), num_slashing_spans)?;
Ok(())
}

Expand Down Expand Up @@ -1754,7 +1751,7 @@ pub mod pallet {
let member_account = T::Lookup::lookup(member_account)?;
let mut member =
PoolMembers::<T>::get(&member_account).ok_or(Error::<T>::PoolMemberNotFound)?;
let current_era = T::StakingInterface::current_era();
let current_era = T::Staking::current_era();

let bonded_pool = BondedPool::<T>::get(member.pool_id)
.defensive_ok_or::<Error<T>>(DefensiveError::PoolNotFound.into())?;
Expand All @@ -1769,10 +1766,8 @@ pub mod pallet {

// Before calculate the `balance_to_unbond`, with call withdraw unbonded to ensure the
// `transferrable_balance` is correct.
let stash_killed = T::StakingInterface::withdraw_unbonded(
bonded_pool.bonded_account(),
num_slashing_spans,
)?;
let stash_killed =
T::Staking::withdraw_unbonded(bonded_pool.bonded_account(), num_slashing_spans)?;

// defensive-only: the depositor puts enough funds into the stash so that it will only
// be destroyed when they are leaving.
Expand Down Expand Up @@ -1960,7 +1955,7 @@ pub mod pallet {
let who = ensure_signed(origin)?;
let bonded_pool = BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?;
ensure!(bonded_pool.can_nominate(&who), Error::<T>::NotNominator);
T::StakingInterface::nominate(bonded_pool.bonded_account(), validators)
T::Staking::nominate(bonded_pool.bonded_account(), validators)
}

/// Set a new state for the pool.
Expand Down Expand Up @@ -2132,7 +2127,7 @@ pub mod pallet {
let who = ensure_signed(origin)?;
let bonded_pool = BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?;
ensure!(bonded_pool.can_nominate(&who), Error::<T>::NotNominator);
T::StakingInterface::chill(bonded_pool.bonded_account())
T::Staking::chill(bonded_pool.bonded_account())
}
}

Expand All @@ -2149,7 +2144,7 @@ pub mod pallet {
"Minimum points to balance ratio must be greater than 0"
);
assert!(
T::StakingInterface::bonding_duration() < TotalUnbondingPools::<T>::get(),
T::Staking::bonding_duration() < TotalUnbondingPools::<T>::get(),
"There must be more unbonding pools then the bonding duration /
so a slash can be applied to relevant unboding pools. (We assume /
the bonding duration > slash deffer duration.",
Expand Down Expand Up @@ -2185,7 +2180,7 @@ impl<T: Config> Pallet<T> {
/// It is essentially `max { MinNominatorBond, MinCreateBond, MinJoinBond }`, where the former
/// is coming from the staking pallet and the latter two are configured in this pallet.
pub fn depositor_min_bond() -> BalanceOf<T> {
T::StakingInterface::minimum_bond()
T::Staking::minimum_bond()
.max(MinCreateBond::<T>::get())
.max(MinJoinBond::<T>::get())
.max(T::Currency::minimum_balance())
Expand All @@ -2212,7 +2207,7 @@ impl<T: Config> Pallet<T> {
debug_assert_eq!(frame_system::Pallet::<T>::consumers(&reward_account), 0);
debug_assert_eq!(frame_system::Pallet::<T>::consumers(&bonded_account), 0);
debug_assert_eq!(
T::StakingInterface::total_stake(&bonded_account).unwrap_or_default(),
T::Staking::total_stake(&bonded_account).unwrap_or_default(),
Zero::zero()
);

Expand Down Expand Up @@ -2487,8 +2482,7 @@ impl<T: Config> Pallet<T> {
let subs = SubPoolsStorage::<T>::get(pool_id).unwrap_or_default();

let sum_unbonding_balance = subs.sum_unbonding_balance();
let bonded_balance =
T::StakingInterface::active_stake(&pool_account).unwrap_or_default();
let bonded_balance = T::Staking::active_stake(&pool_account).unwrap_or_default();
let total_balance = T::Currency::total_balance(&pool_account);

assert!(
Expand Down
2 changes: 1 addition & 1 deletion frame/nomination-pools/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl pools::Config for Runtime {
type RewardCounter = RewardCounter;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
type StakingInterface = StakingMock;
type Staking = StakingMock;
type PostUnbondingPoolsWindow = PostUnbondingPoolsWindow;
type PalletId = PoolsPalletId;
type MaxMetadataLen = MaxMetadataLen;
Expand Down
2 changes: 1 addition & 1 deletion frame/nomination-pools/test-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl pallet_nomination_pools::Config for Runtime {
type RewardCounter = FixedU128;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
type StakingInterface = Staking;
type Staking = Staking;
type PostUnbondingPoolsWindow = PostUnbondingPoolsWindow;
type MaxMetadataLen = ConstU32<256>;
type MaxUnbonding = ConstU32<8>;
Expand Down