mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: remove serde from ChainSpec (#9017)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -6479,7 +6479,6 @@ dependencies = [
|
||||
"reth-primitives-traits",
|
||||
"reth-rpc-types",
|
||||
"reth-trie-common",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
|
||||
@ -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::{
|
||||
@ -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>,
|
||||
|
||||
@ -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},
|
||||
@ -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>,
|
||||
|
||||
|
||||
@ -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;
|
||||
@ -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>,
|
||||
}
|
||||
|
||||
@ -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,
|
||||
};
|
||||
@ -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>,
|
||||
|
||||
@ -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,
|
||||
@ -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>,
|
||||
|
||||
|
||||
@ -26,7 +26,6 @@ alloy-trie.workspace = true
|
||||
|
||||
# misc
|
||||
once_cell.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
derive_more.workspace = true
|
||||
|
||||
|
||||
@ -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};
|
||||
|
||||
@ -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),
|
||||
@ -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.
|
||||
@ -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,
|
||||
@ -333,7 +331,6 @@ 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
|
||||
@ -341,14 +338,12 @@ pub struct ChainSpec {
|
||||
|
||||
/// 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
|
||||
@ -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,
|
||||
}
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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(),
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user