Skip to content

Commit

Permalink
Merge pull request #1858 from subspace/cli-genesis-config
Browse files Browse the repository at this point in the history
Add cli command to load genesis config of the evm domain in json format
  • Loading branch information
NingLin-P authored Aug 23, 2023
2 parents 9c60640 + d60b748 commit 4c30760
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions crates/subspace-node/src/bin/subspace-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ fn main() -> Result<(), Error> {
}
})?;
}
DomainSubcommand::BuildGenesisConfig(cmd) => cmd.run()?,
_ => unimplemented!("Domain subcommand"),
},
None => {
Expand Down
54 changes: 53 additions & 1 deletion crates/subspace-node/src/domain/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::domain::evm_chain_spec;
use crate::domain::evm_chain_spec::{self, SpecId};
use clap::Parser;
use domain_service::DomainConfiguration;
use sc_cli::{
Expand All @@ -27,6 +27,7 @@ use sc_service::BasePath;
use sp_core::crypto::AccountId32;
use sp_domains::DomainId;
use sp_runtime::traits::Convert;
use std::io::Write;
use std::net::SocketAddr;
use std::num::ParseIntError;
use std::path::PathBuf;
Expand All @@ -45,6 +46,9 @@ pub enum Subcommand {
/// Sub-commands concerned with benchmarking.
#[clap(subcommand)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),

/// Build the genesis config of the evm domain chain in json format
BuildGenesisConfig(BuildGenesisConfigCmd),
}

fn parse_domain_id(s: &str) -> std::result::Result<DomainId, ParseIntError> {
Expand Down Expand Up @@ -316,3 +320,51 @@ impl CliConfiguration<Self> for DomainCli {
self.run.telemetry_endpoints(chain_spec)
}
}

// TODO: make the command generic over different runtime type instead of just the evm domain runtime
/// The `build-genesis-config` command used to build the genesis config of the evm domain chain.
#[derive(Debug, Clone, Parser)]
pub struct BuildGenesisConfigCmd {
/// Whether output the WASM runtime code
#[arg(long, default_value_t = false)]
pub with_wasm_code: bool,

/// The base struct of the build-genesis-config command.
#[clap(flatten)]
pub shared_params: SharedParams,
}

impl BuildGenesisConfigCmd {
/// Run the build-genesis-config command
pub fn run(&self) -> sc_cli::Result<()> {
let is_dev = self.shared_params.is_dev();
let chain_id = self.shared_params.chain_id(is_dev);
let mut domain_genesis_config = match chain_id.as_str() {
"gemini-3f" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::Gemini).0,
"devnet" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::DevNet).0,
"dev" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::Dev).0,
"" | "local" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::Local).0,
unknown_id => {
eprintln!(
"unknown chain {unknown_id:?}, expected gemini-3f, devnet, dev, or local",
);
return Ok(());
}
};

if !self.with_wasm_code {
// Clear the WASM code of the genesis config
domain_genesis_config.system.code = Default::default();
}
let raw_domain_genesis_config = serde_json::to_vec(&domain_genesis_config)
.expect("Genesis config serialization never fails; qed");

if std::io::stdout()
.write_all(raw_domain_genesis_config.as_ref())
.is_err()
{
let _ = std::io::stderr().write_all(b"Error writing to stdout\n");
}
Ok(())
}
}
1 change: 0 additions & 1 deletion crates/subspace-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ sp-session = { version = "4.0.0-dev", default-features = false, git = "https://g
sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
sp-version = { version = "22.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
static_assertions = "1.1.0"
subspace-core-primitives = { version = "0.1.0", default-features = false, path = "../subspace-core-primitives" }
subspace-runtime-primitives = { version = "0.1.0", default-features = false, path = "../subspace-runtime-primitives" }
subspace-verification = { version = "0.1.0", default-features = false, path = "../subspace-verification" }
Expand Down

0 comments on commit 4c30760

Please sign in to comment.