Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request paritytech#417 from subspace/secondary-node-cleanup
Browse files Browse the repository at this point in the history
Move secondary chain spec into primary node, remove extra indirection for CLI data structure
  • Loading branch information
nazar-pc authored May 6, 2022
1 parent 181133a commit 0a7f3ae
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 252 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/subspace-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
cirrus-node = { version = "0.1.0", path = "../../cumulus/node" }
cirrus-runtime = { version = "0.1.0", path = "../../cumulus/runtime" }
clap = { version = "3.1.8", features = ["derive"] }
cumulus-client-cli = { version = "0.1.0", path = "../../cumulus/client/cli" }
dirs = "4.0.0"
Expand Down Expand Up @@ -61,5 +62,6 @@ do-not-enforce-cost-of-storage = [
]
runtime-benchmarks = [
"cirrus-node/runtime-benchmarks",
"cirrus-runtime/runtime-benchmarks",
"subspace-runtime/runtime-benchmarks",
]
2 changes: 1 addition & 1 deletion crates/subspace-node/src/bin/subspace-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn set_default_ss58_version<C: AsRef<dyn ChainSpec>>(chain_spec: C) {
}
}

fn main() -> std::result::Result<(), Error> {
fn main() -> Result<(), Error> {
let cli = Cli::from_args();

match &cli.subcommand {
Expand Down
3 changes: 2 additions & 1 deletion crates/subspace-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
mod chain_spec;
mod import_blocks_from_dsn;
mod secondary_chain_cli;
mod secondary_chain_spec;

use crate::chain_spec::SubspaceChainSpec;
pub use crate::import_blocks_from_dsn::ImportBlocksFromDsnCmd;
Expand Down Expand Up @@ -86,7 +87,7 @@ pub enum Subcommand {

/// Run executor sub-commands.
#[clap(subcommand)]
Executor(cirrus_node::cli::Subcommand),
Executor(secondary_chain_cli::Subcommand),

/// Sub-commands concerned with benchmarking.
#[clap(subcommand)]
Expand Down
45 changes: 39 additions & 6 deletions crates/subspace-node/src/secondary_chain_cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::secondary_chain_spec;
use clap::Parser;
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
Expand All @@ -6,6 +7,35 @@ use sc_cli::{
use sc_service::{config::PrometheusConfig, BasePath};
use std::{net::SocketAddr, path::PathBuf};

/// Sub-commands supported by the executor.
#[derive(Debug, clap::Subcommand)]
pub enum Subcommand {
/// Build a chain specification.
BuildSpec(sc_cli::BuildSpecCmd),

/// Validate blocks.
CheckBlock(sc_cli::CheckBlockCmd),

/// Export blocks.
ExportBlocks(sc_cli::ExportBlocksCmd),

/// Export the state of a given block into a chain spec.
ExportState(sc_cli::ExportStateCmd),

/// Import blocks.
ImportBlocks(sc_cli::ImportBlocksCmd),

/// Remove the whole chain.
PurgeChain(cumulus_client_cli::PurgeChainCmd),

/// Revert the chain to a previous state.
Revert(sc_cli::RevertCmd),

/// Sub-commands concerned with benchmarking.
#[clap(subcommand)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
}

#[derive(Debug)]
pub struct SecondaryChainCli {
/// The actual secondary chain cli object.
Expand Down Expand Up @@ -63,14 +93,17 @@ impl SubstrateCli for SecondaryChainCli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
<cirrus_node::cli::Cli as SubstrateCli>::from_iter(
[SecondaryChainCli::executable_name()].iter(),
)
.load_spec(id)
Ok(match id {
"dev" => Box::new(secondary_chain_spec::development_config()),
"" | "local" => Box::new(secondary_chain_spec::local_testnet_config()),
path => Box::new(secondary_chain_spec::ChainSpec::from_json_file(
std::path::PathBuf::from(path),
)?),
})
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
cirrus_node::cli::Cli::native_runtime_version(chain_spec)
fn native_runtime_version(_chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
&cirrus_runtime::VERSION
}
}

Expand Down
125 changes: 125 additions & 0 deletions crates/subspace-node/src/secondary_chain_spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//! Secondary chain configurations.
use cirrus_runtime::{AccountId, Signature};
use frame_support::traits::Get;
use sc_service::{ChainType, Properties};
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
use subspace_runtime::{SS58Prefix, DECIMAL_PLACES};

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<cirrus_runtime::GenesisConfig>;

/// Helper function to generate a crypto pair from seed
pub fn get_pair_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

type AccountPublic = <Signature as Verify>::Signer;

/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_pair_from_seed::<TPublic>(seed)).into_account()
}

pub fn development_config() -> ChainSpec {
let mut properties = Properties::new();
properties.insert("ss58Format".into(), <SS58Prefix as Get<u16>>::get().into());
properties.insert("tokenDecimals".into(), DECIMAL_PLACES.into());
properties.insert("tokenSymbol".into(), "tSSC".into());

ChainSpec::from_genesis(
// Name
"Development",
// ID
"execution_dev",
ChainType::Development,
move || {
testnet_genesis(vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
])
},
vec![],
None,
None,
None,
None,
None,
)
}

pub fn local_testnet_config() -> ChainSpec {
let mut properties = Properties::new();
properties.insert("ss58Format".into(), <SS58Prefix as Get<u16>>::get().into());
properties.insert("tokenDecimals".into(), DECIMAL_PLACES.into());
properties.insert("tokenSymbol".into(), "tSSC".into());

ChainSpec::from_genesis(
// Name
"Local Testnet",
// ID
"execution_local_testnet",
ChainType::Local,
move || {
testnet_genesis(vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
])
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("template-local"),
None,
// Properties
Some(properties),
// Extensions
None,
)
}

fn testnet_genesis(endowed_accounts: Vec<AccountId>) -> cirrus_runtime::GenesisConfig {
cirrus_runtime::GenesisConfig {
system: cirrus_runtime::SystemConfig {
code: cirrus_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
},
transaction_payment: Default::default(),
balances: cirrus_runtime::BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1 << 60))
.collect(),
},
}
}
135 changes: 0 additions & 135 deletions cumulus/node/src/chain_spec.rs

This file was deleted.

Loading

0 comments on commit 0a7f3ae

Please sign in to comment.