mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +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
@@ -177,13 +177,25 @@ decl_storage! {
|
||||
GossipAt get(gossip_at): T::BlockNumber;
|
||||
|
||||
/// The current set of keys that may issue a heartbeat.
|
||||
Keys get(keys) config(): Vec<AuthorityId>;
|
||||
Keys get(keys): Vec<AuthorityId>;
|
||||
|
||||
/// For each session index we keep a mapping of `AuthorityId`
|
||||
/// to `offchain::OpaqueNetworkState`.
|
||||
ReceivedHeartbeats get(received_heartbeats): double_map SessionIndex,
|
||||
blake2_256(AuthIndex) => Vec<u8>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(keys): Vec<AuthorityId>;
|
||||
build(|
|
||||
storage: &mut (sr_primitives::StorageOverlay, sr_primitives::ChildrenStorageOverlay),
|
||||
config: &GenesisConfig
|
||||
| {
|
||||
sr_io::with_storage(
|
||||
storage,
|
||||
|| Module::<T>::initialize_keys(&config.keys),
|
||||
);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -355,11 +367,24 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn initialize_keys(keys: &[AuthorityId]) {
|
||||
if !keys.is_empty() {
|
||||
assert!(Keys::get().is_empty(), "Keys are already initialized!");
|
||||
Keys::put_ref(keys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
|
||||
type Key = AuthorityId;
|
||||
|
||||
fn on_genesis_session<'a, I: 'a>(validators: I)
|
||||
where I: Iterator<Item=(&'a T::AccountId, AuthorityId)>
|
||||
{
|
||||
let keys = validators.map(|x| x.1).collect::<Vec<_>>();
|
||||
Self::initialize_keys(&keys);
|
||||
}
|
||||
|
||||
fn on_new_session<'a, I: 'a>(_changed: bool, validators: I, _queued_validators: I)
|
||||
where I: Iterator<Item=(&'a T::AccountId, AuthorityId)>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user