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

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

Merged
merged 67 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
0811cb9
update set_controller
Apr 28, 2023
6f0be00
clone
Apr 28, 2023
75beff4
bond uses `stash`
May 3, 2023
74d34ea
remove controller from bond(), chill_other test works
May 3, 2023
fc11538
remove ctlr from testing_utils & dead ctlr -> dead payee
May 3, 2023
35d873c
mvs controllers to stashes for 3 tests
May 3, 2023
6e73503
migrate mock bond fns & fix 1 test
May 3, 2023
0379c65
mvs controllers to stashes for 7 tests
May 3, 2023
d29a6a5
mvs controllers to stashes for 9 tests
May 3, 2023
71289da
remove double_controlling_should_fail
May 3, 2023
5198f53
remove double_staking_should_fail
May 3, 2023
db89911
mvs controllers to stashes for 10 tests
May 3, 2023
d13643e
mvs controllers to stashes for 2 tests
May 3, 2023
79f9756
remove payout_creates_controller
May 3, 2023
b5d5426
mvs controllers to stashes for 27 tests
May 3, 2023
b2f0ae1
remove println!
May 3, 2023
9eeb647
fix rewards_should_work
May 3, 2023
93c012f
fix test_payout_stakers
May 3, 2023
efec776
fix bond benchmark
May 3, 2023
b3a1e3f
clone
May 3, 2023
ceb8637
rm unused import
May 3, 2023
24f8dd0
rm unused var
May 3, 2023
c3bf984
rm controller from create_offender
May 3, 2023
dd857e6
fix GenesisConfig stakers
May 4, 2023
6fb61f4
fix controllers in consensus pallets
May 4, 2023
17bba2c
fix unqiue controller in chain_spec
May 4, 2023
465bc13
fmt
May 4, 2023
0d5adaa
fix create_offender
May 4, 2023
7b978ea
fix set_controller benchmark
May 4, 2023
bd91aae
add TODO
May 4, 2023
d8a38ca
Merge remote-tracking branch 'origin/master' into rb-set-controller-t…
May 8, 2023
09cf1d8
Merge remote-tracking branch 'origin/master' into rb-set-controller-t…
May 9, 2023
ada3aeb
create_unique_stash_controller
May 9, 2023
d63f28f
staking benchmarks working
May 9, 2023
36fe69e
fmt
May 9, 2023
e74e8df
fix args
May 9, 2023
e5ce360
rm println
May 9, 2023
d8b0012
import
May 9, 2023
0009a84
import
May 9, 2023
177896e
fix fast unstake tests
May 9, 2023
76547e0
fix staking-tests-e2e
May 9, 2023
55cf31a
fix root-offenses
May 9, 2023
bed8298
fmt
May 9, 2023
8b7e46e
differentiate controller to stash
May 9, 2023
4772a72
bring back change_controller_works w. unique ctrl
May 9, 2023
813f460
bring back double_staking_should_fail
May 9, 2023
dbdb1a6
double_controlling_attempt_should_fail
May 9, 2023
74314f8
bring back payout_creates_controller
May 9, 2023
5243561
add commnet to controller balances
May 9, 2023
cd751a2
+ set_controller call description
May 9, 2023
7580e0d
fmt
May 9, 2023
ead11a9
rm clones
May 9, 2023
e43a676
fmt
May 9, 2023
d94fa54
clippy fixes
May 9, 2023
ba21e58
fmt
May 9, 2023
7b52879
update README
May 9, 2023
74b29aa
small fixes
May 9, 2023
63c9c14
Merge remote-tracking branch 'origin/master' into rb-set-controller-t…
May 9, 2023
106f163
Merge remote-tracking branch 'origin/master' into rb-set-controller-t…
May 10, 2023
701359c
Merge remote-tracking branch 'origin/master' into rb-set-controller-t…
May 10, 2023
6572712
use controller_to_be_deprecated
May 10, 2023
d949382
.comment
May 10, 2023
b5a765e
Merge remote-tracking branch 'origin/master' into rb-set-controller-t…
May 11, 2023
86505f0
comment
May 11, 2023
8c0ae32
Merge remote-tracking branch 'origin/master' into rb-set-controller-t…
May 11, 2023
8a3e876
bump zombienet version
pepoviola May 11, 2023
fa530a3
ci
May 11, 2023
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
5 changes: 3 additions & 2 deletions frame/staking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ 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.
rossbulat marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down
8 changes: 3 additions & 5 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,11 @@ 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, _) = create_stash_controller_inc::<T>(USER_SEED, 100, Default::default())?;
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 {
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
17 changes: 7 additions & 10 deletions frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ pub mod pallet {
Ok(())
}

/// (Re-)set the controller of a stash.
/// (Re-)sets the controller of a stash to the stash itself.
rossbulat marked this conversation as resolved.
Show resolved Hide resolved
///
/// Effects will be felt instantly (as soon as this function is completed successfully).
///
Expand All @@ -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(())
Expand Down
20 changes: 20 additions & 0 deletions frame/staking/src/testing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ pub fn create_stash_controller<T: Config>(
Ok((stash, controller))
}

/// Create a unique stash and controller pair.
pub fn create_stash_controller_inc<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);
let controller = create_funded_user::<T>("controller", n + 1, balance_factor);

let controller_lookup = T::Lookup::unlookup(controller.clone());
let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into();
Staking::<T>::bond(
RawOrigin::Signed(stash.clone()).into(),
controller_lookup,
amount,
destination,
)?;
Ok((stash, controller))
}

/// Create a stash and controller pair with fixed balance.
pub fn create_stash_controller_with_balance<T: Config>(
n: u32,
Expand Down
8 changes: 4 additions & 4 deletions frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,23 @@ fn basic_setup_works() {
#[test]
fn change_controller_works() {
ExtBuilder::default().build_and_execute(|| {
// 10 and 11 are bonded as stash controller.
// 10 and 11 are bonded as controller and stash respectively.
assert_eq!(Staking::bonded(&11), Some(10));

// 10 can control 11 who is initially a validator.
assert_ok!(Staking::chill(RuntimeOrigin::signed(10)));

// change controller
assert_ok!(Staking::set_controller(RuntimeOrigin::signed(11), 5));
assert_eq!(Staking::bonded(&11), Some(5));
assert_ok!(Staking::set_controller(RuntimeOrigin::signed(11)));
assert_eq!(Staking::bonded(&11), Some(11));
mock::start_active_era(1);

// 10 is no longer in control.
assert_noop!(
Staking::validate(RuntimeOrigin::signed(10), ValidatorPrefs::default()),
Error::<Test>::NotController,
);
assert_ok!(Staking::validate(RuntimeOrigin::signed(5), ValidatorPrefs::default()));
assert_ok!(Staking::validate(RuntimeOrigin::signed(11), ValidatorPrefs::default()));
})
}

Expand Down