diff --git a/frame/session/src/lib.rs b/frame/session/src/lib.rs index cf73c9d0fb34185a4c0f45bd1376789405b91bda..69273b9a43ca60ab4f117b73612e3b84a17a16e7 100644 --- a/frame/session/src/lib.rs +++ b/frame/session/src/lib.rs @@ -126,7 +126,7 @@ use support::weights::SimpleDispatchInfo; use sp_runtime::traits::{Convert, Zero, Member, OpaqueKeys}; use sp_staking::SessionIndex; use support::{dispatch::Result, ConsensusEngineId, decl_module, decl_event, decl_storage}; -use support::{ensure, traits::{OnFreeBalanceZero, Get, FindAuthor}, Parameter}; +use support::{ensure, traits::{OnFreeBalanceZero, Get, FindAuthor, ValidatorRegistration}, Parameter}; use system::{self, ensure_signed}; #[cfg(test)] @@ -333,6 +333,12 @@ impl<V> SelectInitialValidators<V> for () { } } +impl<T: Trait> ValidatorRegistration<T::ValidatorId> for Module<T> { + fn is_registered(id: &T::ValidatorId) -> bool { + Self::load_keys(id).is_some() + } +} + pub trait Trait: system::Trait { /// The overarching event type. type Event: From<Event> + Into<<Self as system::Trait>::Event>; diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 3a9b0c2d8bc33372141db3df9522462ac27c35fd..0a94483ec3ecbaa038f51e60431f10ae314e5423 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -769,3 +769,12 @@ pub trait Randomness<Output> { Self::random(&[][..]) } } + +/// Implementors of this trait provide information about whether or not some validator has +/// been registered with them. The [Session module](../../pallet_session/index.html) is an implementor. +pub trait ValidatorRegistration<ValidatorId> { + /// Returns true if the provided validator ID has been registered with the implementing runtime + /// module + fn is_registered(id: &ValidatorId) -> bool; +} +