reth_node_core/cli/config.rs
1//! Config traits for various node components.
2
3use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT_36M;
4use alloy_primitives::Bytes;
5use reth_chainspec::{Chain, ChainKind, NamedChain};
6use reth_network::{protocol::IntoRlpxSubProtocol, NetworkPrimitives};
7use reth_transaction_pool::PoolConfig;
8use std::{borrow::Cow, time::Duration};
9
10/// 60M gas limit
11const ETHEREUM_BLOCK_GAS_LIMIT_60M: u64 = 60_000_000;
12
13/// A trait that provides payload builder settings.
14///
15/// This provides all basic payload builder settings and is implemented by the
16/// [`PayloadBuilderArgs`](crate::args::PayloadBuilderArgs) type.
17pub trait PayloadBuilderConfig {
18 /// Block extra data set by the payload builder.
19 fn extra_data(&self) -> Cow<'_, str>;
20
21 /// Returns the extra data as bytes.
22 fn extra_data_bytes(&self) -> Bytes {
23 self.extra_data().as_bytes().to_vec().into()
24 }
25
26 /// The interval at which the job should build a new payload after the last.
27 fn interval(&self) -> Duration;
28
29 /// The deadline for when the payload builder job should resolve.
30 fn deadline(&self) -> Duration;
31
32 /// Target gas limit for built blocks.
33 fn gas_limit(&self) -> Option<u64>;
34
35 /// Maximum number of tasks to spawn for building a payload.
36 fn max_payload_tasks(&self) -> usize;
37
38 /// Maximum number of blobs to include per block (EIP-7872).
39 ///
40 /// If `None`, defaults to the protocol maximum.
41 fn max_blobs_per_block(&self) -> Option<u64>;
42
43 /// Returns the configured gas limit if set, or a chain-specific default.
44 fn gas_limit_for(&self, chain: Chain) -> u64 {
45 if let Some(limit) = self.gas_limit() {
46 return limit;
47 }
48
49 match chain.kind() {
50 ChainKind::Named(
51 NamedChain::Mainnet | NamedChain::Sepolia | NamedChain::Holesky | NamedChain::Hoodi,
52 ) => ETHEREUM_BLOCK_GAS_LIMIT_60M,
53 _ => ETHEREUM_BLOCK_GAS_LIMIT_36M,
54 }
55 }
56}
57
58/// A trait that represents the configured network and can be used to apply additional configuration
59/// to the network.
60pub trait RethNetworkConfig {
61 /// Adds a new additional protocol to the `RLPx` sub-protocol list.
62 ///
63 /// These additional protocols are negotiated during the `RLPx` handshake.
64 /// If both peers share the same protocol, the corresponding handler will be included alongside
65 /// the `eth` protocol.
66 ///
67 /// See also [`ProtocolHandler`](reth_network::protocol::ProtocolHandler)
68 fn add_rlpx_sub_protocol(&mut self, protocol: impl IntoRlpxSubProtocol);
69
70 /// Returns the secret key used for authenticating sessions.
71 fn secret_key(&self) -> secp256k1::SecretKey;
72
73 // TODO add more network config methods here
74}
75
76impl<N: NetworkPrimitives> RethNetworkConfig for reth_network::NetworkManager<N> {
77 fn add_rlpx_sub_protocol(&mut self, protocol: impl IntoRlpxSubProtocol) {
78 Self::add_rlpx_sub_protocol(self, protocol);
79 }
80
81 fn secret_key(&self) -> secp256k1::SecretKey {
82 Self::secret_key(self)
83 }
84}
85
86/// A trait that provides all basic config values for the transaction pool and is implemented by the
87/// [`TxPoolArgs`](crate::args::TxPoolArgs) type.
88pub trait RethTransactionPoolConfig {
89 /// Returns transaction pool configuration.
90 fn pool_config(&self) -> PoolConfig;
91
92 /// Returns max batch size for transaction batch insertion.
93 fn max_batch_size(&self) -> usize;
94}