diff --git a/pallets/staking/src/pallet/mod.rs b/pallets/staking/src/pallet/mod.rs index 390fb8c4d6..51ce56252f 100644 --- a/pallets/staking/src/pallet/mod.rs +++ b/pallets/staking/src/pallet/mod.rs @@ -1013,6 +1013,11 @@ pub mod pallet { return Err(Error::::AlreadyBonded.into()); } + // An existing controller cannot become a stash. + if >::contains_key(&stash) { + return Err(Error::::AlreadyPaired.into()); + } + let controller = T::Lookup::lookup(controller)?; if >::contains_key(&controller) { @@ -1407,11 +1412,18 @@ pub mod pallet { controller: AccountIdLookupOf, ) -> DispatchResult { let stash = ensure_signed(origin)?; + let old_controller = Self::bonded(&stash).ok_or(Error::::NotStash)?; let controller = T::Lookup::lookup(controller)?; + if >::contains_key(&controller) { return Err(Error::::AlreadyPaired.into()); } + // Prevents stashes which are controllers from calling the extrinsic + if >::contains_key(&stash) { + return Err(Error::::BadState.into()); + } + if controller != old_controller { >::insert(&stash, &controller); if let Some(l) = >::take(&old_controller) {