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

Kusama chainspecs #888

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ use service;
/// specification).
#[derive(Clone, Debug)]
pub enum ChainSpec {
/// Whatever the current runtime is, with just Alice as an auth.
Development,
/// Whatever the current runtime is, with simple Alice/Bob auths.
LocalTestnet,
/// Whatever the current polkadot runtime is, with just Alice as an auth.
PolkadotDevelopment,
/// Whatever the current pokadot runtime is, with simple Alice/Bob auths.
PolkadotLocalTestnet,
/// The Kusama network.
Kusama,
/// Whatever the current kusama runtime is, with just Alice as an auth.
KusamaDevelopment,
/// The Westend network,
Westend,
/// Whatever the current runtime is with the "global testnet" defaults.
StagingTestnet,
/// Whatever the current polkadot runtime is with the "global testnet" defaults.
PolkadotStagingTestnet,
/// Whatever the current kusama runtime is with the "global testnet" defaults.
KusamaStagingTestnet,
/// Whatever the current kusama runtime is, with simple Alice/Bob auths.
KusamaLocalTestnet,
}

impl Default for ChainSpec {
Expand All @@ -42,33 +48,41 @@ impl Default for ChainSpec {

/// Get a chain config from a spec setting.
impl ChainSpec {
pub(crate) fn load(self) -> Result<service::ChainSpec, String> {
match self {
ChainSpec::Development => Ok(service::chain_spec::development_config()),
ChainSpec::LocalTestnet => Ok(service::chain_spec::local_testnet_config()),
ChainSpec::StagingTestnet => Ok(service::chain_spec::staging_testnet_config()),
ChainSpec::Westend => service::chain_spec::westend_config(),
ChainSpec::Kusama => service::chain_spec::kusama_config(),
}
pub(crate) fn load(self) -> Result<Box<dyn service::ChainSpec>, String> {
Ok(match self {
ChainSpec::PolkadotDevelopment => Box::new(service::chain_spec::polkadot_development_config()),
ChainSpec::PolkadotLocalTestnet => Box::new(service::chain_spec::polkadot_local_testnet_config()),
ChainSpec::PolkadotStagingTestnet => Box::new(service::chain_spec::polkadot_staging_testnet_config()),
ChainSpec::KusamaDevelopment =>Box::new(service::chain_spec::kusama_development_config()),
ChainSpec::KusamaLocalTestnet => Box::new(service::chain_spec::kusama_local_testnet_config()),
ChainSpec::KusamaStagingTestnet => Box::new(service::chain_spec::kusama_staging_testnet_config()),
ChainSpec::Westend => Box::new(service::chain_spec::westend_config()?),
ChainSpec::Kusama => Box::new(service::chain_spec::kusama_config()?),
})
}

pub(crate) fn from(s: &str) -> Option<Self> {
match s {
"dev" => Some(ChainSpec::Development),
"local" => Some(ChainSpec::LocalTestnet),
"polkadot-dev" => Some(ChainSpec::PolkadotDevelopment),
"polkadot-local" => Some(ChainSpec::PolkadotLocalTestnet),
"polkadot-staging" => Some(ChainSpec::PolkadotStagingTestnet),
"kusama-dev" => Some(ChainSpec::KusamaDevelopment),
"kusama-local" => Some(ChainSpec::KusamaLocalTestnet),
"kusama-staging" => Some(ChainSpec::KusamaStagingTestnet),
"kusama" => Some(ChainSpec::Kusama),
"westend" => Some(ChainSpec::Westend),
"staging" => Some(ChainSpec::StagingTestnet),
"" => Some(ChainSpec::default()),
_ => None,
}
}
}

/// Load the `ChainSpec` for the given `id`.
pub fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
/// `force_kusama` treats chain specs coming from a file as kusama specs.
pub fn load_spec(id: &str, force_kusama: bool) -> Result<Box<dyn service::ChainSpec>, String> {
Ok(match ChainSpec::from(id) {
Some(spec) => Some(spec.load()?),
None => None,
Some(spec) => spec.load()?,
None if force_kusama => Box::new(service::KusamaChainSpec::from_json_file(std::path::PathBuf::from(id))?),
None => Box::new(service::PolkadotChainSpec::from_json_file(std::path::PathBuf::from(id))?),
})
}
13 changes: 12 additions & 1 deletion cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//! Polkadot CLI library.

use structopt::StructOpt;
pub use sc_cli::RunCmd;

#[allow(missing_docs)]
#[derive(Debug, StructOpt, Clone)]
Expand Down Expand Up @@ -45,6 +44,18 @@ pub struct ValidationWorkerCommand {
pub mem_id: String,
}

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

/// Force using Kusama native runtime.
#[structopt(long = "force-kusama")]
pub force_kusama: bool,
bkchr marked this conversation as resolved.
Show resolved Hide resolved
}

#[allow(missing_docs)]
#[derive(Debug, StructOpt, Clone)]
#[structopt(settings = &[
Expand Down
19 changes: 14 additions & 5 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ pub fn run(version: VersionInfo) -> sc_cli::Result<()> {

let mut config = service::Configuration::from_version(&version);
config.impl_name = "parity-polkadot";
let force_kusama = opt.run.force_kusama;

match opt.subcommand {
None => {
opt.run.init(&version)?;
opt.run.update_config(&mut config, load_spec, &version)?;
opt.run.base.init(&version)?;
opt.run.base.update_config(
&mut config,
|id| load_spec(id, force_kusama),
&version
)?;

let is_kusama = config.chain_spec.as_ref().map_or(false, |s| s.is_kusama());
let is_kusama = config.expect_chain_spec().is_kusama();

info!("{}", version.name);
info!(" version {}", config.full_version());
Expand Down Expand Up @@ -69,9 +74,13 @@ pub fn run(version: VersionInfo) -> sc_cli::Result<()> {
},
Some(Subcommand::Base(cmd)) => {
cmd.init(&version)?;
cmd.update_config(&mut config, load_spec, &version)?;
cmd.update_config(
&mut config,
|id| load_spec(id, force_kusama),
&version
)?;

let is_kusama = config.chain_spec.as_ref().map_or(false, |s| s.is_kusama());
let is_kusama = config.expect_chain_spec().is_kusama();

if is_kusama {
cmd.run(config, service::new_chain_ops::<
Expand Down
Loading