From 0a3f326e56131bb7c6d3015b3c3ea09032826116 Mon Sep 17 00:00:00 2001 From: Spencer Judge Date: Thu, 5 Dec 2019 01:42:42 -0800 Subject: [PATCH] Expose some of session module's storage as public, as well as the set_keys transaction (#4175) * Expose some of session's storage as public, as well as set_keys Seemingly there's no reason not to do this, as anyone can always do it the "hard way" by constructing storage keys or extrinsics. * Use trait to expose `is_registered` function * Missed removing a pub keyword * Move trait to support, add docstrings --- substrate/frame/session/src/lib.rs | 8 +++++++- substrate/frame/support/src/traits.rs | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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; +} +