diff --git a/Cargo.lock b/Cargo.lock index c7c6feda..777cc9dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2449,11 +2449,6 @@ dependencies = [ "crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "pdqselect" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "peeking_take_while" version = "0.1.2" @@ -2646,8 +2641,8 @@ dependencies = [ "substrate-basic-authorship 2.0.0", "substrate-cli 2.0.0", "substrate-client 2.0.0", - "substrate-consensus-babe 2.0.0", - "substrate-consensus-babe-primitives 2.0.0", + "substrate-consensus-aura 2.0.0", + "substrate-consensus-aura-primitives 2.0.0", "substrate-executor 2.0.0", "substrate-finality-grandpa 2.0.0", "substrate-finality-grandpa-primitives 2.0.0", @@ -2671,7 +2666,7 @@ dependencies = [ "sr-primitives 2.0.0", "sr-std 2.0.0", "sr-version 2.0.0", - "srml-babe 2.0.0", + "srml-aura 2.0.0", "srml-balances 2.0.0", "srml-executive 2.0.0", "srml-grandpa 2.0.0", @@ -2682,7 +2677,7 @@ dependencies = [ "srml-system 2.0.0", "srml-timestamp 2.0.0", "substrate-client 2.0.0", - "substrate-consensus-babe-primitives 2.0.0", + "substrate-consensus-aura-primitives 2.0.0", "substrate-offchain-primitives 2.0.0", "substrate-primitives 2.0.0", "substrate-session 2.0.0", @@ -3348,37 +3343,22 @@ dependencies = [ ] [[package]] -name = "srml-authorship" -version = "0.1.0" -dependencies = [ - "impl-trait-for-tuples 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "sr-io 2.0.0", - "sr-primitives 2.0.0", - "sr-std 2.0.0", - "srml-support 2.0.0", - "srml-system 2.0.0", - "substrate-inherents 2.0.0", - "substrate-primitives 2.0.0", -] - -[[package]] -name = "srml-babe" +name = "srml-aura" version = "2.0.0" dependencies = [ - "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (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-session 2.0.0", "srml-support 2.0.0", "srml-system 2.0.0", "srml-timestamp 2.0.0", - "substrate-consensus-babe-primitives 2.0.0", + "substrate-application-crypto 2.0.0", + "substrate-consensus-aura-primitives 2.0.0", "substrate-inherents 2.0.0", + "substrate-primitives 2.0.0", ] [[package]] @@ -3842,41 +3822,43 @@ dependencies = [ ] [[package]] -name = "substrate-consensus-babe" +name = "substrate-consensus-aura" version = "2.0.0" dependencies = [ - "fork-tree 2.0.0", + "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "merlin 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-bigint 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pdqselect 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "schnorrkel 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-version 2.0.0", - "srml-babe 2.0.0", + "srml-aura 2.0.0", "srml-support 2.0.0", "substrate-application-crypto 2.0.0", "substrate-client 2.0.0", - "substrate-consensus-babe-primitives 2.0.0", + "substrate-consensus-aura-primitives 2.0.0", "substrate-consensus-common 2.0.0", "substrate-consensus-slots 2.0.0", - "substrate-consensus-uncles 2.0.0", - "substrate-header-metadata 2.0.0", "substrate-inherents 2.0.0", "substrate-keystore 2.0.0", "substrate-primitives 2.0.0", "substrate-telemetry 2.0.0", ] +[[package]] +name = "substrate-consensus-aura-primitives" +version = "2.0.0" +dependencies = [ + "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-primitives 2.0.0", + "sr-std 2.0.0", + "substrate-application-crypto 2.0.0", + "substrate-client 2.0.0", +] + [[package]] name = "substrate-consensus-babe-primitives" version = "2.0.0" @@ -3925,19 +3907,6 @@ dependencies = [ "substrate-telemetry 2.0.0", ] -[[package]] -name = "substrate-consensus-uncles" -version = "2.0.0" -dependencies = [ - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "sr-primitives 2.0.0", - "srml-authorship 0.1.0", - "substrate-client 2.0.0", - "substrate-consensus-common 2.0.0", - "substrate-inherents 2.0.0", - "substrate-primitives 2.0.0", -] - [[package]] name = "substrate-executor" version = "2.0.0" @@ -5483,7 +5452,6 @@ dependencies = [ "checksum paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "423a519e1c6e828f1e73b720f9d9ed2fa643dce8a7737fb43235ce0b41eeaa49" "checksum paste-impl 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "4214c9e912ef61bf42b81ba9a47e8aad1b2ffaf739ab162bf96d1e011f54e6c5" "checksum pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9" -"checksum pdqselect 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ec91767ecc0a0bbe558ce8c9da33c068066c57ecc8bb8477ef8c1ad3ef77c27" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" diff --git a/node/Cargo.toml b/node/Cargo.toml index d8257e26..a65e850b 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -24,13 +24,13 @@ version = "3.1.3" [dependencies.radicle_registry_runtime] path = "../runtime" -[dependencies.babe] -path = "../substrate/core/consensus/babe" -package = "substrate-consensus-babe" +[dependencies.aura] +path = "../substrate/core/consensus/aura" +package = "substrate-consensus-aura" -[dependencies.babe-primitives] -path = "../substrate/core/consensus/babe/primitives" -package = "substrate-consensus-babe-primitives" +[dependencies.aura-primitives] +path = "../substrate/core/consensus/aura/primitives" +package = "substrate-consensus-aura-primitives" [dependencies.basic-authorship] path = "../substrate/core/basic-authorship" diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index ecf27436..b63d7dec 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -1,8 +1,8 @@ -use babe_primitives::AuthorityId as BabeId; +use aura_primitives::sr25519::AuthorityId as AuraId; use grandpa_primitives::AuthorityId as GrandpaId; use primitives::{Pair, Public}; use radicle_registry_runtime::{ - AccountId, BabeConfig, BalancesConfig, GenesisConfig, GrandpaConfig, IndicesConfig, SudoConfig, + AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, IndicesConfig, SudoConfig, SystemConfig, WASM_BINARY, }; use substrate_service; @@ -32,12 +32,12 @@ pub fn get_from_seed(seed: &str) -> ::Pu } /// Helper function to generate stash, controller and session key from seed -pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, GrandpaId, BabeId) { +pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, GrandpaId, AuraId) { ( get_from_seed::(&format!("{}//stash", seed)), get_from_seed::(seed), get_from_seed::(seed), - get_from_seed::(seed), + get_from_seed::(seed), ) } @@ -113,7 +113,7 @@ impl Alternative { } fn testnet_genesis( - initial_authorities: Vec<(AccountId, AccountId, GrandpaId, BabeId)>, + initial_authorities: Vec<(AccountId, AccountId, GrandpaId, AuraId)>, root_key: AccountId, endowed_accounts: Vec, _enable_println: bool, @@ -135,11 +135,8 @@ fn testnet_genesis( vesting: vec![], }), srml_sudo: Some(SudoConfig { key: root_key }), - srml_babe: Some(BabeConfig { - authorities: initial_authorities - .iter() - .map(|x| (x.3.clone(), 1)) - .collect(), + srml_aura: Some(AuraConfig { + authorities: initial_authorities.iter().map(|x| (x.3.clone())).collect(), }), srml_grandpa: Some(GrandpaConfig { authorities: initial_authorities diff --git a/node/src/cli.rs b/node/src/cli.rs index 54a82f3f..5cef167f 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -1,5 +1,6 @@ use crate::chain_spec; use crate::service; +use aura_primitives::sr25519::AuthorityPair as AuraPair; use futures::{future, sync::oneshot, Future}; use log::info; use std::cell::RefCell; diff --git a/node/src/service.rs b/node/src/service.rs index 3a3d21b4..aca0bca5 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -1,6 +1,6 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. -use babe; +use aura_primitives::sr25519::AuthorityPair as AuraPair; use futures::prelude::*; use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider}; use inherents::InherentDataProviders; @@ -51,36 +51,29 @@ macro_rules! new_full_start { transaction_pool::FullChainApi::new(client), )) })? - .with_import_queue(|_config, client, mut select_chain, _transaction_pool| { + .with_import_queue(|_config, client, mut select_chain, transaction_pool| { let select_chain = select_chain .take() .ok_or_else(|| substrate_service::Error::SelectChainRequired)?; + let (grandpa_block_import, grandpa_link) = grandpa::block_import::<_, _, _, radicle_registry_runtime::RuntimeApi, _, _>( client.clone(), &*client, select_chain, )?; - let justification_import = grandpa_block_import.clone(); - - let (babe_block_import, babe_link) = babe::block_import( - babe::Config::get_or_compute(&*client)?, - grandpa_block_import, - client.clone(), - client.clone(), - )?; - let import_queue = babe::import_queue( - babe_link.clone(), - babe_block_import.clone(), - Some(Box::new(justification_import)), + let import_queue = aura::import_queue::<_, _, AuraPair, _>( + aura::SlotDuration::get_or_compute(&*client)?, + Box::new(grandpa_block_import.clone()), + Some(Box::new(grandpa_block_import.clone())), None, - client.clone(), client, inherent_data_providers.clone(), + Some(transaction_pool), )?; - import_setup = Some((babe_block_import, grandpa_link, babe_link)); + import_setup = Some((grandpa_block_import, grandpa_link)); Ok(import_queue) })?; @@ -107,7 +100,7 @@ pub fn new_full( })? .build()?; - let (block_import, grandpa_link, babe_link) = import_setup.take().expect( + let (block_import, grandpa_link) = import_setup.take().expect( "Link Half and Block Import are present for Full Services or setup failed before. qed", ); @@ -122,22 +115,21 @@ pub fn new_full( .select_chain() .ok_or(ServiceError::SelectChainRequired)?; - let babe_config = babe::BabeParams { - keystore: service.keystore(), + let aura = aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _>( + aura::SlotDuration::get_or_compute(&*client)?, client, select_chain, - env: proposer, block_import, - sync_oracle: service.network(), - inherent_data_providers: inherent_data_providers.clone(), + proposer, + service.network(), + inherent_data_providers.clone(), force_authoring, - babe_link, - }; + service.keystore(), + )?; - let babe = babe::start_babe(babe_config)?; - let select = babe.select(service.on_exit()).then(|_| Ok(())); + let select = aura.select(service.on_exit()).then(|_| Ok(())); - // the BABE authoring task is considered infallible, i.e. if it + // the AURA authoring task is considered essential, i.e. if it // fails we take down the service with it. service.spawn_essential_task(select); } @@ -169,6 +161,7 @@ pub fn new_full( inherent_data_providers: inherent_data_providers.clone(), on_exit: service.on_exit(), telemetry_on_connect: Some(service.telemetry_on_connect_stream()), + // voting_rule: grandpa::VotingRulesBuilder::default().build(), }; // the GRANDPA voter task is considered infallible, i.e. @@ -214,26 +207,18 @@ pub fn new_light( Arc::new(fetch_checker), client.clone(), )?; - let finality_proof_import = grandpa_block_import.clone(); let finality_proof_request_builder = finality_proof_import.create_finality_proof_request_builder(); - let (babe_block_import, babe_link) = babe::block_import( - babe::Config::get_or_compute(&*client)?, - grandpa_block_import, - client.clone(), - client.clone(), - )?; - - let import_queue = babe::import_queue( - babe_link.clone(), - babe_block_import, + let import_queue = aura::import_queue::<_, _, AuraPair, ()>( + aura::SlotDuration::get_or_compute(&*client)?, + Box::new(grandpa_block_import), None, Some(Box::new(finality_proof_import)), - client.clone(), client, inherent_data_providers.clone(), + None, )?; Ok((import_queue, finality_proof_request_builder)) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index f64c6199..050289a9 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -14,7 +14,7 @@ std = [ "sr-io/std", "sr-std/std", "sr-version/std", - "srml-babe/std", + "srml-aura/std", "srml-balances/std", "srml-executive/std", "srml-grandpa/std", @@ -24,7 +24,7 @@ std = [ "srml-system/std", "srml-timestamp/std", "substrate-client/std", - "substrate-consensus-babe-primitives/std", + "substrate-consensus-aura-primitives/std", "substrate-offchain-primitives/std", "substrate-primitives/std", "substrate-session/std", @@ -45,12 +45,12 @@ version = "1.0.101" default-features = false version = "1.0.0" -[dependencies.srml-babe] -path = "../substrate/srml/babe" +[dependencies.srml-aura] +path = "../substrate/srml/aura" default-features = false -[dependencies.substrate-consensus-babe-primitives] -path = "../substrate/core/consensus/babe/primitives" +[dependencies.substrate-consensus-aura-primitives] +path = "../substrate/core/consensus/aura/primitives" default-features = false [dependencies.srml-balances] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 68859192..597c0ddd 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -18,18 +18,17 @@ use sr_primitives::{ }; use sr_std::prelude::*; use srml_support::{construct_runtime, parameter_types, traits::Randomness}; -use substrate_consensus_babe_primitives::BabeConfiguration; use substrate_primitives::{crypto::key_types, ed25519, OpaqueMetadata}; #[cfg(feature = "std")] use sr_version::NativeVersion; use sr_version::RuntimeVersion; -use srml_babe::AuthorityId as BabeId; use srml_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight}; use substrate_client::{ block_builder::api::{self as block_builder_api, CheckInherentsResult, InherentData}, impl_runtime_apis, runtime_api as client_api, }; +use substrate_consensus_aura_primitives::sr25519::AuthorityId as AuraId; /// An index to a block. pub type BlockNumber = u32; @@ -78,14 +77,12 @@ pub mod opaque { /// Opaque block identifier type. pub type BlockId = generic::BlockId; - pub type SessionHandlers = (Grandpa, Babe); - impl_opaque_keys! { pub struct SessionKeys { + #[id(key_types::AURA)] + pub aura: AuraId, #[id(key_types::GRANDPA)] pub grandpa: GrandpaId, - #[id(key_types::BABE)] - pub babe: BabeId, } } } @@ -184,10 +181,8 @@ parameter_types! { pub const ExpectedBlockTime: u64 = MILLISECS_PER_BLOCK; } -impl srml_babe::Trait for Runtime { - type EpochDuration = EpochDuration; - type ExpectedBlockTime = ExpectedBlockTime; - type EpochChangeTrigger = srml_babe::SameAuthoritiesForever; +impl srml_aura::Trait for Runtime { + type AuthorityId = AuraId; } impl srml_grandpa::Trait for Runtime { @@ -213,7 +208,7 @@ parameter_types! { impl srml_timestamp::Trait for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; - type OnTimestampSet = Babe; + type OnTimestampSet = Aura; type MinimumPeriod = MinimumPeriod; } @@ -266,7 +261,7 @@ construct_runtime!( System: system::{Module, Call, Storage, Config, Event}, Timestamp: srml_timestamp::{Module, Call, Storage, Inherent}, RandomnessCollectiveFlip: srml_randomness_collective_flip::{Module, Storage}, - Babe: srml_babe::{Module, Call, Storage, Config, Inherent(Timestamp)}, + Aura: srml_aura::{Module, Config, Inherent(Timestamp)}, Grandpa: srml_grandpa::{Module, Call, Storage, Config, Event}, Indices: srml_indices::{default, Config}, Balances: srml_balances::{default, Error}, @@ -369,21 +364,13 @@ impl_runtime_apis! { } } - impl substrate_consensus_babe_primitives::BabeApi for Runtime { - fn configuration() -> BabeConfiguration { - // The choice of `c` parameter (where `1 - c` represents the - // probability of a slot being empty), is done in accordance to the - // slot duration and expected target block time, for safely - // resisting network delays of maximum two seconds. - // - BabeConfiguration { - slot_duration: Babe::slot_duration(), - epoch_length: EpochDuration::get(), - c: PRIMARY_PROBABILITY, - genesis_authorities: Babe::authorities(), - randomness: Babe::randomness(), - secondary_slots: true, - } + impl substrate_consensus_aura_primitives::AuraApi for Runtime { + fn slot_duration() -> u64 { + Aura::slot_duration() + } + + fn authorities() -> Vec { + Aura::authorities() } }