Update Node Template: 7d7e74fb7

main
Shawn Tabrizi 2019-09-25 02:40:55 +02:00
parent 3abe9654b5
commit cd271e0972
7 changed files with 1184 additions and 1074 deletions

1806
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,5 @@
[build-dependencies] [build-dependencies]
vergen = '3' vergen = '3'
[profile.release]
panic = 'unwind'
[workspace]
members = ['runtime']
[dependencies] [dependencies]
derive_more = '0.14.0' derive_more = '0.14.0'
@ -18,17 +13,17 @@ trie-root = '0.15.2'
[dependencies.babe] [dependencies.babe]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-consensus-babe' package = 'substrate-consensus-babe'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.babe-primitives] [dependencies.babe-primitives]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-consensus-babe-primitives' package = 'substrate-consensus-babe-primitives'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.basic-authorship] [dependencies.basic-authorship]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-basic-authorship' package = 'substrate-basic-authorship'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.codec] [dependencies.codec]
package = 'parity-scale-codec' package = 'parity-scale-codec'
@ -41,22 +36,22 @@ version = '3.0'
[dependencies.grandpa] [dependencies.grandpa]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-finality-grandpa' package = 'substrate-finality-grandpa'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.grandpa-primitives] [dependencies.grandpa-primitives]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-finality-grandpa-primitives' package = 'substrate-finality-grandpa-primitives'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.inherents] [dependencies.inherents]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-inherents' package = 'substrate-inherents'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.network] [dependencies.network]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-network' package = 'substrate-network'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.node-template-runtime] [dependencies.node-template-runtime]
path = 'runtime' path = 'runtime'
@ -64,32 +59,32 @@ path = 'runtime'
[dependencies.primitives] [dependencies.primitives]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-primitives' package = 'substrate-primitives'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.sr-io] [dependencies.sr-io]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.substrate-cli] [dependencies.substrate-cli]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.substrate-client] [dependencies.substrate-client]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.substrate-executor] [dependencies.substrate-executor]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.substrate-service] [dependencies.substrate-service]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.transaction-pool] [dependencies.transaction-pool]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-transaction-pool' package = 'substrate-transaction-pool'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90' rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[package] [package]
authors = ['Anonymous'] authors = ['Anonymous']
@ -97,6 +92,11 @@ build = 'build.rs'
edition = '2018' edition = '2018'
name = 'node-template' name = 'node-template'
version = '2.0.0' version = '2.0.0'
[profile.release]
panic = 'unwind'
[workspace]
members = ['runtime']
[[bin]] [[bin]]
name = 'node-template' name = 'node-template'

View File

@ -3,133 +3,9 @@ authors = ['Anonymous']
edition = '2018' edition = '2018'
name = 'node-template-runtime' name = 'node-template-runtime'
version = '2.0.0' version = '2.0.0'
[dependencies.babe]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-babe'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.babe-primitives]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-consensus-babe-primitives'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.balances]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-balances'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.client]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-client'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.codec]
default-features = false
features = ['derive']
package = 'parity-scale-codec'
version = '1.0.0'
[dependencies.executive]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-executive'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.grandpa]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-grandpa'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.indices]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-indices'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.offchain-primitives]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-offchain-primitives'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.primitives]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-primitives'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.rstd]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'sr-std'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.runtime-io]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'sr-io'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.safe-mix]
default-features = false
version = '1.0'
[dependencies.serde]
features = ['derive']
optional = true
version = '1.0'
[dependencies.sr-primitives]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.substrate-session]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.sudo]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-sudo'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.support]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-support'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.system]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-system'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.timestamp]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-timestamp'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[dependencies.version]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'sr-version'
rev = '3ba0f2a2dbd37c31851a0ff1c1c0c47aa940de90'
[build-dependencies.wasm-builder-runner]
package = 'substrate-wasm-builder-runner'
version = '1.0.2'
[features] [features]
default = ['std'] default = ['std']
no_std = []
std = [ std = [
'codec/std', 'codec/std',
'client/std', 'client/std',
@ -153,3 +29,126 @@ std = [
'offchain-primitives/std', 'offchain-primitives/std',
'substrate-session/std', 'substrate-session/std',
] ]
[build-dependencies.wasm-builder-runner]
package = 'substrate-wasm-builder-runner'
version = '1.0.2'
[dependencies.babe]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-babe'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.babe-primitives]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-consensus-babe-primitives'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.balances]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-balances'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.client]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-client'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.codec]
default-features = false
features = ['derive']
package = 'parity-scale-codec'
version = '1.0.0'
[dependencies.executive]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-executive'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.grandpa]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-grandpa'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.indices]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-indices'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.offchain-primitives]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-offchain-primitives'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.primitives]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-primitives'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.rstd]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'sr-std'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.runtime-io]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'sr-io'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.safe-mix]
default-features = false
version = '1.0'
[dependencies.serde]
features = ['derive']
optional = true
version = '1.0'
[dependencies.sr-primitives]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.substrate-session]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.sudo]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-sudo'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.support]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-support'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.system]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-system'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.timestamp]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-timestamp'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'
[dependencies.version]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'sr-version'
rev = '7d7e74fb77b6bee2ce9d6ebafcae09caff2d0e50'

