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

Make --collator reusable and imply --validator #380

Merged
34 changes: 34 additions & 0 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,37 @@ impl sc_cli::CliConfiguration for PurgeChainCmd {
Some(&self.base.database_params)
}
}

/// The `run` command used to run a node.
#[derive(Debug, StructOpt)]
pub struct RunCmd {
/// Our run command inherents from sc_cli's
#[structopt(flatten)]
pub base: sc_cli::RunCmd,

/// Id of the parachain this collator collates for.
#[structopt(long)]
pub parachain_id: Option<u32>,

/// Run node as collator.
///
/// Note that this is the same as running with `--validator`.
#[structopt(long, conflicts_with = "validator")]
pub collator: bool,
}

impl sc_cli::CliConfiguration for RunCmd {
fn shared_params(&self) -> &sc_cli::SharedParams {
&self.base.shared_params
}

fn role(&self, is_dev: bool) -> sc_cli::Result<sc_cli::Role> {
let is_authority = self.base.validator || self.collator || is_dev;

Ok(if is_authority {
sc_service::Role::Authority
} else {
sc_service::Role::Full
})
}
}
JoshOrndorff marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 1 addition & 25 deletions rococo-parachains/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,6 @@ pub struct ExportGenesisWasmCommand {
pub chain: Option<String>,
}

#[derive(Debug, StructOpt)]
pub struct RunCmd {
#[structopt(flatten)]
pub base: sc_cli::RunCmd,

/// Id of the parachain this collator collates for.
#[structopt(long)]
pub parachain_id: Option<u32>,
}

impl std::ops::Deref for RunCmd {
type Target = sc_cli::RunCmd;

fn deref(&self) -> &Self::Target {
&self.base
}
}
JoshOrndorff marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Debug, StructOpt)]
#[structopt(settings = &[
structopt::clap::AppSettings::GlobalVersion,
Expand All @@ -117,13 +99,7 @@ pub struct Cli {
pub subcommand: Option<Subcommand>,

#[structopt(flatten)]
pub run: RunCmd,

/// Run node as collator.
///
/// Note that this is the same as running with `--validator`.
#[structopt(long, conflicts_with = "validator")]
pub collator: bool,
pub run: cumulus_client_cli::RunCmd,

/// Relaychain arguments
#[structopt(raw = true)]
Expand Down
7 changes: 3 additions & 4 deletions rococo-parachains/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub fn run() -> Result<()> {
Ok(())
}
None => {
let runner = cli.create_runner(&*cli.run)?;
let runner = cli.create_runner(&cli.run)?;

runner.run_node_until_exit(|config| async move {
// TODO
Expand Down Expand Up @@ -312,14 +312,13 @@ pub fn run() -> Result<()> {
task_executor,
)
.map_err(|err| format!("Relay chain argument error: {}", err))?;
let collator = cli.run.base.validator || cli.collator;

info!("Parachain id: {:?}", id);
info!("Parachain Account: {}", parachain_account);
info!("Parachain genesis state: {}", genesis_state);
info!("Is collating: {}", if collator { "yes" } else { "no" });
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });

crate::service::start_node(config, key, polkadot_config, id, collator)
crate::service::start_node(config, key, polkadot_config, id)
.await
.map(|r| r.0)
.map_err(Into::into)
Expand Down
4 changes: 1 addition & 3 deletions rococo-parachains/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ async fn start_node_impl<RB>(
collator_key: CollatorPair,
polkadot_config: Configuration,
id: ParaId,
validator: bool,
rpc_ext_builder: RB,
) -> sc_service::error::Result<(TaskManager, Arc<TFullClient<Block, RuntimeApi, Executor>>)>
where
Expand Down Expand Up @@ -171,6 +170,7 @@ where
polkadot_full_node.backend.clone(),
);

let validator = parachain_config.role.is_authority();
let prometheus_registry = parachain_config.prometheus_registry().cloned();
let transaction_pool = params.transaction_pool.clone();
let mut task_manager = params.task_manager;
Expand Down Expand Up @@ -266,14 +266,12 @@ pub async fn start_node(
collator_key: CollatorPair,
polkadot_config: Configuration,
id: ParaId,
validator: bool,
) -> sc_service::error::Result<(TaskManager, Arc<TFullClient<Block, RuntimeApi, Executor>>)> {
start_node_impl(
parachain_config,
collator_key,
polkadot_config,
id,
validator,
|_| Default::default(),
)
.await
Expand Down