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 /// Returns the configured gas limit if set, or a chain-specific default.
39 fn gas_limit_for(&self, chain: Chain) -> u64 {
40 if let Some(limit) = self.gas_limit() {
41 return limit;
42 }
43
44 match chain.kind() {
45 ChainKind::Named(NamedChain::Sepolia | NamedChain::Holesky | NamedChain::Hoodi) => {
46 ETHEREUM_BLOCK_GAS_LIMIT_60M
47 }
48 ChainKind::Named(NamedChain::Mainnet) => ETHEREUM_BLOCK_GAS_LIMIT_60M,
49 _ => ETHEREUM_BLOCK_GAS_LIMIT_36M,
50 }
51 }
52}
53
54/// A trait that represents the configured network and can be used to apply additional configuration
55/// to the network.
56pub trait RethNetworkConfig {
57 /// Adds a new additional protocol to the `RLPx` sub-protocol list.
58 ///
59 /// These additional protocols are negotiated during the `RLPx` handshake.
60 /// If both peers share the same protocol, the corresponding handler will be included alongside
61 /// the `eth` protocol.
62 ///
63 /// See also [`ProtocolHandler`](reth_network::protocol::ProtocolHandler)
64 fn add_rlpx_sub_protocol(&mut self, protocol: impl IntoRlpxSubProtocol);
65
66 /// Returns the secret key used for authenticating sessions.
67 fn secret_key(&self) -> secp256k1::SecretKey;
68
69 // TODO add more network config methods here
70}
71
72impl<N: NetworkPrimitives> RethNetworkConfig for reth_network::NetworkManager<N> {
73 fn add_rlpx_sub_protocol(&mut self, protocol: impl IntoRlpxSubProtocol) {
74 Self::add_rlpx_sub_protocol(self, protocol);
75 }
76
77 fn secret_key(&self) -> secp256k1::SecretKey {
78 Self::secret_key(self)
79 }
80}
81
82/// A trait that provides all basic config values for the transaction pool and is implemented by the
83/// [`TxPoolArgs`](crate::args::TxPoolArgs) type.
84pub trait RethTransactionPoolConfig {
85 /// Returns transaction pool configuration.
86 fn pool_config(&self) -> PoolConfig;
87
88 /// Returns max batch size for transaction batch insertion.
89 fn max_batch_size(&self) -> usize;
90}