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