Skip to content

Commit

Permalink
Prevent a stash accounts to become controllers (#1661)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Dossa <[email protected]>
  • Loading branch information
HenriqueNogara and adamdossa authored May 7, 2024
1 parent 16a5e85 commit d11817f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pallets/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,11 @@ pub mod pallet {
return Err(Error::<T>::AlreadyBonded.into());
}

// An existing controller cannot become a stash.
if <Ledger<T>>::contains_key(&stash) {
return Err(Error::<T>::AlreadyPaired.into());
}

let controller = T::Lookup::lookup(controller)?;

if <Ledger<T>>::contains_key(&controller) {
Expand Down Expand Up @@ -1407,11 +1412,18 @@ pub mod pallet {
controller: AccountIdLookupOf<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) {
return Err(Error::<T>::AlreadyPaired.into());
}
// Prevents stashes which are controllers from calling the extrinsic
if <Ledger<T>>::contains_key(&stash) {
return Err(Error::<T>::BadState.into());
}

if controller != old_controller {
<Bonded<T>>::insert(&stash, &controller);
if let Some(l) = <Ledger<T>>::take(&old_controller) {
Expand Down

0 comments on commit d11817f

Please sign in to comment.