Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion node-template/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
153 changes: 31 additions & 122 deletions node-template/src/service.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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::<
Expand All @@ -42,63 +39,35 @@ 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)
}}
}

/// Builds a new service for a full client.
pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisConfig>)
-> Result<impl AbstractService, ServiceError>
{

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(),
Expand All @@ -109,68 +78,25 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
let select_chain = service.select_chain()
.ok_or(ServiceError::SelectChainRequired)?;

let babe_config = babe::BabeParams {
keystore: service.keystore(),
client,
let aura = aura::start_aura::<_, _, _, _, _, aura_primitives::sr25519::AuthorityPair, _, _, _>(
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)
}

Expand All @@ -187,40 +113,23 @@ pub fn new_light<C: Send + Default + 'static>(config: Configuration<C, GenesisCo
.with_transaction_pool(|config, client|
Ok(TransactionPool::new(config, transaction_pool::FullChainApi::new(client)))
)?
.with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, _tx_pool| {
let fetch_checker = fetcher
.map(|fetcher| fetcher.checker().clone())
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
let grandpa_block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, _>(
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<_>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the explicit cast necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing as Box<_> gives me an error:

Shawns-MacBook-Pro:substrate shawntabrizi$ cargo build -p node-template
   Compiling node-template v2.0.0 (/Users/shawntabrizi/Documents/GitHub/substrate/node-template)
error[E0599]: no method named `build` found for type `substrate_service::builder::ServiceBuilder<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>, node_template_runtime::RuntimeApi, C, node_template_runtime::GenesisConfig, std::option::Option<()>, substrate_client::client::Client<substrate_client::light::backend::Backend<substrate_client_db::light::LightStorage<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>, substrate_primitives::hasher::blake2::Blake2Hasher>, substrate_client::light::call_executor::GenesisCallExecutor<substrate_client::light::backend::Backend<substrate_client_db::light::LightStorage<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>, substrate_primitives::hasher::blake2::Blake2Hasher>, substrate_client::call_executor::LocalCallExecutor<substrate_client::light::backend::Backend<substrate_client_db::light::LightStorage<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>, substrate_primitives::hasher::blake2::Blake2Hasher>, substrate_executor::native_executor::NativeExecutor<service::Executor>>>, sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>, node_template_runtime::RuntimeApi>, alloc::sync::Arc<substrate_network::on_demand_layer::OnDemand<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>>, substrate_client::client::LongestChain<substrate_client::light::backend::Backend<substrate_client_db::light::LightStorage<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>, substrate_primitives::hasher::blake2::Blake2Hasher>, sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>, substrate_consensus_common::import_queue::basic_queue::BasicQueue<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>, std::boxed::Box<substrate_network::config::DummyFinalityProofRequestBuilder>, alloc::sync::Arc<dyn substrate_network::chain::FinalityProofProvider<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>>, service::NodeProtocol, substrate_transaction_graph::pool::Pool<substrate_transaction_pool::api::FullChainApi<substrate_client::client::Client<substrate_client::light::backend::Backend<substrate_client_db::light::LightStorage<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>, substrate_primitives::hasher::blake2::Blake2Hasher>, substrate_client::light::call_executor::GenesisCallExecutor<substrate_client::light::backend::Backend<substrate_client_db::light::LightStorage<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>, substrate_primitives::hasher::blake2::Blake2Hasher>, substrate_client::call_executor::LocalCallExecutor<substrate_client::light::backend::Backend<substrate_client_db::light::LightStorage<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>, substrate_primitives::hasher::blake2::Blake2Hasher>, substrate_executor::native_executor::NativeExecutor<service::Executor>>>, sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>, node_template_runtime::RuntimeApi>, sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>>, (), substrate_service::builder::LightRpcBuilder<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>, node_template_runtime::RuntimeApi, service::Executor>, substrate_client::light::backend::Backend<substrate_client_db::light::LightStorage<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u32, sr_primitives::traits::BlakeTwo256>, sr_primitives::OpaqueExtrinsic>>, substrate_primitives::hasher::blake2::Blake2Hasher>>` in the current scope
   --> node-template/src/service.rs:135:4
    |
135 |         .build()
    |          ^^^^^

error: aborting due to previous error

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()
}