Skip to content

Commit

Permalink
chore: remove serde from ChainSpec (#9017)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo authored Jun 21, 2024
1 parent b9b61b3 commit 2473ed8
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 25 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.

4 changes: 2 additions & 2 deletions bin/reth/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::{
args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
utils::{chain_help, chain_value_parser, SUPPORTED_CHAINS},
LogArgs,
},
commands::{
Expand Down Expand Up @@ -46,7 +46,7 @@ pub struct Cli<Ext: clap::Args + fmt::Debug = NoArgs> {
value_name = "CHAIN_OR_PATH",
long_help = chain_help(),
default_value = SUPPORTED_CHAINS[0],
value_parser = genesis_value_parser,
value_parser = chain_value_parser,
global = true,
)]
chain: Arc<ChainSpec>,
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/commands/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_downloaders::{bodies::noop::NoopBodiesDownloader, headers::noop::NoopHe
use reth_evm::noop::NoopBlockExecutorProvider;
use reth_node_core::{
args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
utils::{chain_help, chain_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, DatadirArgs,
},
dirs::{ChainPath, DataDirPath},
Expand Down Expand Up @@ -42,7 +42,7 @@ pub struct EnvironmentArgs {
value_name = "CHAIN_OR_PATH",
long_help = chain_help(),
default_value = SUPPORTED_CHAINS[0],
value_parser = genesis_value_parser
value_parser = chain_value_parser
)]
pub chain: Arc<ChainSpec>,

Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/commands/dump_genesis.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Command that dumps genesis block JSON configuration to stdout
use crate::args::utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS};
use crate::args::utils::{chain_help, chain_value_parser, SUPPORTED_CHAINS};
use clap::Parser;
use reth_chainspec::ChainSpec;
use std::sync::Arc;
Expand All @@ -15,7 +15,7 @@ pub struct DumpGenesisCommand {
value_name = "CHAIN_OR_PATH",
long_help = chain_help(),
default_value = SUPPORTED_CHAINS[0],
value_parser = genesis_value_parser
value_parser = chain_value_parser
)]
chain: Arc<ChainSpec>,
}
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/commands/node/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Main node command for launching a node
use crate::args::{
utils::{chain_help, genesis_value_parser, parse_socket_address, SUPPORTED_CHAINS},
utils::{chain_help, chain_value_parser, parse_socket_address, SUPPORTED_CHAINS},
DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, PruningArgs,
RpcServerArgs, TxPoolArgs,
};
Expand Down Expand Up @@ -29,7 +29,7 @@ pub struct NodeCommand<Ext: clap::Args + fmt::Debug = NoArgs> {
long_help = chain_help(),
default_value = SUPPORTED_CHAINS[0],
default_value_if("dev", "true", "dev"),
value_parser = genesis_value_parser,
value_parser = chain_value_parser,
required = false,
)]
pub chain: Arc<ChainSpec>,
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/commands/p2p/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
args::{
get_secret_key,
utils::{chain_help, genesis_value_parser, hash_or_num_value_parser, SUPPORTED_CHAINS},
utils::{chain_help, chain_value_parser, hash_or_num_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, DiscoveryArgs, NetworkArgs,
},
utils::get_single_header,
Expand Down Expand Up @@ -40,7 +40,7 @@ pub struct Command {
value_name = "CHAIN_OR_PATH",
long_help = chain_help(),
default_value = SUPPORTED_CHAINS[0],
value_parser = genesis_value_parser
value_parser = chain_value_parser
)]
chain: Arc<ChainSpec>,

Expand Down
1 change: 0 additions & 1 deletion crates/chainspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ alloy-trie.workspace = true

# misc
once_cell.workspace = true
serde.workspace = true
serde_json.workspace = true
derive_more.workspace = true

Expand Down
12 changes: 3 additions & 9 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use reth_primitives_traits::{
Header, SealedHeader,
};
use reth_trie_common::root::state_root_ref_unhashed;
use serde::{Deserialize, Serialize};
#[cfg(feature = "std")]
use std::{collections::BTreeMap, sync::Arc};

