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
+41 -32
View File
@@ -76,16 +76,36 @@ pub fn create_stash_controller<T: Config>(
balance_factor: u32,
destination: RewardDestination<T::AccountId>,
) -> Result<(T::AccountId, T::AccountId), &'static str> {
let stash = create_funded_user::<T>("stash", n, balance_factor);
let controller = create_funded_user::<T>("controller", n, balance_factor);
let controller_lookup = T::Lookup::unlookup(controller.clone());
let staker = create_funded_user::<T>("stash", n, balance_factor);
let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into();
Staking::<T>::bond(
RawOrigin::Signed(stash.clone()).into(),
controller_lookup,
amount,
destination,
)?;
Staking::<T>::bond(RawOrigin::Signed(staker.clone()).into(), amount, destination)?;
Ok((staker.clone(), staker))
}
/// Create a unique stash and controller pair.
pub fn create_unique_stash_controller<T: Config>(
n: u32,
balance_factor: u32,
destination: RewardDestination<T::AccountId>,
dead_controller: bool,
) -> Result<(T::AccountId, T::AccountId), &'static str> {
let stash = create_funded_user::<T>("stash", n, balance_factor);
let controller = if dead_controller {
create_funded_user::<T>("controller", n, 0)
} else {
create_funded_user::<T>("controller", n, balance_factor)
};
let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into();
Staking::<T>::bond(RawOrigin::Signed(stash.clone()).into(), amount, destination)?;
// update ledger to be a *different* controller to stash
if let Some(l) = Ledger::<T>::take(&stash) {
<Ledger<T>>::insert(&controller, l);
}
// update bonded account to be unique controller
<Bonded<T>>::insert(&stash, &controller);
Ok((stash, controller))
}
@@ -95,38 +115,27 @@ pub fn create_stash_controller_with_balance<T: Config>(
balance: crate::BalanceOf<T>,
destination: RewardDestination<T::AccountId>,
) -> Result<(T::AccountId, T::AccountId), &'static str> {
let stash = create_funded_user_with_balance::<T>("stash", n, balance);
let controller = create_funded_user_with_balance::<T>("controller", n, balance);
let controller_lookup = T::Lookup::unlookup(controller.clone());
Staking::<T>::bond(
RawOrigin::Signed(stash.clone()).into(),
controller_lookup,
balance,
destination,
)?;
Ok((stash, controller))
let staker = create_funded_user_with_balance::<T>("stash", n, balance);
Staking::<T>::bond(RawOrigin::Signed(staker.clone()).into(), balance, destination)?;
Ok((staker.clone(), staker))
}
/// Create a stash and controller pair, where the controller is dead, and payouts go to controller.
/// This is used to test worst case payout scenarios.
pub fn create_stash_and_dead_controller<T: Config>(
/// Create a stash and controller pair, where payouts go to a dead payee account. This is used to
/// test worst case payout scenarios.
pub fn create_stash_and_dead_payee<T: Config>(
n: u32,
balance_factor: u32,
destination: RewardDestination<T::AccountId>,
) -> Result<(T::AccountId, T::AccountId), &'static str> {
let stash = create_funded_user::<T>("stash", n, balance_factor);
// controller has no funds
let controller = create_funded_user::<T>("controller", n, 0);
let controller_lookup = T::Lookup::unlookup(controller.clone());
let staker = create_funded_user::<T>("stash", n, 0);
// payee has no funds
let payee = create_funded_user::<T>("payee", n, 0);
let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into();
Staking::<T>::bond(
RawOrigin::Signed(stash.clone()).into(),
controller_lookup,
RawOrigin::Signed(staker.clone()).into(),
amount,
destination,
RewardDestination::Account(payee),
)?;
Ok((stash, controller))
Ok((staker.clone(), staker))
}
/// create `max` validators.