From 2d38695375ca7a99cd54188565f06238bb9e2b24 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 1 Jun 2022 02:14:00 +0300 Subject: [PATCH 1/3] Introduce `sc-subspace-chain-specs` crate --- Cargo.lock | 14 +- crates/sc-subspace-chain-specs/Cargo.toml | 20 ++ crates/sc-subspace-chain-specs/src/lib.rs | 53 ++++ crates/sc-subspace-chain-specs/src/utils.rs | 269 ++++++++++++++++++ crates/subspace-node/Cargo.toml | 2 +- crates/subspace-node/src/bin/subspace-node.rs | 8 +- crates/subspace-node/src/chain_spec.rs | 27 +- crates/subspace-node/src/chain_spec_utils.rs | 269 +----------------- crates/subspace-node/src/lib.rs | 3 +- .../src/secondary_chain/chain_spec.rs | 26 +- .../subspace-node/src/secondary_chain/cli.rs | 7 +- 11 files changed, 386 insertions(+), 312 deletions(-) create mode 100644 crates/sc-subspace-chain-specs/Cargo.toml create mode 100644 crates/sc-subspace-chain-specs/src/lib.rs create mode 100644 crates/sc-subspace-chain-specs/src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index 43b0048126..9628fe791f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6606,6 +6606,18 @@ dependencies = [ "sp-core", ] +[[package]] +name = "sc-subspace-chain-specs" +version = "0.1.0" +dependencies = [ + "sc-chain-spec", + "sc-service", + "sc-telemetry", + "serde", + "sp-core", + "sp-runtime", +] + [[package]] name = "sc-sysinfo" version = "6.0.0-dev" @@ -8098,12 +8110,12 @@ dependencies = [ "futures 0.3.21", "log", "parity-scale-codec", - "sc-chain-spec", "sc-cli", "sc-client-api", "sc-consensus", "sc-executor", "sc-service", + "sc-subspace-chain-specs", "sc-telemetry", "sc-tracing", "serde", diff --git a/crates/sc-subspace-chain-specs/Cargo.toml b/crates/sc-subspace-chain-specs/Cargo.toml new file mode 100644 index 0000000000..3ff7b9773f --- /dev/null +++ b/crates/sc-subspace-chain-specs/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "sc-subspace-chain-specs" +description = "Chain specification data structures tailored for Subspace" +license = "Apache-2.0" +version = "0.1.0" +authors = ["Nazar Mokrynskyi "] +edition = "2021" +include = [ + "/src", + "/Cargo.toml", + "/README.md", +] + +[dependencies] +sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd" } +sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd", features = ["wasmtime"] } +sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd" } +serde = "1.0.137" +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd" } +sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd" } diff --git a/crates/sc-subspace-chain-specs/src/lib.rs b/crates/sc-subspace-chain-specs/src/lib.rs new file mode 100644 index 0000000000..28aefccc22 --- /dev/null +++ b/crates/sc-subspace-chain-specs/src/lib.rs @@ -0,0 +1,53 @@ +// Copyright (C) 2021 Subspace Labs, Inc. +// SPDX-License-Identifier: GPL-3.0-or-later + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Chain specification data structures tailored for Subspace. + +mod utils; + +use crate::utils::SerializableChainSpec; +use sc_chain_spec::{ChainSpecExtension, RuntimeGenesis}; +use serde::{Deserialize, Serialize}; + +/// The extensions for the [`ConsensusChainSpec`]. +#[derive(Serialize, Deserialize, ChainSpecExtension)] +#[serde(deny_unknown_fields, rename_all = "camelCase")] +#[serde(bound = "")] +pub struct ChainSpecExtensions +where + ExecutionGenesisConfig: RuntimeGenesis + 'static, +{ + /// Chain spec of execution chain. + pub execution_chain_spec: ExecutionChainSpec, +} + +impl Clone for ChainSpecExtensions +where + ExecutionGenesisConfig: RuntimeGenesis + 'static, +{ + fn clone(&self) -> Self { + Self { + execution_chain_spec: self.execution_chain_spec.clone(), + } + } +} + +/// Specialized `ChainSpec` for the consensus runtime. +pub type ConsensusChainSpec = + SerializableChainSpec>; + +/// Specialized `ChainSpec` for the execution runtime. +pub type ExecutionChainSpec = SerializableChainSpec; diff --git a/crates/sc-subspace-chain-specs/src/utils.rs b/crates/sc-subspace-chain-specs/src/utils.rs new file mode 100644 index 0000000000..f4d4f8ea71 --- /dev/null +++ b/crates/sc-subspace-chain-specs/src/utils.rs @@ -0,0 +1,269 @@ +use sc_chain_spec::{ + ChainSpec, ChainType, GenericChainSpec, GetExtension, NoExtension, RuntimeGenesis, +}; +use sc_service::config::MultiaddrWithPeerId; +use sc_service::Properties; +use sc_telemetry::TelemetryEndpoints; +use serde::de::Visitor; +use serde::ser::Error as _; +use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; +use sp_core::storage::Storage; +use sp_runtime::BuildStorage; +use std::borrow::Cow; +use std::collections::BTreeMap; +use std::fmt; +use std::marker::PhantomData; +use std::path::PathBuf; + +pub struct SerializableChainSpec { + chain_spec: GenericChainSpec, +} + +impl Clone for SerializableChainSpec +where + Extensions: Clone, +{ + fn clone(&self) -> Self { + Self { + chain_spec: self.chain_spec.clone(), + } + } +} + +impl Serialize for SerializableChainSpec +where + GenesisConfig: RuntimeGenesis + 'static, + Extensions: GetExtension + Serialize + Clone + Send + Sync + 'static, +{ + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str(&self.as_json(true).map_err(S::Error::custom)?) + } +} + +impl<'de, GenesisConfig, Extensions> Deserialize<'de> + for SerializableChainSpec +where + Extensions: de::DeserializeOwned, +{ + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct StringVisitor { + _phantom_data: PhantomData<(GenesisConfig, Extensions)>, + } + + impl<'de, GenesisConfig, Extensions> Visitor<'de> for StringVisitor + where + Extensions: de::DeserializeOwned, + { + type Value = SerializableChainSpec; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("ExecutionChainSpec") + } + + fn visit_str(self, value: &str) -> Result + where + E: de::Error, + { + self.visit_string(value.to_string()) + } + + fn visit_string(self, value: String) -> Result + where + E: de::Error, + { + Self::Value::from_json_bytes(value.into_bytes()).map_err(E::custom) + } + } + deserializer.deserialize_string(StringVisitor { + _phantom_data: PhantomData::default(), + }) + } +} + +impl BuildStorage for SerializableChainSpec +where + GenesisConfig: RuntimeGenesis, +{ + fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> { + self.chain_spec.assimilate_storage(storage) + } +} + +impl ChainSpec for SerializableChainSpec +where + GenesisConfig: RuntimeGenesis + 'static, + Extensions: GetExtension + Serialize + Clone + Send + Sync + 'static, +{ + fn name(&self) -> &str { + self.chain_spec.name() + } + + fn id(&self) -> &str { + self.chain_spec.id() + } + + fn chain_type(&self) -> ChainType { + ChainSpec::chain_type(&self.chain_spec) + } + + fn boot_nodes(&self) -> &[MultiaddrWithPeerId] { + self.chain_spec.boot_nodes() + } + + fn telemetry_endpoints(&self) -> &Option { + self.chain_spec.telemetry_endpoints() + } + + fn protocol_id(&self) -> Option<&str> { + self.chain_spec.protocol_id() + } + + fn fork_id(&self) -> Option<&str> { + self.chain_spec.fork_id() + } + + fn properties(&self) -> Properties { + self.chain_spec.properties() + } + + fn extensions(&self) -> &dyn GetExtension { + self.chain_spec.extensions() + } + + fn extensions_mut(&mut self) -> &mut dyn GetExtension { + self.chain_spec.extensions_mut() + } + + fn add_boot_node(&mut self, addr: MultiaddrWithPeerId) { + self.chain_spec.add_boot_node(addr) + } + + fn as_json(&self, raw: bool) -> Result { + self.chain_spec.as_json(raw) + } + + fn as_storage_builder(&self) -> &dyn BuildStorage { + self.chain_spec.as_storage_builder() + } + + fn cloned_box(&self) -> Box { + self.chain_spec.cloned_box() + } + + fn set_storage(&mut self, storage: Storage) { + self.chain_spec.set_storage(storage) + } + + fn code_substitutes(&self) -> BTreeMap> { + self.chain_spec.code_substitutes() + } +} + +impl SerializableChainSpec +where + GenesisConfig: RuntimeGenesis + 'static, + Extensions: GetExtension + Serialize + Clone + Send + Sync + 'static, +{ + /// A list of bootnode addresses. + pub fn boot_nodes(&self) -> &[MultiaddrWithPeerId] { + self.chain_spec.boot_nodes() + } + + /// Spec name. + pub fn name(&self) -> &str { + self.chain_spec.name() + } + + /// Spec id. + pub fn id(&self) -> &str { + self.chain_spec.id() + } + + /// Telemetry endpoints (if any) + pub fn telemetry_endpoints(&self) -> &Option { + self.chain_spec.telemetry_endpoints() + } + + /// Network protocol id. + pub fn protocol_id(&self) -> Option<&str> { + self.chain_spec.protocol_id() + } + + /// Optional network fork identifier. + pub fn fork_id(&self) -> Option<&str> { + self.chain_spec.fork_id() + } + + /// Additional loosly-typed properties of the chain. + /// + /// Returns an empty JSON object if 'properties' not defined in config + pub fn properties(&self) -> Properties { + self.chain_spec.properties() + } + + /// Add a bootnode to the list. + pub fn add_boot_node(&mut self, addr: MultiaddrWithPeerId) { + self.chain_spec.add_boot_node(addr) + } + + /// Returns a reference to the defined chain spec extensions. + pub fn extensions(&self) -> &Extensions { + self.chain_spec.extensions() + } + + /// Returns a mutable reference to the defined chain spec extensions. + pub fn extensions_mut(&mut self) -> &mut Extensions { + self.chain_spec.extensions_mut() + } + + /// Create hardcoded spec. + #[allow(clippy::too_many_arguments)] + pub fn from_genesis GenesisConfig + 'static + Send + Sync>( + name: &str, + id: &str, + chain_type: ChainType, + constructor: F, + boot_nodes: Vec, + telemetry_endpoints: Option, + protocol_id: Option<&str>, + fork_id: Option<&str>, + properties: Option, + extensions: Extensions, + ) -> Self { + Self { + chain_spec: GenericChainSpec::from_genesis( + name, + id, + chain_type, + constructor, + boot_nodes, + telemetry_endpoints, + protocol_id, + fork_id, + properties, + extensions, + ), + } + } +} + +impl SerializableChainSpec +where + Extensions: de::DeserializeOwned, +{ + /// Parse json content into a `ChainSpec` + pub fn from_json_bytes(json: impl Into>) -> Result { + GenericChainSpec::from_json_bytes(json).map(|chain_spec| Self { chain_spec }) + } + + /// Parse json file into a `ChainSpec` + pub fn from_json_file(path: PathBuf) -> Result { + GenericChainSpec::from_json_file(path).map(|chain_spec| Self { chain_spec }) + } +} diff --git a/crates/subspace-node/Cargo.toml b/crates/subspace-node/Cargo.toml index 35e8d700c7..11da15b135 100644 --- a/crates/subspace-node/Cargo.toml +++ b/crates/subspace-node/Cargo.toml @@ -29,10 +29,10 @@ frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/su futures = "0.3.21" log = "0.4.17" parity-scale-codec = "3.1.2" -sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd" } sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd", features = ["wasmtime"] } sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd" } sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd" } +sc-subspace-chain-specs = { version = "0.1.0", path = "../sc-subspace-chain-specs" } sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd", features = ["wasmtime"] } sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd", features = ["wasmtime"] } sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "24bea4c3cba7479e2cf2976a21e8111dfda6b1cd" } diff --git a/crates/subspace-node/src/bin/subspace-node.rs b/crates/subspace-node/src/bin/subspace-node.rs index 5d5788f5da..7d7064db22 100644 --- a/crates/subspace-node/src/bin/subspace-node.rs +++ b/crates/subspace-node/src/bin/subspace-node.rs @@ -16,14 +16,16 @@ //! Subspace node implementation. +use cirrus_runtime::GenesisConfig as ExecutionGenesisConfig; use frame_benchmarking_cli::BenchmarkCmd; use futures::future::TryFutureExt; use futures::StreamExt; use sc_cli::{ChainSpec, CliConfiguration, Database, DatabaseParams, SubstrateCli}; use sc_service::PartialComponents; +use sc_subspace_chain_specs::ExecutionChainSpec; use sp_core::crypto::Ss58AddressFormat; use std::any::TypeId; -use subspace_node::{Cli, ExecutionChainSpec, ExecutorDispatch, SecondaryChainCli, Subcommand}; +use subspace_node::{Cli, ExecutorDispatch, SecondaryChainCli, Subcommand}; use subspace_runtime::{Block, RuntimeApi}; use subspace_service::SubspaceConfiguration; @@ -210,7 +212,7 @@ fn main() -> Result<(), Error> { let maybe_secondary_chain_spec = primary_chain_config .chain_spec .extensions() - .get_any(TypeId::of::()) + .get_any(TypeId::of::>()) .downcast_ref() .cloned(); @@ -323,7 +325,7 @@ fn main() -> Result<(), Error> { let maybe_secondary_chain_spec = primary_chain_config .chain_spec .extensions() - .get_any(TypeId::of::()) + .get_any(TypeId::of::>()) .downcast_ref() .cloned(); diff --git a/crates/subspace-node/src/chain_spec.rs b/crates/subspace-node/src/chain_spec.rs index aa772c933f..0fa9cc321e 100644 --- a/crates/subspace-node/src/chain_spec.rs +++ b/crates/subspace-node/src/chain_spec.rs @@ -18,14 +18,12 @@ use crate::chain_spec_utils::{ chain_spec_properties, get_account_id_from_seed, get_public_key_from_seed, - SerializableChainSpec, }; use crate::secondary_chain; -use crate::secondary_chain::chain_spec::ExecutionChainSpec; -use sc_chain_spec::ChainSpecExtension; +use cirrus_runtime::GenesisConfig as ExecutionGenesisConfig; use sc_service::ChainType; +use sc_subspace_chain_specs::{ChainSpecExtensions, ConsensusChainSpec}; use sc_telemetry::TelemetryEndpoints; -use serde::{Deserialize, Serialize}; use sp_core::crypto::Ss58Codec; use sp_executor::ExecutorId; use subspace_runtime::{ @@ -65,22 +63,13 @@ const TOKEN_GRANTS: &[(&str, u128)] = &[ ("5FZwEgsvZz1vpeH7UsskmNmTpbfXvAcojjgVfShgbRqgC1nx", 27_800), ]; -/// The extensions for the [`ConsensusChainSpec`]. -#[derive(Clone, Serialize, Deserialize, ChainSpecExtension)] -#[serde(deny_unknown_fields, rename_all = "camelCase")] -pub struct ChainSpecExtensions { - /// Chain spec of execution chain. - pub execution_chain_spec: ExecutionChainSpec, -} - -/// The `ChainSpec` parameterized for the consensus runtime. -pub type ConsensusChainSpec = SerializableChainSpec; - -pub fn gemini_config() -> Result { +pub fn gemini_config() -> Result, String> +{ ConsensusChainSpec::from_json_bytes(GEMINI_1_CHAIN_SPEC) } -pub fn gemini_config_compiled() -> Result { +pub fn gemini_config_compiled( +) -> Result, String> { Ok(ConsensusChainSpec::from_genesis( // Name "Subspace Gemini 1", @@ -167,7 +156,7 @@ pub fn gemini_config_compiled() -> Result { )) } -pub fn dev_config() -> Result { +pub fn dev_config() -> Result, String> { let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; Ok(ConsensusChainSpec::from_genesis( @@ -214,7 +203,7 @@ pub fn dev_config() -> Result { )) } -pub fn local_config() -> Result { +pub fn local_config() -> Result, String> { let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; Ok(ConsensusChainSpec::from_genesis( diff --git a/crates/subspace-node/src/chain_spec_utils.rs b/crates/subspace-node/src/chain_spec_utils.rs index 9af17cc036..fe013fca5d 100644 --- a/crates/subspace-node/src/chain_spec_utils.rs +++ b/crates/subspace-node/src/chain_spec_utils.rs @@ -1,23 +1,9 @@ use frame_support::traits::Get; -use sc_chain_spec::{ - ChainSpec, ChainType, GenericChainSpec, GetExtension, NoExtension, RuntimeGenesis, -}; -use sc_service::config::MultiaddrWithPeerId; use sc_service::Properties; -use sc_telemetry::TelemetryEndpoints; -use serde::de::Visitor; -use serde::ser::Error as _; -use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use sp_core::crypto::AccountId32; -use sp_core::storage::Storage; use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::IdentifyAccount; -use sp_runtime::{BuildStorage, MultiSigner}; -use std::borrow::Cow; -use std::collections::BTreeMap; -use std::fmt; -use std::marker::PhantomData; -use std::path::PathBuf; +use sp_runtime::MultiSigner; use subspace_runtime::SS58Prefix; use subspace_runtime_primitives::DECIMAL_PLACES; @@ -45,256 +31,3 @@ pub(crate) fn get_public_key_from_seed( pub(crate) fn get_account_id_from_seed(seed: &'static str) -> AccountId32 { MultiSigner::from(get_public_key_from_seed::(seed)).into_account() } - -pub struct SerializableChainSpec { - chain_spec: GenericChainSpec, -} - -impl Clone for SerializableChainSpec -where - Extensions: Clone, -{ - fn clone(&self) -> Self { - Self { - chain_spec: self.chain_spec.clone(), - } - } -} - -impl Serialize for SerializableChainSpec -where - GenesisConfig: RuntimeGenesis + 'static, - Extensions: GetExtension + Serialize + Clone + Send + Sync + 'static, -{ - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.serialize_str(&self.as_json(true).map_err(S::Error::custom)?) - } -} - -impl<'de, GenesisConfig, Extensions> Deserialize<'de> - for SerializableChainSpec -where - Extensions: de::DeserializeOwned, -{ - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - struct StringVisitor { - _phantom_data: PhantomData<(GenesisConfig, Extensions)>, - } - - impl<'de, GenesisConfig, Extensions> Visitor<'de> for StringVisitor - where - Extensions: de::DeserializeOwned, - { - type Value = SerializableChainSpec; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("ExecutionChainSpec") - } - - fn visit_str(self, value: &str) -> Result - where - E: de::Error, - { - self.visit_string(value.to_string()) - } - - fn visit_string(self, value: String) -> Result - where - E: de::Error, - { - Self::Value::from_json_bytes(value.into_bytes()).map_err(E::custom) - } - } - deserializer.deserialize_string(StringVisitor { - _phantom_data: PhantomData::default(), - }) - } -} - -impl BuildStorage for SerializableChainSpec -where - GenesisConfig: RuntimeGenesis, -{ - fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> { - self.chain_spec.assimilate_storage(storage) - } -} - -impl ChainSpec for SerializableChainSpec -where - GenesisConfig: RuntimeGenesis + 'static, - Extensions: GetExtension + Serialize + Clone + Send + Sync + 'static, -{ - fn name(&self) -> &str { - self.chain_spec.name() - } - - fn id(&self) -> &str { - self.chain_spec.id() - } - - fn chain_type(&self) -> ChainType { - ChainSpec::chain_type(&self.chain_spec) - } - - fn boot_nodes(&self) -> &[MultiaddrWithPeerId] { - self.chain_spec.boot_nodes() - } - - fn telemetry_endpoints(&self) -> &Option { - self.chain_spec.telemetry_endpoints() - } - - fn protocol_id(&self) -> Option<&str> { - self.chain_spec.protocol_id() - } - - fn fork_id(&self) -> Option<&str> { - self.chain_spec.fork_id() - } - - fn properties(&self) -> Properties { - self.chain_spec.properties() - } - - fn extensions(&self) -> &dyn GetExtension { - self.chain_spec.extensions() - } - - fn extensions_mut(&mut self) -> &mut dyn GetExtension { - self.chain_spec.extensions_mut() - } - - fn add_boot_node(&mut self, addr: MultiaddrWithPeerId) { - self.chain_spec.add_boot_node(addr) - } - - fn as_json(&self, raw: bool) -> Result { - self.chain_spec.as_json(raw) - } - - fn as_storage_builder(&self) -> &dyn BuildStorage { - self.chain_spec.as_storage_builder() - } - - fn cloned_box(&self) -> Box { - self.chain_spec.cloned_box() - } - - fn set_storage(&mut self, storage: Storage) { - self.chain_spec.set_storage(storage) - } - - fn code_substitutes(&self) -> BTreeMap> { - self.chain_spec.code_substitutes() - } -} - -impl SerializableChainSpec -where - GenesisConfig: RuntimeGenesis + 'static, - Extensions: GetExtension + Serialize + Clone + Send + Sync + 'static, -{ - /// A list of bootnode addresses. - pub fn boot_nodes(&self) -> &[MultiaddrWithPeerId] { - self.chain_spec.boot_nodes() - } - - /// Spec name. - pub fn name(&self) -> &str { - self.chain_spec.name() - } - - /// Spec id. - pub fn id(&self) -> &str { - self.chain_spec.id() - } - - /// Telemetry endpoints (if any) - pub fn telemetry_endpoints(&self) -> &Option { - self.chain_spec.telemetry_endpoints() - } - - /// Network protocol id. - pub fn protocol_id(&self) -> Option<&str> { - self.chain_spec.protocol_id() - } - - /// Optional network fork identifier. - pub fn fork_id(&self) -> Option<&str> { - self.chain_spec.fork_id() - } - - /// Additional loosly-typed properties of the chain. - /// - /// Returns an empty JSON object if 'properties' not defined in config - pub fn properties(&self) -> Properties { - self.chain_spec.properties() - } - - /// Add a bootnode to the list. - pub fn add_boot_node(&mut self, addr: MultiaddrWithPeerId) { - self.chain_spec.add_boot_node(addr) - } - - /// Returns a reference to the defined chain spec extensions. - pub fn extensions(&self) -> &Extensions { - self.chain_spec.extensions() - } - - /// Returns a mutable reference to the defined chain spec extensions. - pub fn extensions_mut(&mut self) -> &mut Extensions { - self.chain_spec.extensions_mut() - } - - /// Create hardcoded spec. - #[allow(clippy::too_many_arguments)] - pub fn from_genesis GenesisConfig + 'static + Send + Sync>( - name: &str, - id: &str, - chain_type: ChainType, - constructor: F, - boot_nodes: Vec, - telemetry_endpoints: Option, - protocol_id: Option<&str>, - fork_id: Option<&str>, - properties: Option, - extensions: Extensions, - ) -> Self { - Self { - chain_spec: GenericChainSpec::from_genesis( - name, - id, - chain_type, - constructor, - boot_nodes, - telemetry_endpoints, - protocol_id, - fork_id, - properties, - extensions, - ), - } - } -} - -impl SerializableChainSpec -where - Extensions: de::DeserializeOwned, -{ - /// Parse json content into a `ChainSpec` - pub fn from_json_bytes(json: impl Into>) -> Result { - GenericChainSpec::from_json_bytes(json).map(|chain_spec| Self { chain_spec }) - } - - /// Parse json file into a `ChainSpec` - pub fn from_json_file(path: PathBuf) -> Result { - GenericChainSpec::from_json_file(path).map(|chain_spec| Self { chain_spec }) - } -} diff --git a/crates/subspace-node/src/lib.rs b/crates/subspace-node/src/lib.rs index 1c714102c8..e076837896 100644 --- a/crates/subspace-node/src/lib.rs +++ b/crates/subspace-node/src/lib.rs @@ -21,14 +21,13 @@ mod chain_spec_utils; mod import_blocks_from_dsn; mod secondary_chain; -pub use crate::chain_spec::{ChainSpecExtensions, ConsensusChainSpec}; pub use crate::import_blocks_from_dsn::ImportBlocksFromDsnCmd; -pub use crate::secondary_chain::chain_spec::ExecutionChainSpec; pub use crate::secondary_chain::cli::SecondaryChainCli; use clap::Parser; use sc_cli::{RunCmd, SubstrateCli}; use sc_executor::{NativeExecutionDispatch, RuntimeVersion}; use sc_service::ChainSpec; +use sc_subspace_chain_specs::ConsensusChainSpec; use sc_telemetry::serde_json; use std::io::Write; use std::{fs, io}; diff --git a/crates/subspace-node/src/secondary_chain/chain_spec.rs b/crates/subspace-node/src/secondary_chain/chain_spec.rs index cd503ec306..c91478ad9a 100644 --- a/crates/subspace-node/src/secondary_chain/chain_spec.rs +++ b/crates/subspace-node/src/secondary_chain/chain_spec.rs @@ -16,18 +16,14 @@ //! Secondary chain configurations. -use crate::chain_spec_utils::{ - chain_spec_properties, get_account_id_from_seed, SerializableChainSpec, -}; -use cirrus_runtime::AccountId; +use crate::chain_spec_utils::{chain_spec_properties, get_account_id_from_seed}; +use cirrus_runtime::{AccountId, BalancesConfig, GenesisConfig, SystemConfig, WASM_BINARY}; use sc_service::ChainType; +use sc_subspace_chain_specs::ExecutionChainSpec; use sp_core::crypto::Ss58Codec; use subspace_runtime_primitives::SSC; -/// Specialized `ChainSpec` for the normal parachain runtime. -pub type ExecutionChainSpec = SerializableChainSpec; - -pub fn development_config() -> ExecutionChainSpec { +pub fn development_config() -> ExecutionChainSpec { ExecutionChainSpec::from_genesis( // Name "Development", @@ -51,7 +47,7 @@ pub fn development_config() -> ExecutionChainSpec { ) } -pub fn local_testnet_config() -> ExecutionChainSpec { +pub fn local_testnet_config() -> ExecutionChainSpec { ExecutionChainSpec::from_genesis( // Name "Local Testnet", @@ -88,7 +84,7 @@ pub fn local_testnet_config() -> ExecutionChainSpec { ) } -pub fn gemini_config() -> ExecutionChainSpec { +pub fn gemini_config() -> ExecutionChainSpec { ExecutionChainSpec::from_genesis( // Name "Subspace Gemini 1 Execution", @@ -116,15 +112,15 @@ pub fn gemini_config() -> ExecutionChainSpec { ) } -fn testnet_genesis(endowed_accounts: Vec) -> cirrus_runtime::GenesisConfig { - cirrus_runtime::GenesisConfig { - system: cirrus_runtime::SystemConfig { - code: cirrus_runtime::WASM_BINARY +fn testnet_genesis(endowed_accounts: Vec) -> GenesisConfig { + GenesisConfig { + system: SystemConfig { + code: WASM_BINARY .expect("WASM binary was not build, please build it!") .to_vec(), }, transaction_payment: Default::default(), - balances: cirrus_runtime::BalancesConfig { + balances: BalancesConfig { balances: endowed_accounts .iter() .cloned() diff --git a/crates/subspace-node/src/secondary_chain/cli.rs b/crates/subspace-node/src/secondary_chain/cli.rs index 4065bd44f1..29d7c5a113 100644 --- a/crates/subspace-node/src/secondary_chain/cli.rs +++ b/crates/subspace-node/src/secondary_chain/cli.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::ExecutionChainSpec; +use cirrus_runtime::GenesisConfig as ExecutionGenesisConfig; use clap::Parser; use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, @@ -22,6 +22,7 @@ use sc_cli::{ }; use sc_service::config::PrometheusConfig; use sc_service::BasePath; +use sc_subspace_chain_specs::ExecutionChainSpec; use std::net::SocketAddr; use std::path::PathBuf; @@ -47,7 +48,7 @@ pub struct SecondaryChainCli { pub base_path: Option, /// Specification of the secondary chain derived from primary chain spec. - pub chain_spec: ExecutionChainSpec, + pub chain_spec: ExecutionChainSpec, } impl SecondaryChainCli { @@ -56,7 +57,7 @@ impl SecondaryChainCli { /// If no explicit base path for the secondary chain, the default value will be `primary_base_path/executor`. pub fn new<'a>( base_path: Option, - chain_spec: ExecutionChainSpec, + chain_spec: ExecutionChainSpec, secondary_chain_args: impl Iterator, ) -> Self { Self { From 6284fb0c30aa873d49a66862730fac66b42bbcac Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 1 Jun 2022 03:38:22 +0300 Subject: [PATCH 2/3] Strip more stuff to free additional space in CI --- .github/workflows/rust.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index 225a25744d..a446fc87b3 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -15,7 +15,8 @@ env: CARGO_INCREMENTAL: 0 CARGO_TERM_COLOR: always # Build smaller artifacts to avoid running out of space in CI - RUSTFLAGS: -C strip=debuginfo -C opt-level=s + # TODO: Try to remove once https://github.com/paritytech/substrate/issues/11538 is resolved + RUSTFLAGS: -C strip=symbols -C opt-level=s jobs: cargo-fmt: From 4f03bc36d19148b8a1736556051f29f2608dc9da Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 1 Jun 2022 05:52:57 +0300 Subject: [PATCH 3/3] Fix license --- crates/sc-subspace-chain-specs/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/sc-subspace-chain-specs/Cargo.toml b/crates/sc-subspace-chain-specs/Cargo.toml index 3ff7b9773f..e957ea6897 100644 --- a/crates/sc-subspace-chain-specs/Cargo.toml +++ b/crates/sc-subspace-chain-specs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "sc-subspace-chain-specs" description = "Chain specification data structures tailored for Subspace" -license = "Apache-2.0" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" version = "0.1.0" authors = ["Nazar Mokrynskyi "] edition = "2021"