diff --git a/substrate/frame/session/src/lib.rs b/substrate/frame/session/src/lib.rs index cf73c9d0fb..69273b9a43 100644 --- a/substrate/frame/session/src/lib.rs +++ b/substrate/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 SelectInitialValidators for () { } } +impl ValidatorRegistration for Module { + 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 + Into<::Event>; diff --git a/substrate/frame/support/src/traits.rs b/substrate/frame/support/src/traits.rs index 3a9b0c2d8b..0a94483ec3 100644 --- a/substrate/frame/support/src/traits.rs +++ b/substrate/frame/support/src/traits.rs @@ -769,3 +769,12 @@ pub trait Randomness { 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 { + /// Returns true if the provided validator ID has been registered with the implementing runtime + /// module + fn is_registered(id: &ValidatorId) -> bool; +} +