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:
André Silva
2019-08-16 10:24:06 +02:00
committed by Svyatoslav Nikolsky
parent 3590c9c33f
commit d1dde7e087
12 changed files with 146 additions and 14 deletions
+26 -1
View File
@@ -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)>
{