Expand Down Expand Up @@ -290,8 +289,7 @@ pub static BASE_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {

/// A wrapper around [`BaseFeeParams`] that allows for specifying constant or dynamic EIP-1559
/// parameters based on the active [Hardfork].
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(untagged)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum BaseFeeParamsKind {
/// Constant [`BaseFeeParams`]; used for chains that don't have dynamic EIP-1559 parameters
Constant(BaseFeeParams),
Expand All @@ -314,7 +312,7 @@ impl From<ForkBaseFeeParams> for BaseFeeParamsKind {

/// A type alias to a vector of tuples of [Hardfork] and [`BaseFeeParams`], sorted by [Hardfork]
/// activation order. This is used to specify dynamic EIP-1559 parameters for chains like Optimism.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, From)]
#[derive(Clone, Debug, PartialEq, Eq, From)]
pub struct ForkBaseFeeParams(Vec<(Hardfork, BaseFeeParams)>);

/// An Ethereum chain specification.
Expand All @@ -324,7 +322,7 @@ pub struct ForkBaseFeeParams(Vec<(Hardfork, BaseFeeParams)>);
/// - Meta-information about the chain (the chain ID)
/// - The genesis block of the chain ([`Genesis`])
/// - What hardforks are activated, and under which conditions
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ChainSpec {
/// The chain ID
pub chain: Chain,
Expand All @@ -333,22 +331,19 @@ pub struct ChainSpec {
///
/// This acts as a small cache for known chains. If the chain is known, then the genesis hash
/// is also known ahead of time, and this will be `Some`.
#[serde(skip, default)]
pub genesis_hash: Option<B256>,

/// The genesis block
pub genesis: Genesis,

/// The block at which [`Hardfork::Paris`] was activated and the final difficulty at this
/// block.
#[serde(skip, default)]
pub paris_block_and_final_difficulty: Option<(u64, U256)>,

/// The active hard forks and their activation conditions
pub hardforks: BTreeMap<Hardfork, ForkCondition>,

/// The deposit contract deployed for `PoS`
#[serde(skip, default)]
pub deposit_contract: Option<DepositContract>,

/// The parameters that configure how a block's base fee is computed
Expand All @@ -357,7 +352,6 @@ pub struct ChainSpec {
/// The delete limit for pruner, per block. In the actual pruner run it will be multiplied by
/// the amount of blocks between pruner runs to account for the difference in amount of new
/// data coming in.
#[serde(default)]
pub prune_delete_limit: usize,
}

Expand Down
1 change: 1 addition & 0 deletions crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pub struct NetworkConfigBuilder {
/// How to configure the sessions manager
sessions_config: Option<SessionsConfig>,
/// The network's chain spec
#[serde(skip)]
chain_spec: Arc<ChainSpec>,
/// The default mode of the network.
network_mode: NetworkMode,
Expand Down
7 changes: 3 additions & 4 deletions crates/node-core/src/args/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ pub fn chain_help() -> String {
/// Clap value parser for [`ChainSpec`]s.
///
/// The value parser matches either a known chain, the path
/// to a json file, or a json formatted string in-memory. The json can be either
/// a serialized [`ChainSpec`] or Genesis struct.
pub fn genesis_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error> {
/// to a json file, or a json formatted string in-memory. The json needs to be a Genesis struct.
pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error> {
Ok(match s {
#[cfg(not(feature = "optimism"))]
"mainnet" => MAINNET.clone(),
Expand Down Expand Up @@ -146,7 +145,7 @@ mod tests {
#[test]
fn parse_known_chain_spec() {
for chain in SUPPORTED_CHAINS {
genesis_value_parser(chain).unwrap();
chain_value_parser(chain).unwrap();
}
}

Expand Down

0 comments on commit 2473ed8

Please sign in to comment.