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

More lenient mechanism for identifying stash accounts in purge_keys #10004

Merged
merged 5 commits into from
Oct 14, 2021
Merged
Changes from 3 commits
Commits
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
14 changes: 7 additions & 7 deletions frame/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ use sp_runtime::{
ConsensusEngineId, KeyTypeId, Permill, RuntimeAppPublic,
};
use sp_staking::SessionIndex;
use sp_std::{
marker::PhantomData,
ops::{Rem, Sub},
prelude::*,
};

use sp_std::{prelude::*, convert::TryFrom, marker::PhantomData, ops::{Rem, Sub}};
use frame_support::{
codec::{Decode, MaxEncodedLen},
dispatch::{DispatchError, DispatchResult},
Expand Down Expand Up @@ -377,7 +372,8 @@ pub mod pallet {
type Event: From<Event> + IsType<<Self as frame_system::Config>::Event>;

/// A stable ID for a validator.
type ValidatorId: Member + Parameter + MaybeSerializeDeserialize + MaxEncodedLen;
type ValidatorId: Member + Parameter + MaybeSerializeDeserialize + MaxEncodedLen
+ TryFrom<Self::AccountId>;

/// A conversion from account ID to validator ID.
///
Expand Down Expand Up @@ -841,6 +837,10 @@ impl<T: Config> Pallet<T> {

fn do_purge_keys(account: &T::AccountId) -> DispatchResult {
let who = T::ValidatorIdOf::convert(account.clone())
// `purge_keys` may not have a controller-stash pair any more. If so then we expect the
// stash account to be passed in directly and convert that to a `ValidatorId` using the
// `TryFrom` trait if supported.
.or_else(|| T::ValidatorId::try_from(account.clone()).ok())
.ok_or(Error::<T>::NoAssociatedValidatorId)?;

let old_keys = Self::take_keys(&who).ok_or(Error::<T>::NoKeys)?;
Expand Down