mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 09:27:59 +00:00
session: add handler for genesis session (#3413)
* session: add handler for genesis session * node: bump spec version * aura: handle on_genesis_session * srml: make sure we don't re-initialize genesis authorities * session: fix mock * node: remove genesis authorities from chain spec * staking: fix mock * srml: don't initialize genesis authorities twice * aura: don't reinitialize genesis authorities * aura: fix runtime_io dependency * Bump runtime
This commit is contained in:
committed by
Svyatoslav Nikolsky
parent
3590c9c33f
commit
d1dde7e087
@@ -187,6 +187,12 @@ impl<A> OnSessionEnding<A> for () {
|
||||
|
||||
/// Handler for when a session keys set changes.
|
||||
pub trait SessionHandler<ValidatorId> {
|
||||
/// 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<Ks: OpaqueKeys>(validators: &[(ValidatorId, Ks)]);
|
||||
|
||||
/// Session set has changed; act appropriately.
|
||||
fn on_new_session<Ks: OpaqueKeys>(
|
||||
changed: bool,
|
||||
@@ -203,14 +209,19 @@ pub trait OneSessionHandler<ValidatorId> {
|
||||
/// The key type expected.
|
||||
type Key: Decode + Default + AppKey;
|
||||
|
||||
fn on_genesis_session<'a, I: 'a>(validators: I)
|
||||
where I: Iterator<Item=(&'a ValidatorId, Self::Key)>, ValidatorId: 'a;
|
||||
|
||||
fn on_new_session<'a, I: 'a>(changed: bool, validators: I, queued_validators: I)
|
||||
where I: Iterator<Item=(&'a ValidatorId, Self::Key)>, ValidatorId: 'a;
|
||||
|
||||
fn on_disabled(i: usize);
|
||||
}
|
||||
|
||||
macro_rules! impl_session_handlers {
|
||||
() => (
|
||||
impl<AId> SessionHandler<AId> for () {
|
||||
fn on_genesis_session<Ks: OpaqueKeys>(_: &[(AId, Ks)]) {}
|
||||
fn on_new_session<Ks: OpaqueKeys>(_: bool, _: &[(AId, Ks)], _: &[(AId, Ks)]) {}
|
||||
fn on_disabled(_: usize) {}
|
||||
}
|
||||
@@ -218,6 +229,15 @@ macro_rules! impl_session_handlers {
|
||||
|
||||
( $($t:ident)* ) => {
|
||||
impl<AId, $( $t: OneSessionHandler<AId> ),*> SessionHandler<AId> for ( $( $t , )* ) {
|
||||
fn on_genesis_session<Ks: OpaqueKeys>(validators: &[(AId, Ks)]) {
|
||||
$(
|
||||
let our_keys: Box<dyn Iterator<Item=_>> = Box::new(validators.iter()
|
||||
.map(|k| (&k.0, k.1.get::<$t::Key>(<$t::Key as AppKey>::ID)
|
||||
.unwrap_or_default())));
|
||||
|
||||
$t::on_genesis_session(our_keys);
|
||||
)*
|
||||
}
|
||||
fn on_new_session<Ks: OpaqueKeys>(
|
||||
changed: bool,
|
||||
validators: &[(AId, Ks)],
|
||||
@@ -348,6 +368,9 @@ decl_storage! {
|
||||
))
|
||||
.collect();
|
||||
|
||||
// Tell everyone about the genesis session keys
|
||||
T::SessionHandler::on_genesis_session::<T::Keys>(&queued_keys);
|
||||
|
||||
<Validators<T>>::put(initial_validators);
|
||||
<QueuedKeys<T>>::put(queued_keys);
|
||||
});
|
||||
|
||||
@@ -62,6 +62,7 @@ impl ShouldEndSession<u64> for TestShouldEndSession {
|
||||
|
||||
pub struct TestSessionHandler;
|
||||
impl SessionHandler<u64> for TestSessionHandler {
|
||||
fn on_genesis_session<T: OpaqueKeys>(_validators: &[(u64, T)]) {}
|
||||
fn on_new_session<T: OpaqueKeys>(
|
||||
changed: bool,
|
||||
validators: &[(u64, T)],
|
||||
|
||||
Reference in New Issue
Block a user