From b6eee1841b5d9d0f0944e3a42e94094c6b5c282a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Thu, 15 Aug 2019 23:30:46 +0200 Subject: [PATCH 01/11] session: add handler for genesis session --- node/cli/src/chain_spec.rs | 6 +++--- srml/babe/src/lib.rs | 22 +++++++++++++++++----- srml/grandpa/src/lib.rs | 9 ++++++++- srml/im-online/src/lib.rs | 6 ++++++ srml/session/src/lib.rs | 23 +++++++++++++++++++++++ 5 files changed, 57 insertions(+), 9 deletions(-) diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index fbc3f18f65c52..7dd7c09bfbfb1 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -166,13 +166,13 @@ fn staging_testnet_config_genesis() -> GenesisConfig { key: endowed_accounts[0].clone(), }), babe: Some(BabeConfig { - authorities: initial_authorities.iter().map(|x| (x.3.clone(), 1)).collect(), + authorities: vec![], }), im_online: Some(ImOnlineConfig { - keys: initial_authorities.iter().map(|x| x.4.clone()).collect(), + keys: vec![], }), grandpa: Some(GrandpaConfig { - authorities: initial_authorities.iter().map(|x| (x.2.clone(), 1)).collect(), + authorities: vec![], }), membership_Instance1: Some(Default::default()), } diff --git a/srml/babe/src/lib.rs b/srml/babe/src/lib.rs index 918400dd80035..983090ace241a 100644 --- a/srml/babe/src/lib.rs +++ b/srml/babe/src/lib.rs @@ -292,6 +292,15 @@ impl Module { this_randomness } + fn set_authorities<'a, I: 'a>(authorities: I) + where I: Iterator + { + let authorities = authorities.map(|(_account, k)| { + (k, 1) + }).collect::>(); + + Authorities::put(authorities); + } } impl OnTimestampSet for Module { @@ -300,6 +309,13 @@ impl OnTimestampSet for Module { impl session::OneSessionHandler for Module { type Key = AuthorityId; + + fn on_genesis_session<'a, I: 'a>(validators: I) + where I: Iterator + { + Self::set_authorities(validators); + } + fn on_new_session<'a, I: 'a>(_changed: bool, validators: I, queued_validators: I) where I: Iterator { @@ -311,11 +327,7 @@ impl session::OneSessionHandler for Module { EpochIndex::put(epoch_index); // Update authorities. - let authorities = validators.map(|(_account, k)| { - (k, 1) - }).collect::>(); - - Authorities::put(authorities); + Self::set_authorities(validators); // Update epoch start slot. let now = CurrentSlot::get(); diff --git a/srml/grandpa/src/lib.rs b/srml/grandpa/src/lib.rs index 3f4b26c17d74c..e704d6e1a1e69 100644 --- a/srml/grandpa/src/lib.rs +++ b/srml/grandpa/src/lib.rs @@ -346,12 +346,19 @@ impl Module { impl session::OneSessionHandler for Module { type Key = AuthorityId; + fn on_genesis_session<'a, I: 'a>(validators: I) + where I: Iterator + { + let authorities = validators.map(|(_, k)| (k, 1)).collect::>(); + Authorities::put(authorities); + } + fn on_new_session<'a, I: 'a>(changed: bool, validators: I, _queued_validators: I) where I: Iterator { // instant changes if changed { - let next_authorities = validators.map(|(_, k)| (k, 1u64)).collect::>(); + let next_authorities = validators.map(|(_, k)| (k, 1)).collect::>(); let last_authorities = >::grandpa_authorities(); if next_authorities != last_authorities { if let Some((further_wait, median)) = >::take() { diff --git a/srml/im-online/src/lib.rs b/srml/im-online/src/lib.rs index 512fca0c0c526..2d852cea31d6d 100644 --- a/srml/im-online/src/lib.rs +++ b/srml/im-online/src/lib.rs @@ -360,6 +360,12 @@ impl Module { impl session::OneSessionHandler for Module { type Key = AuthorityId; + fn on_genesis_session<'a, I: 'a>(validators: I) + where I: Iterator + { + Keys::put(validators.map(|x| x.1).collect::>()); + } + fn on_new_session<'a, I: 'a>(_changed: bool, _validators: I, next_validators: I) where I: Iterator { diff --git a/srml/session/src/lib.rs b/srml/session/src/lib.rs index 53c5c9b394f8b..800ccc2e7eb7b 100644 --- a/srml/session/src/lib.rs +++ b/srml/session/src/lib.rs @@ -187,6 +187,12 @@ impl OnSessionEnding for () { /// Handler for when a session keys set changes. pub trait SessionHandler { + /// 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(validators: &[(ValidatorId, Ks)]); + /// Session set has changed; act appropriately. fn on_new_session( changed: bool, @@ -203,14 +209,19 @@ pub trait OneSessionHandler { /// The key type expected. type Key: Decode + Default + AppKey; + fn on_genesis_session<'a, I: 'a>(validators: I) + where I: Iterator, ValidatorId: 'a; + fn on_new_session<'a, I: 'a>(changed: bool, validators: I, queued_validators: I) where I: Iterator, ValidatorId: 'a; + fn on_disabled(i: usize); } macro_rules! impl_session_handlers { () => ( impl SessionHandler for () { + fn on_genesis_session(_: &[(AId, Ks)]) {} fn on_new_session(_: bool, _: &[(AId, Ks)], _: &[(AId, Ks)]) {} fn on_disabled(_: usize) {} } @@ -218,6 +229,15 @@ macro_rules! impl_session_handlers { ( $($t:ident)* ) => { impl ),*> SessionHandler for ( $( $t , )* ) { + fn on_genesis_session(validators: &[(AId, Ks)]) { + $( + let our_keys: Box> = 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( changed: bool, validators: &[(AId, Ks)], @@ -348,6 +368,9 @@ decl_storage! { )) .collect(); + // Tell everyone about the genesis session keys + T::SessionHandler::on_genesis_session::(&queued_keys); + >::put(initial_validators); >::put(queued_keys); }); From ddea718797a5e0ebd42f74975d53a8efb415fd34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Thu, 15 Aug 2019 23:35:15 +0200 Subject: [PATCH 02/11] node: bump spec version --- node/runtime/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index d0405151047fb..1b6acb3d78956 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -80,8 +80,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to equal spec_version. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 141, - impl_version: 141, + spec_version: 142, + impl_version: 142, apis: RUNTIME_API_VERSIONS, }; From 4ef9388d181e10dcff275866edca0e7ea451afa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Thu, 15 Aug 2019 23:40:21 +0200 Subject: [PATCH 03/11] aura: handle on_genesis_session --- srml/aura/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/srml/aura/src/lib.rs b/srml/aura/src/lib.rs index 6d707fc8e195f..253b589dce8a7 100644 --- a/srml/aura/src/lib.rs +++ b/srml/aura/src/lib.rs @@ -188,6 +188,13 @@ impl Module { impl session::OneSessionHandler for Module { type Key = T::AuthorityId; + fn on_genesis_session<'a, I: 'a>(validators: I) + where I: Iterator + { + let authorities = validators.map(|(_, k)| k).collect::>(); + >::put(&authorities); + } + fn on_new_session<'a, I: 'a>(changed: bool, validators: I, _queued_validators: I) where I: Iterator { @@ -200,6 +207,7 @@ impl session::OneSessionHandler for Module { } } } + fn on_disabled(i: usize) { let log: DigestItem = DigestItem::Consensus( AURA_ENGINE_ID, From 6f0196e607341193f0c9aecc68e5fe05dccaa8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Thu, 15 Aug 2019 23:51:37 +0200 Subject: [PATCH 04/11] srml: make sure we don't re-initialize genesis authorities --- srml/aura/src/lib.rs | 1 + srml/babe/src/lib.rs | 1 + srml/grandpa/src/lib.rs | 1 + srml/im-online/src/lib.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/srml/aura/src/lib.rs b/srml/aura/src/lib.rs index 253b589dce8a7..f555ff8927094 100644 --- a/srml/aura/src/lib.rs +++ b/srml/aura/src/lib.rs @@ -191,6 +191,7 @@ impl session::OneSessionHandler for Module { fn on_genesis_session<'a, I: 'a>(validators: I) where I: Iterator { + assert!(>::get().is_empty(), "Authorities are already initialized!"); let authorities = validators.map(|(_, k)| k).collect::>(); >::put(&authorities); } diff --git a/srml/babe/src/lib.rs b/srml/babe/src/lib.rs index 983090ace241a..f9f35c44c1655 100644 --- a/srml/babe/src/lib.rs +++ b/srml/babe/src/lib.rs @@ -313,6 +313,7 @@ impl session::OneSessionHandler for Module { fn on_genesis_session<'a, I: 'a>(validators: I) where I: Iterator { + assert!(Authorities::get().is_empty(), "Authorities are already initialized!"); Self::set_authorities(validators); } diff --git a/srml/grandpa/src/lib.rs b/srml/grandpa/src/lib.rs index e704d6e1a1e69..6d0ceba3446d8 100644 --- a/srml/grandpa/src/lib.rs +++ b/srml/grandpa/src/lib.rs @@ -349,6 +349,7 @@ impl session::OneSessionHandler for Module { fn on_genesis_session<'a, I: 'a>(validators: I) where I: Iterator { + assert!(Authorities::get().is_empty(), "Authorities are already initialized!"); let authorities = validators.map(|(_, k)| (k, 1)).collect::>(); Authorities::put(authorities); } diff --git a/srml/im-online/src/lib.rs b/srml/im-online/src/lib.rs index 2d852cea31d6d..26e3f814ba30c 100644 --- a/srml/im-online/src/lib.rs +++ b/srml/im-online/src/lib.rs @@ -363,6 +363,7 @@ impl session::OneSessionHandler for Module { fn on_genesis_session<'a, I: 'a>(validators: I) where I: Iterator { + assert!(Keys::get().is_empty(), "Keys are already initialized!"); Keys::put(validators.map(|x| x.1).collect::>()); } From edb85598185243a12193fc84acf0b39b4a237c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Thu, 15 Aug 2019 23:58:01 +0200 Subject: [PATCH 05/11] session: fix mock --- srml/session/src/mock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/srml/session/src/mock.rs b/srml/session/src/mock.rs index 66bf93032d29f..f3324af875947 100644 --- a/srml/session/src/mock.rs +++ b/srml/session/src/mock.rs @@ -62,6 +62,7 @@ impl ShouldEndSession for TestShouldEndSession { pub struct TestSessionHandler; impl SessionHandler for TestSessionHandler { + fn on_genesis_session(validators: &[(u64, T)]) {} fn on_new_session( changed: bool, validators: &[(u64, T)], From 2d3c8e3ac6510fd65cef4b9fb4b683aad2e8db09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Fri, 16 Aug 2019 00:04:40 +0200 Subject: [PATCH 06/11] node: remove genesis authorities from chain spec --- node/cli/src/chain_spec.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index 7dd7c09bfbfb1..0784b02dc1b13 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -298,13 +298,13 @@ pub fn testnet_genesis( key: root_key, }), babe: Some(BabeConfig { - authorities: initial_authorities.iter().map(|x| (x.3.clone(), 1)).collect(), + authorities: vec![], }), im_online: Some(ImOnlineConfig{ - keys: initial_authorities.iter().map(|x| x.4.clone()).collect(), + keys: vec![], }), grandpa: Some(GrandpaConfig { - authorities: initial_authorities.iter().map(|x| (x.2.clone(), 1)).collect(), + authorities: vec![], }), membership_Instance1: Some(Default::default()), } From 90bd3f24d52cd239b2f08e9344494b1a0dbf9cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Fri, 16 Aug 2019 00:40:58 +0200 Subject: [PATCH 07/11] staking: fix mock --- srml/staking/src/mock.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/srml/staking/src/mock.rs b/srml/staking/src/mock.rs index d8233e5f45dfa..35738b12cbea7 100644 --- a/srml/staking/src/mock.rs +++ b/srml/staking/src/mock.rs @@ -52,6 +52,8 @@ thread_local! { pub struct TestSessionHandler; impl session::SessionHandler for TestSessionHandler { + fn on_genesis_session(validators: &[(AccountId, Ks)]) {} + fn on_new_session( _changed: bool, validators: &[(AccountId, Ks)], From c5c7eaf8bab6ddc61ff279136966ab5ab4545c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Fri, 16 Aug 2019 01:51:16 +0200 Subject: [PATCH 08/11] srml: don't initialize genesis authorities twice --- srml/babe/src/lib.rs | 37 +++++++++++++++++++++++++------------ srml/grandpa/Cargo.toml | 1 + srml/grandpa/src/lib.rs | 25 +++++++++++++++++++++---- srml/im-online/src/lib.rs | 23 ++++++++++++++++++++--- 4 files changed, 67 insertions(+), 19 deletions(-) diff --git a/srml/babe/src/lib.rs b/srml/babe/src/lib.rs index f9f35c44c1655..ac97425ee74d9 100644 --- a/srml/babe/src/lib.rs +++ b/srml/babe/src/lib.rs @@ -123,7 +123,7 @@ decl_storage! { pub EpochIndex get(epoch_index): u64; /// Current epoch authorities. - pub Authorities get(authorities) config(): Vec<(AuthorityId, BabeWeight)>; + pub Authorities get(authorities): Vec<(AuthorityId, BabeWeight)>; /// Slot at which the current epoch started. It is possible that no /// block was authored at the given slot and the epoch change was @@ -163,6 +163,18 @@ decl_storage! { SegmentIndex build(|_| 0): u32; UnderConstruction: map u32 => Vec<[u8; 32 /* VRF_OUTPUT_LENGTH */]>; } + add_extra_genesis { + config(authorities): Vec<(AuthorityId, BabeWeight)>; + build(| + storage: &mut (sr_primitives::StorageOverlay, sr_primitives::ChildrenStorageOverlay), + config: &GenesisConfig + | { + runtime_io::with_storage( + storage, + || Module::::initialize_authorities(&config.authorities), + ); + }) + } } decl_module! { @@ -292,14 +304,11 @@ impl Module { this_randomness } - fn set_authorities<'a, I: 'a>(authorities: I) - where I: Iterator - { - let authorities = authorities.map(|(_account, k)| { - (k, 1) - }).collect::>(); - - Authorities::put(authorities); + fn initialize_authorities(authorities: &[(AuthorityId, BabeWeight)]) { + if !authorities.is_empty() { + assert!(Authorities::get().is_empty(), "Authorities are already initialized!"); + Authorities::put_ref(authorities); + } } } @@ -313,8 +322,8 @@ impl session::OneSessionHandler for Module { fn on_genesis_session<'a, I: 'a>(validators: I) where I: Iterator { - assert!(Authorities::get().is_empty(), "Authorities are already initialized!"); - Self::set_authorities(validators); + let authorities = validators.map(|(_, k)| (k, 1)).collect::>(); + Self::initialize_authorities(&authorities); } fn on_new_session<'a, I: 'a>(_changed: bool, validators: I, queued_validators: I) @@ -328,7 +337,11 @@ impl session::OneSessionHandler for Module { EpochIndex::put(epoch_index); // Update authorities. - Self::set_authorities(validators); + let authorities = validators.map(|(_account, k)| { + (k, 1) + }).collect::>(); + + Authorities::put(authorities); // Update epoch start slot. let now = CurrentSlot::get(); diff --git a/srml/grandpa/Cargo.toml b/srml/grandpa/Cargo.toml index 2466b8e012ec5..67dca3e15a1e6 100644 --- a/srml/grandpa/Cargo.toml +++ b/srml/grandpa/Cargo.toml @@ -10,6 +10,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", default-features = primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } substrate-finality-grandpa-primitives = { path = "../../core/finality-grandpa/primitives", default-features = false } rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } +runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false, features = [ "wasm-nice-panic-message" ] } sr-primitives = { path = "../../core/sr-primitives", default-features = false } srml-support = { path = "../support", default-features = false } system = { package = "srml-system", path = "../system", default-features = false } diff --git a/srml/grandpa/src/lib.rs b/srml/grandpa/src/lib.rs index 6d0ceba3446d8..1db616cc044cb 100644 --- a/srml/grandpa/src/lib.rs +++ b/srml/grandpa/src/lib.rs @@ -133,7 +133,7 @@ decl_event!( decl_storage! { trait Store for Module as GrandpaFinality { /// The current authority set. - Authorities get(authorities) config(): Vec<(AuthorityId, AuthorityWeight)>; + Authorities get(authorities): Vec<(AuthorityId, AuthorityWeight)>; /// State of the current authority set. State get(state): StoredState = StoredState::Live; @@ -147,6 +147,18 @@ decl_storage! { /// `true` if we are currently stalled. Stalled get(stalled): Option<(T::BlockNumber, T::BlockNumber)>; } + add_extra_genesis { + config(authorities): Vec<(AuthorityId, AuthorityWeight)>; + build(| + storage: &mut (sr_primitives::StorageOverlay, sr_primitives::ChildrenStorageOverlay), + config: &GenesisConfig + | { + runtime_io::with_storage( + storage, + || Module::::initialize_authorities(&config.authorities), + ); + }) + } } decl_module! { @@ -310,6 +322,13 @@ impl Module { let log: DigestItem = DigestItem::Consensus(GRANDPA_ENGINE_ID, log.encode()); >::deposit_log(log.into()); } + + fn initialize_authorities(authorities: &[(AuthorityId, AuthorityWeight)]) { + if !authorities.is_empty() { + assert!(Authorities::get().is_empty(), "Authorities are already initialized!"); + Authorities::put_ref(authorities); + } + } } impl Module { @@ -349,9 +368,7 @@ impl session::OneSessionHandler for Module { fn on_genesis_session<'a, I: 'a>(validators: I) where I: Iterator { - assert!(Authorities::get().is_empty(), "Authorities are already initialized!"); - let authorities = validators.map(|(_, k)| (k, 1)).collect::>(); - Authorities::put(authorities); + Self::initialize_authorities(&validators.map(|(_, k)| (k, 1)).collect::>()); } fn on_new_session<'a, I: 'a>(changed: bool, validators: I, _queued_validators: I) diff --git a/srml/im-online/src/lib.rs b/srml/im-online/src/lib.rs index 26e3f814ba30c..0a1fd73fb8c60 100644 --- a/srml/im-online/src/lib.rs +++ b/srml/im-online/src/lib.rs @@ -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; + Keys get(keys): Vec; /// For each session index we keep a mapping of `AuthorityId` /// to `offchain::OpaqueNetworkState`. ReceivedHeartbeats get(received_heartbeats): double_map SessionIndex, blake2_256(AuthIndex) => Vec; } + add_extra_genesis { + config(keys): Vec; + build(| + storage: &mut (sr_primitives::StorageOverlay, sr_primitives::ChildrenStorageOverlay), + config: &GenesisConfig + | { + sr_io::with_storage( + storage, + || Module::::initialize_keys(&config.keys), + ); + }) + } } @@ -355,6 +367,12 @@ impl Module { } } + fn initialize_keys(keys: &[AuthorityId]) { + if !keys.is_empty() { + assert!(Keys::get().is_empty(), "Keys are already initialized!"); + Keys::put_ref(keys); + } + } } impl session::OneSessionHandler for Module { @@ -363,8 +381,7 @@ impl session::OneSessionHandler for Module { fn on_genesis_session<'a, I: 'a>(validators: I) where I: Iterator { - assert!(Keys::get().is_empty(), "Keys are already initialized!"); - Keys::put(validators.map(|x| x.1).collect::>()); + Self::initialize_keys(&validators.map(|x| x.1).collect::>()); } fn on_new_session<'a, I: 'a>(_changed: bool, _validators: I, next_validators: I) From f48246095506365b42eabc8741fad528f445bd3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Fri, 16 Aug 2019 01:55:56 +0200 Subject: [PATCH 09/11] aura: don't reinitialize genesis authorities --- srml/aura/Cargo.toml | 1 + srml/aura/src/lib.rs | 24 +++++++++++++++++++++--- srml/grandpa/src/lib.rs | 3 ++- srml/grandpa/src/mock.rs | 2 +- srml/im-online/src/lib.rs | 3 ++- srml/session/src/mock.rs | 2 +- srml/staking/src/mock.rs | 2 +- 7 files changed, 29 insertions(+), 8 deletions(-) diff --git a/srml/aura/Cargo.toml b/srml/aura/Cargo.toml index 955831ba29910..05631ea40ee2d 100644 --- a/srml/aura/Cargo.toml +++ b/srml/aura/Cargo.toml @@ -12,6 +12,7 @@ rstd = { package = "sr-std", path = "../../core/sr-std", default-features = fals sr-primitives = { path = "../../core/sr-primitives", default-features = false } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } app-crypto = { package = "substrate-application-crypto", path = "../../core/application-crypto", default-features = false } +runtime_io = { package = "sr-io", path = "../../core/sr-io" } srml-support = { path = "../support", default-features = false } system = { package = "srml-system", path = "../system", default-features = false } timestamp = { package = "srml-timestamp", path = "../timestamp", default-features = false } diff --git a/srml/aura/src/lib.rs b/srml/aura/src/lib.rs index f555ff8927094..2fd317766a260 100644 --- a/srml/aura/src/lib.rs +++ b/srml/aura/src/lib.rs @@ -165,7 +165,19 @@ decl_storage! { LastTimestamp get(last) build(|_| 0.into()): T::Moment; /// The current authorities - pub Authorities get(authorities) config(): Vec; + pub Authorities get(authorities): Vec; + } + add_extra_genesis { + config(authorities): Vec; + build(| + storage: &mut (sr_primitives::StorageOverlay, sr_primitives::ChildrenStorageOverlay), + config: &GenesisConfig + | { + runtime_io::with_storage( + storage, + || Module::::initialize_authorities(&config.authorities), + ); + }) } } @@ -183,6 +195,13 @@ impl Module { ); >::deposit_log(log.into()); } + + fn initialize_authorities(authorities: &[T::AuthorityId]) { + if !authorities.is_empty() { + assert!(>::get().is_empty(), "Authorities are already initialized!"); + >::put_ref(authorities); + } + } } impl session::OneSessionHandler for Module { @@ -191,9 +210,8 @@ impl session::OneSessionHandler for Module { fn on_genesis_session<'a, I: 'a>(validators: I) where I: Iterator { - assert!(>::get().is_empty(), "Authorities are already initialized!"); let authorities = validators.map(|(_, k)| k).collect::>(); - >::put(&authorities); + Self::initialize_authorities(&authorities); } fn on_new_session<'a, I: 'a>(changed: bool, validators: I, _queued_validators: I) diff --git a/srml/grandpa/src/lib.rs b/srml/grandpa/src/lib.rs index 1db616cc044cb..fe60e58d2e355 100644 --- a/srml/grandpa/src/lib.rs +++ b/srml/grandpa/src/lib.rs @@ -368,7 +368,8 @@ impl session::OneSessionHandler for Module { fn on_genesis_session<'a, I: 'a>(validators: I) where I: Iterator { - Self::initialize_authorities(&validators.map(|(_, k)| (k, 1)).collect::>()); + let authorities = validators.map(|(_, k)| (k, 1)).collect::>(); + Self::initialize_authorities(&authorities); } fn on_new_session<'a, I: 'a>(changed: bool, validators: I, _queued_validators: I) diff --git a/srml/grandpa/src/mock.rs b/srml/grandpa/src/mock.rs index e3c53510deae4..0f2cc90c1f9e9 100644 --- a/srml/grandpa/src/mock.rs +++ b/srml/grandpa/src/mock.rs @@ -85,7 +85,7 @@ pub fn new_test_ext(authorities: Vec<(u64, u64)>) -> runtime_io::TestExternaliti let mut t = system::GenesisConfig::default().build_storage::().unwrap(); GenesisConfig { authorities: to_authorities(authorities), - }.assimilate_storage(&mut t).unwrap(); + }.assimilate_storage::(&mut t).unwrap(); t.into() } diff --git a/srml/im-online/src/lib.rs b/srml/im-online/src/lib.rs index 0a1fd73fb8c60..f09f147ec2af5 100644 --- a/srml/im-online/src/lib.rs +++ b/srml/im-online/src/lib.rs @@ -381,7 +381,8 @@ impl session::OneSessionHandler for Module { fn on_genesis_session<'a, I: 'a>(validators: I) where I: Iterator { - Self::initialize_keys(&validators.map(|x| x.1).collect::>()); + let keys = validators.map(|x| x.1).collect::>(); + Self::initialize_keys(&keys); } fn on_new_session<'a, I: 'a>(_changed: bool, _validators: I, next_validators: I) diff --git a/srml/session/src/mock.rs b/srml/session/src/mock.rs index f3324af875947..74380426beb15 100644 --- a/srml/session/src/mock.rs +++ b/srml/session/src/mock.rs @@ -62,7 +62,7 @@ impl ShouldEndSession for TestShouldEndSession { pub struct TestSessionHandler; impl SessionHandler for TestSessionHandler { - fn on_genesis_session(validators: &[(u64, T)]) {} + fn on_genesis_session(_validators: &[(u64, T)]) {} fn on_new_session( changed: bool, validators: &[(u64, T)], diff --git a/srml/staking/src/mock.rs b/srml/staking/src/mock.rs index 35738b12cbea7..19192144a9373 100644 --- a/srml/staking/src/mock.rs +++ b/srml/staking/src/mock.rs @@ -52,7 +52,7 @@ thread_local! { pub struct TestSessionHandler; impl session::SessionHandler for TestSessionHandler { - fn on_genesis_session(validators: &[(AccountId, Ks)]) {} + fn on_genesis_session(_validators: &[(AccountId, Ks)]) {} fn on_new_session( _changed: bool, From 6d7b21a0dd09b81cf4c2c282f353adcab0cfee1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Fri, 16 Aug 2019 02:53:57 +0200 Subject: [PATCH 10/11] aura: fix runtime_io dependency --- srml/aura/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srml/aura/Cargo.toml b/srml/aura/Cargo.toml index 05631ea40ee2d..98612cb6750ff 100644 --- a/srml/aura/Cargo.toml +++ b/srml/aura/Cargo.toml @@ -12,7 +12,7 @@ rstd = { package = "sr-std", path = "../../core/sr-std", default-features = fals sr-primitives = { path = "../../core/sr-primitives", default-features = false } primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } app-crypto = { package = "substrate-application-crypto", path = "../../core/application-crypto", default-features = false } -runtime_io = { package = "sr-io", path = "../../core/sr-io" } +runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false, features = [ "wasm-nice-panic-message" ] } srml-support = { path = "../support", default-features = false } system = { package = "srml-system", path = "../system", default-features = false } timestamp = { package = "srml-timestamp", path = "../timestamp", default-features = false } From f6d08c5c2bdffb10dc771e7250899ca5566ab65f Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 16 Aug 2019 10:05:29 +0200 Subject: [PATCH 11/11] Bump runtime --- node/runtime/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 1b6acb3d78956..d3eced8f61caa 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -80,8 +80,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to equal spec_version. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 142, - impl_version: 142, + spec_version: 143, + impl_version: 143, apis: RUNTIME_API_VERSIONS, };