Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add dumpgenesis subcommand #6797

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion bin/reth/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::{
},
cli::ext::RethCliExt,
commands::{
config_cmd, db, debug_cmd, import, init_cmd, node, p2p, recover, stage, test_vectors,
config_cmd, db, debug_cmd, dump_genesis, import, init_cmd, node, p2p, recover, stage,
test_vectors,
},
core::cli::runner::CliRunner,
version::{LONG_VERSION, SHORT_VERSION},
Expand Down Expand Up @@ -81,6 +82,7 @@ impl<Ext: RethCliExt> Cli<Ext> {
Commands::Node(command) => runner.run_command_until_exit(|ctx| command.execute(ctx)),
Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Import(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::DumpGenesis(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Db(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Stage(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::P2P(command) => runner.run_until_ctrl_c(command.execute()),
Expand Down Expand Up @@ -128,6 +130,9 @@ pub enum Commands<Ext: RethCliExt = ()> {
/// This syncs RLP encoded blocks from a file.
#[command(name = "import")]
Import(import::ImportCommand),
/// Dumps genesis block JSON configuration to stdout.
#[command(name = "dumpgenesis")]
DumpGenesis(dump_genesis::DumpGenesisCommand),
/// Database debugging utilities
#[command(name = "db")]
Db(db::Command),
Expand Down
57 changes: 57 additions & 0 deletions bin/reth/src/commands/dump_genesis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! Command that dumps genesis block JSON configuration to stdout

use crate::args::utils;
use clap::Parser;
use reth_primitives::ChainSpec;
use std::sync::Arc;

/// Dumps genesis block JSON configuration to stdout, test(todo!(abner))
#[derive(Debug, Parser)]
pub struct DumpGenesisCommand {
/// Görli network: pre-configured proof-of-authority test network
#[arg(long, verbatim_doc_comment)]
goerli: bool,

/// Ethereum mainnet
#[arg(long, verbatim_doc_comment)]
mainnet: bool,

/// Holesky network: pre-configured proof-of-stake test network
#[arg(long, verbatim_doc_comment)]
holesky: bool,

/// Sepolia network: pre-configured proof-of-work test network
#[arg(long, verbatim_doc_comment)]
sepolia: bool,
AbnerZheng marked this conversation as resolved.
Show resolved Hide resolved

/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
#[arg(
long,
value_name = "CHAIN_OR_PATH",
long_help = chain_help(),
default_value = SUPPORTED_CHAINS[0],
value_parser = genesis_value_parser
onbjerg marked this conversation as resolved.
Show resolved Hide resolved
)]
chain: Arc<ChainSpec>,
}

impl DumpGenesisCommand {
/// Execute the `dumpgenesis` command
pub async fn execute(self) -> eyre::Result<()> {
let genesis = if self.mainnet {
reth_primitives::MAINNET.genesis()
} else if self.holesky {
reth_primitives::HOLESKY.genesis()
} else if self.sepolia {
reth_primitives::SEPOLIA.genesis()
} else if self.goerli {
reth_primitives::GOERLI.genesis()
} else {
self.chain.genesis()
};
println!("{}", serde_json::to_string_pretty(genesis)?);
Ok(())
}
}
2 changes: 2 additions & 0 deletions bin/reth/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
pub mod config_cmd;
pub mod db;
pub mod debug_cmd;
pub mod dump_genesis;
pub mod import;
pub mod init_cmd;

pub mod node;
pub mod p2p;
pub mod recover;
Expand Down
Loading