[Enhancement] Convert fast-unstake to use StakingInterface, decouplin… (#12424)

* [Enhancement] Convert fast-unstake to use StakingInterface, decoupling it from Staking

* Update primitives/staking/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update primitives/staking/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* fix validator comment

* remove todo

* ideas from Kian (#12474)

Co-authored-by: kianenigma <kian@parity.io>

* Rename StakingInterface -> Staking for nomination-pools

* Staking fixes

* StakingInterface changes

* fix fast-unstake

* fix nomination-pools

* Fix fast-unstake tests

* Fix benches for fast-unstake

* fix is_unbonding

* fix nomination pools

* fix node code

* add mock comments

* fix imports

* remove todo

* more fixes

* more fixes

* bench fixes

* more fixes

* more fixes

* import fix

* more fixes

* more bench fix

* refix

* refix

* Update primitives/staking/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* is_unbonding returns a result

* fix

* review fixes

* more review fixes

* more fixes

* more fixes

* Update frame/fast-unstake/src/benchmarking.rs

Co-authored-by: Squirrel <gilescope@gmail.com>

* remove redundant CurrencyBalance from nom-pools

* remove CB

* rephrase

* Apply suggestions from code review

* Update frame/nomination-pools/src/tests.rs

* finish damn renamed

* clippy fix

* fix

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: kianenigma <kian@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Squirrel <gilescope@gmail.com>
This commit is contained in:
Roman Useinov
2022-10-29 11:22:58 +02:00
committed by GitHub
parent 3faa0bd20d
commit 4bc091f4a9
16 changed files with 371 additions and 304 deletions
@@ -26,22 +26,15 @@ use frame_support::{
traits::{Currency, EnsureOrigin, Get, Hooks},
};
use frame_system::RawOrigin;
use pallet_staking::Pallet as Staking;
use sp_runtime::traits::{StaticLookup, Zero};
use sp_staking::EraIndex;
use sp_runtime::traits::Zero;
use sp_staking::{EraIndex, StakingInterface};
use sp_std::prelude::*;
const USER_SEED: u32 = 0;
const DEFAULT_BACKER_PER_VALIDATOR: u32 = 128;
const MAX_VALIDATORS: u32 = 128;
type CurrencyOf<T> = <T as pallet_staking::Config>::Currency;
fn l<T: Config>(
who: T::AccountId,
) -> <<T as frame_system::Config>::Lookup as StaticLookup>::Source {
T::Lookup::unlookup(who)
}
type CurrencyOf<T> = <T as Config>::Currency;
fn create_unexposed_nominator<T: Config>() -> T::AccountId {
let account = frame_benchmarking::account::<T::AccountId>("nominator_42", 0, USER_SEED);
@@ -53,18 +46,9 @@ fn fund_and_bond_account<T: Config>(account: &T::AccountId) {
let stake = CurrencyOf::<T>::minimum_balance() * 100u32.into();
CurrencyOf::<T>::make_free_balance_be(&account, stake * 10u32.into());
let account_lookup = l::<T>(account.clone());
// bond and nominate ourselves, this will guarantee that we are not backing anyone.
assert_ok!(Staking::<T>::bond(
RawOrigin::Signed(account.clone()).into(),
account_lookup.clone(),
stake,
pallet_staking::RewardDestination::Controller,
));
assert_ok!(Staking::<T>::nominate(
RawOrigin::Signed(account.clone()).into(),
vec![account_lookup]
));
assert_ok!(T::Staking::bond(account, stake, account));
assert_ok!(T::Staking::nominate(account, vec![account.clone()]));
}
pub(crate) fn fast_unstake_events<T: Config>() -> Vec<crate::Event<T>> {
@@ -91,13 +75,11 @@ fn setup_staking<T: Config>(v: u32, until: EraIndex) {
.map(|s| {
let who = frame_benchmarking::account::<T::AccountId>("nominator", era, s);
let value = ed;
pallet_staking::IndividualExposure { who, value }
(who, value)
})
.collect::<Vec<_>>();
let exposure =
pallet_staking::Exposure { total: Default::default(), own: Default::default(), others };
validators.iter().for_each(|v| {
Staking::<T>::add_era_stakers(era, v.clone(), exposure.clone());
T::Staking::add_era_stakers(&era, &v, others.clone());
});
}
}
@@ -137,13 +119,13 @@ benchmarks! {
// on_idle, when we check some number of eras,
on_idle_check {
// number of eras multiplied by validators in that era.
let x in (<T as pallet_staking::Config>::BondingDuration::get() * 1) .. (<T as pallet_staking::Config>::BondingDuration::get() * MAX_VALIDATORS);
let x in (T::Staking::bonding_duration() * 1) .. (T::Staking::bonding_duration() * MAX_VALIDATORS);
let v = x / <T as pallet_staking::Config>::BondingDuration::get();
let u = <T as pallet_staking::Config>::BondingDuration::get();
let u = T::Staking::bonding_duration();
let v = x / u;
ErasToCheckPerBlock::<T>::put(u);
pallet_staking::CurrentEra::<T>::put(u);
T::Staking::set_current_era(u);
// setup staking with v validators and u eras of data (0..=u)
setup_staking::<T>(v, u);