Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Allow startinc collator without relay-chain args
Browse files Browse the repository at this point in the history
  • Loading branch information
skunert committed May 18, 2022
1 parent 4784f5f commit f22c70e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ pub struct CollatorOptions {
pub relay_chain_rpc_url: Option<Url>,
}

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`.
Expand Down
11 changes: 10 additions & 1 deletion parachain-template/node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -113,17 +114,25 @@ pub struct RelayChainCli {

/// The base path that should be used by the relay chain.
pub base_path: Option<PathBuf>,

pub is_rpc_collator: bool,
}

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<Item = &'a String>,
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(),
}
}
}
3 changes: 3 additions & 0 deletions parachain-template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl SubstrateCli for RelayChainCli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
let id = if self.is_rpc_collator { "polkadot" } else { id };
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion polkadot-parachains/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use crate::chain_spec;
use clap::Parser;
use cumulus_client_cli::CollatorOptions;
use sc_cli;
use std::path::PathBuf;

Expand Down Expand Up @@ -134,17 +135,25 @@ pub struct RelayChainCli {

/// The base path that should be used by the relay chain.
pub base_path: Option<PathBuf>,

pub is_rpc_collator: bool,
}

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<Item = &'a String>,
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(),
}
}
}
3 changes: 3 additions & 0 deletions polkadot-parachains/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ impl SubstrateCli for RelayChainCli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, 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)
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f22c70e

Please sign in to comment.