From eec76978d59e7636080ded2b888c56ff81de2640 Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Wed, 16 Feb 2022 21:41:24 +0800 Subject: [PATCH 1/7] Extract `subspace-service` from `subspace-node` --- Cargo.lock | 96 +++++++----- crates/subspace-node/Cargo.toml | 46 +----- crates/subspace-node/src/command.rs | 88 ++++++----- crates/subspace-node/src/lib.rs | 4 - crates/subspace-service/Cargo.toml | 75 ++++++++++ .../src/chain_spec.rs | 73 +++++---- .../src/lib.rs} | 140 +++++++++++++++--- .../src/rpc.rs | 0 cumulus/client/cirrus-service/Cargo.toml | 2 +- cumulus/client/cirrus-service/src/lib.rs | 3 +- .../client/consensus/relay-chain/Cargo.toml | 2 +- .../client/consensus/relay-chain/src/lib.rs | 2 +- cumulus/parachain-template/node/Cargo.toml | 1 + .../parachain-template/node/src/service.rs | 3 +- 14 files changed, 348 insertions(+), 187 deletions(-) create mode 100644 crates/subspace-service/Cargo.toml rename crates/{subspace-node => subspace-service}/src/chain_spec.rs (80%) rename crates/{subspace-node/src/service.rs => subspace-service/src/lib.rs} (79%) rename crates/{subspace-node => subspace-service}/src/rpc.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 90efb0ab9c0a8..ff7917ae14a99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -928,7 +928,7 @@ dependencies = [ "sp-core", "sp-inherents", "sp-runtime", - "subspace-node", + "subspace-service", "tracing", ] @@ -1451,8 +1451,8 @@ dependencies = [ "sp-core", "sp-inherents", "sp-runtime", - "subspace-node", "subspace-runtime-primitives", + "subspace-service", "substrate-prometheus-endpoint", "tracing", ] @@ -5169,6 +5169,7 @@ dependencies = [ "sp-timestamp", "sp-transaction-pool", "subspace-node", + "subspace-service", "substrate-build-script-utils", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", @@ -8614,50 +8615,14 @@ dependencies = [ name = "subspace-node" version = "0.1.0" dependencies = [ - "cirrus-node-primitives", "clap 3.0.13", - "frame-benchmarking", "frame-benchmarking-cli", - "frame-support", "futures 0.3.19", - "jsonrpc-core", - "lru 0.7.2", - "pallet-transaction-payment-rpc", - "polkadot-node-collation-generation", - "polkadot-node-core-chain-api", - "polkadot-node-core-runtime-api", - "polkadot-node-subsystem-util", - "polkadot-overseer", - "sc-basic-authorship", "sc-cli", - "sc-client-api", - "sc-consensus", - "sc-consensus-slots", - "sc-consensus-subspace", - "sc-consensus-subspace-rpc", - "sc-consensus-uncles", - "sc-executor", - "sc-network", - "sc-rpc", - "sc-rpc-api", "sc-service", - "sc-telemetry", - "sc-transaction-pool", - "sc-transaction-pool-api", - "serde_json", - "sp-api", - "sp-authorship", - "sp-block-builder", - "sp-blockchain", - "sp-consensus", - "sp-consensus-subspace", "sp-core", - "sp-runtime", - "sp-timestamp", - "subspace-runtime", + "subspace-service", "substrate-build-script-utils", - "substrate-frame-rpc-system", - "substrate-prometheus-endpoint", "thiserror", ] @@ -8728,6 +8693,59 @@ dependencies = [ "subspace-core-primitives", ] +[[package]] +name = "subspace-service" +version = "0.1.0" +dependencies = [ + "cirrus-node-primitives", + "frame-support", + "frame-system-rpc-runtime-api", + "futures 0.3.19", + "jsonrpc-core", + "lru 0.7.2", + "pallet-transaction-payment-rpc", + "pallet-transaction-payment-rpc-runtime-api", + "polkadot-node-collation-generation", + "polkadot-node-core-chain-api", + "polkadot-node-core-runtime-api", + "polkadot-node-subsystem-util", + "polkadot-overseer", + "sc-basic-authorship", + "sc-client-api", + "sc-consensus", + "sc-consensus-slots", + "sc-consensus-subspace", + "sc-consensus-subspace-rpc", + "sc-consensus-uncles", + "sc-executor", + "sc-network", + "sc-rpc", + "sc-rpc-api", + "sc-service", + "sc-telemetry", + "sc-transaction-pool", + "sc-transaction-pool-api", + "sp-api", + "sp-authorship", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-consensus-subspace", + "sp-core", + "sp-executor", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-timestamp", + "sp-transaction-pool", + "sp-trie", + "subspace-runtime", + "subspace-runtime-primitives", + "substrate-frame-rpc-system", + "substrate-prometheus-endpoint", + "thiserror", +] + [[package]] name = "subspace-solving" version = "0.1.0" diff --git a/crates/subspace-node/Cargo.toml b/crates/subspace-node/Cargo.toml index a415868670843..6664f1f1c5318 100644 --- a/crates/subspace-node/Cargo.toml +++ b/crates/subspace-node/Cargo.toml @@ -19,49 +19,13 @@ include = [ targets = ["x86_64-unknown-linux-gnu"] [dependencies] -cirrus-node-primitives = { version = "0.1.0", path = "../cirrus-node-primitives" } -frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +clap = { version = "3.0.13", features = ["derive"] } frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } futures = "0.3.19" -jsonrpc-core = "18.0.0" -lru = "0.7.2" -pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -polkadot-overseer = { path = "../../polkadot/node/overseer" } -polkadot-node-collation-generation = { path = "../../polkadot/node/collation-generation" } -polkadot-node-core-chain-api = { path = "../../polkadot/node/core/chain-api" } -polkadot-node-core-runtime-api = { path = "../../polkadot/node/core/runtime-api" } -polkadot-node-subsystem-util = { path = "../../polkadot/node/subsystem-util" } -sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6", features = ["wasmtime"] } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sc-consensus-subspace = { version = "0.1.0", path = "../sc-consensus-subspace" } -sc-consensus-subspace-rpc = { version = "0.1.0", path = "../sc-consensus-subspace-rpc" } -sc-consensus-slots = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sc-consensus-uncles = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6", features = ["wasmtime"] } -sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6", features = ["wasmtime"] } -sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -serde_json = "1.0.74" -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sp-authorship = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sp-consensus-subspace = { version = "0.1.0", path = "../sp-consensus-subspace" } sp-core = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sp-runtime = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -clap = { version = "3.0.13", features = ["derive"] } -subspace-runtime = { version = "0.1.0", features = ["do-not-enforce-cost-of-storage"], path = "../subspace-runtime" } -substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } -substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +subspace-service = { version = "0.1.0", path = "../subspace-service" } thiserror = "1.0.30" [build-dependencies] @@ -70,8 +34,6 @@ substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/pa [features] default = [] runtime-benchmarks = [ - "subspace-runtime/runtime-benchmarks", + "subspace-service/runtime-benchmarks", ] -# This feature makes `testnet` chain spec to use `chain-spec.json` file in the root of the repo instead of compiled -# version -json-chain-spec = [] +json-chain-spec = ["subspace-service/json-chain-spec"] diff --git a/crates/subspace-node/src/command.rs b/crates/subspace-node/src/command.rs index db0c580591c74..2e7830b4c87cd 100644 --- a/crates/subspace-node/src/command.rs +++ b/crates/subspace-node/src/command.rs @@ -15,18 +15,17 @@ // along with this program. If not, see . use crate::cli::{Cli, Subcommand}; -use crate::{chain_spec, service}; +use futures::future::TryFutureExt; use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli}; -use sc_service::PartialComponents; use sp_core::crypto::Ss58AddressFormat; -use subspace_runtime::Block; +use subspace_service::{chain_spec, subspace_runtime, SubspaceExecutorDispatch}; /// Subspace node error. #[derive(thiserror::Error, Debug)] pub enum Error { /// Subspace service error. #[error(transparent)] - SubspaceService(#[from] service::Error), + SubspaceService(#[from] subspace_service::Error), /// CLI error. #[error(transparent)] @@ -74,10 +73,10 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { - "testnet" => Box::new(chain_spec::testnet_config()?), - "dev" => Box::new(chain_spec::development_config()?), - "" | "local" => Box::new(chain_spec::local_testnet_config()?), - path => Box::new(chain_spec::ChainSpec::from_json_file( + "testnet" => Box::new(chain_spec::subspace_testnet_config()?), + "dev" => Box::new(chain_spec::subspace_development_config()?), + "" | "local" => Box::new(chain_spec::subspace_local_testnet_config()?), + path => Box::new(chain_spec::SubspaceChainSpec::from_json_file( std::path::PathBuf::from(path), )?), }) @@ -121,51 +120,49 @@ pub fn run() -> std::result::Result<(), Error> { Some(Subcommand::CheckBlock(cmd)) => { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.async_run(|config| { - let PartialComponents { - client, + runner.async_run(|mut config| { + let (client, _, import_queue, task_manager) = + subspace_service::new_chain_ops(&mut config)?; + Ok(( + cmd.run(client, import_queue).map_err(Error::SubstrateCli), task_manager, - import_queue, - .. - } = service::new_partial(&config)?; - Ok((cmd.run(client, import_queue), task_manager)) + )) })?; } Some(Subcommand::ExportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.async_run(|config| { - let PartialComponents { - client, + runner.async_run(|mut config| { + let (client, _, _, task_manager) = subspace_service::new_chain_ops(&mut config)?; + Ok(( + cmd.run(client, config.database) + .map_err(Error::SubstrateCli), task_manager, - .. - } = service::new_partial(&config)?; - Ok((cmd.run(client, config.database), task_manager)) + )) })?; } Some(Subcommand::ExportState(cmd)) => { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.async_run(|config| { - let PartialComponents { - client, + runner.async_run(|mut config| { + let (client, _, _, task_manager) = subspace_service::new_chain_ops(&mut config)?; + Ok(( + cmd.run(client, config.chain_spec) + .map_err(Error::SubstrateCli), task_manager, - .. - } = service::new_partial(&config)?; - Ok((cmd.run(client, config.chain_spec), task_manager)) + )) })?; } Some(Subcommand::ImportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.async_run(|config| { - let PartialComponents { - client, + runner.async_run(|mut config| { + let (client, _, import_queue, task_manager) = + subspace_service::new_chain_ops(&mut config)?; + Ok(( + cmd.run(client, import_queue).map_err(Error::SubstrateCli), task_manager, - import_queue, - .. - } = service::new_partial(&config)?; - Ok((cmd.run(client, import_queue), task_manager)) + )) })?; } Some(Subcommand::PurgeChain(cmd)) => { @@ -175,21 +172,22 @@ pub fn run() -> std::result::Result<(), Error> { Some(Subcommand::Revert(cmd)) => { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.async_run(|config| { - let PartialComponents { - client, + runner.async_run(|mut config| { + let (client, backend, _, task_manager) = + subspace_service::new_chain_ops(&mut config)?; + Ok(( + cmd.run(client, backend).map_err(Error::SubstrateCli), task_manager, - backend, - .. - } = service::new_partial(&config)?; - Ok((cmd.run(client, backend), task_manager)) + )) })?; } Some(Subcommand::Benchmark(cmd)) => { if cfg!(feature = "runtime-benchmarks") { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.sync_run(|config| cmd.run::(config))?; + runner.sync_run(|config| { + cmd.run::(config) + })?; } else { return Err(Error::Other( "Benchmarking wasn't enabled when building the node. You can enable it with \ @@ -202,9 +200,9 @@ pub fn run() -> std::result::Result<(), Error> { let runner = cli.create_runner(&cli.run.base)?; set_default_ss58_version(&runner.config().chain_spec); runner.run_node_until_exit(|config| async move { - service::new_full(config) - .await - .map(|full| full.task_manager) + subspace_service::new_full::(config) + .await + .map(|full| full.task_manager) })?; } } diff --git a/crates/subspace-node/src/lib.rs b/crates/subspace-node/src/lib.rs index 8aaf4bedff946..4959d68acc7f8 100644 --- a/crates/subspace-node/src/lib.rs +++ b/crates/subspace-node/src/lib.rs @@ -18,11 +18,7 @@ #![warn(missing_docs)] -mod chain_spec; -#[macro_use] -pub mod service; pub mod cli; mod command; -mod rpc; pub use self::command::{run, Error}; diff --git a/crates/subspace-service/Cargo.toml b/crates/subspace-service/Cargo.toml new file mode 100644 index 0000000000000..1f114dd1cfe66 --- /dev/null +++ b/crates/subspace-service/Cargo.toml @@ -0,0 +1,75 @@ +[package] +name = "subspace-service" +version = "0.1.0" +authors = ["Subspace Labs "] +description = "A Subspace Network Blockchain node." +edition = "2021" +license = "GPL-3.0-or-later" +homepage = "https://subspace.network" +repository = "https://github.com/subspace/subspace" +include = [ + "/src", + "/Cargo.toml", +] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +cirrus-node-primitives = { version = "0.1.0", path = "../cirrus-node-primitives" } +frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +futures = "0.3.19" +jsonrpc-core = "18.0.0" +lru = "0.7.2" +pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +polkadot-overseer = { path = "../../polkadot/node/overseer" } +polkadot-node-collation-generation = { path = "../../polkadot/node/collation-generation" } +polkadot-node-core-chain-api = { path = "../../polkadot/node/core/chain-api" } +polkadot-node-core-runtime-api = { path = "../../polkadot/node/core/runtime-api" } +polkadot-node-subsystem-util = { path = "../../polkadot/node/subsystem-util" } +sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sc-consensus-subspace = { version = "0.1.0", path = "../sc-consensus-subspace" } +sc-consensus-subspace-rpc = { version = "0.1.0", path = "../sc-consensus-subspace-rpc" } +sc-consensus-slots = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sc-consensus-uncles = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6", features = ["wasmtime"] } +sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6", features = ["wasmtime"] } +sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-authorship = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-consensus-subspace = { version = "0.1.0", path = "../sp-consensus-subspace" } +sp-core = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-executor = { version = "0.1.0", path = "../sp-executor" } +sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-runtime = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +sp-trie = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +subspace-runtime = { version = "0.1.0", features = ["do-not-enforce-cost-of-storage"], path = "../subspace-runtime" } +subspace-runtime-primitives = { version = "0.1.0", path = "../subspace-runtime-primitives" } +substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +thiserror = "1.0.30" + +sp-session = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +frame-system-rpc-runtime-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } +pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "2c4549689dbb86c23725dac2f82af35faa07c9f6" } + +[features] +default = [] +runtime-benchmarks = [ + "subspace-runtime/runtime-benchmarks", +] +# This feature makes `testnet` chain spec to use `chain-spec.json` file in the root of the repo instead of compiled +# version +json-chain-spec = [] diff --git a/crates/subspace-node/src/chain_spec.rs b/crates/subspace-service/src/chain_spec.rs similarity index 80% rename from crates/subspace-node/src/chain_spec.rs rename to crates/subspace-service/src/chain_spec.rs index 5ec96a7690cdb..bc99ab7de7f55 100644 --- a/crates/subspace-node/src/chain_spec.rs +++ b/crates/subspace-service/src/chain_spec.rs @@ -14,16 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +//! Subspace chain configurations. + use frame_support::traits::Get; use sc_service::{ChainType, Properties}; use sc_telemetry::TelemetryEndpoints; use sp_core::crypto::Ss58Codec; use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; -use subspace_runtime::{ - AccountId, Balance, BalancesConfig, BlockNumber, GenesisConfig, SS58Prefix, Signature, - SudoConfig, SystemConfig, VestingConfig, DECIMAL_PLACES, MILLISECS_PER_BLOCK, SSC, WASM_BINARY, -}; +use subspace_runtime_primitives::{AccountId, Balance, BlockNumber, Signature}; // The URL for the telemetry server. const POLKADOT_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; @@ -55,8 +54,8 @@ const TOKEN_GRANTS: &[(&str, u128)] = &[ ("5FZwEgsvZz1vpeH7UsskmNmTpbfXvAcojjgVfShgbRqgC1nx", 27_800), ]; -/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. -pub type ChainSpec = sc_service::GenericChainSpec; +/// The `ChainSpec` parameterized for the subspace runtime. +pub type SubspaceChainSpec = sc_service::GenericChainSpec; /// Generate a crypto pair from seed. pub fn get_from_seed(seed: &str) -> ::Public { @@ -73,17 +72,22 @@ pub fn get_account_id_from_seed(seed: &str) -> AccountId { } #[cfg(feature = "json-chain-spec")] -pub fn testnet_config() -> Result { - ChainSpec::from_json_bytes(&include_bytes!("../../../chain-spec.json")[..]) +pub fn subspace_testnet_config() -> Result { + SubspaceChainSpec::from_json_bytes(&include_bytes!("../../../chain-spec.json")[..]) } #[cfg(not(feature = "json-chain-spec"))] -pub fn testnet_config() -> Result { +pub fn subspace_testnet_config() -> Result { + use subspace_runtime::{SS58Prefix, SSC}; + let mut properties = Properties::new(); properties.insert("ss58Format".into(), >::get().into()); - properties.insert("tokenDecimals".into(), DECIMAL_PLACES.into()); + properties.insert( + "tokenDecimals".into(), + subspace_runtime::DECIMAL_PLACES.into(), + ); properties.insert("tokenSymbol".into(), "tSSC".into()); - Ok(ChainSpec::from_genesis( + Ok(SubspaceChainSpec::from_genesis( // Name "Subspace testnet", // ID @@ -110,9 +114,10 @@ pub fn testnet_config() -> Result { // TODO: Adjust start block to real value before mainnet launch let start_block = 100_000_000; - let one_month_in_blocks = - u32::try_from(3600 * 24 * 30 * MILLISECS_PER_BLOCK / 1000) - .expect("One month of blocks always fits in u32; qed"); + let one_month_in_blocks = u32::try_from( + 3600 * 24 * 30 * subspace_runtime::MILLISECS_PER_BLOCK / 1000, + ) + .expect("One month of blocks always fits in u32; qed"); // Add balance so it can be locked balances.push((account_id.clone(), amount)); @@ -137,8 +142,8 @@ pub fn testnet_config() -> Result { ] }) .collect::>(); - create_genesis_config( - WASM_BINARY.expect("Wasm binary must be built for testnet"), + subspace_genesis_config( + subspace_runtime::WASM_BINARY.expect("Wasm binary must be built for testnet"), sudo_account, balances, vesting_schedules, @@ -161,17 +166,20 @@ pub fn testnet_config() -> Result { )) } -pub fn development_config() -> Result { - let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; +pub fn subspace_development_config() -> Result { + use subspace_runtime::SSC; - Ok(ChainSpec::from_genesis( + let wasm_binary = subspace_runtime::WASM_BINARY + .ok_or_else(|| "Development wasm not available".to_string())?; + + Ok(SubspaceChainSpec::from_genesis( // Name "Development", // ID "dev", ChainType::Development, || { - create_genesis_config( + subspace_genesis_config( wasm_binary, // Sudo account get_account_id_from_seed("Alice"), @@ -199,17 +207,20 @@ pub fn development_config() -> Result { )) } -pub fn local_testnet_config() -> Result { - let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; +pub fn subspace_local_testnet_config() -> Result { + use subspace_runtime::SSC; + + let wasm_binary = subspace_runtime::WASM_BINARY + .ok_or_else(|| "Development wasm not available".to_string())?; - Ok(ChainSpec::from_genesis( + Ok(SubspaceChainSpec::from_genesis( // Name "Local Testnet", // ID "local_testnet", ChainType::Local, || { - create_genesis_config( + subspace_genesis_config( wasm_binary, // Sudo account get_account_id_from_seed("Alice"), @@ -246,24 +257,24 @@ pub fn local_testnet_config() -> Result { } /// Configure initial storage state for FRAME modules. -fn create_genesis_config( +fn subspace_genesis_config( wasm_binary: &[u8], sudo_account: AccountId, balances: Vec<(AccountId, Balance)>, // who, start, period, period_count, per_period vesting: Vec<(AccountId, BlockNumber, BlockNumber, u32, Balance)>, -) -> GenesisConfig { - GenesisConfig { - system: SystemConfig { +) -> subspace_runtime::GenesisConfig { + subspace_runtime::GenesisConfig { + system: subspace_runtime::SystemConfig { // Add Wasm runtime to storage. code: wasm_binary.to_vec(), }, - balances: BalancesConfig { balances }, + balances: subspace_runtime::BalancesConfig { balances }, transaction_payment: Default::default(), - sudo: SudoConfig { + sudo: subspace_runtime::SudoConfig { // Assign network admin rights. key: Some(sudo_account), }, - vesting: VestingConfig { vesting }, + vesting: subspace_runtime::VestingConfig { vesting }, } } diff --git a/crates/subspace-node/src/service.rs b/crates/subspace-service/src/lib.rs similarity index 79% rename from crates/subspace-node/src/service.rs rename to crates/subspace-service/src/lib.rs index 66a22845fc6db..f649e82d185a7 100644 --- a/crates/subspace-node/src/service.rs +++ b/crates/subspace-service/src/lib.rs @@ -16,6 +16,9 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. +pub mod chain_spec; +pub mod rpc; + use lru::LruCache; use polkadot_node_collation_generation::CollationGenerationSubsystem; use polkadot_node_core_chain_api::ChainApiSubsystem; @@ -27,16 +30,52 @@ use polkadot_overseer::{ }; use sc_client_api::ExecutorProvider; use sc_consensus_slots::SlotProportion; -use sc_executor::NativeElseWasmExecutor; +use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch}; use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; use sc_telemetry::{Telemetry, TelemetryWorker}; use sp_api::ConstructRuntimeApi; use sp_blockchain::HeaderBackend; use sp_consensus::SelectChain; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; +use sp_runtime::traits::{BlakeTwo256, Block as BlockT, Header as HeaderT}; use std::sync::Arc; -use subspace_runtime::opaque::BlockId; -use subspace_runtime::{self, opaque::Block, RuntimeApi}; +pub use subspace_runtime; +use subspace_runtime_primitives::{ + opaque::{Block, BlockId}, + AccountId, Balance, Index as Nonce, +}; + +/// A set of APIs that subspace-like runtimes must implement. +pub trait RuntimeApiCollection: + sp_api::ApiExt + + sp_api::Metadata + + sp_block_builder::BlockBuilder + + sp_executor::ExecutorApi + + sp_offchain::OffchainWorkerApi + + sp_session::SessionKeys + + sp_consensus_subspace::SubspaceApi + + sp_transaction_pool::runtime_api::TaggedTransactionQueue + + frame_system_rpc_runtime_api::AccountNonceApi + + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi +where + >::StateBackend: sp_api::StateBackend, +{ +} + +impl RuntimeApiCollection for Api +where + Api: sp_api::ApiExt + + sp_api::Metadata + + sp_block_builder::BlockBuilder + + sp_executor::ExecutorApi + + sp_offchain::OffchainWorkerApi + + sp_session::SessionKeys + + sp_consensus_subspace::SubspaceApi + + sp_transaction_pool::runtime_api::TaggedTransactionQueue + + frame_system_rpc_runtime_api::AccountNonceApi + + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi, + >::StateBackend: sp_api::StateBackend, +{ +} /// Error type for Subspace service. #[derive(thiserror::Error, Debug)] @@ -61,6 +100,10 @@ pub enum Error { #[error(transparent)] Consensus(#[from] sp_consensus::Error), + /// Telemetry error. + #[error(transparent)] + Telemetry(#[from] sc_telemetry::Error), + /// Polkadot overseer error. #[error("Failed to create an overseer")] Overseer(#[from] polkadot_overseer::SubsystemError), @@ -71,9 +114,9 @@ pub enum Error { } /// Subspace native executor instance. -pub struct ExecutorDispatch; +pub struct SubspaceExecutorDispatch; -impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { +impl sc_executor::NativeExecutionDispatch for SubspaceExecutorDispatch { /// Only enable the benchmarking host functions when we actually want to benchmark. #[cfg(feature = "runtime-benchmarks")] type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; @@ -90,31 +133,48 @@ impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { } } -/// Subspace full client. -pub type FullClient = +/// Subspace-like full client. +pub type FullClient = sc_service::TFullClient>; + +/// Full client using subspace-runtime. +pub type SubspaceClient = FullClient; + type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; /// Creates `PartialComponents` for Subspace client. #[allow(clippy::type_complexity)] -pub fn new_partial( +pub fn new_partial( config: &Configuration, ) -> Result< sc_service::PartialComponents< - FullClient, + FullClient, FullBackend, FullSelectChain, - sc_consensus::DefaultImportQueue, - sc_transaction_pool::FullPool, + sc_consensus::DefaultImportQueue>, + sc_transaction_pool::FullPool>, ( - sc_consensus_subspace::SubspaceBlockImport>, + sc_consensus_subspace::SubspaceBlockImport< + Block, + FullClient, + Arc>, + >, sc_consensus_subspace::SubspaceLink, Option, ), >, ServiceError, -> { +> +where + RuntimeApi: ConstructRuntimeApi> + + Send + + Sync + + 'static, + RuntimeApi::RuntimeApi: + RuntimeApiCollection>, + ExecutorDispatch: NativeExecutionDispatch + 'static, +{ let telemetry = config .telemetry_endpoints .clone() @@ -211,12 +271,18 @@ pub fn new_partial( } /// Returns the active leaves the overseer should start with. -async fn active_leaves( +async fn active_leaves( select_chain: &impl SelectChain, - client: &FullClient, + client: &FullClient, ) -> Result, Error> where - RuntimeApi: ConstructRuntimeApi + Send + Sync + 'static, + RuntimeApi: ConstructRuntimeApi> + + Send + + Sync + + 'static, + RuntimeApi::RuntimeApi: + RuntimeApiCollection>, + ExecutorDispatch: NativeExecutionDispatch + 'static, { let best_block = select_chain.best_chain().await?; @@ -275,7 +341,18 @@ pub struct NewFull { } /// Builds a new service for a full client. -pub async fn new_full(config: Configuration) -> Result>, Error> { +pub async fn new_full( + config: Configuration, +) -> Result>>, Error> +where + RuntimeApi: ConstructRuntimeApi> + + Send + + Sync + + 'static, + RuntimeApi::RuntimeApi: + RuntimeApiCollection>, + ExecutorDispatch: NativeExecutionDispatch + 'static, +{ let sc_service::PartialComponents { client, backend, @@ -285,7 +362,7 @@ pub async fn new_full(config: Configuration) -> Result>, select_chain, transaction_pool, other: (block_import, subspace_link, mut telemetry), - } = new_partial(&config)?; + } = new_partial::(&config)?; let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { @@ -516,3 +593,28 @@ pub async fn new_full(config: Configuration) -> Result>, backend, }) } + +/// Builds a new object suitable for chain operations. +pub fn new_chain_ops( + mut config: &mut Configuration, +) -> Result< + ( + Arc>, + Arc, + sc_consensus::BasicQueue>, + TaskManager, + ), + Error, +> { + config.keystore = sc_service::config::KeystoreConfig::InMemory; + + let sc_service::PartialComponents { + client, + backend, + import_queue, + task_manager, + .. + } = new_partial::(config)?; + + Ok((client, backend, import_queue, task_manager)) +} diff --git a/crates/subspace-node/src/rpc.rs b/crates/subspace-service/src/rpc.rs similarity index 100% rename from crates/subspace-node/src/rpc.rs rename to crates/subspace-service/src/rpc.rs diff --git a/cumulus/client/cirrus-service/Cargo.toml b/cumulus/client/cirrus-service/Cargo.toml index f2e0b4479d257..f142b7f8e3673 100644 --- a/cumulus/client/cirrus-service/Cargo.toml +++ b/cumulus/client/cirrus-service/Cargo.toml @@ -38,4 +38,4 @@ cirrus-node-primitives = { path = "../../../crates/cirrus-node-primitives" } cirrus-primitives = { path = "../../primitives" } # Subspace -subspace-node = { path = "../../../crates/subspace-node" } +subspace-service = { path = "../../../crates/subspace-service" } diff --git a/cumulus/client/cirrus-service/src/lib.rs b/cumulus/client/cirrus-service/src/lib.rs index 46b141c3a5805..eb2ae186f1bee 100644 --- a/cumulus/client/cirrus-service/src/lib.rs +++ b/cumulus/client/cirrus-service/src/lib.rs @@ -49,7 +49,6 @@ use cumulus_client_consensus_common::RelaychainClient; pub mod genesis; use cirrus_node_primitives::CollatorPair; -use subspace_node::service as subspace_service; /// The primary chain full node handle. pub struct PrimaryFullNode { @@ -245,7 +244,7 @@ pub fn prepare_node_config(mut parachain_config: Configuration) -> Configuration #[sc_tracing::logging::prefix_logs_with("Primarychain")] pub async fn build_subspace_full_node( config: Configuration, -) -> Result>, sc_service::Error> { +) -> Result>, sc_service::Error> { let is_light = matches!(config.role, Role::Light); if is_light { Err(sc_service::Error::Other("Light client not supported.".into())) diff --git a/cumulus/client/consensus/relay-chain/Cargo.toml b/cumulus/client/consensus/relay-chain/Cargo.toml index 3457996d35fc6..fe30616682d1b 100644 --- a/cumulus/client/consensus/relay-chain/Cargo.toml +++ b/cumulus/client/consensus/relay-chain/Cargo.toml @@ -28,5 +28,5 @@ parking_lot = "0.12.0" tracing = "0.1.22" cirrus-node-primitives = { path = "../../../../crates/cirrus-node-primitives" } -subspace-node = { path = "../../../../crates/subspace-node" } subspace-runtime-primitives = { path = "../../../../crates/subspace-runtime-primitives" } +subspace-service = { path = "../../../../crates/subspace-service" } diff --git a/cumulus/client/consensus/relay-chain/src/lib.rs b/cumulus/client/consensus/relay-chain/src/lib.rs index b9f33e3d4e0f4..f3ad301f6574c 100644 --- a/cumulus/client/consensus/relay-chain/src/lib.rs +++ b/cumulus/client/consensus/relay-chain/src/lib.rs @@ -239,7 +239,7 @@ pub struct BuildPrimaryChainConsensusParams { pub proposer_factory: PF, pub create_inherent_data_providers: CIDP, pub block_import: BI, - pub relay_chain_client: Arc, + pub relay_chain_client: Arc, pub relay_chain_backend: Arc, } diff --git a/cumulus/parachain-template/node/Cargo.toml b/cumulus/parachain-template/node/Cargo.toml index 5b7448697214d..6cdf364ebf84b 100644 --- a/cumulus/parachain-template/node/Cargo.toml +++ b/cumulus/parachain-template/node/Cargo.toml @@ -86,3 +86,4 @@ cirrus-primitives = { path = "../../primitives" } # Subspace dependencies subspace-node = { path = "../../../crates/subspace-node" } +subspace-service = { path = "../../../crates/subspace-service" } diff --git a/cumulus/parachain-template/node/src/service.rs b/cumulus/parachain-template/node/src/service.rs index f83ec7961903c..9a388aabaa18d 100644 --- a/cumulus/parachain-template/node/src/service.rs +++ b/cumulus/parachain-template/node/src/service.rs @@ -25,7 +25,6 @@ use substrate_prometheus_endpoint::Registry; use cumulus_client_consensus_relay_chain::{ build_primary_chain_consensus, BuildPrimaryChainConsensusParams, }; -use subspace_node::service as subspace_service; /// Native executor instance. pub struct TemplateRuntimeExecutor; @@ -211,7 +210,7 @@ where Option<&Registry>, Option, &TaskManager, - &subspace_service::NewFull>, + &subspace_service::NewFull>, Arc< sc_transaction_pool::FullPool< Block, From d26ea46bf6a584aff48069ac666b17478a86ec1c Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Wed, 16 Feb 2022 22:38:43 +0800 Subject: [PATCH 2/7] Add new slot and block signing stream to `NewFull` in subspace-service These two streams will be used in mocking the farmer functionalities in the test environment. --- crates/subspace-service/Cargo.toml | 2 +- crates/subspace-service/src/lib.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/subspace-service/Cargo.toml b/crates/subspace-service/Cargo.toml index 1f114dd1cfe66..6199ad8b4dc01 100644 --- a/crates/subspace-service/Cargo.toml +++ b/crates/subspace-service/Cargo.toml @@ -2,7 +2,7 @@ name = "subspace-service" version = "0.1.0" authors = ["Subspace Labs "] -description = "A Subspace Network Blockchain node." +description = "Subspace service." edition = "2021" license = "GPL-3.0-or-later" homepage = "https://subspace.network" diff --git a/crates/subspace-service/src/lib.rs b/crates/subspace-service/src/lib.rs index f649e82d185a7..3b95655503eb5 100644 --- a/crates/subspace-service/src/lib.rs +++ b/crates/subspace-service/src/lib.rs @@ -30,6 +30,9 @@ use polkadot_overseer::{ }; use sc_client_api::ExecutorProvider; use sc_consensus_slots::SlotProportion; +use sc_consensus_subspace::{ + notification::SubspaceNotificationStream, BlockSigningNotification, NewSlotNotification, +}; use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch}; use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; use sc_telemetry::{Telemetry, TelemetryWorker}; @@ -338,6 +341,10 @@ pub struct NewFull { pub rpc_handlers: sc_service::RpcHandlers, /// Full client backend. pub backend: Arc, + /// New slot stream. + pub new_slot_notification_stream: SubspaceNotificationStream, + /// Block signing stream. + pub block_signing_notification_stream: SubspaceNotificationStream, } /// Builds a new service for a full client. @@ -553,6 +560,8 @@ where let rpc_extensions_builder = { let client = client.clone(); let pool = transaction_pool.clone(); + let new_slot_notification_stream = new_slot_notification_stream.clone(); + let block_signing_notification_stream = block_signing_notification_stream.clone(); Box::new(move |deny_unsafe, subscription_executor| { let deps = crate::rpc::FullDeps { @@ -591,10 +600,13 @@ where network, rpc_handlers, backend, + new_slot_notification_stream, + block_signing_notification_stream, }) } /// Builds a new object suitable for chain operations. +#[allow(clippy::type_complexity)] pub fn new_chain_ops( mut config: &mut Configuration, ) -> Result< From 7b6d0a41c190f32cd8ded13888b18d4a8582b4d7 Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Thu, 17 Feb 2022 20:10:55 +0800 Subject: [PATCH 3/7] Allow disabling the rpc extensions when invoking `new_full` --- crates/subspace-node/src/command.rs | 2 +- crates/subspace-service/src/lib.rs | 47 ++++++++++++------------ cumulus/client/cirrus-service/src/lib.rs | 2 +- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/crates/subspace-node/src/command.rs b/crates/subspace-node/src/command.rs index 2e7830b4c87cd..26bb82c5723d7 100644 --- a/crates/subspace-node/src/command.rs +++ b/crates/subspace-node/src/command.rs @@ -200,7 +200,7 @@ pub fn run() -> std::result::Result<(), Error> { let runner = cli.create_runner(&cli.run.base)?; set_default_ss58_version(&runner.config().chain_spec); runner.run_node_until_exit(|config| async move { - subspace_service::new_full::(config) + subspace_service::new_full::(config, true) .await .map(|full| full.task_manager) })?; diff --git a/crates/subspace-service/src/lib.rs b/crates/subspace-service/src/lib.rs index 3b95655503eb5..3517de63b1e40 100644 --- a/crates/subspace-service/src/lib.rs +++ b/crates/subspace-service/src/lib.rs @@ -350,6 +350,7 @@ pub struct NewFull { /// Builds a new service for a full client. pub async fn new_full( config: Configuration, + enable_rpc_extensions: bool, ) -> Result>>, Error> where RuntimeApi: ConstructRuntimeApi> @@ -557,34 +558,34 @@ where ); } - let rpc_extensions_builder = { - let client = client.clone(); - let pool = transaction_pool.clone(); - let new_slot_notification_stream = new_slot_notification_stream.clone(); - let block_signing_notification_stream = block_signing_notification_stream.clone(); - - Box::new(move |deny_unsafe, subscription_executor| { - let deps = crate::rpc::FullDeps { - client: client.clone(), - pool: pool.clone(), - deny_unsafe, - subscription_executor, - new_slot_notification_stream: new_slot_notification_stream.clone(), - block_signing_notification_stream: block_signing_notification_stream.clone(), - archived_segment_notification_stream: archived_segment_notification_stream.clone(), - }; - - Ok(crate::rpc::create_full(deps)) - }) - }; - let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { network: network.clone(), client: client.clone(), keystore: keystore_container.sync_keystore(), task_manager: &mut task_manager, - transaction_pool, - rpc_extensions_builder, + transaction_pool: transaction_pool.clone(), + rpc_extensions_builder: if enable_rpc_extensions { + let client = client.clone(); + let new_slot_notification_stream = new_slot_notification_stream.clone(); + let block_signing_notification_stream = block_signing_notification_stream.clone(); + + Box::new(move |deny_unsafe, subscription_executor| { + let deps = crate::rpc::FullDeps { + client: client.clone(), + pool: transaction_pool.clone(), + deny_unsafe, + subscription_executor, + new_slot_notification_stream: new_slot_notification_stream.clone(), + block_signing_notification_stream: block_signing_notification_stream.clone(), + archived_segment_notification_stream: archived_segment_notification_stream + .clone(), + }; + + Ok(crate::rpc::create_full(deps)) + }) + } else { + Box::new(|_, _| Ok(Default::default())) + }, backend: backend.clone(), system_rpc_tx, config, diff --git a/cumulus/client/cirrus-service/src/lib.rs b/cumulus/client/cirrus-service/src/lib.rs index eb2ae186f1bee..f768e57f3f486 100644 --- a/cumulus/client/cirrus-service/src/lib.rs +++ b/cumulus/client/cirrus-service/src/lib.rs @@ -250,7 +250,7 @@ pub async fn build_subspace_full_node( Err(sc_service::Error::Other("Light client not supported.".into())) } else { let collator_key = CollatorPair::generate().0; - let primary_chain_full_node = subspace_service::new_full(config) + let primary_chain_full_node = subspace_service::new_full(config, false) .await .map_err(|_| sc_service::Error::Other("Failed to build a full subspace node".into()))?; Ok(PrimaryFullNode { primary_chain_full_node, collator_key }) From 1f889eeb4a9abff31af391b92f0dc6ab1fd3f2ef Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Thu, 17 Feb 2022 16:35:45 +0200 Subject: [PATCH 4/7] Remove unnecessary keystore override --- crates/subspace-service/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/subspace-service/src/lib.rs b/crates/subspace-service/src/lib.rs index 3517de63b1e40..de23ab796ac46 100644 --- a/crates/subspace-service/src/lib.rs +++ b/crates/subspace-service/src/lib.rs @@ -619,8 +619,6 @@ pub fn new_chain_ops( ), Error, > { - config.keystore = sc_service::config::KeystoreConfig::InMemory; - let sc_service::PartialComponents { client, backend, From 6222b42bb72fc02d6a6bbaee55687120c99cf37a Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Thu, 17 Feb 2022 18:11:58 +0200 Subject: [PATCH 5/7] Remove unnecessary abstractions, move some logic from `subspace-service` back into `subspace-node` --- Cargo.lock | 9 ++- crates/cirrus-node-primitives/src/lib.rs | 2 - crates/subspace-node/Cargo.toml | 13 +++- .../src/chain_spec.rs | 0 crates/subspace-node/src/command.rs | 75 +++++++++++++++---- crates/subspace-node/src/lib.rs | 1 + crates/subspace-runtime/src/lib.rs | 2 +- crates/subspace-service/Cargo.toml | 4 - crates/subspace-service/src/lib.rs | 49 ------------ crates/subspace-service/src/rpc.rs | 3 +- cumulus/client/cirrus-executor/src/lib.rs | 5 +- cumulus/client/cirrus-service/src/lib.rs | 50 ++----------- .../client/consensus/relay-chain/src/lib.rs | 43 ----------- cumulus/parachain-template/node/Cargo.toml | 2 +- .../parachain-template/node/src/service.rs | 61 ++++++++------- 15 files changed, 122 insertions(+), 197 deletions(-) rename crates/{subspace-service => subspace-node}/src/chain_spec.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index ea6a9455a8473..1fd812f082079 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5148,7 +5148,6 @@ dependencies = [ "sc-client-api", "sc-consensus", "sc-executor", - "sc-keystore", "sc-network", "sc-rpc", "sc-rpc-api", @@ -5171,6 +5170,7 @@ dependencies = [ "sp-timestamp", "sp-transaction-pool", "subspace-node", + "subspace-runtime", "subspace-service", "substrate-build-script-utils", "substrate-frame-rpc-system", @@ -8629,10 +8629,16 @@ version = "0.1.0" dependencies = [ "clap 3.0.13", "frame-benchmarking-cli", + "frame-support", "futures 0.3.19", "sc-cli", + "sc-executor", "sc-service", + "sc-telemetry", "sp-core", + "sp-runtime", + "subspace-runtime", + "subspace-runtime-primitives", "subspace-service", "substrate-build-script-utils", "thiserror", @@ -8751,7 +8757,6 @@ dependencies = [ "sp-timestamp", "sp-transaction-pool", "sp-trie", - "subspace-runtime", "subspace-runtime-primitives", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", diff --git a/crates/cirrus-node-primitives/src/lib.rs b/crates/cirrus-node-primitives/src/lib.rs index 455f8b2f155c7..629e0d07f7924 100644 --- a/crates/cirrus-node-primitives/src/lib.rs +++ b/crates/cirrus-node-primitives/src/lib.rs @@ -152,8 +152,6 @@ pub type CollatorSignature = collator_app::Signature; /// Configuration for the collation generator pub struct CollationGenerationConfig { - /// Collator's authentication key, so it can sign things. - pub key: CollatorPair, /// Transaction bundle function. See [`BundlerFn`] for more details. pub bundler: BundlerFn, /// State processor function. See [`ProcessorFn`] for more details. diff --git a/crates/subspace-node/Cargo.toml b/crates/subspace-node/Cargo.toml index 2df343ea03c77..6c9bb0aa00423 100644 --- a/crates/subspace-node/Cargo.toml +++ b/crates/subspace-node/Cargo.toml @@ -21,10 +21,16 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] clap = { version = "3.0.13", features = ["derive"] } frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } +frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } futures = "0.3.19" sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927", features = ["wasmtime"] } +sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927", features = ["wasmtime"] } sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927", features = ["wasmtime"] } +sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } sp-core = { version = "5.0.0", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } +sp-runtime = { version = "5.0.0", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } +subspace-runtime = { version = "0.1.0", path = "../subspace-runtime" } +subspace-runtime-primitives = { version = "0.1.0", path = "../subspace-runtime-primitives" } subspace-service = { version = "0.1.0", path = "../subspace-service" } thiserror = "1.0.30" @@ -32,8 +38,11 @@ thiserror = "1.0.30" substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } [features] -default = [] +default = ["do-not-enforce-cost-of-storage"] +do-not-enforce-cost-of-storage = [ + "subspace-runtime/do-not-enforce-cost-of-storage" +] runtime-benchmarks = [ - "subspace-service/runtime-benchmarks", + "subspace-runtime/runtime-benchmarks", ] json-chain-spec = ["subspace-service/json-chain-spec"] diff --git a/crates/subspace-service/src/chain_spec.rs b/crates/subspace-node/src/chain_spec.rs similarity index 100% rename from crates/subspace-service/src/chain_spec.rs rename to crates/subspace-node/src/chain_spec.rs diff --git a/crates/subspace-node/src/command.rs b/crates/subspace-node/src/command.rs index 26bb82c5723d7..64c3349c9ae53 100644 --- a/crates/subspace-node/src/command.rs +++ b/crates/subspace-node/src/command.rs @@ -14,11 +14,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use crate::chain_spec; use crate::cli::{Cli, Subcommand}; use futures::future::TryFutureExt; use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli}; +use sc_executor::NativeExecutionDispatch; use sp_core::crypto::Ss58AddressFormat; -use subspace_service::{chain_spec, subspace_runtime, SubspaceExecutorDispatch}; +use subspace_runtime::RuntimeApi; /// Subspace node error. #[derive(thiserror::Error, Debug)] @@ -46,6 +48,25 @@ impl From for Error { } } +struct ExecutorDispatch; + +impl NativeExecutionDispatch for ExecutorDispatch { + /// Only enable the benchmarking host functions when we actually want to benchmark. + #[cfg(feature = "runtime-benchmarks")] + type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; + /// Otherwise we only use the default Substrate host functions. + #[cfg(not(feature = "runtime-benchmarks"))] + type ExtendHostFunctions = (); + + fn dispatch(method: &str, data: &[u8]) -> Option> { + subspace_runtime::api::dispatch(method, data) + } + + fn native_version() -> sc_executor::NativeVersion { + subspace_runtime::native_version() + } +} + impl SubstrateCli for Cli { fn impl_name() -> String { "Subspace".into() @@ -120,9 +141,13 @@ pub fn run() -> std::result::Result<(), Error> { Some(Subcommand::CheckBlock(cmd)) => { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.async_run(|mut config| { - let (client, _, import_queue, task_manager) = - subspace_service::new_chain_ops(&mut config)?; + runner.async_run(|config| { + let sc_service::PartialComponents { + client, + import_queue, + task_manager, + .. + } = subspace_service::new_partial::(&config)?; Ok(( cmd.run(client, import_queue).map_err(Error::SubstrateCli), task_manager, @@ -132,8 +157,12 @@ pub fn run() -> std::result::Result<(), Error> { Some(Subcommand::ExportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.async_run(|mut config| { - let (client, _, _, task_manager) = subspace_service::new_chain_ops(&mut config)?; + runner.async_run(|config| { + let sc_service::PartialComponents { + client, + task_manager, + .. + } = subspace_service::new_partial::(&config)?; Ok(( cmd.run(client, config.database) .map_err(Error::SubstrateCli), @@ -144,8 +173,12 @@ pub fn run() -> std::result::Result<(), Error> { Some(Subcommand::ExportState(cmd)) => { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.async_run(|mut config| { - let (client, _, _, task_manager) = subspace_service::new_chain_ops(&mut config)?; + runner.async_run(|config| { + let sc_service::PartialComponents { + client, + task_manager, + .. + } = subspace_service::new_partial::(&config)?; Ok(( cmd.run(client, config.chain_spec) .map_err(Error::SubstrateCli), @@ -156,9 +189,13 @@ pub fn run() -> std::result::Result<(), Error> { Some(Subcommand::ImportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.async_run(|mut config| { - let (client, _, import_queue, task_manager) = - subspace_service::new_chain_ops(&mut config)?; + runner.async_run(|config| { + let sc_service::PartialComponents { + client, + import_queue, + task_manager, + .. + } = subspace_service::new_partial::(&config)?; Ok(( cmd.run(client, import_queue).map_err(Error::SubstrateCli), task_manager, @@ -172,9 +209,13 @@ pub fn run() -> std::result::Result<(), Error> { Some(Subcommand::Revert(cmd)) => { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); - runner.async_run(|mut config| { - let (client, backend, _, task_manager) = - subspace_service::new_chain_ops(&mut config)?; + runner.async_run(|config| { + let sc_service::PartialComponents { + client, + backend, + task_manager, + .. + } = subspace_service::new_partial::(&config)?; Ok(( cmd.run(client, backend).map_err(Error::SubstrateCli), task_manager, @@ -186,7 +227,7 @@ pub fn run() -> std::result::Result<(), Error> { let runner = cli.create_runner(cmd)?; set_default_ss58_version(&runner.config().chain_spec); runner.sync_run(|config| { - cmd.run::(config) + cmd.run::(config) })?; } else { return Err(Error::Other( @@ -200,7 +241,9 @@ pub fn run() -> std::result::Result<(), Error> { let runner = cli.create_runner(&cli.run.base)?; set_default_ss58_version(&runner.config().chain_spec); runner.run_node_until_exit(|config| async move { - subspace_service::new_full::(config, true) + subspace_service::new_full::( + config, true, + ) .await .map(|full| full.task_manager) })?; diff --git a/crates/subspace-node/src/lib.rs b/crates/subspace-node/src/lib.rs index 4959d68acc7f8..9d3a218ffff90 100644 --- a/crates/subspace-node/src/lib.rs +++ b/crates/subspace-node/src/lib.rs @@ -18,6 +18,7 @@ #![warn(missing_docs)] +mod chain_spec; pub mod cli; mod command; diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index 79cc3e26fb097..c8193d7453556 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -56,7 +56,7 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use subspace_core_primitives::objects::{BlockObject, BlockObjectMapping}; use subspace_core_primitives::{Randomness, RootBlock, Sha256Hash, PIECE_SIZE}; -pub use subspace_runtime_primitives::{ +use subspace_runtime_primitives::{ opaque, AccountId, Balance, BlockNumber, Hash, Index, Moment, Signature, CONFIRMATION_DEPTH_K, MIN_REPLICATION_FACTOR, RECORDED_HISTORY_SEGMENT_SIZE, RECORD_SIZE, STORAGE_FEES_ESCROW_BLOCK_REWARD, STORAGE_FEES_ESCROW_BLOCK_TAX, diff --git a/crates/subspace-service/Cargo.toml b/crates/subspace-service/Cargo.toml index e80b60d40ebee..dcfbefed495de 100644 --- a/crates/subspace-service/Cargo.toml +++ b/crates/subspace-service/Cargo.toml @@ -55,7 +55,6 @@ sp-runtime = { version = "5.0.0", git = "https://github.com/paritytech/substrate sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } sp-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } sp-trie = { version = "5.0.0", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } -subspace-runtime = { version = "0.1.0", features = ["do-not-enforce-cost-of-storage"], path = "../subspace-runtime" } subspace-runtime-primitives = { version = "0.1.0", path = "../subspace-runtime-primitives" } substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } @@ -67,9 +66,6 @@ pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", git = "htt [features] default = [] -runtime-benchmarks = [ - "subspace-runtime/runtime-benchmarks", -] # This feature makes `testnet` chain spec to use `chain-spec.json` file in the root of the repo instead of compiled # version json-chain-spec = [] diff --git a/crates/subspace-service/src/lib.rs b/crates/subspace-service/src/lib.rs index de23ab796ac46..e98a50945e807 100644 --- a/crates/subspace-service/src/lib.rs +++ b/crates/subspace-service/src/lib.rs @@ -16,7 +16,6 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. -pub mod chain_spec; pub mod rpc; use lru::LruCache; @@ -41,7 +40,6 @@ use sp_blockchain::HeaderBackend; use sp_consensus::SelectChain; use sp_runtime::traits::{BlakeTwo256, Block as BlockT, Header as HeaderT}; use std::sync::Arc; -pub use subspace_runtime; use subspace_runtime_primitives::{ opaque::{Block, BlockId}, AccountId, Balance, Index as Nonce, @@ -116,33 +114,10 @@ pub enum Error { Prometheus(#[from] substrate_prometheus_endpoint::PrometheusError), } -/// Subspace native executor instance. -pub struct SubspaceExecutorDispatch; - -impl sc_executor::NativeExecutionDispatch for SubspaceExecutorDispatch { - /// Only enable the benchmarking host functions when we actually want to benchmark. - #[cfg(feature = "runtime-benchmarks")] - type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; - /// Otherwise we only use the default Substrate host functions. - #[cfg(not(feature = "runtime-benchmarks"))] - type ExtendHostFunctions = (); - - fn dispatch(method: &str, data: &[u8]) -> Option> { - subspace_runtime::api::dispatch(method, data) - } - - fn native_version() -> sc_executor::NativeVersion { - subspace_runtime::native_version() - } -} - /// Subspace-like full client. pub type FullClient = sc_service::TFullClient>; -/// Full client using subspace-runtime. -pub type SubspaceClient = FullClient; - type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; @@ -605,27 +580,3 @@ where block_signing_notification_stream, }) } - -/// Builds a new object suitable for chain operations. -#[allow(clippy::type_complexity)] -pub fn new_chain_ops( - mut config: &mut Configuration, -) -> Result< - ( - Arc>, - Arc, - sc_consensus::BasicQueue>, - TaskManager, - ), - Error, -> { - let sc_service::PartialComponents { - client, - backend, - import_queue, - task_manager, - .. - } = new_partial::(config)?; - - Ok((client, backend, import_queue, task_manager)) -} diff --git a/crates/subspace-service/src/rpc.rs b/crates/subspace-service/src/rpc.rs index 16e025b50f066..f3be821dfc47f 100644 --- a/crates/subspace-service/src/rpc.rs +++ b/crates/subspace-service/src/rpc.rs @@ -31,7 +31,8 @@ use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use std::sync::Arc; -use subspace_runtime::{opaque::Block, AccountId, Balance, Index}; +use subspace_runtime_primitives::opaque::Block; +use subspace_runtime_primitives::{AccountId, Balance, Index}; /// Full client dependencies. pub struct FullDeps { diff --git a/cumulus/client/cirrus-executor/src/lib.rs b/cumulus/client/cirrus-executor/src/lib.rs index d49b713bd7d91..0656dd33099e9 100644 --- a/cumulus/client/cirrus-executor/src/lib.rs +++ b/cumulus/client/cirrus-executor/src/lib.rs @@ -42,7 +42,7 @@ use polkadot_overseer::Handle as OverseerHandle; use cirrus_client_executor_gossip::{Action, GossipMessageHandler}; use cirrus_node_primitives::{ - BundleResult, CollationGenerationConfig, CollatorPair, ExecutorSlotInfo, ProcessorResult, + BundleResult, CollationGenerationConfig, ExecutorSlotInfo, ProcessorResult, }; use cirrus_primitives::{AccountId, Hash, SecondaryApi}; use sp_executor::{ @@ -528,7 +528,6 @@ pub struct StartExecutorParams>) + Send + Sync>, pub overseer_handle: OverseerHandle, pub spawner: Spawner, - pub key: CollatorPair, pub parachain_consensus: Box>, pub transaction_pool: Arc, pub bundle_sender: TracingUnboundedSender>, @@ -545,7 +544,6 @@ pub async fn start_executor { - /// The relay chain full node handles. - pub primary_chain_full_node: subspace_service::NewFull, - /// The collator key used by the node. - pub collator_key: CollatorPair, -} - -impl Deref for PrimaryFullNode { - type Target = subspace_service::NewFull; - - fn deref(&self) -> &Self::Target { - &self.primary_chain_full_node - } -} - /// Parameters given to [`start_executor`]. pub struct StartExecutorParams<'a, Block: BlockT, Client, Spawner, RClient, IQ, TP, Backend, CIDP> { pub client: Arc, pub announce_block: Arc>) + Send + Sync>, pub spawner: Spawner, - pub primary_chain_full_node: PrimaryFullNode, + pub primary_chain_full_node: subspace_service::NewFull, pub task_manager: &'a mut TaskManager, pub parachain_consensus: Box>, pub import_queue: IQ, @@ -153,7 +135,6 @@ where announce_block, overseer_handle, spawner, - key: primary_chain_full_node.collator_key.clone(), parachain_consensus, transaction_pool, bundle_sender, @@ -176,7 +157,7 @@ where .spawn_essential_handle() .spawn_blocking("cirrus-gossip", None, executor_gossip); - task_manager.add_child(primary_chain_full_node.primary_chain_full_node.task_manager); + task_manager.add_child(primary_chain_full_node.task_manager); Ok(()) } @@ -184,7 +165,7 @@ where /// Parameters given to [`start_full_node`]. pub struct StartFullNodeParams<'a, Block: BlockT, Client, PClient> { pub client: Arc, - pub primary_chain_full_node: PrimaryFullNode, + pub primary_chain_full_node: subspace_service::NewFull, pub task_manager: &'a mut TaskManager, pub announce_block: Arc>) + Send + Sync>, } @@ -225,7 +206,7 @@ where .spawn_essential_handle() .spawn("cumulus-consensus", None, consensus); - task_manager.add_child(primary_chain_full_node.primary_chain_full_node.task_manager); + task_manager.add_child(primary_chain_full_node.task_manager); Ok(()) } @@ -240,23 +221,6 @@ pub fn prepare_node_config(mut parachain_config: Configuration) -> Configuration parachain_config } -/// Build the Subspace full node using the given `config`. -#[sc_tracing::logging::prefix_logs_with("Primarychain")] -pub async fn build_subspace_full_node( - config: Configuration, -) -> Result>, sc_service::Error> { - let is_light = matches!(config.role, Role::Light); - if is_light { - Err(sc_service::Error::Other("Light client not supported.".into())) - } else { - let collator_key = CollatorPair::generate().0; - let primary_chain_full_node = subspace_service::new_full(config, false) - .await - .map_err(|_| sc_service::Error::Other("Failed to build a full subspace node".into()))?; - Ok(PrimaryFullNode { primary_chain_full_node, collator_key }) - } -} - /// A shared import queue /// /// This is basically a hack until the Substrate side is implemented properly. diff --git a/cumulus/client/consensus/relay-chain/src/lib.rs b/cumulus/client/consensus/relay-chain/src/lib.rs index f3ad301f6574c..52fabb451e2cf 100644 --- a/cumulus/client/consensus/relay-chain/src/lib.rs +++ b/cumulus/client/consensus/relay-chain/src/lib.rs @@ -233,46 +233,3 @@ where self.relay_chain_client.block_number_from_id(id) } } - -/// Paramaters of [`build_primary_chain_consensus`]. -pub struct BuildPrimaryChainConsensusParams { - pub proposer_factory: PF, - pub create_inherent_data_providers: CIDP, - pub block_import: BI, - pub relay_chain_client: Arc, - pub relay_chain_backend: Arc, -} - -/// Build the [`PrimaryChainConsensus`]. -/// -/// Returns a boxed [`ParachainConsensus`]. -pub fn build_primary_chain_consensus( - BuildPrimaryChainConsensusParams { - proposer_factory, - create_inherent_data_providers, - block_import, - relay_chain_client, - relay_chain_backend, - }: BuildPrimaryChainConsensusParams, -) -> Box> -where - Block: BlockT, - PF: Environment + Send + Sync + 'static, - PF::Proposer: Proposer< - Block, - Transaction = BI::Transaction, - ProofRecording = EnableProofRecording, - Proof = ::Proof, - >, - BI: BlockImport + Send + Sync + 'static, - RBackend: Backend + 'static, - CIDP: CreateInherentDataProviders + 'static, -{ - Box::new(PrimaryChainConsensus::new( - proposer_factory, - create_inherent_data_providers, - block_import, - relay_chain_client, - relay_chain_backend, - )) -} diff --git a/cumulus/parachain-template/node/Cargo.toml b/cumulus/parachain-template/node/Cargo.toml index 20404953daa81..df84a6436bc1f 100644 --- a/cumulus/parachain-template/node/Cargo.toml +++ b/cumulus/parachain-template/node/Cargo.toml @@ -52,7 +52,6 @@ sc-client-api = { git = "https://github.com/paritytech/substrate", rev = "e6def6 sc-consensus = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } sc-executor = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } sc-network = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } -sc-keystore = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } sc-rpc = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } sc-rpc-api = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } sc-service = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927", features = ["wasmtime"] } @@ -86,4 +85,5 @@ cirrus-primitives = { path = "../../primitives" } # Subspace dependencies subspace-node = { path = "../../../crates/subspace-node" } +subspace-runtime = { path = "../../../crates/subspace-runtime" } subspace-service = { path = "../../../crates/subspace-service" } diff --git a/cumulus/parachain-template/node/src/service.rs b/cumulus/parachain-template/node/src/service.rs index 9a388aabaa18d..de89f32d7c485 100644 --- a/cumulus/parachain-template/node/src/service.rs +++ b/cumulus/parachain-template/node/src/service.rs @@ -5,31 +5,26 @@ use std::sync::Arc; // Local Runtime Types use parachain_template_runtime::{ - opaque::Block, AccountId, Balance, Hash, Index as Nonce, RuntimeApi, + opaque::Block, AccountId, Balance, Index as Nonce, RuntimeApi, }; // Cumulus Imports use cirrus_client_service::prepare_node_config; use cumulus_client_consensus_common::ParachainConsensus; +use cumulus_client_consensus_relay_chain::PrimaryChainConsensus; // Substrate Imports -use sc_executor::NativeElseWasmExecutor; -use sc_network::NetworkService; +use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch}; use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; use sp_api::ConstructRuntimeApi; -use sp_keystore::SyncCryptoStorePtr; use sp_runtime::traits::BlakeTwo256; use substrate_prometheus_endpoint::Registry; -use cumulus_client_consensus_relay_chain::{ - build_primary_chain_consensus, BuildPrimaryChainConsensusParams, -}; - /// Native executor instance. pub struct TemplateRuntimeExecutor; -impl sc_executor::NativeExecutionDispatch for TemplateRuntimeExecutor { +impl NativeExecutionDispatch for TemplateRuntimeExecutor { type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; fn dispatch(method: &str, data: &[u8]) -> Option> { @@ -41,6 +36,20 @@ impl sc_executor::NativeExecutionDispatch for TemplateRuntimeExecutor { } } +struct SubspaceExecutorDispatch; + +impl NativeExecutionDispatch for SubspaceExecutorDispatch { + type ExtendHostFunctions = (); + + fn dispatch(method: &str, data: &[u8]) -> Option> { + subspace_runtime::api::dispatch(method, data) + } + + fn native_version() -> sc_executor::NativeVersion { + subspace_runtime::native_version() + } +} + /// Starts a `ServiceBuilder` for a full service. /// /// Use this macro if you don't actually need the full service, but just the builder in order to @@ -210,16 +219,13 @@ where Option<&Registry>, Option, &TaskManager, - &subspace_service::NewFull>, + &subspace_service::NewFull>>, Arc< sc_transaction_pool::FullPool< Block, TFullClient>, >, >, - Arc>, - SyncCryptoStorePtr, - bool, ) -> Result>, sc_service::Error>, { if matches!(parachain_config.role, Role::Light) { @@ -237,13 +243,16 @@ where let (mut telemetry, _telemetry_worker_handle) = params.other; - let relay_chain_full_node = - cirrus_client_service::build_subspace_full_node(polkadot_config).await?; + // TODO: Add PrimaryChain prefix to logs, was previously done with + // `#[sc_tracing::logging::prefix_logs_with("Primarychain")]` + let primary_chain_full_node = + subspace_service::new_full(polkadot_config, false) + .await + .map_err(|_| sc_service::Error::Other("Failed to build a full subspace node".into()))?; let client = params.client.clone(); let backend = params.backend.clone(); - let force_authoring = parachain_config.force_authoring; let validator = parachain_config.role.is_authority(); let prometheus_registry = parachain_config.prometheus_registry().cloned(); let transaction_pool = params.transaction_pool.clone(); @@ -302,11 +311,8 @@ where prometheus_registry.as_ref(), telemetry.as_ref().map(|t| t.handle()), &task_manager, - &relay_chain_full_node, + &primary_chain_full_node, transaction_pool.clone(), - network.clone(), - params.keystore_container.sync_keystore(), - force_authoring, )?; let spawner = task_manager.spawn_handle(); @@ -315,7 +321,7 @@ where announce_block, client: client.clone(), task_manager: &mut task_manager, - primary_chain_full_node: relay_chain_full_node, + primary_chain_full_node, spawner, parachain_consensus, import_queue, @@ -383,10 +389,7 @@ pub async fn start_parachain_node( telemetry, task_manager, relay_chain_node, - transaction_pool, - _sync_oracle, - _keystore, - _force_authoring| { + transaction_pool| { let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), @@ -398,16 +401,16 @@ pub async fn start_parachain_node( let relay_chain_backend = relay_chain_node.backend.clone(); let relay_chain_client = relay_chain_node.client.clone(); - Ok(build_primary_chain_consensus(BuildPrimaryChainConsensusParams { + Ok(Box::new(PrimaryChainConsensus::new( proposer_factory, - create_inherent_data_providers: move |_, (_relay_parent, _validation_data)| async move { + move |_, (_relay_parent, _validation_data)| async move { let time = sp_timestamp::InherentDataProvider::from_system_time(); Ok(time) }, - block_import: client, + client, relay_chain_client, relay_chain_backend, - })) + ))) }, ) .await From b0f1011bb66983f4c5bfa805ab387c982bf0c440 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Thu, 17 Feb 2022 18:30:10 +0200 Subject: [PATCH 6/7] Remove more unnecessary abstractions --- Cargo.lock | 2 - cumulus/parachain-template/node/Cargo.toml | 2 - .../parachain-template/node/src/service.rs | 82 ++++++------------- 3 files changed, 27 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1fd812f082079..606b16057677f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5132,7 +5132,6 @@ dependencies = [ "cirrus-primitives", "clap 3.0.13", "cumulus-client-cli", - "cumulus-client-consensus-common", "cumulus-client-consensus-relay-chain", "frame-benchmarking", "frame-benchmarking-cli", @@ -5174,7 +5173,6 @@ dependencies = [ "subspace-service", "substrate-build-script-utils", "substrate-frame-rpc-system", - "substrate-prometheus-endpoint", ] [[package]] diff --git a/cumulus/parachain-template/node/Cargo.toml b/cumulus/parachain-template/node/Cargo.toml index df84a6436bc1f..05fc0a84e59dc 100644 --- a/cumulus/parachain-template/node/Cargo.toml +++ b/cumulus/parachain-template/node/Cargo.toml @@ -42,7 +42,6 @@ frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", rev pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } -substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } ## Substrate Client Dependencies sc-basic-authorship = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" } @@ -76,7 +75,6 @@ sp-transaction-pool = { git = "https://github.com/paritytech/substrate", rev = " # Cumulus dependencies cumulus-client-cli = { path = "../../client/cli" } -cumulus-client-consensus-common = { path = "../../client/consensus/common" } cumulus-client-consensus-relay-chain = { path = "../../client/consensus/relay-chain" } cirrus-client-executor = { path = "../../client/cirrus-executor" } cirrus-client-executor-gossip = { path = "../../client/executor-gossip" } diff --git a/cumulus/parachain-template/node/src/service.rs b/cumulus/parachain-template/node/src/service.rs index de89f32d7c485..ed8cfe2efaf53 100644 --- a/cumulus/parachain-template/node/src/service.rs +++ b/cumulus/parachain-template/node/src/service.rs @@ -2,6 +2,7 @@ // std use std::sync::Arc; +use sc_basic_authorship::ProposerFactory; // Local Runtime Types use parachain_template_runtime::{ @@ -10,7 +11,6 @@ use parachain_template_runtime::{ // Cumulus Imports use cirrus_client_service::prepare_node_config; -use cumulus_client_consensus_common::ParachainConsensus; use cumulus_client_consensus_relay_chain::PrimaryChainConsensus; // Substrate Imports @@ -19,7 +19,6 @@ use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClie use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; use sp_api::ConstructRuntimeApi; use sp_runtime::traits::BlakeTwo256; -use substrate_prometheus_endpoint::Registry; /// Native executor instance. pub struct TemplateRuntimeExecutor; @@ -169,12 +168,11 @@ where /// /// This is the actual implementation that is abstract over the executor and the runtime api. #[sc_tracing::logging::prefix_logs_with("Secondarychain")] -async fn start_node_impl( +async fn start_node_impl( parachain_config: Configuration, polkadot_config: Configuration, _rpc_ext_builder: RB, build_import_queue: BIQ, - build_consensus: BIC, ) -> sc_service::error::Result<( TaskManager, Arc>>, @@ -214,19 +212,6 @@ where >, sc_service::Error, > + 'static, - BIC: FnOnce( - Arc>>, - Option<&Registry>, - Option, - &TaskManager, - &subspace_service::NewFull>>, - Arc< - sc_transaction_pool::FullPool< - Block, - TFullClient>, - >, - >, - ) -> Result>, sc_service::Error>, { if matches!(parachain_config.role, Role::Light) { return Err("Light client not supported!".into()) @@ -246,7 +231,10 @@ where // TODO: Add PrimaryChain prefix to logs, was previously done with // `#[sc_tracing::logging::prefix_logs_with("Primarychain")]` let primary_chain_full_node = - subspace_service::new_full(polkadot_config, false) + subspace_service::new_full::( + polkadot_config, + false, + ) .await .map_err(|_| sc_service::Error::Other("Failed to build a full subspace node".into()))?; @@ -306,14 +294,26 @@ where // Basically, all the executor nodes run all the components, the // difference is that only the authority node will try to win the // election for producing bundle and execution receipt. - let parachain_consensus = build_consensus( - client.clone(), - prometheus_registry.as_ref(), - telemetry.as_ref().map(|t| t.handle()), - &task_manager, - &primary_chain_full_node, - transaction_pool.clone(), - )?; + let parachain_consensus = { + let proposer_factory = ProposerFactory::with_proof_recording( + task_manager.spawn_handle(), + client.clone(), + transaction_pool.clone(), + prometheus_registry.as_ref(), + telemetry.as_ref().map(|t| t.handle()), + ); + + Box::new(PrimaryChainConsensus::new( + proposer_factory, + move |_, (_relay_parent, _validation_data)| async move { + let time = sp_timestamp::InherentDataProvider::from_system_time(); + Ok(time) + }, + client.clone(), + primary_chain_full_node.client.clone(), + primary_chain_full_node.backend.clone(), + )) + }; let spawner = task_manager.spawn_handle(); @@ -379,39 +379,11 @@ pub async fn start_parachain_node( TaskManager, Arc>>, )> { - start_node_impl::( + start_node_impl::( parachain_config, polkadot_config, |_| Ok(Default::default()), parachain_build_import_queue, - |client, - prometheus_registry, - telemetry, - task_manager, - relay_chain_node, - transaction_pool| { - let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( - task_manager.spawn_handle(), - client.clone(), - transaction_pool, - prometheus_registry, - telemetry, - ); - - let relay_chain_backend = relay_chain_node.backend.clone(); - let relay_chain_client = relay_chain_node.client.clone(); - - Ok(Box::new(PrimaryChainConsensus::new( - proposer_factory, - move |_, (_relay_parent, _validation_data)| async move { - let time = sp_timestamp::InherentDataProvider::from_system_time(); - Ok(time) - }, - client, - relay_chain_client, - relay_chain_backend, - ))) - }, ) .await } From 02a3da37c071236e02261ea928d3b058eede2764 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Thu, 17 Feb 2022 22:14:22 +0200 Subject: [PATCH 7/7] Restore primary chain tracing prefix --- cumulus/parachain-template/node/src/service.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cumulus/parachain-template/node/src/service.rs b/cumulus/parachain-template/node/src/service.rs index ed8cfe2efaf53..df4ccdfc14f63 100644 --- a/cumulus/parachain-template/node/src/service.rs +++ b/cumulus/parachain-template/node/src/service.rs @@ -17,6 +17,7 @@ use cumulus_client_consensus_relay_chain::PrimaryChainConsensus; use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch}; use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; +use sc_tracing::tracing; use sp_api::ConstructRuntimeApi; use sp_runtime::traits::BlakeTwo256; @@ -228,15 +229,20 @@ where let (mut telemetry, _telemetry_worker_handle) = params.other; - // TODO: Add PrimaryChain prefix to logs, was previously done with - // `#[sc_tracing::logging::prefix_logs_with("Primarychain")]` - let primary_chain_full_node = + let primary_chain_full_node = { + let span = tracing::info_span!( + sc_tracing::logging::PREFIX_LOG_SPAN, + name = "Primarychain" + ); + let _enter = span.enter(); + subspace_service::new_full::( polkadot_config, false, ) .await - .map_err(|_| sc_service::Error::Other("Failed to build a full subspace node".into()))?; + .map_err(|_| sc_service::Error::Other("Failed to build a full subspace node".into()))? + }; let client = params.client.clone(); let backend = params.backend.clone();