diff --git a/node-template/Cargo.toml b/node-template/Cargo.toml index 191f8c396c4bc..2491c96c97bf2 100644 --- a/node-template/Cargo.toml +++ b/node-template/Cargo.toml @@ -27,7 +27,7 @@ substrate-service = { path = "../core/service" } inherents = { package = "substrate-inherents", path = "../core/inherents" } transaction-pool = { package = "substrate-transaction-pool", path = "../core/transaction-pool" } network = { package = "substrate-network", path = "../core/network" } -consensus = { package = "substrate-consensus-aura", path = "../core/consensus/aura" } +aura = { package = "substrate-consensus-aura", path = "../core/consensus/aura" } aura-primitives = { package = "substrate-consensus-aura-primitives", path = "../core/consensus/aura/primitives" } grandpa-primitives = { package = "substrate-finality-grandpa-primitives", path = "../core/finality-grandpa/primitives" } substrate-client = { path = "../core/client" } diff --git a/node-template/src/chain_spec.rs b/node-template/src/chain_spec.rs index b1827677be4a4..00e573d0f4560 100644 --- a/node-template/src/chain_spec.rs +++ b/node-template/src/chain_spec.rs @@ -1,6 +1,6 @@ use primitives::{Pair, Public}; use node_template_runtime::{ - AccountId, AuraConfig, BalancesConfig, GenesisConfig, + AuraId, AccountId, AuraConfig, BalancesConfig, GenesisConfig, SudoConfig, IndicesConfig, SystemConfig, WASM_BINARY, }; use aura_primitives::sr25519::AuthorityPair as AuraPair; diff --git a/node-template/src/service.rs b/node-template/src/service.rs index 2addfb75678fa..b3ec325f4e693 100644 --- a/node-template/src/service.rs +++ b/node-template/src/service.rs @@ -1,14 +1,12 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. -use std::sync::Arc; -use std::time::Duration; use substrate_client::LongestChain; use futures::prelude::*; use node_template_runtime::{self, GenesisConfig, opaque::Block, RuntimeApi}; use substrate_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder}; use transaction_pool::{self, txpool::{Pool as TransactionPool}}; use inherents::InherentDataProviders; -use network::construct_simple_protocol; +use network::{construct_simple_protocol, config::DummyFinalityProofRequestBuilder}; use substrate_executor::native_executor_instance; pub use substrate_executor::NativeExecutor; @@ -30,7 +28,6 @@ construct_simple_protocol! { /// be able to perform chain operations. macro_rules! new_full_start { ($config:expr) => {{ - let mut import_setup = None; let inherent_data_providers = inherents::InherentDataProviders::new(); let builder = substrate_service::ServiceBuilder::new_full::< @@ -42,38 +39,19 @@ macro_rules! new_full_start { .with_transaction_pool(|config, client| Ok(transaction_pool::txpool::Pool::new(config, transaction_pool::FullChainApi::new(client))) )? - .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::<_, _, _, node_template_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)), + .with_import_queue(|_config, client, _select_chain, transaction_pool| { + aura::import_queue::<_, _, aura_primitives::sr25519::AuthorityPair, _>( + aura::SlotDuration::get_or_compute(&*client)?, + Box::new(client.clone()), + None, None, - client.clone(), client, inherent_data_providers.clone(), - )?; - - import_setup = Some((babe_block_import, grandpa_link, babe_link)); - - Ok(import_queue) + Some(transaction_pool), + ).map_err(Into::into) })?; - (builder, import_setup, inherent_data_providers) + (builder, inherent_data_providers) }} } @@ -81,24 +59,15 @@ macro_rules! new_full_start { pub fn new_full(config: Configuration) -> Result { - let is_authority = config.roles.is_authority(); - let name = config.name.clone(); - let disable_grandpa = config.disable_grandpa; let force_authoring = config.force_authoring; - let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config); + let (builder, inherent_data_providers) = new_full_start!(config); let service = builder.with_network_protocol(|_| Ok(NodeProtocol::new()))? - .with_finality_proof_provider(|client, backend| - Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _) - )? + .with_opt_finality_proof_provider(|_, _| Ok(None))? .build()?; - let (block_import, grandpa_link, babe_link) = - import_setup.take() - .expect("Link Half and Block Import are present for Full Services or setup failed before. qed"); - if is_authority { let proposer = basic_authorship::ProposerFactory { client: service.client(), @@ -109,68 +78,25 @@ pub fn new_full(config: Configuration( + aura::SlotDuration::get_or_compute(&*client)?, + client.clone(), select_chain, - env: proposer, - block_import, - sync_oracle: service.network(), - inherent_data_providers: inherent_data_providers.clone(), + client, + 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); } - let grandpa_config = grandpa::Config { - // FIXME #1578 make this available through chainspec - gossip_duration: Duration::from_millis(333), - justification_period: 512, - name: Some(name), - keystore: Some(service.keystore()), - }; - - match (is_authority, disable_grandpa) { - (false, false) => { - // start the lightweight GRANDPA observer - service.spawn_task(Box::new(grandpa::run_grandpa_observer( - grandpa_config, - grandpa_link, - service.network(), - service.on_exit(), - )?)); - }, - (true, false) => { - // start the full GRANDPA voter - let voter_config = grandpa::GrandpaParams { - config: grandpa_config, - link: grandpa_link, - network: service.network(), - inherent_data_providers: inherent_data_providers.clone(), - on_exit: service.on_exit(), - telemetry_on_connect: Some(service.telemetry_on_connect_stream()), - }; - - // the GRANDPA voter task is considered infallible, i.e. - // if it fails we take down the service with it. - service.spawn_essential_task(grandpa::run_grandpa_voter(voter_config)?); - }, - (_, true) => { - grandpa::setup_disabled_grandpa( - service.client(), - &inherent_data_providers, - service.network(), - )?; - }, - } - Ok(service) } @@ -187,40 +113,23 @@ pub fn new_light(config: Configuration( - client.clone(), backend, 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, + .with_import_queue_and_fprb(|_config, client, _backend, _fetcher, _select_chain, _tx_pool| { + let finality_proof_request_builder = Box::new(DummyFinalityProofRequestBuilder::default()) as Box<_>; + let import_queue = aura::import_queue::<_, _, aura_primitives::sr25519::AuthorityPair, ()>( + aura::SlotDuration::get_or_compute(&*client)?, + Box::new(client.clone()), + None, None, - Some(Box::new(finality_proof_import)), - client.clone(), client, inherent_data_providers.clone(), + None, )?; Ok((import_queue, finality_proof_request_builder)) })? .with_network_protocol(|_| Ok(NodeProtocol::new()))? - .with_finality_proof_provider(|client, backend| - Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _) + .with_opt_finality_proof_provider(|_client, _backend| + Ok(None) )? .build() }