View File

@ -19,7 +19,7 @@ use wasm_builder_runner::{build_current_project_with_rustflags, WasmBuilderSourc
fn main() { fn main() {
build_current_project_with_rustflags( build_current_project_with_rustflags(
"wasm_binary.rs", "wasm_binary.rs",
WasmBuilderSource::Crates("1.0.5"), WasmBuilderSource::Crates("1.0.7"),
// This instructs LLD to export __heap_base as a global variable, which is used by the // This instructs LLD to export __heap_base as a global variable, which is used by the
// external memory allocator. // external memory allocator.
"-Clink-arg=--export=__heap_base", "-Clink-arg=--export=__heap_base",

View File

@ -14,11 +14,11 @@ use sr_primitives::{
ApplyResult, transaction_validity::TransactionValidity, generic, create_runtime_str, ApplyResult, transaction_validity::TransactionValidity, generic, create_runtime_str,
impl_opaque_keys, AnySignature impl_opaque_keys, AnySignature
}; };
use sr_primitives::traits::{NumberFor, BlakeTwo256, Block as BlockT, DigestFor, StaticLookup, Verify, ConvertInto}; use sr_primitives::traits::{NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto};
use sr_primitives::weights::Weight; use sr_primitives::weights::Weight;
use babe::{AuthorityId as BabeId}; use babe::{AuthorityId as BabeId};
use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight}; use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
use grandpa::fg_primitives::{self, ScheduledChange}; use grandpa::fg_primitives;
use client::{ use client::{
block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api}, block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api},
runtime_api as client_api, impl_runtime_apis runtime_api as client_api, impl_runtime_apis
@ -208,7 +208,7 @@ impl indices::Trait for Runtime {
} }
parameter_types! { parameter_types! {
pub const MinimumPeriod: u64 = 5000; pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
} }
impl timestamp::Trait for Runtime { impl timestamp::Trait for Runtime {
@ -235,7 +235,6 @@ impl balances::Trait for Runtime {
type OnNewAccount = Indices; type OnNewAccount = Indices;
/// The ubiquitous event type. /// The ubiquitous event type.
type Event = Event; type Event = Event;
type TransactionPayment = (); type TransactionPayment = ();
type DustRemoval = (); type DustRemoval = ();
type TransferPayment = (); type TransferPayment = ();
@ -268,7 +267,7 @@ construct_runtime!(
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)}, Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
Grandpa: grandpa::{Module, Call, Storage, Config, Event}, Grandpa: grandpa::{Module, Call, Storage, Config, Event},
Indices: indices::{default, Config<T>}, Indices: indices::{default, Config<T>},
Balances: balances, Balances: balances::{default, Error},
Sudo: sudo, Sudo: sudo,
// Used for the module template in `./template.rs` // Used for the module template in `./template.rs`
TemplateModule: template::{Module, Call, Storage, Event<T>}, TemplateModule: template::{Module, Call, Storage, Event<T>},
@ -357,45 +356,25 @@ impl_runtime_apis! {
} }
impl fg_primitives::GrandpaApi<Block> for Runtime { impl fg_primitives::GrandpaApi<Block> for Runtime {
fn grandpa_pending_change(digest: &DigestFor<Block>)
-> Option<ScheduledChange<NumberFor<Block>>>
{
Grandpa::pending_change(digest)
}
fn grandpa_forced_change(digest: &DigestFor<Block>)
-> Option<(NumberFor<Block>, ScheduledChange<NumberFor<Block>>)>
{
Grandpa::forced_change(digest)
}
fn grandpa_authorities() -> Vec<(GrandpaId, GrandpaWeight)> { fn grandpa_authorities() -> Vec<(GrandpaId, GrandpaWeight)> {
Grandpa::grandpa_authorities() Grandpa::grandpa_authorities()
} }
} }
impl babe_primitives::BabeApi<Block> for Runtime { impl babe_primitives::BabeApi<Block> for Runtime {
fn startup_data() -> babe_primitives::BabeConfiguration { fn configuration() -> babe_primitives::BabeConfiguration {
// The choice of `c` parameter (where `1 - c` represents the // The choice of `c` parameter (where `1 - c` represents the
// probability of a slot being empty), is done in accordance to the // probability of a slot being empty), is done in accordance to the
// slot duration and expected target block time, for safely // slot duration and expected target block time, for safely
// resisting network delays of maximum two seconds. // resisting network delays of maximum two seconds.
// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results> // <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
babe_primitives::BabeConfiguration { babe_primitives::BabeConfiguration {
median_required_blocks: 1000,
slot_duration: Babe::slot_duration(), slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: PRIMARY_PROBABILITY, c: PRIMARY_PROBABILITY,
} genesis_authorities: Babe::authorities(),
}
fn epoch() -> babe_primitives::Epoch {
babe_primitives::Epoch {
start_slot: Babe::epoch_start_slot(),
authorities: Babe::authorities(),
epoch_index: Babe::epoch_index(),
randomness: Babe::randomness(), randomness: Babe::randomness(),
duration: EpochDuration::get(), secondary_slots: true,
secondary_slots: Babe::secondary_slots().0,
} }
} }
} }

View File

@ -3,10 +3,10 @@
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use substrate_client::LongestChain; use substrate_client::LongestChain;
use babe::{import_queue, start_babe, Config}; use babe;
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider}; use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
use futures::prelude::*; use futures::prelude::*;
use node_template_runtime::{self, GenesisConfig, opaque::Block, RuntimeApi, WASM_BINARY}; use node_template_runtime::{self, GenesisConfig, opaque::Block, RuntimeApi};
use substrate_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder}; use substrate_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder};
use transaction_pool::{self, txpool::{Pool as TransactionPool}}; use transaction_pool::{self, txpool::{Pool as TransactionPool}};
use inherents::InherentDataProviders; use inherents::InherentDataProviders;
@ -18,7 +18,7 @@ pub use substrate_executor::NativeExecutor;
native_executor_instance!( native_executor_instance!(
pub Executor, pub Executor,
node_template_runtime::api::dispatch, node_template_runtime::api::dispatch,
node_template_runtime::native_version node_template_runtime::native_version,
); );
construct_simple_protocol! { construct_simple_protocol! {
@ -34,45 +34,48 @@ macro_rules! new_full_start {
($config:expr) => {{ ($config:expr) => {{
let mut import_setup = None; let mut import_setup = None;
let inherent_data_providers = inherents::InherentDataProviders::new(); let inherent_data_providers = inherents::InherentDataProviders::new();
let mut tasks_to_spawn = None;
let builder = substrate_service::ServiceBuilder::new_full::< let builder = substrate_service::ServiceBuilder::new_full::<
node_template_runtime::opaque::Block, node_template_runtime::RuntimeApi, crate::service::Executor node_template_runtime::opaque::Block, node_template_runtime::RuntimeApi, crate::service::Executor
>($config)? >($config)?
.with_select_chain(|_config, client| { .with_select_chain(|_config, backend| {
#[allow(deprecated)] Ok(substrate_client::LongestChain::new(backend.clone()))
Ok(substrate_client::LongestChain::new(client.backend().clone()))
})? })?
.with_transaction_pool(|config, client| .with_transaction_pool(|config, client|
Ok(transaction_pool::txpool::Pool::new(config, transaction_pool::ChainApi::new(client))) Ok(transaction_pool::txpool::Pool::new(config, transaction_pool::ChainApi::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() let select_chain = select_chain.take()
.ok_or_else(|| substrate_service::Error::SelectChainRequired)?; .ok_or_else(|| substrate_service::Error::SelectChainRequired)?;
let (block_import, link_half) = let (grandpa_block_import, grandpa_link) =
grandpa::block_import::<_, _, _, node_template_runtime::RuntimeApi, _, _>( grandpa::block_import::<_, _, _, node_template_runtime::RuntimeApi, _, _>(
client.clone(), client.clone(), select_chain client.clone(), &*client, select_chain
)?; )?;
let justification_import = block_import.clone(); let justification_import = grandpa_block_import.clone();
let (import_queue, babe_link, babe_block_import, pruning_task) = babe::import_queue( let (babe_block_import, babe_link) = babe::block_import(
babe::Config::get_or_compute(&*client)?, babe::Config::get_or_compute(&*client)?,
block_import, 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)), Some(Box::new(justification_import)),
None, None,
client.clone(), client.clone(),
client, client,
inherent_data_providers.clone(), inherent_data_providers.clone(),
Some(transaction_pool)
)?; )?;
import_setup = Some((babe_block_import.clone(), link_half, babe_link)); import_setup = Some((babe_block_import, grandpa_link, babe_link));
tasks_to_spawn = Some(vec![Box::new(pruning_task)]);
Ok(import_queue) Ok(import_queue)
})?; })?;
(builder, import_setup, inherent_data_providers, tasks_to_spawn) (builder, import_setup, inherent_data_providers)
}} }}
} }
@ -81,30 +84,24 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
-> Result<impl AbstractService, ServiceError> -> Result<impl AbstractService, ServiceError>
{ {
let (builder, mut import_setup, inherent_data_providers, mut tasks_to_spawn) = new_full_start!(config); 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 service = builder.with_network_protocol(|_| Ok(NodeProtocol::new()))? let service = builder.with_network_protocol(|_| Ok(NodeProtocol::new()))?
.with_finality_proof_provider(|client| .with_finality_proof_provider(|client, backend|
Ok(Arc::new(GrandpaFinalityProofProvider::new(client.clone(), client)) as _) Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
)? )?
.build()?; .build()?;
let (block_import, link_half, babe_link) = let (block_import, grandpa_link, babe_link) =
import_setup.take() import_setup.take()
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed"); .expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
// spawn any futures that were created in the previous setup steps if is_authority {
if let Some(tasks) = tasks_to_spawn.take() {
for task in tasks {
service.spawn_task(
task.select(service.on_exit())
.map(|_| ())
.map_err(|_| ())
);
}
}
if service.config().roles.is_authority() {
let proposer = basic_authorship::ProposerFactory { let proposer = basic_authorship::ProposerFactory {
client: service.client(), client: service.client(),
transaction_pool: service.transaction_pool(), transaction_pool: service.transaction_pool(),
@ -115,19 +112,18 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
.ok_or(ServiceError::SelectChainRequired)?; .ok_or(ServiceError::SelectChainRequired)?;
let babe_config = babe::BabeParams { let babe_config = babe::BabeParams {
config: Config::get_or_compute(&*client)?,
keystore: service.keystore(), keystore: service.keystore(),
client, client,
select_chain, select_chain,
block_import,
env: proposer, env: proposer,
block_import,
sync_oracle: service.network(), sync_oracle: service.network(),
inherent_data_providers: inherent_data_providers.clone(), inherent_data_providers: inherent_data_providers.clone(),
force_authoring: service.config().force_authoring, force_authoring,
time_source: babe_link, babe_link,
}; };
let babe = start_babe(babe_config)?; let babe = babe::start_babe(babe_config)?;
let select = babe.select(service.on_exit()).then(|_| Ok(())); let select = babe.select(service.on_exit()).then(|_| Ok(()));
// the BABE authoring task is considered infallible, i.e. if it // the BABE authoring task is considered infallible, i.e. if it
@ -135,29 +131,29 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
service.spawn_essential_task(select); service.spawn_essential_task(select);
} }
let config = grandpa::Config { let grandpa_config = grandpa::Config {
// FIXME #1578 make this available through chainspec // FIXME #1578 make this available through chainspec
gossip_duration: Duration::from_millis(333), gossip_duration: Duration::from_millis(333),
justification_period: 4096, justification_period: 512,
name: Some(service.config().name.clone()), name: Some(name),
keystore: Some(service.keystore()), keystore: Some(service.keystore()),
}; };
match (service.config().roles.is_authority(), service.config().disable_grandpa) { match (is_authority, disable_grandpa) {
(false, false) => { (false, false) => {
// start the lightweight GRANDPA observer // start the lightweight GRANDPA observer
service.spawn_task(Box::new(grandpa::run_grandpa_observer( service.spawn_task(Box::new(grandpa::run_grandpa_observer(
config, grandpa_config,
link_half, grandpa_link,
service.network(), service.network(),
service.on_exit(), service.on_exit(),
)?)); )?));
}, },
(true, false) => { (true, false) => {
// start the full GRANDPA voter // start the full GRANDPA voter
let grandpa_config = grandpa::GrandpaParams { let voter_config = grandpa::GrandpaParams {
config: config, config: grandpa_config,
link: link_half, link: grandpa_link,
network: service.network(), network: service.network(),
inherent_data_providers: inherent_data_providers.clone(), inherent_data_providers: inherent_data_providers.clone(),
on_exit: service.on_exit(), on_exit: service.on_exit(),
@ -166,7 +162,7 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
// the GRANDPA voter task is considered infallible, i.e. // the GRANDPA voter task is considered infallible, i.e.
// if it fails we take down the service with it. // if it fails we take down the service with it.
service.spawn_essential_task(grandpa::run_grandpa_voter(grandpa_config)?); service.spawn_essential_task(grandpa::run_grandpa_voter(voter_config)?);
}, },
(_, true) => { (_, true) => {
grandpa::setup_disabled_grandpa( grandpa::setup_disabled_grandpa(
@ -187,44 +183,46 @@ pub fn new_light<C: Send + Default + 'static>(config: Configuration<C, GenesisCo
let inherent_data_providers = InherentDataProviders::new(); let inherent_data_providers = InherentDataProviders::new();
ServiceBuilder::new_light::<Block, RuntimeApi, Executor>(config)? ServiceBuilder::new_light::<Block, RuntimeApi, Executor>(config)?
.with_select_chain(|_config, client| { .with_select_chain(|_config, backend| {
#[allow(deprecated)] Ok(LongestChain::new(backend.clone()))
Ok(LongestChain::new(client.backend().clone()))
})? })?
.with_transaction_pool(|config, client| .with_transaction_pool(|config, client|
Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client)))
)? )?
.with_import_queue_and_fprb(|_config, client, _select_chain, transaction_pool| { .with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, _tx_pool| {
#[allow(deprecated)] let fetch_checker = fetcher
let fetch_checker = client.backend().blockchain().fetcher()
.upgrade()
.map(|fetcher| fetcher.checker().clone()) .map(|fetcher| fetcher.checker().clone())
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?; .ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
let block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, _>( let grandpa_block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, _>(
client.clone(), Arc::new(fetch_checker), client.clone() client.clone(), backend, Arc::new(fetch_checker), client.clone()
)?; )?;
let finality_proof_import = block_import.clone(); let finality_proof_import = grandpa_block_import.clone();
let finality_proof_request_builder = let finality_proof_request_builder =
finality_proof_import.create_finality_proof_request_builder(); finality_proof_import.create_finality_proof_request_builder();
// FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`. let (babe_block_import, babe_link) = babe::block_import(
let (import_queue, ..) = import_queue( babe::Config::get_or_compute(&*client)?,
Config::get_or_compute(&*client)?, grandpa_block_import,
block_import, client.clone(),
client.clone(),
)?;
let import_queue = babe::import_queue(
babe_link.clone(),
babe_block_import,
None, None,
Some(Box::new(finality_proof_import)), Some(Box::new(finality_proof_import)),
client.clone(), client.clone(),
client, client,
inherent_data_providers.clone(), inherent_data_providers.clone(),
Some(transaction_pool)
)?; )?;
Ok((import_queue, finality_proof_request_builder)) Ok((import_queue, finality_proof_request_builder))
})? })?
.with_network_protocol(|_| Ok(NodeProtocol::new()))? .with_network_protocol(|_| Ok(NodeProtocol::new()))?
.with_finality_proof_provider(|client| .with_finality_proof_provider(|client, backend|
Ok(Arc::new(GrandpaFinalityProofProvider::new(client.clone(), client)) as _) Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
)? )?
.build() .build()
} }

Binary file not shown.