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

Commit

Permalink
Remove parachain-id cli command
Browse files Browse the repository at this point in the history
This was never planned to be a permanent feature. This was mainly added for testing purposes, but
now was copied by everybody. The users should be more specific about the para id and set this
properly in the chain spec.
  • Loading branch information
bkchr committed Nov 9, 2021
1 parent ad51706 commit 0b492ba
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 93 deletions.
8 changes: 1 addition & 7 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ 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>,

/// Run node as collator.
///
/// Note that this is the same as running with `--validator`.
Expand All @@ -142,8 +138,6 @@ pub struct RunCmd {
pub struct NormalizedRunCmd {
/// The cumulus RunCmd inherents from sc_cli's
pub base: sc_cli::RunCmd,
/// Id of the parachain this collator collates for.
pub parachain_id: Option<u32>,
}

impl RunCmd {
Expand All @@ -153,7 +147,7 @@ impl RunCmd {

new_base.validator = self.base.validator || self.collator;

NormalizedRunCmd { base: new_base, parachain_id: self.parachain_id }
NormalizedRunCmd { base: new_base }
}
}

Expand Down
12 changes: 6 additions & 6 deletions parachain-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn template_session_keys(keys: AuraId) -> parachain_template_runtime::Sessio
parachain_template_runtime::SessionKeys { aura: keys }
}

pub fn development_config(id: ParaId) -> ChainSpec {
pub fn development_config() -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "ROC".into());
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn development_config(id: ParaId) -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
id,
1000.into(),
)
},
vec![],
Expand All @@ -107,12 +107,12 @@ pub fn development_config(id: ParaId) -> ChainSpec {
None,
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: id.into(),
para_id: 1000,
},
)
}

pub fn local_testnet_config(id: ParaId) -> ChainSpec {
pub fn local_testnet_config() -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "ROC".into());
Expand Down Expand Up @@ -152,7 +152,7 @@ pub fn local_testnet_config(id: ParaId) -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
id,
1000.into(),
)
},
// Bootnodes
Expand All @@ -166,7 +166,7 @@ pub fn local_testnet_config(id: ParaId) -> ChainSpec {
// Extensions
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: id.into(),
para_id: 1000,
},
)
}
Expand Down
6 changes: 0 additions & 6 deletions parachain-template/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ pub struct ExportGenesisStateCommand {
#[structopt(parse(from_os_str))]
pub output: Option<PathBuf>,

/// Id of the parachain this state is for.
///
/// Default: 100
#[structopt(long, conflicts_with = "chain")]
pub parachain_id: Option<u32>,

/// Write output in binary. Default is to write in hex.
#[structopt(short, long)]
pub raw: bool,
Expand Down
26 changes: 11 additions & 15 deletions parachain-template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::Block as BlockT;
use std::{io::Write, net::SocketAddr};

fn load_spec(
id: &str,
para_id: ParaId,
) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config(para_id)),
"template-rococo" => Box::new(chain_spec::local_testnet_config(para_id)),
"" | "local" => Box::new(chain_spec::local_testnet_config(para_id)),
"dev" => Box::new(chain_spec::development_config()),
"template-rococo" => Box::new(chain_spec::local_testnet_config()),
"" | "local" => Box::new(chain_spec::local_testnet_config()),
path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
})
}
Expand Down Expand Up @@ -62,7 +59,7 @@ impl SubstrateCli for Cli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
load_spec(id, self.run.parachain_id.unwrap_or(2000).into())
load_spec(id)
}

fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
Expand Down Expand Up @@ -194,10 +191,8 @@ pub fn run() -> Result<()> {
builder.with_profiling(sc_tracing::TracingReceiver::Log, "");
let _ = builder.init();

let block: Block = generate_genesis_block(&load_spec(
&params.chain.clone().unwrap_or_default(),
params.parachain_id.unwrap_or(2000).into(),
)?)?;
let block: Block =
generate_genesis_block(&load_spec(&params.chain.clone().unwrap_or_default())?)?;
let raw_header = block.header().encode();
let output_buf = if params.raw {
raw_header
Expand Down Expand Up @@ -248,15 +243,16 @@ pub fn run() -> Result<()> {
let runner = cli.create_runner(&cli.run.normalize())?;

runner.run_node_until_exit(|config| async move {
let para_id =
chain_spec::Extensions::try_get(&*config.chain_spec).map(|e| e.para_id);
let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)
.map(|e| e.para_id)
.ok_or_else(|| "Could not find parachain extension for chain-spec.")?;

let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name()].iter().chain(cli.relaychain_args.iter()),
);

let id = ParaId::from(cli.run.parachain_id.or(para_id).unwrap_or(2000));
let id = ParaId::from(para_id);

let parachain_account =
AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);
Expand Down
Loading

0 comments on commit 0b492ba

Please sign in to comment.