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 _ => ETHEREUM_BLOCK_GAS_LIMIT_36M,
49 }
50 }
51}
52
53/// A trait that represents the configured network and can be used to apply additional configuration
54/// to the network.
55pub trait RethNetworkConfig {
56 /// Adds a new additional protocol to the `RLPx` sub-protocol list.
57 ///
58 /// These additional protocols are negotiated during the `RLPx` handshake.
59 /// If both peers share the same protocol, the corresponding handler will be included alongside
60 /// the `eth` protocol.
61 ///
62 /// See also [`ProtocolHandler`](reth_network::protocol::ProtocolHandler)
63 fn add_rlpx_sub_protocol(&mut self, protocol: impl IntoRlpxSubProtocol);
64
65 /// Returns the secret key used for authenticating sessions.
66 fn secret_key(&self) -> secp256k1::SecretKey;
67
68 // TODO add more network config methods here
69}
70
71impl<N: NetworkPrimitives> RethNetworkConfig for reth_network::NetworkManager<N> {
72 fn add_rlpx_sub_protocol(&mut self, protocol: impl IntoRlpxSubProtocol) {
73 Self::add_rlpx_sub_protocol(self, protocol);
74 }
75
76 fn secret_key(&self) -> secp256k1::SecretKey {
77 Self::secret_key(self)
78 }
79}
80
81/// A trait that provides all basic config values for the transaction pool and is implemented by the
82/// [`TxPoolArgs`](crate::args::TxPoolArgs) type.
83pub trait RethTransactionPoolConfig {
84 /// Returns transaction pool configuration.
85 fn pool_config(&self) -> PoolConfig;
86}