mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 15:21:08 +00:00
Decouple the session validators from im-online (#7127)
* Decouple the session validators from im-online * . * Add SessionInterface trait in im-online Add ValidatorId in im-online Trait Make im-online compile Make substrate binary compile * Fix merging issue * Make all compile * Fix tests * Avoid using frame dep in primitives via pallet-session-common * Merge ValidatorSet into SessionInterface trait Wrap a few too long lines Add some docs * Move pallet-sesion-common into pallet-session * Move SessionInterface to sp-session and impl it in session pallet Ref https://github.com/paritytech/substrate/pull/7127#discussion_r494892472 * Split put historical::FullValidatorIdentification trait * Fix line width * Fix staking mock * Fix session doc test * Simplify <T as ValidatorIdentification<AccountId>>::ValidatorId as ValidatorId<T> * Nits * Clean up. * Make it compile by commenting out report_offence_im_online bench * Tests * Nits * Move OneSessionHandler to sp-session * Fix tests * Add some docs * . * Fix typo * Rename to ValidatorSet::session_index() * Add some more docs * . * Remove extra empty line * Fix line width check . * Apply suggestions from code review * Cleaup Cargo.toml * Aura has migrated to Pallet now Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
This commit is contained in:
@@ -23,13 +23,15 @@ use sp_std::{prelude::*, result, marker::PhantomData, ops::Div, fmt::Debug};
|
||||
use codec::{FullCodec, Codec, Encode, Decode, EncodeLike};
|
||||
use sp_core::u32_trait::Value as U32;
|
||||
use sp_runtime::{
|
||||
RuntimeDebug, ConsensusEngineId, DispatchResult, DispatchError,
|
||||
RuntimeAppPublic, RuntimeDebug, BoundToRuntimeAppPublic,
|
||||
ConsensusEngineId, DispatchResult, DispatchError,
|
||||
traits::{
|
||||
MaybeSerializeDeserialize, AtLeast32Bit, Saturating, TrailingZeroInput, Bounded, Zero,
|
||||
BadOrigin, AtLeast32BitUnsigned, UniqueSaturatedFrom, UniqueSaturatedInto,
|
||||
SaturatedConversion, StoredMapError,
|
||||
MaybeSerializeDeserialize, AtLeast32Bit, Saturating, TrailingZeroInput, Bounded, Zero,
|
||||
BadOrigin, AtLeast32BitUnsigned, Convert, UniqueSaturatedFrom, UniqueSaturatedInto,
|
||||
SaturatedConversion, StoredMapError,
|
||||
},
|
||||
};
|
||||
use sp_staking::SessionIndex;
|
||||
use crate::dispatch::Parameter;
|
||||
use crate::storage::StorageMap;
|
||||
use crate::weights::Weight;
|
||||
@@ -40,6 +42,67 @@ use impl_trait_for_tuples::impl_for_tuples;
|
||||
#[doc(hidden)]
|
||||
pub use sp_std::{mem::{swap, take}, cell::RefCell, vec::Vec, boxed::Box};
|
||||
|
||||
/// A trait for online node inspection in a session.
|
||||
///
|
||||
/// Something that can give information about the current validator set.
|
||||
pub trait ValidatorSet<AccountId> {
|
||||
/// Type for representing validator id in a session.
|
||||
type ValidatorId: Parameter;
|
||||
/// A type for converting `AccountId` to `ValidatorId`.
|
||||
type ValidatorIdOf: Convert<AccountId, Option<Self::ValidatorId>>;
|
||||
|
||||
/// Returns current session index.
|
||||
fn session_index() -> SessionIndex;
|
||||
|
||||
/// Returns the active set of validators.
|
||||
fn validators() -> Vec<Self::ValidatorId>;
|
||||
}
|
||||
|
||||
/// [`ValidatorSet`] combined with an identification.
|
||||
pub trait ValidatorSetWithIdentification<AccountId>: ValidatorSet<AccountId> {
|
||||
/// Full identification of `ValidatorId`.
|
||||
type Identification: Parameter;
|
||||
/// A type for converting `ValidatorId` to `Identification`.
|
||||
type IdentificationOf: Convert<Self::ValidatorId, Option<Self::Identification>>;
|
||||
}
|
||||
|
||||
/// A session handler for specific key type.
|
||||
pub trait OneSessionHandler<ValidatorId>: BoundToRuntimeAppPublic {
|
||||
/// The key type expected.
|
||||
type Key: Decode + Default + RuntimeAppPublic;
|
||||
|
||||
/// The given validator set will be used for the genesis session.
|
||||
/// It is guaranteed that the given validator set will also be used
|
||||
/// for the second session, therefore the first call to `on_new_session`
|
||||
/// should provide the same validator set.
|
||||
fn on_genesis_session<'a, I: 'a>(validators: I)
|
||||
where I: Iterator<Item=(&'a ValidatorId, Self::Key)>, ValidatorId: 'a;
|
||||
|
||||
/// Session set has changed; act appropriately. Note that this can be called
|
||||
/// before initialization of your module.
|
||||
///
|
||||
/// `changed` is true when at least one of the session keys
|
||||
/// or the underlying economic identities/distribution behind one the
|
||||
/// session keys has changed, false otherwise.
|
||||
///
|
||||
/// The `validators` are the validators of the incoming session, and `queued_validators`
|
||||
/// will follow.
|
||||
fn on_new_session<'a, I: 'a>(
|
||||
changed: bool,
|
||||
validators: I,
|
||||
queued_validators: I,
|
||||
) where I: Iterator<Item=(&'a ValidatorId, Self::Key)>, ValidatorId: 'a;
|
||||
|
||||
/// A notification for end of the session.
|
||||
///
|
||||
/// Note it is triggered before any `SessionManager::end_session` handlers,
|
||||
/// so we can still affect the validator set.
|
||||
fn on_before_session_ending() {}
|
||||
|
||||
/// A validator got disabled. Act accordingly until a new session begins.
|
||||
fn on_disabled(_validator_index: usize);
|
||||
}
|
||||
|
||||
/// Simple trait for providing a filter over a reference to some type.
|
||||
pub trait Filter<T> {
|
||||
/// Determine if a given value should be allowed through the filter (returns `true`) or not.
|
||||
|
||||
Reference in New Issue
Block a user