reth_chainspec/
api.rs

1use crate::{ChainSpec, DepositContract};
2use alloc::{boxed::Box, vec::Vec};
3use alloy_chains::Chain;
4use alloy_consensus::Header;
5use alloy_eips::eip1559::BaseFeeParams;
6use alloy_genesis::Genesis;
7use alloy_primitives::B256;
8use core::fmt::{Debug, Display};
9use reth_network_peers::NodeRecord;
10
11/// Trait representing type configuring a chain spec.
12#[auto_impl::auto_impl(&, Arc)]
13pub trait EthChainSpec: Send + Sync + Unpin + Debug {
14    // todo: make chain spec type generic over hardfork
15    //type Hardfork: Clone + Copy + 'static;
16
17    /// The header type of the network.
18    type Header;
19
20    /// Returns the [`Chain`] object this spec targets.
21    fn chain(&self) -> Chain;
22
23    /// Returns the chain id number
24    fn chain_id(&self) -> u64 {
25        self.chain().id()
26    }
27
28    /// Get the [`BaseFeeParams`] for the chain at the given block.
29    fn base_fee_params_at_block(&self, block_number: u64) -> BaseFeeParams;
30
31    /// Get the [`BaseFeeParams`] for the chain at the given timestamp.
32    fn base_fee_params_at_timestamp(&self, timestamp: u64) -> BaseFeeParams;
33
34    /// Returns the deposit contract data for the chain, if it's present
35    fn deposit_contract(&self) -> Option<&DepositContract>;
36
37    /// The genesis hash.
38    fn genesis_hash(&self) -> B256;
39
40    /// The delete limit for pruner, per run.
41    fn prune_delete_limit(&self) -> usize;
42
43    /// Returns a string representation of the hardforks.
44    fn display_hardforks(&self) -> Box<dyn Display>;
45
46    /// The genesis header.
47    fn genesis_header(&self) -> &Self::Header;
48
49    /// The genesis block specification.
50    fn genesis(&self) -> &Genesis;
51
52    /// The bootnodes for the chain, if any.
53    fn bootnodes(&self) -> Option<Vec<NodeRecord>>;
54
55    /// Returns `true` if this chain contains Optimism configuration.
56    fn is_optimism(&self) -> bool {
57        self.chain().is_optimism()
58    }
59
60    /// Returns `true` if this chain contains Ethereum configuration.
61    fn is_ethereum(&self) -> bool {
62        self.chain().is_ethereum()
63    }
64}
65
66impl EthChainSpec for ChainSpec {
67    type Header = Header;
68
69    fn chain(&self) -> Chain {
70        self.chain
71    }
72
73    fn base_fee_params_at_block(&self, block_number: u64) -> BaseFeeParams {
74        self.base_fee_params_at_block(block_number)
75    }
76
77    fn base_fee_params_at_timestamp(&self, timestamp: u64) -> BaseFeeParams {
78        self.base_fee_params_at_timestamp(timestamp)
79    }
80
81    fn deposit_contract(&self) -> Option<&DepositContract> {
82        self.deposit_contract.as_ref()
83    }
84
85    fn genesis_hash(&self) -> B256 {
86        self.genesis_hash()
87    }
88
89    fn prune_delete_limit(&self) -> usize {
90        self.prune_delete_limit
91    }
92
93    fn display_hardforks(&self) -> Box<dyn Display> {
94        Box::new(Self::display_hardforks(self))
95    }
96
97    fn genesis_header(&self) -> &Self::Header {
98        self.genesis_header()
99    }
100
101    fn genesis(&self) -> &Genesis {
102        self.genesis()
103    }
104
105    fn bootnodes(&self) -> Option<Vec<NodeRecord>> {
106        self.bootnodes()
107    }
108
109    fn is_optimism(&self) -> bool {
110        false
111    }
112}