From 144e1e2c4c264cf50be6290a966639c9d1442db0 Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Fri, 15 Apr 2022 10:35:20 +0800 Subject: [PATCH 1/7] Remove subspace-node dep from cirrus-node `RelayChainCli` will be evolved into `SecondaryChainCli` later. --- Cargo.lock | 1 - crates/subspace-node/src/relay_chain_cli.rs | 210 ++++++++++++++++++++ cumulus/node/Cargo.toml | 2 - cumulus/node/src/bin/subspace-executor.rs | 158 --------------- cumulus/node/src/chain_spec.rs | 7 - cumulus/node/src/cli.rs | 205 +------------------ 6 files changed, 211 insertions(+), 372 deletions(-) create mode 100644 crates/subspace-node/src/relay_chain_cli.rs delete mode 100644 cumulus/node/src/bin/subspace-executor.rs diff --git a/Cargo.lock b/Cargo.lock index 5bc1b9ccc5..8c8e0dc7a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -971,7 +971,6 @@ dependencies = [ "sp-runtime", "sp-session", "sp-transaction-pool", - "subspace-node", "subspace-runtime", "subspace-runtime-primitives", "subspace-service", diff --git a/crates/subspace-node/src/relay_chain_cli.rs b/crates/subspace-node/src/relay_chain_cli.rs new file mode 100644 index 0000000000..eb57da85b3 --- /dev/null +++ b/crates/subspace-node/src/relay_chain_cli.rs @@ -0,0 +1,210 @@ +#[derive(Debug)] +pub struct RelayChainCli { + /// The actual relay chain cli object. + pub base: subspace_node::RunCmd, + + /// Optional chain id that should be passed to the relay chain. + pub chain_id: Option, + + /// The base path that should be used by the relay chain. + pub base_path: Option, +} + +impl RelayChainCli { + /// Parse the relay chain CLI parameters using the para chain `Configuration`. + pub fn new<'a>( + para_config: &sc_service::Configuration, + relay_chain_args: impl Iterator, + ) -> Self { + let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec); + let chain_id = extension.map(|e| e.relay_chain.clone()); + let base_path = para_config + .base_path + .as_ref() + .map(|x| x.path().join("polkadot")); + // TODO: we might want to forcibly inject the `--validator` flag. + Self { + base_path, + chain_id, + base: subspace_node::RunCmd::parse_from(relay_chain_args), + } + } +} + +impl SubstrateCli for RelayChainCli { + fn impl_name() -> String { + "Parachain Collator Template".into() + } + + fn impl_version() -> String { + env!("SUBSTRATE_CLI_IMPL_VERSION").into() + } + + fn description() -> String { + "Parachain Collator Template\n\nThe command-line arguments provided first will be \ + passed to the parachain node, while the arguments provided after -- will be passed \ + to the relaychain node.\n\n\ + parachain-collator [parachain-args] -- [relaychain-args]" + .into() + } + + fn author() -> String { + env!("CARGO_PKG_AUTHORS").into() + } + + fn support_url() -> String { + "https://github.com/paritytech/cumulus/issues/new".into() + } + + fn copyright_start_year() -> i32 { + 2020 + } + + fn load_spec(&self, id: &str) -> std::result::Result, String> { + ::from_iter([RelayChainCli::executable_name()].iter()) + .load_spec(id) + } + + fn native_runtime_version(chain_spec: &Box) -> &'static RuntimeVersion { + subspace_node::Cli::native_runtime_version(chain_spec) + } +} + +impl DefaultConfigurationValues for RelayChainCli { + fn p2p_listen_port() -> u16 { + 30334 + } + + fn rpc_ws_listen_port() -> u16 { + 9945 + } + + fn rpc_http_listen_port() -> u16 { + 9934 + } + + fn prometheus_listen_port() -> u16 { + 9616 + } +} + +impl CliConfiguration for RelayChainCli { + fn shared_params(&self) -> &SharedParams { + self.base.base.shared_params() + } + + fn import_params(&self) -> Option<&ImportParams> { + self.base.base.import_params() + } + + fn network_params(&self) -> Option<&NetworkParams> { + self.base.base.network_params() + } + + fn keystore_params(&self) -> Option<&KeystoreParams> { + self.base.base.keystore_params() + } + + fn base_path(&self) -> Result> { + Ok(self + .shared_params() + .base_path() + .or_else(|| self.base_path.clone().map(Into::into))) + } + + fn rpc_http(&self, default_listen_port: u16) -> Result> { + self.base.base.rpc_http(default_listen_port) + } + + fn rpc_ipc(&self) -> Result> { + self.base.base.rpc_ipc() + } + + fn rpc_ws(&self, default_listen_port: u16) -> Result> { + self.base.base.rpc_ws(default_listen_port) + } + + fn prometheus_config( + &self, + default_listen_port: u16, + chain_spec: &Box, + ) -> Result> { + self.base + .base + .prometheus_config(default_listen_port, chain_spec) + } + + fn init( + &self, + _support_url: &String, + _impl_version: &String, + _logger_hook: F, + _config: &sc_service::Configuration, + ) -> Result<()> + where + F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), + { + unreachable!("PolkadotCli is never initialized; qed"); + } + + fn chain_id(&self, is_dev: bool) -> Result { + let chain_id = self.base.base.chain_id(is_dev)?; + + Ok(if chain_id.is_empty() { + self.chain_id.clone().unwrap_or_default() + } else { + chain_id + }) + } + + fn role(&self, is_dev: bool) -> Result { + self.base.base.role(is_dev) + } + + fn transaction_pool(&self) -> Result { + self.base.base.transaction_pool() + } + + fn state_cache_child_ratio(&self) -> Result> { + self.base.base.state_cache_child_ratio() + } + + fn rpc_methods(&self) -> Result { + self.base.base.rpc_methods() + } + + fn rpc_ws_max_connections(&self) -> Result> { + self.base.base.rpc_ws_max_connections() + } + + fn rpc_cors(&self, is_dev: bool) -> Result>> { + self.base.base.rpc_cors(is_dev) + } + + fn default_heap_pages(&self) -> Result> { + self.base.base.default_heap_pages() + } + + fn force_authoring(&self) -> Result { + self.base.base.force_authoring() + } + + fn disable_grandpa(&self) -> Result { + self.base.base.disable_grandpa() + } + + fn max_runtime_instances(&self) -> Result> { + self.base.base.max_runtime_instances() + } + + fn announce_block(&self) -> Result { + self.base.base.announce_block() + } + + fn telemetry_endpoints( + &self, + chain_spec: &Box, + ) -> Result> { + self.base.base.telemetry_endpoints(chain_spec) + } +} diff --git a/cumulus/node/Cargo.toml b/cumulus/node/Cargo.toml index b8d47c2c65..e87b25b2e2 100644 --- a/cumulus/node/Cargo.toml +++ b/cumulus/node/Cargo.toml @@ -70,7 +70,6 @@ cirrus-client-service = { path = "../client/cirrus-service" } cirrus-primitives = { path = "../primitives" } # Subspace dependencies -subspace-node = { path = "../../crates/subspace-node" } subspace-runtime = { path = "../../crates/subspace-runtime" } subspace-runtime-primitives = { path = "../../crates/subspace-runtime-primitives" } subspace-service = { path = "../../crates/subspace-service" } @@ -81,5 +80,4 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/substrate" [features] runtime-benchmarks = [ "cirrus-runtime/runtime-benchmarks", - "subspace-node/runtime-benchmarks", ] diff --git a/cumulus/node/src/bin/subspace-executor.rs b/cumulus/node/src/bin/subspace-executor.rs deleted file mode 100644 index d898293c82..0000000000 --- a/cumulus/node/src/bin/subspace-executor.rs +++ /dev/null @@ -1,158 +0,0 @@ -use cirrus_node::{ - cli::{Cli, RelayChainCli, Subcommand}, - service::{self, new_partial, start_parachain_node, CirrusRuntimeExecutor}, -}; -use cirrus_runtime::{Block, RuntimeApi}; -use frame_benchmarking_cli::BenchmarkCmd; -use log::info; -use sc_cli::{Result, SubstrateCli}; -use sc_service::PartialComponents; - -macro_rules! construct_async_run { - (|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{ - let runner = $cli.create_runner($cmd)?; - runner.async_run(|$config| { - let $components = new_partial::< - RuntimeApi, - CirrusRuntimeExecutor, - _ - >( - &$config, - service::parachain_build_import_queue, - )?; - let task_manager = $components.task_manager; - { $( $code )* }.map(|v| (v, task_manager)) - }) - }} -} - -/// Parse command line arguments into service configuration. -pub fn main() -> Result<()> { - let cli = Cli::from_args(); - - match &cli.subcommand { - Some(Subcommand::BuildSpec(cmd)) => { - let runner = cli.create_runner(cmd)?; - runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) - }, - Some(Subcommand::CheckBlock(cmd)) => { - construct_async_run!(|components, cli, cmd, config| { - Ok(cmd.run(components.client, components.import_queue)) - }) - }, - Some(Subcommand::ExportBlocks(cmd)) => { - construct_async_run!(|components, cli, cmd, config| { - Ok(cmd.run(components.client, config.database)) - }) - }, - Some(Subcommand::ExportState(cmd)) => { - construct_async_run!(|components, cli, cmd, config| { - Ok(cmd.run(components.client, config.chain_spec)) - }) - }, - Some(Subcommand::ImportBlocks(cmd)) => { - construct_async_run!(|components, cli, cmd, config| { - Ok(cmd.run(components.client, components.import_queue)) - }) - }, - Some(Subcommand::PurgeChain(cmd)) => { - let runner = cli.create_runner(cmd)?; - - runner.sync_run(|config| { - let polkadot_cli = RelayChainCli::new( - &config, - [RelayChainCli::executable_name()].iter().chain(cli.relaychain_args.iter()), - ); - - let polkadot_config = SubstrateCli::create_configuration( - &polkadot_cli, - &polkadot_cli, - config.tokio_handle.clone(), - ) - .map_err(|err| format!("Relay chain argument error: {}", err))?; - - cmd.run(config, polkadot_config) - }) - }, - Some(Subcommand::Revert(cmd)) => { - construct_async_run!(|components, cli, cmd, config| { - Ok(cmd.run(components.client, components.backend, None)) - }) - }, - Some(Subcommand::Benchmark(cmd)) => { - let runner = cli.create_runner(cmd)?; - - runner.sync_run(|config| { - let PartialComponents { client, backend, .. } = - service::new_partial(&config, service::parachain_build_import_queue)?; - - // This switch needs to be in the client, since the client decides - // which sub-commands it wants to support. - match cmd { - BenchmarkCmd::Pallet(cmd) => { - if !cfg!(feature = "runtime-benchmarks") { - return Err( - "Runtime benchmarking wasn't enabled when building the node. \ - You can enable it with `--features runtime-benchmarks`." - .into(), - ) - } - - cmd.run::(config) - }, - BenchmarkCmd::Block(cmd) => cmd.run(client), - BenchmarkCmd::Storage(cmd) => { - let db = backend.expose_db(); - let storage = backend.expose_storage(); - - cmd.run(config, client, db, storage) - }, - BenchmarkCmd::Overhead(_cmd) => { - todo!("Not implemented") - // let ext_builder = BenchmarkExtrinsicBuilder::new(client.clone()); - // - // cmd.run(config, client, inherent_benchmark_data()?, Arc::new(ext_builder)) - }, - } - }) - }, - None => { - let runner = cli.create_runner(&cli.run.normalize())?; - - runner.run_node_until_exit(|config| async move { - let polkadot_cli = RelayChainCli::new( - &config, - [RelayChainCli::executable_name()].iter().chain(cli.relaychain_args.iter()), - ); - - let tokio_handle = config.tokio_handle.clone(); - let polkadot_config = - SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) - .map_err(|err| format!("Relay chain argument error: {}", err))?; - - info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); - - let primary_chain_full_node = { - let span = sc_tracing::tracing::info_span!( - sc_tracing::logging::PREFIX_LOG_SPAN, - name = "Primarychain" - ); - let _enter = span.enter(); - - subspace_service::new_full::< - subspace_runtime::RuntimeApi, - subspace_node::ExecutorDispatch, - >(polkadot_config, false) - .map_err(|_| { - sc_service::Error::Other("Failed to build a full subspace node".into()) - })? - }; - - start_parachain_node(config, primary_chain_full_node) - .await - .map(|r| r.0) - .map_err(Into::into) - }) - }, - } -} diff --git a/cumulus/node/src/chain_spec.rs b/cumulus/node/src/chain_spec.rs index f5555e5de9..a392a63512 100644 --- a/cumulus/node/src/chain_spec.rs +++ b/cumulus/node/src/chain_spec.rs @@ -25,13 +25,6 @@ pub struct Extensions { pub relay_chain: String, } -impl Extensions { - /// Try to get the extension from the given `ChainSpec`. - pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { - sc_chain_spec::get_extension(chain_spec.extensions()) - } -} - type AccountPublic = ::Signer; /// Helper function to generate an account ID from seed diff --git a/cumulus/node/src/cli.rs b/cumulus/node/src/cli.rs index ec5fb9f67a..d7f4677aad 100644 --- a/cumulus/node/src/cli.rs +++ b/cumulus/node/src/cli.rs @@ -3,12 +3,7 @@ use crate::chain_spec; use clap::Parser; use sc_chain_spec::ChainSpec; -use sc_cli::{ - CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, - Result, RuntimeVersion, SharedParams, SubstrateCli, -}; -use sc_service::{config::PrometheusConfig, BasePath}; -use std::{net::SocketAddr, path::PathBuf}; +use sc_cli::{RuntimeVersion, SubstrateCli}; /// Sub-commands supported by the collator. #[derive(Debug, clap::Subcommand)] @@ -102,201 +97,3 @@ impl SubstrateCli for Cli { &cirrus_runtime::VERSION } } - -#[derive(Debug)] -pub struct RelayChainCli { - /// The actual relay chain cli object. - pub base: subspace_node::RunCmd, - - /// Optional chain id that should be passed to the relay chain. - pub chain_id: Option, - - /// The base path that should be used by the relay chain. - pub base_path: Option, -} - -impl RelayChainCli { - /// Parse the relay chain CLI parameters using the para chain `Configuration`. - pub fn new<'a>( - para_config: &sc_service::Configuration, - relay_chain_args: impl Iterator, - ) -> Self { - let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec); - let chain_id = extension.map(|e| e.relay_chain.clone()); - let base_path = para_config.base_path.as_ref().map(|x| x.path().join("polkadot")); - // TODO: we might want to forcibly inject the `--validator` flag. - Self { base_path, chain_id, base: subspace_node::RunCmd::parse_from(relay_chain_args) } - } -} - -impl SubstrateCli for RelayChainCli { - fn impl_name() -> String { - "Parachain Collator Template".into() - } - - fn impl_version() -> String { - env!("SUBSTRATE_CLI_IMPL_VERSION").into() - } - - fn description() -> String { - "Parachain Collator Template\n\nThe command-line arguments provided first will be \ - passed to the parachain node, while the arguments provided after -- will be passed \ - to the relaychain node.\n\n\ - parachain-collator [parachain-args] -- [relaychain-args]" - .into() - } - - fn author() -> String { - env!("CARGO_PKG_AUTHORS").into() - } - - fn support_url() -> String { - "https://github.com/paritytech/cumulus/issues/new".into() - } - - fn copyright_start_year() -> i32 { - 2020 - } - - fn load_spec(&self, id: &str) -> std::result::Result, String> { - ::from_iter([RelayChainCli::executable_name()].iter()) - .load_spec(id) - } - - fn native_runtime_version(chain_spec: &Box) -> &'static RuntimeVersion { - subspace_node::Cli::native_runtime_version(chain_spec) - } -} - -impl DefaultConfigurationValues for RelayChainCli { - fn p2p_listen_port() -> u16 { - 30334 - } - - fn rpc_ws_listen_port() -> u16 { - 9945 - } - - fn rpc_http_listen_port() -> u16 { - 9934 - } - - fn prometheus_listen_port() -> u16 { - 9616 - } -} - -impl CliConfiguration for RelayChainCli { - fn shared_params(&self) -> &SharedParams { - self.base.base.shared_params() - } - - fn import_params(&self) -> Option<&ImportParams> { - self.base.base.import_params() - } - - fn network_params(&self) -> Option<&NetworkParams> { - self.base.base.network_params() - } - - fn keystore_params(&self) -> Option<&KeystoreParams> { - self.base.base.keystore_params() - } - - fn base_path(&self) -> Result> { - Ok(self - .shared_params() - .base_path() - .or_else(|| self.base_path.clone().map(Into::into))) - } - - fn rpc_http(&self, default_listen_port: u16) -> Result> { - self.base.base.rpc_http(default_listen_port) - } - - fn rpc_ipc(&self) -> Result> { - self.base.base.rpc_ipc() - } - - fn rpc_ws(&self, default_listen_port: u16) -> Result> { - self.base.base.rpc_ws(default_listen_port) - } - - fn prometheus_config( - &self, - default_listen_port: u16, - chain_spec: &Box, - ) -> Result> { - self.base.base.prometheus_config(default_listen_port, chain_spec) - } - - fn init( - &self, - _support_url: &String, - _impl_version: &String, - _logger_hook: F, - _config: &sc_service::Configuration, - ) -> Result<()> - where - F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), - { - unreachable!("PolkadotCli is never initialized; qed"); - } - - fn chain_id(&self, is_dev: bool) -> Result { - let chain_id = self.base.base.chain_id(is_dev)?; - - Ok(if chain_id.is_empty() { self.chain_id.clone().unwrap_or_default() } else { chain_id }) - } - - fn role(&self, is_dev: bool) -> Result { - self.base.base.role(is_dev) - } - - fn transaction_pool(&self) -> Result { - self.base.base.transaction_pool() - } - - fn state_cache_child_ratio(&self) -> Result> { - self.base.base.state_cache_child_ratio() - } - - fn rpc_methods(&self) -> Result { - self.base.base.rpc_methods() - } - - fn rpc_ws_max_connections(&self) -> Result> { - self.base.base.rpc_ws_max_connections() - } - - fn rpc_cors(&self, is_dev: bool) -> Result>> { - self.base.base.rpc_cors(is_dev) - } - - fn default_heap_pages(&self) -> Result> { - self.base.base.default_heap_pages() - } - - fn force_authoring(&self) -> Result { - self.base.base.force_authoring() - } - - fn disable_grandpa(&self) -> Result { - self.base.base.disable_grandpa() - } - - fn max_runtime_instances(&self) -> Result> { - self.base.base.max_runtime_instances() - } - - fn announce_block(&self) -> Result { - self.base.base.announce_block() - } - - fn telemetry_endpoints( - &self, - chain_spec: &Box, - ) -> Result> { - self.base.base.telemetry_endpoints(chain_spec) - } -} From fabc013c0d0a914d644e789efef429ca7bd923e5 Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Fri, 15 Apr 2022 17:03:19 +0800 Subject: [PATCH 2/7] Executor integration skeleton --- Cargo.lock | 1 + crates/subspace-node/Cargo.toml | 1 + crates/subspace-node/src/bin/subspace-node.rs | 8 ++++++++ crates/subspace-node/src/lib.rs | 13 +++++++++++++ 4 files changed, 23 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 8c8e0dc7a0..7fc823c5ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8581,6 +8581,7 @@ dependencies = [ name = "subspace-node" version = "0.1.0" dependencies = [ + "cirrus-node", "clap 3.1.8", "frame-benchmarking-cli", "frame-support", diff --git a/crates/subspace-node/Cargo.toml b/crates/subspace-node/Cargo.toml index b3a2da48eb..9cf2062387 100644 --- a/crates/subspace-node/Cargo.toml +++ b/crates/subspace-node/Cargo.toml @@ -19,6 +19,7 @@ include = [ targets = ["x86_64-unknown-linux-gnu"] [dependencies] +cirrus-node = { version = "0.1.0", path = "../../cumulus/node" } clap = { version = "3.1.8", features = ["derive"] } frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "c4f3d028621edb293d2c423516221aa396f76a2d" } frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "c4f3d028621edb293d2c423516221aa396f76a2d" } diff --git a/crates/subspace-node/src/bin/subspace-node.rs b/crates/subspace-node/src/bin/subspace-node.rs index 179836b269..89159cbe94 100644 --- a/crates/subspace-node/src/bin/subspace-node.rs +++ b/crates/subspace-node/src/bin/subspace-node.rs @@ -73,6 +73,11 @@ fn set_default_ss58_version>(chain_spec: C) { fn main() -> std::result::Result<(), Error> { let cli = Cli::from_args(); + if !cli.secondarychain_args.is_empty() { + println!("Unimplemented: Run an executor with an embedded primary full node"); + return Ok(()); + } + match &cli.subcommand { Some(Subcommand::Key(cmd)) => cmd.run(&cli)?, Some(Subcommand::BuildSpec(cmd)) => { @@ -222,6 +227,9 @@ fn main() -> std::result::Result<(), Error> { } })?; } + Some(Subcommand::Executor(_cmd)) => { + unimplemented!("Executor subcommand"); + } None => { let runner = cli.create_runner(&cli.run.base)?; set_default_ss58_version(&runner.config().chain_spec); diff --git a/crates/subspace-node/src/lib.rs b/crates/subspace-node/src/lib.rs index 23303100e3..6d6b4197ae 100644 --- a/crates/subspace-node/src/lib.rs +++ b/crates/subspace-node/src/lib.rs @@ -79,6 +79,10 @@ pub enum Subcommand { /// Revert the chain to a previous state. Revert(sc_cli::RevertCmd), + /// Run executor sub-commands. + #[clap(subcommand)] + Executor(cirrus_node::cli::Subcommand), + /// Sub-commands concerned with benchmarking. #[clap(subcommand)] Benchmark(frame_benchmarking_cli::BenchmarkCmd), @@ -94,6 +98,11 @@ pub struct RunCmd { /// Subspace Cli. #[derive(Debug, Parser)] +#[clap( + propagate_version = true, + args_conflicts_with_subcommands = true, + subcommand_negates_reqs = true +)] pub struct Cli { /// Various utility commands. #[clap(subcommand)] @@ -102,6 +111,10 @@ pub struct Cli { /// Run a node. #[clap(flatten)] pub run: RunCmd, + + /// Secondarychain arguments + #[clap(raw = true)] + pub secondarychain_args: Vec, } impl SubstrateCli for Cli { From 4ca6075dc696f82f92cef6ba33e5a8a518f68f63 Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Fri, 15 Apr 2022 20:42:31 +0800 Subject: [PATCH 3/7] Integrate executor into subspace-node --- Cargo.lock | 2 + crates/subspace-node/Cargo.toml | 2 + crates/subspace-node/src/bin/subspace-node.rs | 38 +++++++++- crates/subspace-node/src/lib.rs | 2 + ...ay_chain_cli.rs => secondary_chain_cli.rs} | 69 +++++++------------ 5 files changed, 66 insertions(+), 47 deletions(-) rename crates/subspace-node/src/{relay_chain_cli.rs => secondary_chain_cli.rs} (72%) diff --git a/Cargo.lock b/Cargo.lock index 7fc823c5ff..60c1789d6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8583,6 +8583,7 @@ version = "0.1.0" dependencies = [ "cirrus-node", "clap 3.1.8", + "cumulus-client-cli", "frame-benchmarking-cli", "frame-support", "futures 0.3.21", @@ -8594,6 +8595,7 @@ dependencies = [ "sc-executor", "sc-service", "sc-telemetry", + "sc-tracing", "serde", "sp-consensus", "sp-core", diff --git a/crates/subspace-node/Cargo.toml b/crates/subspace-node/Cargo.toml index 9cf2062387..7901e12afc 100644 --- a/crates/subspace-node/Cargo.toml +++ b/crates/subspace-node/Cargo.toml @@ -21,6 +21,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] cirrus-node = { version = "0.1.0", path = "../../cumulus/node" } clap = { version = "3.1.8", features = ["derive"] } +cumulus-client-cli = { version = "0.1.0", path = "../../cumulus/client/cli" } frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "c4f3d028621edb293d2c423516221aa396f76a2d" } frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "c4f3d028621edb293d2c423516221aa396f76a2d" } futures = "0.3.21" @@ -32,6 +33,7 @@ sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/su sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "c4f3d028621edb293d2c423516221aa396f76a2d", features = ["wasmtime"] } sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "c4f3d028621edb293d2c423516221aa396f76a2d", features = ["wasmtime"] } sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "c4f3d028621edb293d2c423516221aa396f76a2d" } +sc-tracing = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "c4f3d028621edb293d2c423516221aa396f76a2d" } serde = "1.0.136" sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "c4f3d028621edb293d2c423516221aa396f76a2d" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", rev = "c4f3d028621edb293d2c423516221aa396f76a2d" } diff --git a/crates/subspace-node/src/bin/subspace-node.rs b/crates/subspace-node/src/bin/subspace-node.rs index 89159cbe94..1bc250c2c3 100644 --- a/crates/subspace-node/src/bin/subspace-node.rs +++ b/crates/subspace-node/src/bin/subspace-node.rs @@ -18,10 +18,10 @@ use frame_benchmarking_cli::BenchmarkCmd; use futures::future::TryFutureExt; -use sc_cli::{ChainSpec, SubstrateCli}; +use sc_cli::{ChainSpec, CliConfiguration, SubstrateCli}; use sc_service::PartialComponents; use sp_core::crypto::Ss58AddressFormat; -use subspace_node::{Cli, ExecutorDispatch, Subcommand}; +use subspace_node::{Cli, ExecutorDispatch, SecondaryChainCli, Subcommand}; use subspace_runtime::{Block, RuntimeApi}; /// Subspace node error. @@ -74,7 +74,39 @@ fn main() -> std::result::Result<(), Error> { let cli = Cli::from_args(); if !cli.secondarychain_args.is_empty() { - println!("Unimplemented: Run an executor with an embedded primary full node"); + let secondary_chain_cli = + SecondaryChainCli::new(cli.run.base.base_path()?, cli.secondarychain_args.iter()); + + let runner = SubstrateCli::create_runner(&secondary_chain_cli, &secondary_chain_cli)?; + set_default_ss58_version(&runner.config().chain_spec); + runner.run_node_until_exit(|config| async move { + let primary_chain_full_node = { + let span = sc_tracing::tracing::info_span!( + sc_tracing::logging::PREFIX_LOG_SPAN, + name = "Primarychain" + ); + let _enter = span.enter(); + + let primary_config = cli + .create_configuration(&cli.run.base, config.tokio_handle.clone()) + .map_err(|_| { + sc_service::Error::Other("Failed to create subspace configuration".into()) + })?; + + subspace_service::new_full::( + primary_config, + false, + ) + .map_err(|_| { + sc_service::Error::Other("Failed to build a full subspace node".into()) + })? + }; + + cirrus_node::service::start_parachain_node(config, primary_chain_full_node) + .await + .map(|r| r.0) + })?; + return Ok(()); } diff --git a/crates/subspace-node/src/lib.rs b/crates/subspace-node/src/lib.rs index 6d6b4197ae..7d839e363b 100644 --- a/crates/subspace-node/src/lib.rs +++ b/crates/subspace-node/src/lib.rs @@ -18,8 +18,10 @@ mod chain_spec; mod import_blocks_from_dsn; +mod secondary_chain_cli; pub use crate::import_blocks_from_dsn::ImportBlocksFromDsnCmd; +pub use crate::secondary_chain_cli::SecondaryChainCli; use clap::Parser; use sc_cli::SubstrateCli; use sc_executor::{NativeExecutionDispatch, RuntimeVersion}; diff --git a/crates/subspace-node/src/relay_chain_cli.rs b/crates/subspace-node/src/secondary_chain_cli.rs similarity index 72% rename from crates/subspace-node/src/relay_chain_cli.rs rename to crates/subspace-node/src/secondary_chain_cli.rs index eb57da85b3..7a061b3b17 100644 --- a/crates/subspace-node/src/relay_chain_cli.rs +++ b/crates/subspace-node/src/secondary_chain_cli.rs @@ -1,37 +1,35 @@ +use clap::Parser; +use sc_cli::{ + ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, + NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli, +}; +use sc_service::{config::PrometheusConfig, BasePath}; +use std::{net::SocketAddr, path::PathBuf}; + #[derive(Debug)] -pub struct RelayChainCli { +pub struct SecondaryChainCli { /// The actual relay chain cli object. - pub base: subspace_node::RunCmd, - - /// Optional chain id that should be passed to the relay chain. - pub chain_id: Option, + pub base: cumulus_client_cli::RunCmd, /// The base path that should be used by the relay chain. pub base_path: Option, } -impl RelayChainCli { +impl SecondaryChainCli { /// Parse the relay chain CLI parameters using the para chain `Configuration`. pub fn new<'a>( - para_config: &sc_service::Configuration, + primary_base_path: Option, relay_chain_args: impl Iterator, ) -> Self { - let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec); - let chain_id = extension.map(|e| e.relay_chain.clone()); - let base_path = para_config - .base_path - .as_ref() - .map(|x| x.path().join("polkadot")); - // TODO: we might want to forcibly inject the `--validator` flag. + let base_path = primary_base_path.map(|x| x.path().join("executor")); Self { base_path, - chain_id, - base: subspace_node::RunCmd::parse_from(relay_chain_args), + base: cumulus_client_cli::RunCmd::parse_from(relay_chain_args), } } } -impl SubstrateCli for RelayChainCli { +impl SubstrateCli for SecondaryChainCli { fn impl_name() -> String { "Parachain Collator Template".into() } @@ -60,17 +58,19 @@ impl SubstrateCli for RelayChainCli { 2020 } - fn load_spec(&self, id: &str) -> std::result::Result, String> { - ::from_iter([RelayChainCli::executable_name()].iter()) - .load_spec(id) + fn load_spec(&self, id: &str) -> std::result::Result, String> { + ::from_iter( + [SecondaryChainCli::executable_name()].iter(), + ) + .load_spec(id) } fn native_runtime_version(chain_spec: &Box) -> &'static RuntimeVersion { - subspace_node::Cli::native_runtime_version(chain_spec) + cirrus_node::cli::Cli::native_runtime_version(chain_spec) } } -impl DefaultConfigurationValues for RelayChainCli { +impl DefaultConfigurationValues for SecondaryChainCli { fn p2p_listen_port() -> u16 { 30334 } @@ -88,7 +88,7 @@ impl DefaultConfigurationValues for RelayChainCli { } } -impl CliConfiguration for RelayChainCli { +impl CliConfiguration for SecondaryChainCli { fn shared_params(&self) -> &SharedParams { self.base.base.shared_params() } @@ -127,34 +127,15 @@ impl CliConfiguration for RelayChainCli { fn prometheus_config( &self, default_listen_port: u16, - chain_spec: &Box, + chain_spec: &Box, ) -> Result> { self.base .base .prometheus_config(default_listen_port, chain_spec) } - fn init( - &self, - _support_url: &String, - _impl_version: &String, - _logger_hook: F, - _config: &sc_service::Configuration, - ) -> Result<()> - where - F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), - { - unreachable!("PolkadotCli is never initialized; qed"); - } - fn chain_id(&self, is_dev: bool) -> Result { - let chain_id = self.base.base.chain_id(is_dev)?; - - Ok(if chain_id.is_empty() { - self.chain_id.clone().unwrap_or_default() - } else { - chain_id - }) + self.base.base.chain_id(is_dev) } fn role(&self, is_dev: bool) -> Result { From 4cc85bc2da65237b53f2c8054b56a57dc6606d40 Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Sat, 16 Apr 2022 11:19:23 +0800 Subject: [PATCH 4/7] Force the embedded primary full node to be an authority node It's mandatory to run the embedded subspace node in authorty mode for now, I was stucked for a while due to the CLI flag `--validator` was missed, so it makes sense to me to forcibly enforce this flag. --- crates/subspace-node/src/bin/subspace-node.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/subspace-node/src/bin/subspace-node.rs b/crates/subspace-node/src/bin/subspace-node.rs index 1bc250c2c3..666aab5500 100644 --- a/crates/subspace-node/src/bin/subspace-node.rs +++ b/crates/subspace-node/src/bin/subspace-node.rs @@ -19,7 +19,7 @@ use frame_benchmarking_cli::BenchmarkCmd; use futures::future::TryFutureExt; use sc_cli::{ChainSpec, CliConfiguration, SubstrateCli}; -use sc_service::PartialComponents; +use sc_service::{PartialComponents, Role}; use sp_core::crypto::Ss58AddressFormat; use subspace_node::{Cli, ExecutorDispatch, SecondaryChainCli, Subcommand}; use subspace_runtime::{Block, RuntimeApi}; @@ -87,12 +87,16 @@ fn main() -> std::result::Result<(), Error> { ); let _enter = span.enter(); - let primary_config = cli + let mut primary_config = cli .create_configuration(&cli.run.base, config.tokio_handle.clone()) .map_err(|_| { sc_service::Error::Other("Failed to create subspace configuration".into()) })?; + // The embedded primary full node must be an authority node for the new slots + // notification. + primary_config.role = Role::Authority; + subspace_service::new_full::( primary_config, false, From 1f6783e9a89fb39a6ecef1e93cf1f5ce80fd9ea5 Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Sat, 16 Apr 2022 11:35:55 +0800 Subject: [PATCH 5/7] Update docs and comments --- crates/subspace-node/src/lib.rs | 5 +++++ .../subspace-node/src/secondary_chain_cli.rs | 20 +++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/subspace-node/src/lib.rs b/crates/subspace-node/src/lib.rs index 7d839e363b..5ae1ff824f 100644 --- a/crates/subspace-node/src/lib.rs +++ b/crates/subspace-node/src/lib.rs @@ -115,6 +115,11 @@ pub struct Cli { pub run: RunCmd, /// Secondarychain arguments + /// + /// The command-line arguments provided first will be passed to the embedded primary node, + /// while the arguments provided after -- will be passed to the executor node. + /// + /// subspace-node [primarychain-args] -- [secondarychain-args] #[clap(raw = true)] pub secondarychain_args: Vec, } diff --git a/crates/subspace-node/src/secondary_chain_cli.rs b/crates/subspace-node/src/secondary_chain_cli.rs index 7a061b3b17..c1115c3bf2 100644 --- a/crates/subspace-node/src/secondary_chain_cli.rs +++ b/crates/subspace-node/src/secondary_chain_cli.rs @@ -8,15 +8,17 @@ use std::{net::SocketAddr, path::PathBuf}; #[derive(Debug)] pub struct SecondaryChainCli { - /// The actual relay chain cli object. + /// The actual secondary chain cli object. pub base: cumulus_client_cli::RunCmd, - /// The base path that should be used by the relay chain. + /// The base path that should be used by the secondary chain. pub base_path: Option, } impl SecondaryChainCli { - /// Parse the relay chain CLI parameters using the para chain `Configuration`. + /// Constructs a new instance of [`SecondaryChainCli`]. + /// + /// If no explicit base path for the secondary chain, the default value will be `primary_base_path/executor`. pub fn new<'a>( primary_base_path: Option, relay_chain_args: impl Iterator, @@ -31,7 +33,7 @@ impl SecondaryChainCli { impl SubstrateCli for SecondaryChainCli { fn impl_name() -> String { - "Parachain Collator Template".into() + "Subspace Executor".into() } fn impl_version() -> String { @@ -39,11 +41,7 @@ impl SubstrateCli for SecondaryChainCli { } fn description() -> String { - "Parachain Collator Template\n\nThe command-line arguments provided first will be \ - passed to the parachain node, while the arguments provided after -- will be passed \ - to the relaychain node.\n\n\ - parachain-collator [parachain-args] -- [relaychain-args]" - .into() + "Subspace Executor".into() } fn author() -> String { @@ -51,11 +49,11 @@ impl SubstrateCli for SecondaryChainCli { } fn support_url() -> String { - "https://github.com/paritytech/cumulus/issues/new".into() + "https://github.com/subspace/subspace/issues/new".into() } fn copyright_start_year() -> i32 { - 2020 + 2022 } fn load_spec(&self, id: &str) -> std::result::Result, String> { From 3a05f5c1775121e840f8550d1dbd719ad4c47ae0 Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Sat, 16 Apr 2022 11:56:38 +0800 Subject: [PATCH 6/7] Update instructions for running an executor local network --- cumulus/node/README.md | 104 ++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/cumulus/node/README.md b/cumulus/node/README.md index b1f10b131c..1f75d161e0 100644 --- a/cumulus/node/README.md +++ b/cumulus/node/README.md @@ -10,36 +10,40 @@ Compile all the binaries: $ cargo build --release ``` -Build a chain spec which will be used for running the embedded primary node. - -```bash -$ ./target/release/subspace-node build-spec --chain=dev --raw --disable-default-bootnode > dev.json -``` - ### Spin up a local testnet 1. Run a primary node. ```bash $ ./target/release/subspace-node --dev -d tmp --log=txpool=trace,gossip::executor=trace -2022-04-01 09:45:14.383 INFO main sc_cli::runner: Subspace -2022-04-01 09:45:14.384 INFO main sc_cli::runner: ✌️ version 0.1.0-c3a2fe306-aarch64-macos -2022-04-01 09:45:14.384 INFO main sc_cli::runner: ❀️ by Subspace Labs , 2021-2022 -2022-04-01 09:45:14.384 INFO main sc_cli::runner: πŸ“‹ Chain specification: Development -2022-04-01 09:45:14.384 INFO main sc_cli::runner: 🏷 Node name: spotty-tomatoes-2275 -2022-04-01 09:45:14.384 INFO main sc_cli::runner: πŸ‘€ Role: AUTHORITY -2022-04-01 09:45:14.384 INFO main sc_cli::runner: πŸ’Ύ Database: RocksDb at tmp/chains/dev/db/full -2022-04-01 09:45:14.384 INFO main sc_cli::runner: β›“ Native runtime: subspace-100 (subspace-1.tx1.au1) -2022-04-01 09:45:14.557 INFO main sc_service::client::client: πŸ”¨ Initializing Genesis block/state (state: 0x5c13…52fa, header-hash: 0x64be…e482) -2022-04-01 09:45:14.693 INFO main subspace: Starting archiving from genesis -2022-04-01 09:45:14.718 INFO main subspace: Archiving already produced blocks 0..=0 -2022-04-01 09:45:14.782 WARN main sc_service::config: Using default protocol ID "sup" because none is configured in the chain specs -2022-04-01 09:45:14.782 INFO main sub-libp2p: 🏷 Local node identity is: 12D3KooWRq7JqggfhBMzYY2bhAPzfR44zqgZUkphYi11UrYCVa94 -2022-04-01 09:45:14.785 INFO main subspace: πŸ§‘β€πŸŒΎ Starting Subspace Authorship worker -2022-04-01 09:45:14.787 INFO main sc_service::builder: πŸ“¦ Highest known block at #0 -2022-04-01 09:45:14.787 INFO tokio-runtime-worker substrate_prometheus_endpoint: 〽️ Prometheus exporter started at 127.0.0.1:9615 -2022-04-01 09:45:14.787 INFO main parity_ws: Listening for new connections on 127.0.0.1:9944. -2022-04-01 09:45:19.793 INFO tokio-runtime-worker substrate: πŸ’€ Idle (0 peers), best: #0 (0x64be…e482), finalized #0 (0x64be…e482), ⬇ 0 ⬆ 0 +2022-04-16 11:40:57.269 INFO main sc_cli::runner: Subspace +2022-04-16 11:40:57.269 INFO main sc_cli::runner: ✌️ version 0.1.0-ab4a59751 +2022-04-16 11:40:57.269 INFO main sc_cli::runner: ❀️ by Subspace Labs , 2021-2022 +2022-04-16 11:40:57.269 INFO main sc_cli::runner: πŸ“‹ Chain specification: Development +2022-04-16 11:40:57.269 INFO main sc_cli::runner: 🏷 Node name: harmonious-feast-4450 +2022-04-16 11:40:57.269 INFO main sc_cli::runner: πŸ‘€ Role: AUTHORITY +2022-04-16 11:40:57.269 INFO main sc_cli::runner: πŸ’Ύ Database: RocksDb at tmp/chains/dev/db/full +2022-04-16 11:40:57.269 INFO main sc_cli::runner: β›“ Native runtime: subspace-100 (subspace-1.tx1.au1) +2022-04-16 11:40:57.484 INFO main sc_service::client::client: πŸ”¨ Initializing Genesis block/state (state: 0x12cf…0724, header-hash: 0x42de…9335) +2022-04-16 11:40:57.635 INFO main subspace: Starting archiving from genesis +2022-04-16 11:40:57.667 INFO main subspace: Archiving already produced blocks 0..=0 +2022-04-16 11:40:57.756 WARN main sc_service::config: Using default protocol ID "sup" because none is configured in the chain specs +2022-04-16 11:40:57.757 INFO main sub-libp2p: 🏷 Local node identity is: 12D3KooWMQYGEy2eEcci2RoLZSiBdMj34UjipYR4GryjHkNsDXYW +2022-04-16 11:40:57.759 INFO main subspace: πŸ§‘β€πŸŒΎ Starting Subspace Authorship worker +2022-04-16 11:40:57.768 INFO main sc_sysinfo: πŸ’» Operating system: linux +2022-04-16 11:40:57.768 INFO main sc_sysinfo: πŸ’» CPU architecture: x86_64 +2022-04-16 11:40:57.768 INFO main sc_sysinfo: πŸ’» Target environment: gnu +2022-04-16 11:40:57.768 INFO main sc_sysinfo: πŸ’» CPU: AMD Ryzen 9 5900X 12-Core Processor +2022-04-16 11:40:57.768 INFO main sc_sysinfo: πŸ’» CPU cores: 12 +2022-04-16 11:40:57.768 INFO main sc_sysinfo: πŸ’» Memory: 64252MB +2022-04-16 11:40:57.768 INFO main sc_sysinfo: πŸ’» Kernel: 5.13.0-35-generic +2022-04-16 11:40:57.768 INFO main sc_sysinfo: πŸ’» Linux distribution: Ubuntu 20.04.4 LTS +2022-04-16 11:40:57.768 INFO main sc_sysinfo: πŸ’» Virtual machine: no +2022-04-16 11:40:57.768 INFO main sc_service::builder: πŸ“¦ Highest known block at #0 +2022-04-16 11:40:57.768 INFO main parity_ws: Listening for new connections on 127.0.0.1:9944. +2022-04-16 11:40:57.811 INFO ThreadId(84) parity_ws::io: Accepted a new tcp connection from 127.0.0.1:58000. +2022-04-16 11:41:02.768 INFO tokio-runtime-worker substrate: πŸ’€ Idle (0 peers), best: #0 (0x42de…9335), finalized #0 (0x42de…9335), ⬇ 0 ⬆ 0 + ``` Note the `Local node identity`(`12D3KooWRreNzoMVgM6HtPVP27enDaAuPuPbYgGCrSr2RWD8UBGf`) from the log output. the embedded primary node will use it to craft a bootnode for connecting to the primary node. You can also directly retrieve the primary peer id using the RPC `system_localPeerId`. @@ -57,22 +61,20 @@ Now the primary node should be producing blocks. Ensure the bootnode for the primary node is correct and run this command to start an executor: ```bash -$ ./target/release/subspace-executor \ - --alice \ - --collator \ - --force-authoring \ - --base-path first-db \ - --port 40333 \ - --log=cirrus=trace,txpool=trace,gossip=trace \ - --rpc-port 8845 \ - --ws-port 8846 \ +$ ./target/release/subspace-node \ + --chain dev \ + -d db1 \ + --log=trace \ + --bootnodes "/ip4/127.0.0.1/tcp/30333/p2p/PRIMARY_PEER_ID" \ + --port 30343 \ + --ws-port 9977 \ -- \ - --validator \ - --log=trace \ - --chain dev.json \ - --bootnodes "/ip4/127.0.0.1/tcp/30333/p2p/PRIMARY_PEER_ID" \ - --port 30343 \ - --ws-port 9977 + --alice \ + --port 40333 \ + --log=txpool=trace,gossip=trace \ + --rpc-port 8845 \ + --ws-port 8846 \ + ``` The log for running the secondary node will be prefixed as `[Secondarychain]`, you should see it start to produce blocks as well. @@ -94,18 +96,16 @@ The log for running the secondary node will be prefixed as `[Secondarychain]`, y 3. Run another executor as a full node. ```bash -$ ./target/release/subspace-executor \ - --alice \ - --base-path second-db \ - --port 40233 \ - --log=cirrus=trace,txpool=trace,gossip=trace \ - --rpc-port 8745 \ - --ws-port 8746 \ +$ ./target/release/subspace-node \ + --chain dev \ + -d db2 \ + --bootnodes "/ip4/127.0.0.1/tcp/30333/p2p/PRIMARY_PEER_ID" \ + --port 30443 \ + --ws-port 9987 -- \ - --validator \ - --log=trace \ - --chain dev.json \ - --bootnodes "/ip4/127.0.0.1/tcp/30333/p2p/PRIMARY_PEER_ID" \ - --port 30443 \ - --ws-port 9987 + --alice \ + --port 40233 \ + --log=cirrus=trace,txpool=trace,gossip=trace \ + --rpc-port 8745 \ + --ws-port 8746 \ ``` From fba21ad1355e475a0ddf63fb747464cc04a524be Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Sat, 16 Apr 2022 20:07:49 +0800 Subject: [PATCH 7/7] Apply code review --- crates/subspace-node/Cargo.toml | 1 + crates/subspace-node/src/bin/subspace-node.rs | 106 +++++++++--------- 2 files changed, 55 insertions(+), 52 deletions(-) diff --git a/crates/subspace-node/Cargo.toml b/crates/subspace-node/Cargo.toml index 7901e12afc..2ee699005a 100644 --- a/crates/subspace-node/Cargo.toml +++ b/crates/subspace-node/Cargo.toml @@ -57,6 +57,7 @@ do-not-enforce-cost-of-storage = [ "subspace-runtime/do-not-enforce-cost-of-storage" ] runtime-benchmarks = [ + "cirrus-node/runtime-benchmarks", "subspace-runtime/runtime-benchmarks", ] json-chain-spec = ["subspace-service/json-chain-spec"] diff --git a/crates/subspace-node/src/bin/subspace-node.rs b/crates/subspace-node/src/bin/subspace-node.rs index 666aab5500..ddc7b64a4e 100644 --- a/crates/subspace-node/src/bin/subspace-node.rs +++ b/crates/subspace-node/src/bin/subspace-node.rs @@ -73,47 +73,6 @@ fn set_default_ss58_version>(chain_spec: C) { fn main() -> std::result::Result<(), Error> { let cli = Cli::from_args(); - if !cli.secondarychain_args.is_empty() { - let secondary_chain_cli = - SecondaryChainCli::new(cli.run.base.base_path()?, cli.secondarychain_args.iter()); - - let runner = SubstrateCli::create_runner(&secondary_chain_cli, &secondary_chain_cli)?; - set_default_ss58_version(&runner.config().chain_spec); - runner.run_node_until_exit(|config| async move { - let primary_chain_full_node = { - let span = sc_tracing::tracing::info_span!( - sc_tracing::logging::PREFIX_LOG_SPAN, - name = "Primarychain" - ); - let _enter = span.enter(); - - let mut primary_config = cli - .create_configuration(&cli.run.base, config.tokio_handle.clone()) - .map_err(|_| { - sc_service::Error::Other("Failed to create subspace configuration".into()) - })?; - - // The embedded primary full node must be an authority node for the new slots - // notification. - primary_config.role = Role::Authority; - - subspace_service::new_full::( - primary_config, - false, - ) - .map_err(|_| { - sc_service::Error::Other("Failed to build a full subspace node".into()) - })? - }; - - cirrus_node::service::start_parachain_node(config, primary_chain_full_node) - .await - .map(|r| r.0) - })?; - - return Ok(()); - } - match &cli.subcommand { Some(Subcommand::Key(cmd)) => cmd.run(&cli)?, Some(Subcommand::BuildSpec(cmd)) => { @@ -267,17 +226,60 @@ fn main() -> std::result::Result<(), Error> { unimplemented!("Executor subcommand"); } None => { - 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, - ) - .map(|full| { - full.network_starter.start_network(); - full.task_manager - }) - })?; + if !cli.secondarychain_args.is_empty() { + // Run an executor node, which contains an embedded subspace full node. + let secondary_chain_cli = SecondaryChainCli::new( + cli.run.base.base_path()?, + cli.secondarychain_args.iter(), + ); + let runner = + SubstrateCli::create_runner(&secondary_chain_cli, &secondary_chain_cli)?; + set_default_ss58_version(&runner.config().chain_spec); + runner.run_node_until_exit(|config| async move { + let primary_chain_full_node = { + let span = sc_tracing::tracing::info_span!( + sc_tracing::logging::PREFIX_LOG_SPAN, + name = "Primarychain" + ); + let _enter = span.enter(); + + let mut primary_config = cli + .create_configuration(&cli.run.base, config.tokio_handle.clone()) + .map_err(|_| { + sc_service::Error::Other("Failed to create subspace configuration".into()) + })?; + + // The embedded primary full node must be an authority node for the new slots + // notification. + primary_config.role = Role::Authority; + + subspace_service::new_full::( + primary_config, + false, + ) + .map_err(|_| { + sc_service::Error::Other("Failed to build a full subspace node".into()) + })? + }; + + cirrus_node::service::start_parachain_node(config, primary_chain_full_node) + .await + .map(|r| r.0) + })?; + } else { + // Run a regular subspace node. + 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, + ) + .map(|full| { + full.network_starter.start_network(); + full.task_manager + }) + })?; + } } }