mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 18:31:05 +00:00
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:
@@ -61,7 +61,7 @@ variables:
|
||||
|
||||
NEXTEST_FAILURE_OUTPUT: immediate-final
|
||||
NEXTEST_SUCCESS_OUTPUT: final
|
||||
ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.48"
|
||||
ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.52"
|
||||
|
||||
default:
|
||||
retry:
|
||||
|
||||
@@ -274,7 +274,7 @@ pub fn testnet_genesis(
|
||||
let mut rng = rand::thread_rng();
|
||||
let stakers = initial_authorities
|
||||
.iter()
|
||||
.map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
|
||||
.map(|x| (x.0.clone(), x.0.clone(), STASH, StakerStatus::Validator))
|
||||
.chain(initial_nominators.iter().map(|x| {
|
||||
use rand::{seq::SliceRandom, Rng};
|
||||
let limit = (MaxNominations::get() as usize).min(initial_authorities.len());
|
||||
|
||||
@@ -65,9 +65,9 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Gen
|
||||
},
|
||||
staking: StakingConfig {
|
||||
stakers: vec![
|
||||
(dave(), alice(), 111 * DOLLARS, StakerStatus::Validator),
|
||||
(eve(), bob(), 100 * DOLLARS, StakerStatus::Validator),
|
||||
(ferdie(), charlie(), 100 * DOLLARS, StakerStatus::Validator),
|
||||
(dave(), dave(), 111 * DOLLARS, StakerStatus::Validator),
|
||||
(eve(), eve(), 100 * DOLLARS, StakerStatus::Validator),
|
||||
(ferdie(), ferdie(), 100 * DOLLARS, StakerStatus::Validator),
|
||||
],
|
||||
validator_count: 3,
|
||||
minimum_validator_count: 0,
|
||||
|
||||
@@ -368,11 +368,9 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> sp_io::Tes
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
|
||||
// controllers are the index + 1000
|
||||
// controllers are same as stash
|
||||
let stakers: Vec<_> = (0..authorities.len())
|
||||
.map(|i| {
|
||||
(i as u64, i as u64 + 1000, 10_000, pallet_staking::StakerStatus::<u64>::Validator)
|
||||
})
|
||||
.map(|i| (i as u64, i as u64, 10_000, pallet_staking::StakerStatus::<u64>::Validator))
|
||||
.collect();
|
||||
|
||||
let staking_config = pallet_staking::GenesisConfig::<Test> {
|
||||
|
||||
@@ -284,11 +284,9 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<BeefyId>) -> TestExternalit
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
|
||||
// controllers are the index + 1000
|
||||
// controllers are same as stash
|
||||
let stakers: Vec<_> = (0..authorities.len())
|
||||
.map(|i| {
|
||||
(i as u64, i as u64 + 1000, 10_000, pallet_staking::StakerStatus::<u64>::Validator)
|
||||
})
|
||||
.map(|i| (i as u64, i as u64, 10_000, pallet_staking::StakerStatus::<u64>::Validator))
|
||||
.collect();
|
||||
|
||||
let staking_config = pallet_staking::GenesisConfig::<Test> {
|
||||
|
||||
@@ -372,19 +372,19 @@ impl Default for StakingExtBuilder {
|
||||
let stakers = vec![
|
||||
// (stash, ctrl, stake, status)
|
||||
// these two will be elected in the default test where we elect 2.
|
||||
(11, 10, 1000, StakerStatus::<AccountId>::Validator),
|
||||
(21, 20, 1000, StakerStatus::<AccountId>::Validator),
|
||||
// loser validatos if validator_count() is default.
|
||||
(31, 30, 500, StakerStatus::<AccountId>::Validator),
|
||||
(41, 40, 500, StakerStatus::<AccountId>::Validator),
|
||||
(51, 50, 500, StakerStatus::<AccountId>::Validator),
|
||||
(61, 60, 500, StakerStatus::<AccountId>::Validator),
|
||||
(71, 70, 500, StakerStatus::<AccountId>::Validator),
|
||||
(81, 80, 500, StakerStatus::<AccountId>::Validator),
|
||||
(91, 90, 500, StakerStatus::<AccountId>::Validator),
|
||||
(101, 100, 500, StakerStatus::<AccountId>::Validator),
|
||||
(11, 11, 1000, StakerStatus::<AccountId>::Validator),
|
||||
(21, 21, 1000, StakerStatus::<AccountId>::Validator),
|
||||
// loser validators if validator_count() is default.
|
||||
(31, 31, 500, StakerStatus::<AccountId>::Validator),
|
||||
(41, 41, 1500, StakerStatus::<AccountId>::Validator),
|
||||
(51, 51, 1500, StakerStatus::<AccountId>::Validator),
|
||||
(61, 61, 1500, StakerStatus::<AccountId>::Validator),
|
||||
(71, 71, 1500, StakerStatus::<AccountId>::Validator),
|
||||
(81, 81, 1500, StakerStatus::<AccountId>::Validator),
|
||||
(91, 91, 1500, StakerStatus::<AccountId>::Validator),
|
||||
(101, 101, 500, StakerStatus::<AccountId>::Validator),
|
||||
// an idle validator
|
||||
(201, 200, 1000, StakerStatus::<AccountId>::Idle),
|
||||
(201, 201, 1000, StakerStatus::<AccountId>::Idle),
|
||||
];
|
||||
|
||||
Self {
|
||||
@@ -439,7 +439,7 @@ impl Default for BalancesExtBuilder {
|
||||
(2, 20),
|
||||
(3, 300),
|
||||
(4, 400),
|
||||
// controllers
|
||||
// controllers (still used in some tests. Soon to be deprecated).
|
||||
(10, 100),
|
||||
(20, 100),
|
||||
(30, 100),
|
||||
|
||||
@@ -234,11 +234,11 @@ impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
unexposed: vec![
|
||||
(1, 2, 7 + 100),
|
||||
(3, 4, 7 + 100),
|
||||
(5, 6, 7 + 100),
|
||||
(7, 8, 7 + 100),
|
||||
(9, 10, 7 + 100),
|
||||
(1, 1, 7 + 100),
|
||||
(3, 3, 7 + 100),
|
||||
(5, 5, 7 + 100),
|
||||
(7, 7, 7 + 100),
|
||||
(9, 9, 7 + 100),
|
||||
],
|
||||
}
|
||||
}
|
||||
@@ -290,12 +290,6 @@ impl ExtBuilder {
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|(stash, _, balance)| (stash, balance * 2))
|
||||
.chain(
|
||||
self.unexposed
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|(_, ctrl, balance)| (ctrl, balance * 2)),
|
||||
)
|
||||
.chain(validators_range.clone().map(|x| (x, 7 + 100)))
|
||||
.chain(nominators_range.clone().map(|x| (x, 7 + 100)))
|
||||
.collect::<Vec<_>>(),
|
||||
@@ -377,7 +371,6 @@ pub fn create_exposed_nominator(exposed: AccountId, era: u32) {
|
||||
Balances::make_free_balance_be(&exposed, 100);
|
||||
assert_ok!(Staking::bond(
|
||||
RuntimeOrigin::signed(exposed),
|
||||
exposed,
|
||||
10,
|
||||
pallet_staking::RewardDestination::Staked
|
||||
));
|
||||
|
||||
@@ -37,7 +37,7 @@ fn register_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
ErasToCheckPerBlock::<T>::put(1);
|
||||
// Controller account registers for fast unstake.
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
// Ensure stash is in the queue.
|
||||
assert_ne!(Queue::<T>::get(1), None);
|
||||
});
|
||||
@@ -52,7 +52,7 @@ fn register_insufficient_funds_fails() {
|
||||
|
||||
// Controller account registers for fast unstake.
|
||||
assert_noop!(
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)),
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)),
|
||||
BalancesError::<T, _>::InsufficientBalance,
|
||||
);
|
||||
|
||||
@@ -65,7 +65,7 @@ fn register_insufficient_funds_fails() {
|
||||
fn register_disabled_fails() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_noop!(
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)),
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)),
|
||||
Error::<T>::CallNotAllowed
|
||||
);
|
||||
});
|
||||
@@ -81,7 +81,7 @@ fn cannot_register_if_not_bonded() {
|
||||
}
|
||||
// Attempt to fast unstake.
|
||||
assert_noop!(
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)),
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)),
|
||||
Error::<T>::NotController
|
||||
);
|
||||
});
|
||||
@@ -95,7 +95,7 @@ fn cannot_register_if_in_queue() {
|
||||
Queue::<T>::insert(1, 10);
|
||||
// Cannot re-register, already in queue
|
||||
assert_noop!(
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)),
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)),
|
||||
Error::<T>::AlreadyQueued
|
||||
);
|
||||
});
|
||||
@@ -112,7 +112,7 @@ fn cannot_register_if_head() {
|
||||
});
|
||||
// Controller attempts to regsiter
|
||||
assert_noop!(
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)),
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)),
|
||||
Error::<T>::AlreadyHead
|
||||
);
|
||||
});
|
||||
@@ -123,10 +123,10 @@ fn cannot_register_if_has_unlocking_chunks() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
ErasToCheckPerBlock::<T>::put(1);
|
||||
// Start unbonding half of staked tokens
|
||||
assert_ok!(Staking::unbond(RuntimeOrigin::signed(2), 50_u128));
|
||||
assert_ok!(Staking::unbond(RuntimeOrigin::signed(1), 50_u128));
|
||||
// Cannot register for fast unstake with unlock chunks active
|
||||
assert_noop!(
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)),
|
||||
FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)),
|
||||
Error::<T>::NotFullyBonded
|
||||
);
|
||||
});
|
||||
@@ -140,11 +140,11 @@ fn deregister_works() {
|
||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), 0);
|
||||
|
||||
// Controller account registers for fast unstake.
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), Deposit::get());
|
||||
|
||||
// Controller then changes mind and deregisters.
|
||||
assert_ok!(FastUnstake::deregister(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::deregister(RuntimeOrigin::signed(1)));
|
||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), 0);
|
||||
|
||||
// Ensure stash no longer exists in the queue.
|
||||
@@ -156,9 +156,9 @@ fn deregister_works() {
|
||||
fn deregister_disabled_fails() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
ErasToCheckPerBlock::<T>::put(1);
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
ErasToCheckPerBlock::<T>::put(0);
|
||||
assert_noop!(FastUnstake::deregister(RuntimeOrigin::signed(2)), Error::<T>::CallNotAllowed);
|
||||
assert_noop!(FastUnstake::deregister(RuntimeOrigin::signed(1)), Error::<T>::CallNotAllowed);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -166,10 +166,10 @@ fn deregister_disabled_fails() {
|
||||
fn cannot_deregister_if_not_controller() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
ErasToCheckPerBlock::<T>::put(1);
|
||||
// Controller account registers for fast unstake.
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
// Stash tries to deregister.
|
||||
assert_noop!(FastUnstake::deregister(RuntimeOrigin::signed(1)), Error::<T>::NotController);
|
||||
// Controller (same as stash) account registers for fast unstake.
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
// Another account tries to deregister.
|
||||
assert_noop!(FastUnstake::deregister(RuntimeOrigin::signed(2)), Error::<T>::NotController);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ fn cannot_deregister_if_not_queued() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
ErasToCheckPerBlock::<T>::put(1);
|
||||
// Controller tries to deregister without first registering
|
||||
assert_noop!(FastUnstake::deregister(RuntimeOrigin::signed(2)), Error::<T>::NotQueued);
|
||||
assert_noop!(FastUnstake::deregister(RuntimeOrigin::signed(1)), Error::<T>::NotQueued);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -187,14 +187,14 @@ fn cannot_deregister_already_head() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
ErasToCheckPerBlock::<T>::put(1);
|
||||
// Controller attempts to register, should fail
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
// Insert some Head item for stash.
|
||||
Head::<T>::put(UnstakeRequest {
|
||||
stashes: bounded_vec![(1, Deposit::get())],
|
||||
checked: bounded_vec![],
|
||||
});
|
||||
// Controller attempts to deregister
|
||||
assert_noop!(FastUnstake::deregister(RuntimeOrigin::signed(2)), Error::<T>::AlreadyHead);
|
||||
assert_noop!(FastUnstake::deregister(RuntimeOrigin::signed(1)), Error::<T>::AlreadyHead);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ fn control_works() {
|
||||
fn control_must_be_control_origin() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
// account without control (root) origin wants to only check 1 era per block.
|
||||
assert_noop!(FastUnstake::control(RuntimeOrigin::signed(1), 1_u32), BadOrigin);
|
||||
assert_noop!(FastUnstake::control(RuntimeOrigin::signed(2), 1_u32), BadOrigin);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ mod on_idle {
|
||||
CurrentEra::<T>::put(BondingDuration::get());
|
||||
|
||||
// set up Queue item
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_eq!(Queue::<T>::get(1), Some(Deposit::get()));
|
||||
|
||||
// call on_idle with no remaining weight
|
||||
@@ -245,11 +245,11 @@ mod on_idle {
|
||||
// given
|
||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), 0);
|
||||
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(4)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(6)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(8)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(10)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(3)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(5)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(7)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(9)));
|
||||
|
||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), Deposit::get());
|
||||
|
||||
@@ -310,9 +310,9 @@ mod on_idle {
|
||||
CurrentEra::<T>::put(BondingDuration::get());
|
||||
|
||||
// register multi accounts for fast unstake
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_eq!(Queue::<T>::get(1), Some(Deposit::get()));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(4)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(3)));
|
||||
assert_eq!(Queue::<T>::get(3), Some(Deposit::get()));
|
||||
|
||||
// assert 2 queue items are in Queue & None in Head to start with
|
||||
@@ -363,7 +363,7 @@ mod on_idle {
|
||||
CurrentEra::<T>::put(BondingDuration::get());
|
||||
|
||||
// register for fast unstake
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_eq!(Queue::<T>::get(1), Some(Deposit::get()));
|
||||
|
||||
// process on idle
|
||||
@@ -405,7 +405,7 @@ mod on_idle {
|
||||
Balances::make_free_balance_be(&2, 100);
|
||||
|
||||
// register for fast unstake
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_eq!(Queue::<T>::get(1), Some(Deposit::get()));
|
||||
|
||||
// process on idle
|
||||
@@ -446,7 +446,7 @@ mod on_idle {
|
||||
CurrentEra::<T>::put(BondingDuration::get());
|
||||
|
||||
// register for fast unstake
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_eq!(Queue::<T>::get(1), Some(Deposit::get()));
|
||||
|
||||
// process on idle
|
||||
@@ -524,7 +524,7 @@ mod on_idle {
|
||||
CurrentEra::<T>::put(BondingDuration::get());
|
||||
|
||||
// register for fast unstake
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_eq!(Queue::<T>::get(1), Some(Deposit::get()));
|
||||
|
||||
next_block(true);
|
||||
@@ -605,7 +605,7 @@ mod on_idle {
|
||||
CurrentEra::<T>::put(BondingDuration::get());
|
||||
|
||||
// register for fast unstake
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
|
||||
// process 2 blocks
|
||||
next_block(true);
|
||||
@@ -812,7 +812,7 @@ mod on_idle {
|
||||
|
||||
// create a new validator that 100% not exposed.
|
||||
Balances::make_free_balance_be(&42, 100 + Deposit::get());
|
||||
assert_ok!(Staking::bond(RuntimeOrigin::signed(42), 42, 10, RewardDestination::Staked));
|
||||
assert_ok!(Staking::bond(RuntimeOrigin::signed(42), 10, RewardDestination::Staked));
|
||||
assert_ok!(Staking::validate(RuntimeOrigin::signed(42), Default::default()));
|
||||
|
||||
// let them register:
|
||||
@@ -851,10 +851,10 @@ mod batched {
|
||||
ErasToCheckPerBlock::<T>::put(BondingDuration::get() + 1);
|
||||
CurrentEra::<T>::put(BondingDuration::get());
|
||||
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(4)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(6)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(8)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(3)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(5)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(7)));
|
||||
|
||||
assert_eq!(Queue::<T>::count(), 4);
|
||||
assert_eq!(Head::<T>::get(), None);
|
||||
@@ -902,10 +902,10 @@ mod batched {
|
||||
ErasToCheckPerBlock::<T>::put(2);
|
||||
CurrentEra::<T>::put(BondingDuration::get());
|
||||
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(4)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(6)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(8)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(3)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(5)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(7)));
|
||||
|
||||
assert_eq!(Queue::<T>::count(), 4);
|
||||
assert_eq!(Head::<T>::get(), None);
|
||||
@@ -969,8 +969,8 @@ mod batched {
|
||||
CurrentEra::<T>::put(BondingDuration::get());
|
||||
|
||||
// register two good ones.
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(4)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(3)));
|
||||
create_exposed_nominator(666, 1);
|
||||
create_exposed_nominator(667, 3);
|
||||
|
||||
@@ -1045,8 +1045,8 @@ mod batched {
|
||||
next_block(true);
|
||||
|
||||
// ..and register two good ones.
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(4)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(3)));
|
||||
|
||||
// then one of the bad ones is reaped.
|
||||
assert_eq!(
|
||||
|
||||
@@ -284,11 +284,9 @@ pub fn new_test_ext_raw_authorities(authorities: AuthorityList) -> sp_io::TestEx
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
|
||||
// controllers are the index + 1000
|
||||
// controllers are the same as stash
|
||||
let stakers: Vec<_> = (0..authorities.len())
|
||||
.map(|i| {
|
||||
(i as u64, i as u64 + 1000, 10_000, pallet_staking::StakerStatus::<u64>::Validator)
|
||||
})
|
||||
.map(|i| (i as u64, i as u64, 10_000, pallet_staking::StakerStatus::<u64>::Validator))
|
||||
.collect();
|
||||
|
||||
let staking_config = pallet_staking::GenesisConfig::<Test> {
|
||||
|
||||
@@ -107,8 +107,7 @@ fn bond_amount<T: Config>() -> BalanceOf<T> {
|
||||
|
||||
fn create_offender<T: Config>(n: u32, nominators: u32) -> Result<Offender<T>, &'static str> {
|
||||
let stash: T::AccountId = account("stash", n, SEED);
|
||||
let controller: T::AccountId = account("controller", n, SEED);
|
||||
let controller_lookup: LookupSourceOf<T> = T::Lookup::unlookup(controller.clone());
|
||||
let stash_lookup: LookupSourceOf<T> = T::Lookup::unlookup(stash.clone());
|
||||
let reward_destination = RewardDestination::Staked;
|
||||
let amount = bond_amount::<T>();
|
||||
// add twice as much balance to prevent the account from being killed.
|
||||
@@ -116,14 +115,13 @@ fn create_offender<T: Config>(n: u32, nominators: u32) -> Result<Offender<T>, &'
|
||||
T::Currency::make_free_balance_be(&stash, free_amount);
|
||||
Staking::<T>::bond(
|
||||
RawOrigin::Signed(stash.clone()).into(),
|
||||
controller_lookup.clone(),
|
||||
amount,
|
||||
reward_destination.clone(),
|
||||
)?;
|
||||
|
||||
let validator_prefs =
|
||||
ValidatorPrefs { commission: Perbill::from_percent(50), ..Default::default() };
|
||||
Staking::<T>::validate(RawOrigin::Signed(controller.clone()).into(), validator_prefs)?;
|
||||
Staking::<T>::validate(RawOrigin::Signed(stash.clone()).into(), validator_prefs)?;
|
||||
|
||||
let mut individual_exposures = vec![];
|
||||
let mut nominator_stashes = vec![];
|
||||
@@ -131,22 +129,17 @@ fn create_offender<T: Config>(n: u32, nominators: u32) -> Result<Offender<T>, &'
|
||||
for i in 0..nominators {
|
||||
let nominator_stash: T::AccountId =
|
||||
account("nominator stash", n * MAX_NOMINATORS + i, SEED);
|
||||
let nominator_controller: T::AccountId =
|
||||
account("nominator controller", n * MAX_NOMINATORS + i, SEED);
|
||||
let nominator_controller_lookup: LookupSourceOf<T> =
|
||||
T::Lookup::unlookup(nominator_controller.clone());
|
||||
T::Currency::make_free_balance_be(&nominator_stash, free_amount);
|
||||
|
||||
Staking::<T>::bond(
|
||||
RawOrigin::Signed(nominator_stash.clone()).into(),
|
||||
nominator_controller_lookup.clone(),
|
||||
amount,
|
||||
reward_destination.clone(),
|
||||
)?;
|
||||
|
||||
let selected_validators: Vec<LookupSourceOf<T>> = vec![controller_lookup.clone()];
|
||||
let selected_validators: Vec<LookupSourceOf<T>> = vec![stash_lookup.clone()];
|
||||
Staking::<T>::nominate(
|
||||
RawOrigin::Signed(nominator_controller.clone()).into(),
|
||||
RawOrigin::Signed(nominator_stash.clone()).into(),
|
||||
selected_validators,
|
||||
)?;
|
||||
|
||||
@@ -159,7 +152,7 @@ fn create_offender<T: Config>(n: u32, nominators: u32) -> Result<Offender<T>, &'
|
||||
let current_era = 0u32;
|
||||
Staking::<T>::add_era_stakers(current_era, stash.clone(), exposure);
|
||||
|
||||
Ok(Offender { controller, stash, nominator_stashes })
|
||||
Ok(Offender { controller: stash.clone(), stash, nominator_stashes })
|
||||
}
|
||||
|
||||
fn make_offenders<T: Config>(
|
||||
|
||||
@@ -259,7 +259,7 @@ impl ExtBuilder {
|
||||
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
balances: vec![
|
||||
//controllers
|
||||
// controllers (still used in some tests. Soon to be deprecated).
|
||||
(10, self.balance_factor * 50),
|
||||
(20, self.balance_factor * 50),
|
||||
(30, self.balance_factor * 50),
|
||||
@@ -277,12 +277,12 @@ impl ExtBuilder {
|
||||
let stakers = vec![
|
||||
// (stash, ctrl, stake, status)
|
||||
// these two will be elected in the default test where we elect 2.
|
||||
(11, 10, 1000, StakerStatus::<AccountId>::Validator),
|
||||
(21, 20, 1000, StakerStatus::<AccountId>::Validator),
|
||||
(11, 11, 1000, StakerStatus::<AccountId>::Validator),
|
||||
(21, 21, 1000, StakerStatus::<AccountId>::Validator),
|
||||
// a loser validator
|
||||
(31, 30, 500, StakerStatus::<AccountId>::Validator),
|
||||
(31, 31, 500, StakerStatus::<AccountId>::Validator),
|
||||
// an idle validator
|
||||
(41, 40, 1000, StakerStatus::<AccountId>::Idle),
|
||||
(41, 41, 1000, StakerStatus::<AccountId>::Idle),
|
||||
];
|
||||
|
||||
let _ = pallet_staking::GenesisConfig::<Test> {
|
||||
|
||||
@@ -59,6 +59,7 @@ benchmarks! {
|
||||
n,
|
||||
<T as pallet_staking::Config>::MaxNominations::get(),
|
||||
false,
|
||||
true,
|
||||
RewardDestination::Staked,
|
||||
)?;
|
||||
let v_controller = pallet_staking::Pallet::<T>::bonded(&v_stash).ok_or("not stash")?;
|
||||
@@ -76,7 +77,8 @@ benchmarks! {
|
||||
n,
|
||||
<T as pallet_staking::Config>::MaxNominations::get(),
|
||||
false,
|
||||
RewardDestination::Staked
|
||||
true,
|
||||
RewardDestination::Staked,
|
||||
)?;
|
||||
let v_controller = pallet_staking::Pallet::<T>::bonded(&v_stash).ok_or("not stash")?;
|
||||
let keys = T::Keys::decode(&mut TrailingZeroInput::zeroes()).unwrap();
|
||||
|
||||
@@ -50,8 +50,12 @@ used.
|
||||
|
||||
An account pair can become bonded using the [`bond`](https://docs.rs/pallet-staking/latest/pallet_staking/enum.Call.html#variant.bond) call.
|
||||
|
||||
Stash accounts can change their associated controller using the
|
||||
[`set_controller`](https://docs.rs/pallet-staking/latest/pallet_staking/enum.Call.html#variant.set_controller) call.
|
||||
Stash accounts can update their associated controller back to their stash account using the
|
||||
[`set_controller`](https://docs.rs/pallet-staking/latest/pallet_staking/enum.Call.html#variant.set_controller)
|
||||
call.
|
||||
|
||||
Note: Controller accounts are being deprecated in favor of proxy accounts, so it is no longer
|
||||
possible to set a unique address for a stash's controller.
|
||||
|
||||
There are three possible roles that any staked account pair can be in: `Validator`, `Nominator`
|
||||
and `Idle` (defined in [`StakerStatus`](https://docs.rs/pallet-staking/latest/pallet_staking/enum.StakerStatus.html)). There are three
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
//!
|
||||
//! An account pair can become bonded using the [`bond`](Call::bond) call.
|
||||
//!
|
||||
//! Stash accounts can change their associated controller using the
|
||||
//! Stash accounts can update their associated controller back to the stash account using the
|
||||
//! [`set_controller`](Call::set_controller) call.
|
||||
//!
|
||||
//! There are three possible roles that any staked account pair can be in: `Validator`, `Nominator`
|
||||
|
||||
@@ -432,7 +432,7 @@ impl ExtBuilder {
|
||||
(2, 20 * self.balance_factor),
|
||||
(3, 300 * self.balance_factor),
|
||||
(4, 400 * self.balance_factor),
|
||||
// controllers
|
||||
// controllers (still used in some tests. Soon to be deprecated).
|
||||
(10, self.balance_factor),
|
||||
(20, self.balance_factor),
|
||||
(30, self.balance_factor),
|
||||
@@ -465,18 +465,18 @@ impl ExtBuilder {
|
||||
stakers = vec![
|
||||
// (stash, ctrl, stake, status)
|
||||
// these two will be elected in the default test where we elect 2.
|
||||
(11, 10, self.balance_factor * 1000, StakerStatus::<AccountId>::Validator),
|
||||
(21, 20, self.balance_factor * 1000, StakerStatus::<AccountId>::Validator),
|
||||
(11, 11, self.balance_factor * 1000, StakerStatus::<AccountId>::Validator),
|
||||
(21, 21, self.balance_factor * 1000, StakerStatus::<AccountId>::Validator),
|
||||
// a loser validator
|
||||
(31, 30, self.balance_factor * 500, StakerStatus::<AccountId>::Validator),
|
||||
(31, 31, self.balance_factor * 500, StakerStatus::<AccountId>::Validator),
|
||||
// an idle validator
|
||||
(41, 40, self.balance_factor * 1000, StakerStatus::<AccountId>::Idle),
|
||||
(41, 41, self.balance_factor * 1000, StakerStatus::<AccountId>::Idle),
|
||||
];
|
||||
// optionally add a nominator
|
||||
if self.nominate {
|
||||
stakers.push((
|
||||
101,
|
||||
100,
|
||||
101,
|
||||
self.balance_factor * 500,
|
||||
StakerStatus::<AccountId>::Nominator(vec![11, 21]),
|
||||
))
|
||||
@@ -563,35 +563,24 @@ pub(crate) fn current_era() -> EraIndex {
|
||||
Staking::current_era().unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn bond(stash: AccountId, ctrl: AccountId, val: Balance) {
|
||||
let _ = Balances::make_free_balance_be(&stash, val);
|
||||
let _ = Balances::make_free_balance_be(&ctrl, val);
|
||||
assert_ok!(Staking::bond(
|
||||
RuntimeOrigin::signed(stash),
|
||||
ctrl,
|
||||
val,
|
||||
RewardDestination::Controller
|
||||
));
|
||||
pub(crate) fn bond(who: AccountId, val: Balance) {
|
||||
let _ = Balances::make_free_balance_be(&who, val);
|
||||
assert_ok!(Staking::bond(RuntimeOrigin::signed(who), val, RewardDestination::Controller));
|
||||
}
|
||||
|
||||
pub(crate) fn bond_validator(stash: AccountId, ctrl: AccountId, val: Balance) {
|
||||
bond(stash, ctrl, val);
|
||||
assert_ok!(Staking::validate(RuntimeOrigin::signed(ctrl), ValidatorPrefs::default()));
|
||||
pub(crate) fn bond_validator(who: AccountId, val: Balance) {
|
||||
bond(who, val);
|
||||
assert_ok!(Staking::validate(RuntimeOrigin::signed(who), ValidatorPrefs::default()));
|
||||
assert_ok!(Session::set_keys(
|
||||
RuntimeOrigin::signed(ctrl),
|
||||
SessionKeys { other: ctrl.into() },
|
||||
RuntimeOrigin::signed(who),
|
||||
SessionKeys { other: who.into() },
|
||||
vec![]
|
||||
));
|
||||
}
|
||||
|
||||
pub(crate) fn bond_nominator(
|
||||
stash: AccountId,
|
||||
ctrl: AccountId,
|
||||
val: Balance,
|
||||
target: Vec<AccountId>,
|
||||
) {
|
||||
bond(stash, ctrl, val);
|
||||
assert_ok!(Staking::nominate(RuntimeOrigin::signed(ctrl), target));
|
||||
pub(crate) fn bond_nominator(who: AccountId, val: Balance, target: Vec<AccountId>) {
|
||||
bond(who, val);
|
||||
assert_ok!(Staking::nominate(RuntimeOrigin::signed(who), target));
|
||||
}
|
||||
|
||||
/// Progress to the given block, triggering session and era changes as we progress.
|
||||
|
||||
@@ -1651,7 +1651,6 @@ impl<T: Config> StakingInterface for Pallet<T> {
|
||||
) -> DispatchResult {
|
||||
Self::bond(
|
||||
RawOrigin::Signed(who.clone()).into(),
|
||||
T::Lookup::unlookup(who.clone()),
|
||||
value,
|
||||
RewardDestination::Account(payee.clone()),
|
||||
)
|
||||
|
||||
@@ -645,7 +645,6 @@ pub mod pallet {
|
||||
);
|
||||
frame_support::assert_ok!(<Pallet<T>>::bond(
|
||||
T::RuntimeOrigin::from(Some(stash.clone()).into()),
|
||||
T::Lookup::unlookup(controller.clone()),
|
||||
balance,
|
||||
RewardDestination::Staked,
|
||||
));
|
||||
@@ -850,19 +849,17 @@ pub mod pallet {
|
||||
#[pallet::weight(T::WeightInfo::bond())]
|
||||
pub fn bond(
|
||||
origin: OriginFor<T>,
|
||||
controller: AccountIdLookupOf<T>,
|
||||
#[pallet::compact] value: BalanceOf<T>,
|
||||
payee: RewardDestination<T::AccountId>,
|
||||
) -> DispatchResult {
|
||||
let stash = ensure_signed(origin)?;
|
||||
let controller_to_be_deprecated = stash.clone();
|
||||
|
||||
if <Bonded<T>>::contains_key(&stash) {
|
||||
return Err(Error::<T>::AlreadyBonded.into())
|
||||
}
|
||||
|
||||
let controller = T::Lookup::lookup(controller)?;
|
||||
|
||||
if <Ledger<T>>::contains_key(&controller) {
|
||||
if <Ledger<T>>::contains_key(&controller_to_be_deprecated) {
|
||||
return Err(Error::<T>::AlreadyPaired.into())
|
||||
}
|
||||
|
||||
@@ -875,7 +872,7 @@ pub mod pallet {
|
||||
|
||||
// You're auto-bonded forever, here. We might improve this by only bonding when
|
||||
// you actually validate/nominate and remove once you unbond __everything__.
|
||||
<Bonded<T>>::insert(&stash, &controller);
|
||||
<Bonded<T>>::insert(&stash, &stash);
|
||||
<Payee<T>>::insert(&stash, payee);
|
||||
|
||||
let current_era = CurrentEra::<T>::get().unwrap_or(0);
|
||||
@@ -886,7 +883,7 @@ pub mod pallet {
|
||||
let value = value.min(stash_balance);
|
||||
Self::deposit_event(Event::<T>::Bonded { stash: stash.clone(), amount: value });
|
||||
let item = StakingLedger {
|
||||
stash,
|
||||
stash: stash.clone(),
|
||||
total: value,
|
||||
active: value,
|
||||
unlocking: Default::default(),
|
||||
@@ -897,7 +894,7 @@ pub mod pallet {
|
||||
// satisfied.
|
||||
.defensive_map_err(|_| Error::<T>::BoundNotMet)?,
|
||||
};
|
||||
Self::update_ledger(&controller, &item);
|
||||
Self::update_ledger(&controller_to_be_deprecated, &item);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1237,7 +1234,10 @@ pub mod pallet {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// (Re-)set the controller of a stash.
|
||||
/// (Re-)sets the controller of a stash to the stash itself. This function previously
|
||||
/// accepted a `controller` argument to set the controller to an account other than the
|
||||
/// stash itself. This functionality has now been removed, now only setting the controller
|
||||
/// to the stash, if it is not already.
|
||||
///
|
||||
/// Effects will be felt instantly (as soon as this function is completed successfully).
|
||||
///
|
||||
@@ -1250,20 +1250,17 @@ pub mod pallet {
|
||||
/// - Writes are limited to the `origin` account key.
|
||||
#[pallet::call_index(8)]
|
||||
#[pallet::weight(T::WeightInfo::set_controller())]
|
||||
pub fn set_controller(
|
||||
origin: OriginFor<T>,
|
||||
controller: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
pub fn set_controller(origin: OriginFor<T>) -> DispatchResult {
|
||||
let stash = ensure_signed(origin)?;
|
||||
let old_controller = Self::bonded(&stash).ok_or(Error::<T>::NotStash)?;
|
||||
let controller = T::Lookup::lookup(controller)?;
|
||||
if <Ledger<T>>::contains_key(&controller) {
|
||||
|
||||
if <Ledger<T>>::contains_key(&stash) {
|
||||
return Err(Error::<T>::AlreadyPaired.into())
|
||||
}
|
||||
if controller != old_controller {
|
||||
<Bonded<T>>::insert(&stash, &controller);
|
||||
if old_controller != stash {
|
||||
<Bonded<T>>::insert(&stash, &stash);
|
||||
if let Some(l) = <Ledger<T>>::take(&old_controller) {
|
||||
<Ledger<T>>::insert(&controller, l);
|
||||
<Ledger<T>>::insert(&stash, l);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -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.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user