From 410289222002b38786d6fdb28f08b5e583359829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Tue, 27 Aug 2019 20:25:49 +0100 Subject: [PATCH 01/10] im-online: support using ed25519 and sr25519 crypto --- srml/im-online/src/lib.rs | 75 +++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/srml/im-online/src/lib.rs b/srml/im-online/src/lib.rs index 760ab79eb9e2d..f246b56f54746 100644 --- a/srml/im-online/src/lib.rs +++ b/srml/im-online/src/lib.rs @@ -67,7 +67,7 @@ // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] -use app_crypto::RuntimeAppPublic; +use app_crypto::{AppPublic, RuntimeAppPublic}; use codec::{Encode, Decode}; use primitives::offchain::{OpaqueNetworkState, StorageKind}; use rstd::prelude::*; @@ -75,7 +75,7 @@ use session::historical::IdentificationTuple; use sr_io::Printable; use sr_primitives::{ Perbill, ApplyError, - traits::{Extrinsic as ExtrinsicT, Convert}, + traits::{Convert, Extrinsic as ExtrinsicT, Member}, transaction_validity::{TransactionValidity, TransactionLongevity, ValidTransaction}, }; use sr_staking_primitives::{ @@ -83,28 +83,44 @@ use sr_staking_primitives::{ offence::{ReportOffence, Offence, Kind}, }; use srml_support::{ - StorageValue, decl_module, decl_event, decl_storage, StorageDoubleMap, print, ensure + decl_module, decl_event, decl_storage, print, ensure, + Parameter, StorageValue, StorageDoubleMap, }; use system::ensure_none; -mod app { - pub use app_crypto::sr25519 as crypto; +mod app_sr25519 { use app_crypto::{app_crypto, key_types::IM_ONLINE, sr25519}; - app_crypto!(sr25519, IM_ONLINE); } -/// A Babe authority keypair. Necessarily equivalent to the schnorrkel public key used in -/// the main Babe module. If that ever changes, then this must, too. -#[cfg(feature = "std")] -pub type AuthorityPair = app::Pair; +pub mod sr25519 { + /// An i'm online keypair using sr25519 as its crypto. + #[cfg(feature = "std")] + pub type AuthorityPair = super::app_sr25519::Pair; + + /// An i'm online signature using sr25519 as its crypto. + pub type AuthoritySignature = super::app_sr25519::Signature; + + /// An i'm online identifier using sr25519 as its crypto. + pub type AuthorityId = super::app_sr25519::Public; +} + +mod app_ed25519 { + use app_crypto::{app_crypto, key_types::IM_ONLINE, ed25519}; + app_crypto!(ed25519, IM_ONLINE); +} + +pub mod ed25519 { + /// An i'm online keypair using ed25519 as its crypto. + #[cfg(feature = "std")] + pub type AuthorityPair = super::app_ed25519::Pair; -/// A Babe authority signature. -pub type AuthoritySignature = app::Signature; + /// An i'm online signature using ed25519 as its crypto. + pub type AuthoritySignature = super::app_ed25519::Signature; -/// A Babe authority identifier. Necessarily equivalent to the schnorrkel public key used in -/// the main Babe module. If that ever changes, then this must, too. -pub type AuthorityId = app::Public; + /// An i'm online identifier using ed25519 as its crypto. + pub type AuthorityId = super::app_ed25519::Public; +} // The local storage database key under which the worker progress status // is tracked. @@ -158,8 +174,11 @@ pub struct Heartbeat } pub trait Trait: system::Trait + session::historical::Trait { + /// The identifier type for an authority. + type AuthorityId: Member + Parameter + AppPublic + RuntimeAppPublic + Default; + /// The overarching event type. - type Event: From + Into<::Event>; + type Event: From> + Into<::Event>; /// The function call. type Call: From>; @@ -181,7 +200,9 @@ pub trait Trait: system::Trait + session::historical::Trait { } decl_event!( - pub enum Event { + pub enum Event where + ::AuthorityId, + { /// A new heartbeat was received from `AuthorityId` HeartbeatReceived(AuthorityId), } @@ -193,7 +214,7 @@ decl_storage! { GossipAt get(gossip_at): T::BlockNumber; /// The current set of keys that may issue a heartbeat. - Keys get(keys): Vec; + Keys get(keys): Vec; /// For each session index we keep a mapping of `AuthorityId` /// to `offchain::OpaqueNetworkState`. @@ -201,10 +222,10 @@ decl_storage! { blake2_256(AuthIndex) => Vec; } add_extra_genesis { - config(keys): Vec; + config(keys): Vec; build(| storage: &mut (sr_primitives::StorageOverlay, sr_primitives::ChildrenStorageOverlay), - config: &GenesisConfig + config: &GenesisConfig | { sr_io::with_storage( storage, @@ -217,12 +238,12 @@ decl_storage! { decl_module! { pub struct Module for enum Call where origin: T::Origin { - fn deposit_event() = default; + fn deposit_event() = default; fn heartbeat( origin, heartbeat: Heartbeat, - signature: AuthoritySignature + signature: ::Signature ) { ensure_none(origin)?; @@ -298,7 +319,7 @@ impl Module { fn do_gossip_at(block_number: T::BlockNumber) -> Result<(), OffchainErr> { // we run only when a local authority key is configured let authorities = Keys::get(); - let mut local_keys = app::Public::all(); + let mut local_keys = T::AuthorityId::all(); local_keys.sort(); for (authority_index, key) in authorities.into_iter() @@ -389,7 +410,7 @@ impl Module { } } - fn initialize_keys(keys: &[AuthorityId]) { + fn initialize_keys(keys: &[T::AuthorityId]) { if !keys.is_empty() { assert!(Keys::get().is_empty(), "Keys are already initialized!"); Keys::put_ref(keys); @@ -399,17 +420,17 @@ impl Module { impl session::OneSessionHandler for Module { - type Key = AuthorityId; + type Key = T::AuthorityId; fn on_genesis_session<'a, I: 'a>(validators: I) - where I: Iterator + where I: Iterator { let keys = validators.map(|x| x.1).collect::>(); Self::initialize_keys(&keys); } fn on_new_session<'a, I: 'a>(_changed: bool, validators: I, _queued_validators: I) - where I: Iterator + where I: Iterator { // Reset heartbeats ::remove_prefix(&>::current_index()); From c6f7099ce14377e36e8ccb73f6071f617f0c1858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 27 Aug 2019 22:00:16 +0200 Subject: [PATCH 02/10] app-crypto: add trait bounds to RuntimePublic::Signature --- core/application-crypto/src/traits.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/application-crypto/src/traits.rs b/core/application-crypto/src/traits.rs index d7f1eafe35407..323c9c3e54c55 100644 --- a/core/application-crypto/src/traits.rs +++ b/core/application-crypto/src/traits.rs @@ -17,6 +17,7 @@ use primitives::crypto::{KeyTypeId, CryptoType, IsWrappedBy, Public}; #[cfg(feature = "std")] use primitives::crypto::Pair; +use codec::Codec; /// An application-specific key. pub trait AppKey: 'static + Send + Sync + Sized + CryptoType + Clone { @@ -72,7 +73,7 @@ pub trait AppSignature: AppKey + Eq + PartialEq + MaybeDebugHash { /// A runtime interface for a public key. pub trait RuntimePublic: Sized { /// The signature that will be generated when signing with the corresponding private key. - type Signature; + type Signature: Codec + MaybeDebugHash + Eq + PartialEq + Clone; /// Returns all public keys for the given key type in the keystore. fn all(key_type: KeyTypeId) -> crate::Vec; @@ -97,7 +98,7 @@ pub trait RuntimePublic: Sized { /// A runtime interface for an application's public key. pub trait RuntimeAppPublic: Sized { /// The signature that will be generated when signing with the corresponding private key. - type Signature; + type Signature: Codec + MaybeDebugHash + Eq + PartialEq + Clone; /// Returns all public keys for this application in the keystore. fn all() -> crate::Vec; From eefe7c3c7ca9f812d6634c930271a764cb61f297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Tue, 27 Aug 2019 21:04:55 +0100 Subject: [PATCH 03/10] im-online: add missing type annotations --- srml/im-online/src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/srml/im-online/src/lib.rs b/srml/im-online/src/lib.rs index f246b56f54746..98804b192140e 100644 --- a/srml/im-online/src/lib.rs +++ b/srml/im-online/src/lib.rs @@ -253,7 +253,7 @@ decl_module! { ¤t_session, &heartbeat.authority_index ); - let keys = Keys::get(); + let keys = Keys::::get(); let public = keys.get(heartbeat.authority_index as usize); if let (true, Some(public)) = (!exists, public) { let signature_valid = heartbeat.using_encoded(|encoded_heartbeat| { @@ -261,7 +261,7 @@ decl_module! { }); ensure!(signature_valid, "Invalid heartbeat signature."); - Self::deposit_event(Event::HeartbeatReceived(public.clone())); + Self::deposit_event(Event::::HeartbeatReceived(public.clone())); let network_state = heartbeat.network_state.encode(); ::insert( @@ -318,7 +318,7 @@ impl Module { fn do_gossip_at(block_number: T::BlockNumber) -> Result<(), OffchainErr> { // we run only when a local authority key is configured - let authorities = Keys::get(); + let authorities = Keys::::get(); let mut local_keys = T::AuthorityId::all(); local_keys.sort(); @@ -412,8 +412,8 @@ impl Module { fn initialize_keys(keys: &[T::AuthorityId]) { if !keys.is_empty() { - assert!(Keys::get().is_empty(), "Keys are already initialized!"); - Keys::put_ref(keys); + assert!(Keys::::get().is_empty(), "Keys are already initialized!"); + Keys::::put_ref(keys); } } } @@ -439,7 +439,7 @@ impl session::OneSessionHandler for Module { >::put(>::block_number()); // Remember who the authorities are for the new session. - Keys::put(validators.map(|x| x.1).collect::>()); + Keys::::put(validators.map(|x| x.1).collect::>()); } fn on_before_session_ending() { @@ -447,7 +447,7 @@ impl session::OneSessionHandler for Module { let current_session = >::current_index(); - let keys = Keys::get(); + let keys = Keys::::get(); let current_elected = T::CurrentElectedSet::current_elected_set(); // The invariant is that these two are of the same length. @@ -502,7 +502,7 @@ impl srml_support::unsigned::ValidateUnsigned for Module { } // verify that the incoming (unverified) pubkey is actually an authority id - let keys = Keys::get(); + let keys = Keys::::get(); let authority_id = match keys.get(heartbeat.authority_index as usize) { Some(id) => id, None => return TransactionValidity::Invalid(ApplyError::BadSignature as i8), From af3093a6aa15979e96e133b729d2e75a48209153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Tue, 27 Aug 2019 21:41:12 +0100 Subject: [PATCH 04/10] authority-discovery: depend on im-online module and use its crypto --- Cargo.lock | 1 + srml/authority-discovery/Cargo.toml | 3 + srml/authority-discovery/src/lib.rs | 99 ++++++++++++++++++----------- 3 files changed, 67 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 375d03fa47192..b1936f4177091 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3826,6 +3826,7 @@ dependencies = [ "serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", + "sr-staking-primitives 2.0.0", "sr-std 2.0.0", "srml-im-online 0.1.0", "srml-session 2.0.0", diff --git a/srml/authority-discovery/Cargo.toml b/srml/authority-discovery/Cargo.toml index 5d52bdb2461fa..f4c2d4e2b0bd0 100644 --- a/srml/authority-discovery/Cargo.toml +++ b/srml/authority-discovery/Cargo.toml @@ -17,6 +17,9 @@ srml-support = { path = "../support", default-features = false } sr-io = { package = "sr-io", path = "../../core/sr-io", default-features = false } system = { package = "srml-system", path = "../system", default-features = false } +[dev-dependencies] +sr-staking-primitives = { path = "../../core/sr-staking-primitives", default-features = false } + [features] default = ["std"] std = [ diff --git a/srml/authority-discovery/src/lib.rs b/srml/authority-discovery/src/lib.rs index 00912aeffed8b..aec683391df33 100644 --- a/srml/authority-discovery/src/lib.rs +++ b/srml/authority-discovery/src/lib.rs @@ -33,18 +33,20 @@ use codec::{Decode, Encode}; use rstd::prelude::*; use srml_support::{decl_module, decl_storage, StorageValue}; -pub trait Trait: system::Trait + session::Trait {} +pub trait Trait: system::Trait + session::Trait + im_online::Trait {} + +type AuthorityIdFor = ::AuthorityId; decl_storage! { trait Store for Module as AuthorityDiscovery { /// The current set of keys that may issue a heartbeat. - Keys get(keys): Vec; + Keys get(keys): Vec>; } add_extra_genesis { - config(keys): Vec; + config(keys): Vec>; build(| storage: &mut (sr_primitives::StorageOverlay, sr_primitives::ChildrenStorageOverlay), - config: &GenesisConfig + config: &GenesisConfig, | { sr_io::with_storage( storage, @@ -64,10 +66,10 @@ impl Module { /// set, otherwise this function returns None. The restriction might be /// softened in the future in case a consumer needs to learn own authority /// identifier. - pub fn authority_id() -> Option { - let authorities = Keys::get(); + pub fn authority_id() -> Option> { + let authorities = Keys::::get(); - let local_keys = im_online::AuthorityId::all(); + let local_keys = >::all(); authorities.into_iter().find_map(|authority| { if local_keys.contains(&authority) { @@ -79,12 +81,12 @@ impl Module { } /// Retrieve authority identifiers of the current authority set. - pub fn authorities() -> Vec { - Keys::get() + pub fn authorities() -> Vec> { + Keys::::get() } /// Sign the given payload with the private key corresponding to the given authority id. - pub fn sign(payload: Vec, authority_id: im_online::AuthorityId) -> Option> { + pub fn sign(payload: Vec, authority_id: AuthorityIdFor) -> Option> { authority_id.sign(&payload).map(|s| s.encode()) } @@ -93,27 +95,27 @@ impl Module { pub fn verify( payload: Vec, signature: Vec, - authority_id: im_online::AuthorityId, + authority_id: AuthorityIdFor, ) -> bool { - im_online::AuthoritySignature::decode(&mut &signature[..]) + as RuntimeAppPublic>::Signature::decode(&mut &signature[..]) .map(|s| authority_id.verify(&payload, &s)) .unwrap_or(false) } - fn initialize_keys(keys: &[im_online::AuthorityId]) { + fn initialize_keys(keys: &[AuthorityIdFor]) { if !keys.is_empty() { - assert!(Keys::get().is_empty(), "Keys are already initialized!"); - Keys::put_ref(keys); + assert!(Keys::::get().is_empty(), "Keys are already initialized!"); + Keys::::put_ref(keys); } } } impl session::OneSessionHandler for Module { - type Key = im_online::AuthorityId; + type Key = AuthorityIdFor; fn on_genesis_session<'a, I: 'a>(validators: I) where - I: Iterator, + I: Iterator, { let keys = validators.map(|x| x.1).collect::>(); Self::initialize_keys(&keys); @@ -121,10 +123,10 @@ impl session::OneSessionHandler for Module { fn on_new_session<'a, I: 'a>(_changed: bool, _validators: I, next_validators: I) where - I: Iterator, + I: Iterator, { // Remember who the authorities are for the new session. - Keys::put(next_validators.map(|x| x.1).collect::>()); + Keys::::put(next_validators.map(|x| x.1).collect::>()); } fn on_disabled(_i: usize) { @@ -139,9 +141,11 @@ mod tests { use primitives::testing::KeyStore; use primitives::{crypto::key_types, sr25519, traits::BareCryptoStore, H256}; use sr_io::{with_externalities, TestExternalities}; + use sr_primitives::generic::UncheckedExtrinsic; use sr_primitives::testing::{Header, UintAuthorityId}; use sr_primitives::traits::{ConvertInto, IdentityLookup, OpaqueKeys}; use sr_primitives::Perbill; + use sr_staking_primitives::CurrentElectedSet; use srml_support::{impl_outer_origin, parameter_types}; type AuthorityDiscovery = Module; @@ -151,12 +155,21 @@ mod tests { pub struct Test; impl Trait for Test {} + type AuthorityId = im_online::sr25519::AuthorityId; + + pub struct DummyCurrentElectedSet(std::marker::PhantomData); + impl CurrentElectedSet for DummyCurrentElectedSet { + fn current_elected_set() -> Vec { + vec![] + } + } + pub struct TestOnSessionEnding; - impl session::OnSessionEnding for TestOnSessionEnding { + impl session::OnSessionEnding for TestOnSessionEnding { fn on_session_ending( _: SessionIndex, _: SessionIndex, - ) -> Option> { + ) -> Option> { None } } @@ -167,11 +180,25 @@ mod tests { type ShouldEndSession = session::PeriodicSessions; type SessionHandler = TestSessionHandler; type Event = (); - type ValidatorId = im_online::AuthorityId; + type ValidatorId = AuthorityId; type ValidatorIdOf = ConvertInto; type SelectInitialValidators = (); } + impl session::historical::Trait for Test { + type FullIdentification = (); + type FullIdentificationOf = (); + } + + impl im_online::Trait for Test { + type Call = im_online::Call; + type Event = (); + type AuthorityId = AuthorityId; + type UncheckedExtrinsic = UncheckedExtrinsic<(), im_online::Call, (), ()>; + type ReportUnresponsiveness = (); + type CurrentElectedSet = DummyCurrentElectedSet; + } + pub type BlockNumber = u64; parameter_types! { @@ -191,7 +218,7 @@ mod tests { type Call = (); type Hash = H256; type Hashing = ::sr_primitives::traits::BlakeTwo256; - type AccountId = im_online::AuthorityId; + type AccountId = AuthorityId; type Lookup = IdentityLookup; type Header = Header; type WeightMultiplierUpdate = (); @@ -208,17 +235,17 @@ mod tests { } pub struct TestSessionHandler; - impl session::SessionHandler for TestSessionHandler { + impl session::SessionHandler for TestSessionHandler { fn on_new_session( _changed: bool, - _validators: &[(im_online::AuthorityId, Ks)], - _queued_validators: &[(im_online::AuthorityId, Ks)], + _validators: &[(AuthorityId, Ks)], + _queued_validators: &[(AuthorityId, Ks)], ) { } fn on_disabled(_validator_index: usize) {} - fn on_genesis_session(_validators: &[(im_online::AuthorityId, Ks)]) {} + fn on_genesis_session(_validators: &[(AuthorityId, Ks)]) {} } #[test] @@ -236,17 +263,17 @@ mod tests { .sr25519_public_keys(key_types::IM_ONLINE) .pop() .unwrap(); - let authority_id = im_online::AuthorityId::from(public_key); + let authority_id = AuthorityId::from(public_key); // Build genesis. let mut t = system::GenesisConfig::default() .build_storage::() .unwrap(); - GenesisConfig { + GenesisConfig:: { keys: vec![authority_id.clone()], } - .assimilate_storage::(&mut t) + .assimilate_storage(&mut t) .unwrap(); // Create externalities. @@ -279,11 +306,11 @@ mod tests { let keys = vec![(); 5] .iter() .map(|_x| sr25519::Pair::generate_with_phrase(None).0.public()) - .map(im_online::AuthorityId::from) + .map(AuthorityId::from) .collect(); - GenesisConfig { keys: keys } - .assimilate_storage::(&mut t) + GenesisConfig:: { keys: keys } + .assimilate_storage(&mut t) .unwrap(); // Create externalities. @@ -310,17 +337,17 @@ mod tests { .sr25519_public_keys(key_types::IM_ONLINE) .pop() .unwrap(); - let authority_id = im_online::AuthorityId::from(public_key); + let authority_id = AuthorityId::from(public_key); // Build genesis. let mut t = system::GenesisConfig::default() .build_storage::() .unwrap(); - GenesisConfig { + GenesisConfig:: { keys: vec![authority_id.clone()], } - .assimilate_storage::(&mut t) + .assimilate_storage(&mut t) .unwrap(); // Create externalities. From 9ac39a953a01df310086a24e5e0f866ac2addbab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Tue, 27 Aug 2019 21:51:02 +0100 Subject: [PATCH 05/10] node: set i'm online crypto to sr25519 --- node/cli/src/chain_spec.rs | 2 +- node/runtime/src/lib.rs | 17 +++++++++-------- srml/authority-discovery/src/lib.rs | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index f83958eef482c..00bcb2577613d 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -30,7 +30,7 @@ use hex_literal::hex; use substrate_telemetry::TelemetryEndpoints; use grandpa_primitives::{AuthorityId as GrandpaId}; use babe_primitives::{AuthorityId as BabeId}; -use im_online::AuthorityId as ImOnlineId; +use im_online::sr25519::{AuthorityId as ImOnlineId}; use sr_primitives::Perbill; const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 5260a3ef43751..78cc6d21dba12 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -47,7 +47,7 @@ use elections::VoteIndex; use version::NativeVersion; use primitives::OpaqueMetadata; use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight}; -use im_online::{AuthorityId as ImOnlineId}; +use im_online::sr25519::{AuthorityId as ImOnlineId}; #[cfg(any(feature = "std", test))] pub use sr_primitives::BuildStorage; @@ -393,6 +393,7 @@ impl sudo::Trait for Runtime { } impl im_online::Trait for Runtime { + type AuthorityId = ImOnlineId; type Call = Call; type Event = Event; type UncheckedExtrinsic = UncheckedExtrinsic; @@ -447,8 +448,8 @@ construct_runtime!( Treasury: treasury::{Module, Call, Storage, Event}, Contracts: contracts, Sudo: sudo, - ImOnline: im_online::{Module, Call, Storage, Event, ValidateUnsigned, Config}, - AuthorityDiscovery: authority_discovery::{Module, Call, Config}, + ImOnline: im_online::{Module, Call, Storage, Event, ValidateUnsigned, Config}, + AuthorityDiscovery: authority_discovery::{Module, Call, Config}, Offences: offences::{Module, Call, Storage, Event}, } ); @@ -578,19 +579,19 @@ impl_runtime_apis! { } } - impl authority_discovery_primitives::AuthorityDiscoveryApi for Runtime { - fn authority_id() -> Option { + impl authority_discovery_primitives::AuthorityDiscoveryApi for Runtime { + fn authority_id() -> Option { AuthorityDiscovery::authority_id() } - fn authorities() -> Vec { + fn authorities() -> Vec { AuthorityDiscovery::authorities() } - fn sign(payload: Vec, authority_id: im_online::AuthorityId) -> Option> { + fn sign(payload: Vec, authority_id: ImOnlineId) -> Option> { AuthorityDiscovery::sign(payload, authority_id) } - fn verify(payload: Vec, signature: Vec, public_key: im_online::AuthorityId) -> bool { + fn verify(payload: Vec, signature: Vec, public_key: ImOnlineId) -> bool { AuthorityDiscovery::verify(payload, signature, public_key) } } diff --git a/srml/authority-discovery/src/lib.rs b/srml/authority-discovery/src/lib.rs index aec683391df33..ffcb6672c8662 100644 --- a/srml/authority-discovery/src/lib.rs +++ b/srml/authority-discovery/src/lib.rs @@ -191,9 +191,9 @@ mod tests { } impl im_online::Trait for Test { + type AuthorityId = AuthorityId; type Call = im_online::Call; type Event = (); - type AuthorityId = AuthorityId; type UncheckedExtrinsic = UncheckedExtrinsic<(), im_online::Call, (), ()>; type ReportUnresponsiveness = (); type CurrentElectedSet = DummyCurrentElectedSet; From af95cf6ee75f9d69001d5662be3cf6646138fcfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Tue, 27 Aug 2019 21:51:22 +0100 Subject: [PATCH 06/10] node: bump spec_version --- node/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 78cc6d21dba12..d23e3bb457542 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -79,7 +79,7 @@ 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: 153, + spec_version: 154, impl_version: 154, apis: RUNTIME_API_VERSIONS, }; From ee666e5f1b46b6e5be9e9c82326e711d64f41b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Wed, 28 Aug 2019 11:49:26 +0100 Subject: [PATCH 07/10] rpc: don't generate i'm online pubkey in insert_key method --- core/rpc/src/author/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/rpc/src/author/mod.rs b/core/rpc/src/author/mod.rs index 6e2d7aa92abc9..0290a534ea549 100644 --- a/core/rpc/src/author/mod.rs +++ b/core/rpc/src/author/mod.rs @@ -162,7 +162,7 @@ impl AuthorApi, BlockHash

