Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

bond_extra for nomination pools #11100

Merged
merged 7 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions frame/bags-list/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ frame_benchmarking::benchmarks! {
vec![heavier, lighter, heavier_prev, heavier_next]
)
}
}

frame_benchmarking::impl_benchmark_test_suite!(
Pallet,
crate::mock::ExtBuilder::default().skip_genesis_ids().build(),
crate::mock::Runtime
);
impl_benchmark_test_suite!(
Pallet,
crate::mock::ExtBuilder::default().skip_genesis_ids().build(),
crate::mock::Runtime
);
}
64 changes: 53 additions & 11 deletions frame/nomination-pools/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use frame_election_provider_support::SortedListProvider;
use frame_support::{ensure, traits::Get};
use frame_system::RawOrigin as Origin;
use pallet_nomination_pools::{
BalanceOf, BondedPoolInner, BondedPools, ConfigOp, Delegators, MaxDelegators,
BalanceOf, BondExtra, BondedPoolInner, BondedPools, ConfigOp, Delegators, MaxDelegators,
MaxDelegatorsPerPool, MaxPools, Metadata, MinCreateBond, MinJoinBond, Pallet as Pools,
PoolRoles, PoolState, RewardPools, SubPoolsStorage,
};
Expand Down Expand Up @@ -75,9 +75,11 @@ fn vote_to_balance<T: pallet_nomination_pools::Config>(
vote.try_into().map_err(|_| "could not convert u64 to Balance")
}

#[allow(unused)]
struct ListScenario<T: pallet_nomination_pools::Config> {
/// Stash/Controller that is expected to be moved.
origin1: T::AccountId,
creator1: T::AccountId,
dest_weight: BalanceOf<T>,
origin1_delegator: Option<T::AccountId>,
}
Expand Down Expand Up @@ -109,7 +111,7 @@ impl<T: Config> ListScenario<T> {
sp_std::mem::forget(i);

// Create accounts with the origin weight
let (_, pool_origin1) = create_pool_account::<T>(USER_SEED + 1, origin_weight);
let (pool_creator1, pool_origin1) = create_pool_account::<T>(USER_SEED + 1, origin_weight);
T::StakingInterface::nominate(
pool_origin1.clone(),
// NOTE: these don't really need to be validators.
Expand Down Expand Up @@ -144,7 +146,12 @@ impl<T: Config> ListScenario<T> {
assert_eq!(vote_to_balance::<T>(weight_of(&pool_origin2)).unwrap(), origin_weight);
assert_eq!(vote_to_balance::<T>(weight_of(&pool_dest1)).unwrap(), dest_weight);

Ok(ListScenario { origin1: pool_origin1, dest_weight, origin1_delegator: None })
Ok(ListScenario {
origin1: pool_origin1,
creator1: pool_creator1,
dest_weight,
origin1_delegator: None,
})
}

fn add_joiner(mut self, amount: BalanceOf<T>) -> Self {
Expand Down Expand Up @@ -214,6 +221,43 @@ frame_benchmarking::benchmarks! {
);
}

bond_extra_transfer {
let origin_weight = pallet_nomination_pools::MinCreateBond::<T>::get()
.max(CurrencyOf::<T>::minimum_balance())
* 2u32.into();
let scenario = ListScenario::<T>::new(origin_weight, true)?;
let extra = scenario.dest_weight.clone() - origin_weight;

// creator of the src pool will bond-extra, bumping itself to dest bag.

}: bond_extra(Origin::Signed(scenario.creator1.clone()), BondExtra::FreeBalance(extra))
verify {
assert_eq!(
T::StakingInterface::active_stake(&scenario.origin1).unwrap(),
scenario.dest_weight
);
}

bond_extra_reward {
let origin_weight = pallet_nomination_pools::MinCreateBond::<T>::get()
.max(CurrencyOf::<T>::minimum_balance())
* 2u32.into();
let scenario = ListScenario::<T>::new(origin_weight, true)?;
let extra = (scenario.dest_weight.clone() - origin_weight).max(CurrencyOf::<T>::minimum_balance());

// transfer exactly `extra` to the depositor of the src pool (1),
let reward_account1 = Pools::<T>::create_reward_account(1);
assert!(extra >= CurrencyOf::<T>::minimum_balance());
CurrencyOf::<T>::deposit_creating(&reward_account1, extra);

}: bond_extra(Origin::Signed(scenario.creator1.clone()), BondExtra::Rewards)
verify {
assert_eq!(
T::StakingInterface::active_stake(&scenario.origin1).unwrap(),
scenario.dest_weight
);
}

claim_payout {
let origin_weight = pallet_nomination_pools::MinCreateBond::<T>::get().max(CurrencyOf::<T>::minimum_balance()) * 2u32.into();
let ed = CurrencyOf::<T>::minimum_balance();
Expand Down Expand Up @@ -560,12 +604,10 @@ frame_benchmarking::benchmarks! {
assert_eq!(MaxDelegators::<T>::get(), Some(u32::MAX));
assert_eq!(MaxDelegatorsPerPool::<T>::get(), Some(u32::MAX));
}
}

// TODO: consider benchmarking slashing logic with pools

frame_benchmarking::impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(),
crate::mock::Runtime
);
impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(),
crate::mock::Runtime
);
}
Loading