Staking::{bond, set_controller} to set controllers to stash only. (#14039)

* update set_controller

* clone

* bond uses `stash`

* remove controller from bond(), chill_other test works

* remove ctlr from testing_utils &  dead ctlr -> dead payee

* mvs controllers to stashes for 3 tests

* migrate mock bond fns & fix 1 test

* mvs controllers to stashes for 7 tests

* mvs controllers to stashes for 9 tests

* remove double_controlling_should_fail

* remove double_staking_should_fail

* mvs controllers to stashes for 10 tests

* mvs controllers to stashes for 2 tests

* remove payout_creates_controller

* mvs controllers to stashes for 27 tests

* remove println!

* fix rewards_should_work

* fix test_payout_stakers

* fix bond benchmark

* clone

* rm unused import

* rm unused var

* rm controller from create_offender

* fix GenesisConfig stakers

* fix controllers in consensus pallets

* fix unqiue controller in chain_spec

* fmt

* fix create_offender

* fix set_controller benchmark

* add TODO

* create_unique_stash_controller

* staking benchmarks working

* fmt

* fix args

* rm println

* import

* import

* fix fast unstake tests

* fix staking-tests-e2e

* fix root-offenses

* fmt

* differentiate controller to stash

* bring back change_controller_works w. unique ctrl

* bring back double_staking_should_fail

* double_controlling_attempt_should_fail

* bring back payout_creates_controller

* add commnet to controller balances

* + set_controller call description

* fmt

* rm clones

* fmt

* clippy fixes

* fmt

* update README

* small fixes

* use controller_to_be_deprecated

* .comment

* comment

* bump zombienet version

* ci

---------

Co-authored-by: parity-processbot <>
Co-authored-by: Javier Viola <javier@parity.io>
This commit is contained in:
Ross Bulat
2023-05-12 02:22:15 +08:00
committed by GitHub
parent 0eeaf7709f
commit 56940bc874
20 changed files with 696 additions and 711 deletions
+25 -14
View File
@@ -71,7 +71,8 @@ pub fn add_slashing_spans<T: Config>(who: &T::AccountId, spans: u32) {
pub fn create_validator_with_nominators<T: Config>(
n: u32,
upper_bound: u32,
dead: bool,
dead_controller: bool,
unique_controller: bool,
destination: RewardDestination<T::AccountId>,
) -> Result<(T::AccountId, Vec<(T::AccountId, T::AccountId)>), &'static str> {
// Clean up any existing state.
@@ -79,7 +80,12 @@ pub fn create_validator_with_nominators<T: Config>(
let mut points_total = 0;
let mut points_individual = Vec::new();
let (v_stash, v_controller) = create_stash_controller::<T>(0, 100, destination.clone())?;
let (v_stash, v_controller) = if unique_controller {
create_unique_stash_controller::<T>(0, 100, destination.clone(), false)?
} else {
create_stash_controller::<T>(0, 100, destination.clone())?
};
let validator_prefs =
ValidatorPrefs { commission: Perbill::from_percent(50), ..Default::default() };
Staking::<T>::validate(RawOrigin::Signed(v_controller).into(), validator_prefs)?;
@@ -93,10 +99,10 @@ pub fn create_validator_with_nominators<T: Config>(
// Give the validator n nominators, but keep total users in the system the same.
for i in 0..upper_bound {
let (n_stash, n_controller) = if !dead {
let (n_stash, n_controller) = if !dead_controller {
create_stash_controller::<T>(u32::MAX - i, 100, destination.clone())?
} else {
create_stash_and_dead_controller::<T>(u32::MAX - i, 100, destination.clone())?
create_unique_stash_controller::<T>(u32::MAX - i, 100, destination.clone(), true)?
};
if i < n {
Staking::<T>::nominate(
@@ -217,15 +223,13 @@ const USER_SEED: u32 = 999666;
benchmarks! {
bond {
let stash = create_funded_user::<T>("stash", USER_SEED, 100);
let controller = create_funded_user::<T>("controller", USER_SEED, 100);
let controller_lookup = T::Lookup::unlookup(controller.clone());
let reward_destination = RewardDestination::Staked;
let amount = T::Currency::minimum_balance() * 10u32.into();
whitelist_account!(stash);
}: _(RawOrigin::Signed(stash.clone()), controller_lookup, amount, reward_destination)
}: _(RawOrigin::Signed(stash.clone()), amount, reward_destination)
verify {
assert!(Bonded::<T>::contains_key(stash));
assert!(Ledger::<T>::contains_key(controller));
assert!(Bonded::<T>::contains_key(stash.clone()));
assert!(Ledger::<T>::contains_key(stash));
}
bond_extra {
@@ -470,13 +474,16 @@ benchmarks! {
}
set_controller {
let (stash, _) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
let new_controller = create_funded_user::<T>("new_controller", USER_SEED, 100);
let new_controller_lookup = T::Lookup::unlookup(new_controller.clone());
let (stash, ctlr) = create_unique_stash_controller::<T>(9000, 100, Default::default(), false)?;
// ensure `ctlr` is the currently stored controller.
assert!(!Ledger::<T>::contains_key(&stash));
assert!(Ledger::<T>::contains_key(&ctlr));
assert_eq!(Bonded::<T>::get(&stash), Some(ctlr.clone()));
whitelist_account!(stash);
}: _(RawOrigin::Signed(stash), new_controller_lookup)
}: _(RawOrigin::Signed(stash.clone()))
verify {
assert!(Ledger::<T>::contains_key(&new_controller));
assert!(Ledger::<T>::contains_key(&stash));
}
set_validator_count {
@@ -551,6 +558,7 @@ benchmarks! {
n,
T::MaxNominatorRewardedPerValidator::get() as u32,
true,
true,
RewardDestination::Controller,
)?;
@@ -584,6 +592,7 @@ benchmarks! {
n,
T::MaxNominatorRewardedPerValidator::get() as u32,
false,
true,
RewardDestination::Staked,
)?;
@@ -978,6 +987,7 @@ mod tests {
n,
<<Test as Config>::MaxNominatorRewardedPerValidator as Get<_>>::get(),
false,
false,
RewardDestination::Staked,
)
.unwrap();
@@ -1007,6 +1017,7 @@ mod tests {
n,
<<Test as Config>::MaxNominatorRewardedPerValidator as Get<_>>::get(),
false,
false,
RewardDestination::Staked,
)
.unwrap();