diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 132cf41d25..f3c88c62cf 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -4442,6 +4442,9 @@ dependencies = [ "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "node-executor 2.0.0", + "node-primitives 2.0.0", + "node-runtime 2.0.0", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4453,6 +4456,7 @@ dependencies = [ "substrate-client-db 2.0.0", "substrate-consensus-common 2.0.0", "substrate-executor 2.0.0", + "substrate-finality-grandpa 2.0.0", "substrate-inherents 2.0.0", "substrate-keystore 2.0.0", "substrate-network 2.0.0", diff --git a/substrate/core/service/Cargo.toml b/substrate/core/service/Cargo.toml index 46a1b85fa2..89708683d0 100644 --- a/substrate/core/service/Cargo.toml +++ b/substrate/core/service/Cargo.toml @@ -34,3 +34,7 @@ offchain = { package = "substrate-offchain", path = "../../core/offchain" } [dev-dependencies] substrate-test-client = { path = "../test-client" } +node-executor = { path = "../../node/executor" } +node-primitives = { path = "../../node/primitives" } +node-runtime = { path = "../../node/runtime" } +grandpa = { package = "substrate-finality-grandpa", path = "../../core/finality-grandpa" } diff --git a/substrate/core/service/src/lib.rs b/substrate/core/service/src/lib.rs index 30a34f7fe2..9c0523b8b4 100644 --- a/substrate/core/service/src/lib.rs +++ b/substrate/core/service/src/lib.rs @@ -540,33 +540,77 @@ impl network::TransactionPool, ComponentBlock< /// /// # Example /// -/// ```nocompile +/// ``` +/// # use substrate_service::{ +/// # construct_service_factory, Service, FullBackend, FullExecutor, LightBackend, LightExecutor, +/// # FullComponents, LightComponents, FactoryFullConfiguration, FullClient, TaskExecutor +/// # }; +/// # use transaction_pool::{self, txpool::{Pool as TransactionPool}}; +/// # use network::construct_simple_protocol; +/// # use client::{self, LongestChain}; +/// # use primitives::{Pair as PairT, ed25519}; +/// # use consensus_common::import_queue::{BasicQueue, Verifier}; +/// # use consensus_common::{BlockOrigin, ImportBlock}; +/// # use node_runtime::{GenesisConfig, RuntimeApi}; +/// # use std::sync::Arc; +/// # use node_primitives::Block; +/// # use runtime_primitives::Justification; +/// # use runtime_primitives::traits::{AuthorityIdFor, Block as BlockT}; +/// # use grandpa; +/// # construct_simple_protocol! { +/// # pub struct NodeProtocol where Block = Block { } +/// # } +/// # struct MyVerifier; +/// # impl Verifier for MyVerifier { +/// # fn verify( +/// # &self, +/// # origin: BlockOrigin, +/// # header: B::Header, +/// # justification: Option, +/// # body: Option>, +/// # ) -> Result<(ImportBlock, Option>>), String> { +/// # unimplemented!(); +/// # } +/// # } +/// type FullChainApi = transaction_pool::ChainApi< +/// client::Client, FullExecutor, Block, RuntimeApi>, Block>; +/// type LightChainApi = transaction_pool::ChainApi< +/// client::Client, LightExecutor, Block, RuntimeApi>, Block>; +/// /// construct_service_factory! { /// struct Factory { -/// // Declare the block type +/// // Declare the block type /// Block = Block, -/// // Declare the network protocol and give an initializer. +/// RuntimeApi = RuntimeApi, +/// // Declare the network protocol and give an initializer. /// NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) }, /// RuntimeDispatch = node_executor::Executor, -/// FullTransactionPoolApi = transaction_pool::ChainApi, FullExecutor, Block> +/// FullTransactionPoolApi = FullChainApi /// { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, -/// LightTransactionPoolApi = transaction_pool::ChainApi, LightExecutor, Block> +/// LightTransactionPoolApi = LightChainApi /// { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, /// Genesis = GenesisConfig, /// Configuration = (), -/// FullService = Service> -/// { |config, executor| Service::>::new(config, executor) }, -/// // Setup as Consensus Authority (if the role and key are given) +/// FullService = FullComponents +/// { |config, executor| >::new(config, executor) }, +/// // Setup as Consensus Authority (if the role and key are given) /// AuthoritySetup = { -/// |service: Self::FullService, executor: TaskExecutor, key: Arc| { Ok(service) }}, -/// LightService = Service> -/// { |config, executor| Service::>::new(config, executor) }, -/// // Declare the import queue. The import queue is special as it takes two initializers. -/// // The first one is for the initializing the full import queue and the second for the -/// // light import queue. -/// ImportQueue = BasicQueue -/// { |_, client| Ok(BasicQueue::new(Arc::new(NoneVerifier {}, client))) } -/// { |_, client| Ok(BasicQueue::new(Arc::new(NoneVerifier {}, client))) }, +/// |service: Self::FullService, executor: TaskExecutor, key: Option>| { +/// Ok(service) +/// }}, +/// LightService = LightComponents +/// { |config, executor| >::new(config, executor) }, +/// FullImportQueue = BasicQueue +/// { |_, client, _| Ok(BasicQueue::new(Arc::new(MyVerifier), client, None, None, None)) }, +/// LightImportQueue = BasicQueue +/// { |_, client| Ok(BasicQueue::new(Arc::new(MyVerifier), client, None, None, None)) }, +/// SelectChain = LongestChain, Self::Block> +/// { |config: &FactoryFullConfiguration, client: Arc>| { +/// Ok(LongestChain::new(client.backend().clone(), client.import_lock())) +/// }}, +/// FinalityProofProvider = { |client: Arc>| { +/// Ok(Some(Arc::new(grandpa::FinalityProofProvider::new(client.clone(), client)) as _)) +/// }}, /// } /// } /// ```