From f22c70e16521f375fe125df5616d48ceea926b1a Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Wed, 18 May 2022 08:54:10 +0200 Subject: [PATCH] Allow startinc collator without relay-chain args --- Cargo.lock | 2 +- client/cli/src/lib.rs | 6 ++++++ parachain-template/node/src/cli.rs | 11 ++++++++++- parachain-template/node/src/command.rs | 3 +++ polkadot-parachains/src/cli.rs | 11 ++++++++++- polkadot-parachains/src/command.rs | 3 +++ 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87951d281a3..7489662f769 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12495,7 +12495,7 @@ version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "digest 0.10.3", "rand 0.8.5", "static_assertions", diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 4b48023d38a..c42f4f85866 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -161,6 +161,12 @@ pub struct CollatorOptions { pub relay_chain_rpc_url: Option, } +impl Default for CollatorOptions { + fn default() -> Self { + Self { relay_chain_rpc_url: None } + } +} + /// A non-redundant version of the `RunCmd` that sets the `validator` field when the /// original `RunCmd` had the `collator` field. /// This is how we make `--collator` imply `--validator`. diff --git a/parachain-template/node/src/cli.rs b/parachain-template/node/src/cli.rs index 0d36120a479..2e54069f20d 100644 --- a/parachain-template/node/src/cli.rs +++ b/parachain-template/node/src/cli.rs @@ -1,5 +1,6 @@ use crate::chain_spec; use clap::Parser; +use cumulus_client_cli::CollatorOptions; use std::path::PathBuf; /// Sub-commands supported by the collator. @@ -113,6 +114,8 @@ pub struct RelayChainCli { /// The base path that should be used by the relay chain. pub base_path: Option, + + pub is_rpc_collator: bool, } impl RelayChainCli { @@ -120,10 +123,16 @@ impl RelayChainCli { pub fn new<'a>( para_config: &sc_service::Configuration, relay_chain_args: impl Iterator, + collator_options: &CollatorOptions, ) -> 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")); - Self { base_path, chain_id, base: polkadot_cli::RunCmd::parse_from(relay_chain_args) } + Self { + base_path, + chain_id, + base: polkadot_cli::RunCmd::parse_from(relay_chain_args), + is_rpc_collator: collator_options.relay_chain_rpc_url.is_some(), + } } } diff --git a/parachain-template/node/src/command.rs b/parachain-template/node/src/command.rs index 4b8db2e2506..ba70fd03837 100644 --- a/parachain-template/node/src/command.rs +++ b/parachain-template/node/src/command.rs @@ -99,6 +99,7 @@ impl SubstrateCli for RelayChainCli { } fn load_spec(&self, id: &str) -> std::result::Result, String> { + let id = if self.is_rpc_collator { "polkadot" } else { id }; polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id) } @@ -171,6 +172,7 @@ pub fn run() -> Result<()> { let polkadot_cli = RelayChainCli::new( &config, [RelayChainCli::executable_name()].iter().chain(cli.relay_chain_args.iter()), + &Default::default(), ); let polkadot_config = SubstrateCli::create_configuration( @@ -304,6 +306,7 @@ pub fn run() -> Result<()> { let polkadot_cli = RelayChainCli::new( &config, [RelayChainCli::executable_name()].iter().chain(cli.relay_chain_args.iter()), + &collator_options, ); let id = ParaId::from(para_id); diff --git a/polkadot-parachains/src/cli.rs b/polkadot-parachains/src/cli.rs index 31ecb8a5aa0..a8dd1979e4d 100644 --- a/polkadot-parachains/src/cli.rs +++ b/polkadot-parachains/src/cli.rs @@ -16,6 +16,7 @@ use crate::chain_spec; use clap::Parser; +use cumulus_client_cli::CollatorOptions; use sc_cli; use std::path::PathBuf; @@ -134,6 +135,8 @@ pub struct RelayChainCli { /// The base path that should be used by the relay chain. pub base_path: Option, + + pub is_rpc_collator: bool, } impl RelayChainCli { @@ -141,10 +144,16 @@ impl RelayChainCli { pub fn new<'a>( para_config: &sc_service::Configuration, relay_chain_args: impl Iterator, + collator_options: &CollatorOptions, ) -> 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")); - Self { base_path, chain_id, base: polkadot_cli::RunCmd::parse_from(relay_chain_args) } + Self { + base_path, + chain_id, + base: polkadot_cli::RunCmd::parse_from(relay_chain_args), + is_rpc_collator: collator_options.relay_chain_rpc_url.is_some(), + } } } diff --git a/polkadot-parachains/src/command.rs b/polkadot-parachains/src/command.rs index 77293e49b47..76c9209ef5b 100644 --- a/polkadot-parachains/src/command.rs +++ b/polkadot-parachains/src/command.rs @@ -251,6 +251,7 @@ impl SubstrateCli for RelayChainCli { } fn load_spec(&self, id: &str) -> std::result::Result, String> { + let id = if self.is_rpc_collator { "polkadot" } else { id }; polkadot_cli::Cli::from_iter([RelayChainCli::executable_name().to_string()].iter()) .load_spec(id) } @@ -407,6 +408,7 @@ pub fn run() -> Result<()> { [RelayChainCli::executable_name().to_string()] .iter() .chain(cli.relaychain_args.iter()), + &Default::default(), ); let polkadot_config = SubstrateCli::create_configuration( @@ -562,6 +564,7 @@ pub fn run() -> Result<()> { [RelayChainCli::executable_name().to_string()] .iter() .chain(cli.relaychain_args.iter()), + &collator_options, ); let id = ParaId::from(para_id);