> for Author whe Some(public) => public.0, None => { let maybe_public = match key_type { - key_types::BABE | key_types::IM_ONLINE | key_types::SR25519 => + key_types::BABE | key_types::SR25519 => sr25519::Pair::from_string(&suri, maybe_password) .map(|pair| pair.public().to_raw_vec()), key_types::GRANDPA | key_types::ED25519 => From c635bd6ba65b15f5c35110ee55948b10e83d5a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Wed, 28 Aug 2019 11:49:54 +0100 Subject: [PATCH 08/10] im-online: fix docs --- srml/im-online/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srml/im-online/src/lib.rs b/srml/im-online/src/lib.rs index 98804b192140e..1482c040a3711 100644 --- a/srml/im-online/src/lib.rs +++ b/srml/im-online/src/lib.rs @@ -180,7 +180,7 @@ pub trait Trait: system::Trait + session::historical::Trait { /// The overarching event type. type Event: From> + Into<::Event>; - /// The function call. + /// A dispatchable call type. type Call: From>; /// A extrinsic right from the external world. This is unchecked and so From 4416dcbe3f9bc809efac91d7dc51a776d92b8b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Wed, 28 Aug 2019 11:52:46 +0100 Subject: [PATCH 09/10] im-online: move app crypto packages --- srml/im-online/src/lib.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/srml/im-online/src/lib.rs b/srml/im-online/src/lib.rs index 1482c040a3711..06a350655bc9d 100644 --- a/srml/im-online/src/lib.rs +++ b/srml/im-online/src/lib.rs @@ -88,38 +88,38 @@ use srml_support::{ }; use system::ensure_none; -mod app_sr25519 { - use app_crypto::{app_crypto, key_types::IM_ONLINE, sr25519}; - app_crypto!(sr25519, IM_ONLINE); -} - pub mod sr25519 { + mod app_sr25519 { + use app_crypto::{app_crypto, key_types::IM_ONLINE, sr25519}; + app_crypto!(sr25519, IM_ONLINE); + } + /// An i'm online keypair using sr25519 as its crypto. #[cfg(feature = "std")] - pub type AuthorityPair = super::app_sr25519::Pair; + pub type AuthorityPair = app_sr25519::Pair; /// An i'm online signature using sr25519 as its crypto. - pub type AuthoritySignature = super::app_sr25519::Signature; + pub type AuthoritySignature = app_sr25519::Signature; /// An i'm online identifier using sr25519 as its crypto. - pub type AuthorityId = super::app_sr25519::Public; -} - -mod app_ed25519 { - use app_crypto::{app_crypto, key_types::IM_ONLINE, ed25519}; - app_crypto!(ed25519, IM_ONLINE); + pub type AuthorityId = app_sr25519::Public; } pub mod ed25519 { + mod app_ed25519 { + use app_crypto::{app_crypto, key_types::IM_ONLINE, ed25519}; + app_crypto!(ed25519, IM_ONLINE); + } + /// An i'm online keypair using ed25519 as its crypto. #[cfg(feature = "std")] - pub type AuthorityPair = super::app_ed25519::Pair; + pub type AuthorityPair = app_ed25519::Pair; /// An i'm online signature using ed25519 as its crypto. - pub type AuthoritySignature = super::app_ed25519::Signature; + pub type AuthoritySignature = app_ed25519::Signature; /// An i'm online identifier using ed25519 as its crypto. - pub type AuthorityId = super::app_ed25519::Public; + pub type AuthorityId = app_ed25519::Public; } // The local storage database key under which the worker progress status From b4e1bb15479b7cdf57a1bfb64aff04c3bda576fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Wed, 28 Aug 2019 11:53:02 +0100 Subject: [PATCH 10/10] aura: move app crypto packages --- core/consensus/aura/primitives/src/lib.rs | 32 +++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/consensus/aura/primitives/src/lib.rs b/core/consensus/aura/primitives/src/lib.rs index 84671e5ae6864..e4620fcdbfdd4 100644 --- a/core/consensus/aura/primitives/src/lib.rs +++ b/core/consensus/aura/primitives/src/lib.rs @@ -23,38 +23,38 @@ use substrate_client::decl_runtime_apis; use rstd::vec::Vec; use sr_primitives::ConsensusEngineId; -mod app_sr25519 { - use app_crypto::{app_crypto, key_types::AURA, sr25519}; - app_crypto!(sr25519, AURA); -} - pub mod sr25519 { + mod app_sr25519 { + use app_crypto::{app_crypto, key_types::AURA, sr25519}; + app_crypto!(sr25519, AURA); + } + /// An Aura authority keypair using S/R 25519 as its crypto. #[cfg(feature = "std")] - pub type AuthorityPair = super::app_sr25519::Pair; + pub type AuthorityPair = app_sr25519::Pair; /// An Aura authority signature using S/R 25519 as its crypto. - pub type AuthoritySignature = super::app_sr25519::Signature; + pub type AuthoritySignature = app_sr25519::Signature; /// An Aura authority identifier using S/R 25519 as its crypto. - pub type AuthorityId = super::app_sr25519::Public; -} - -mod app_ed25519 { - use app_crypto::{app_crypto, key_types::AURA, ed25519}; - app_crypto!(ed25519, AURA); + pub type AuthorityId = app_sr25519::Public; } pub mod ed25519 { + mod app_ed25519 { + use app_crypto::{app_crypto, key_types::AURA, ed25519}; + app_crypto!(ed25519, AURA); + } + /// An Aura authority keypair using Ed25519 as its crypto. #[cfg(feature = "std")] - pub type AuthorityPair = super::app_ed25519::Pair; + pub type AuthorityPair = app_ed25519::Pair; /// An Aura authority signature using Ed25519 as its crypto. - pub type AuthoritySignature = super::app_ed25519::Signature; + pub type AuthoritySignature = app_ed25519::Signature; /// An Aura authority identifier using Ed25519 as its crypto. - pub type AuthorityId = super::app_ed25519::Public; + pub type AuthorityId = app_ed25519::Public; } /// The `ConsensusEngineId` of AuRa.