mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +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
@@ -165,7 +165,19 @@ decl_storage! {
|
||||
LastTimestamp get(last) build(|_| 0.into()): T::Moment;
|
||||
|
||||
/// The current authorities
|
||||
pub Authorities get(authorities) config(): Vec<T::AuthorityId>;
|
||||
pub Authorities get(authorities): Vec<T::AuthorityId>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(authorities): Vec<T::AuthorityId>;
|
||||
build(|
|
||||
storage: &mut (sr_primitives::StorageOverlay, sr_primitives::ChildrenStorageOverlay),
|
||||
config: &GenesisConfig<T>
|
||||
| {
|
||||
runtime_io::with_storage(
|
||||
storage,
|
||||
|| Module::<T>::initialize_authorities(&config.authorities),
|
||||
);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,11 +195,25 @@ impl<T: Trait> Module<T> {
|
||||
);
|
||||
<system::Module<T>>::deposit_log(log.into());
|
||||
}
|
||||
|
||||
fn initialize_authorities(authorities: &[T::AuthorityId]) {
|
||||
if !authorities.is_empty() {
|
||||
assert!(<Authorities<T>>::get().is_empty(), "Authorities are already initialized!");
|
||||
<Authorities<T>>::put_ref(authorities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
|
||||
type Key = T::AuthorityId;
|
||||
|
||||
fn on_genesis_session<'a, I: 'a>(validators: I)
|
||||
where I: Iterator<Item=(&'a T::AccountId, T::AuthorityId)>
|
||||
{
|
||||
let authorities = validators.map(|(_, k)| k).collect::<Vec<_>>();
|
||||
Self::initialize_authorities(&authorities);
|
||||
}
|
||||
|
||||
fn on_new_session<'a, I: 'a>(changed: bool, validators: I, _queued_validators: I)
|
||||
where I: Iterator<Item=(&'a T::AccountId, T::AuthorityId)>
|
||||
{
|
||||
@@ -200,6 +226,7 @@ impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn on_disabled(i: usize) {
|
||||
let log: DigestItem<T::Hash> = DigestItem::Consensus(
|
||||
AURA_ENGINE_ID,
|
||||
|
||||
Reference in New Issue
Block a user