reth_rpc_eth_types/builder/
config.rs1use std::time::Duration;
4
5use crate::{
6 EthStateCacheConfig, FeeHistoryCacheConfig, ForwardConfig, GasPriceOracleConfig,
7 RPC_DEFAULT_GAS_CAP,
8};
9use reqwest::Url;
10use reth_rpc_server_types::constants::{
11 default_max_tracing_requests, DEFAULT_ETH_PROOF_WINDOW, DEFAULT_MAX_BLOCKING_IO_REQUEST,
12 DEFAULT_MAX_BLOCKS_PER_FILTER, DEFAULT_MAX_LOGS_PER_RESPONSE, DEFAULT_MAX_SIMULATE_BLOCKS,
13 DEFAULT_MAX_TRACE_FILTER_BLOCKS, DEFAULT_PROOF_PERMITS,
14 RPC_DEFAULT_SEND_RAW_TX_SYNC_TIMEOUT_SECS,
15};
16use serde::{Deserialize, Serialize};
17
18pub const DEFAULT_STALE_FILTER_TTL: Duration = Duration::from_secs(5 * 60);
20
21#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Default)]
23#[serde(rename_all = "lowercase")]
24pub enum PendingBlockKind {
25 Empty,
27 None,
29 #[default]
31 Full,
32}
33
34impl std::str::FromStr for PendingBlockKind {
35 type Err = String;
36
37 fn from_str(s: &str) -> Result<Self, Self::Err> {
38 match s.to_lowercase().as_str() {
39 "empty" => Ok(Self::Empty),
40 "none" => Ok(Self::None),
41 "full" => Ok(Self::Full),
42 _ => Err(format!(
43 "Invalid pending block kind: {s}. Valid options are: empty, none, full"
44 )),
45 }
46 }
47}
48
49impl PendingBlockKind {
50 pub const fn is_none(&self) -> bool {
52 matches!(self, Self::None)
53 }
54
55 pub const fn is_empty(&self) -> bool {
57 matches!(self, Self::Empty)
58 }
59}
60
61#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
63pub struct EthConfig {
64 pub cache: EthStateCacheConfig,
66 pub gas_oracle: GasPriceOracleConfig,
68 pub eth_proof_window: u64,
70 pub max_tracing_requests: usize,
72 pub max_blocking_io_requests: usize,
81 pub max_trace_filter_blocks: u64,
83 pub max_blocks_per_filter: u64,
85 pub max_logs_per_response: usize,
87 pub rpc_gas_cap: u64,
91 pub rpc_max_simulate_blocks: u64,
93 pub compute_state_root_for_eth_simulate: bool,
95 pub stale_filter_ttl: Duration,
98 pub fee_history_cache: FeeHistoryCacheConfig,
100 pub proof_permits: usize,
102 pub max_batch_size: usize,
104 pub pending_block_kind: PendingBlockKind,
106 pub raw_tx_forwarder: ForwardConfig,
108 pub send_raw_transaction_sync_timeout: Duration,
110 pub rpc_evm_memory_limit: u64,
112 pub force_blob_sidecar_upcasting: bool,
117}
118
119impl EthConfig {
120 pub fn filter_config(&self) -> EthFilterConfig {
122 EthFilterConfig::default()
123 .max_blocks_per_filter(self.max_blocks_per_filter)
124 .max_logs_per_response(self.max_logs_per_response)
125 .stale_filter_ttl(self.stale_filter_ttl)
126 }
127}
128
129impl Default for EthConfig {
130 fn default() -> Self {
131 Self {
132 cache: EthStateCacheConfig::default(),
133 gas_oracle: GasPriceOracleConfig::default(),
134 eth_proof_window: DEFAULT_ETH_PROOF_WINDOW,
135 max_tracing_requests: default_max_tracing_requests(),
136 max_blocking_io_requests: DEFAULT_MAX_BLOCKING_IO_REQUEST,
137 max_trace_filter_blocks: DEFAULT_MAX_TRACE_FILTER_BLOCKS,
138 max_blocks_per_filter: DEFAULT_MAX_BLOCKS_PER_FILTER,
139 max_logs_per_response: DEFAULT_MAX_LOGS_PER_RESPONSE,
140 rpc_gas_cap: RPC_DEFAULT_GAS_CAP.into(),
141 rpc_max_simulate_blocks: DEFAULT_MAX_SIMULATE_BLOCKS,
142 compute_state_root_for_eth_simulate: false,
143 stale_filter_ttl: DEFAULT_STALE_FILTER_TTL,
144 fee_history_cache: FeeHistoryCacheConfig::default(),
145 proof_permits: DEFAULT_PROOF_PERMITS,
146 max_batch_size: 1,
147 pending_block_kind: PendingBlockKind::Full,
148 raw_tx_forwarder: ForwardConfig::default(),
149 send_raw_transaction_sync_timeout: RPC_DEFAULT_SEND_RAW_TX_SYNC_TIMEOUT_SECS,
150 rpc_evm_memory_limit: (1 << 32) - 1,
151 force_blob_sidecar_upcasting: false,
152 }
153 }
154}
155
156impl EthConfig {
157 pub const fn state_cache(mut self, cache: EthStateCacheConfig) -> Self {
159 self.cache = cache;
160 self
161 }
162
163 pub const fn gpo_config(mut self, gas_oracle_config: GasPriceOracleConfig) -> Self {
165 self.gas_oracle = gas_oracle_config;
166 self
167 }
168
169 pub const fn max_tracing_requests(mut self, max_requests: usize) -> Self {
171 self.max_tracing_requests = max_requests;
172 self
173 }
174
175 pub const fn max_blocking_io_requests(mut self, max_requests: usize) -> Self {
177 self.max_blocking_io_requests = max_requests;
178 self
179 }
180
181 pub const fn max_blocks_per_filter(mut self, max_blocks: u64) -> Self {
183 self.max_blocks_per_filter = max_blocks;
184 self
185 }
186
187 pub const fn max_trace_filter_blocks(mut self, max_blocks: u64) -> Self {
189 self.max_trace_filter_blocks = max_blocks;
190 self
191 }
192
193 pub const fn max_logs_per_response(mut self, max_logs: usize) -> Self {
195 self.max_logs_per_response = max_logs;
196 self
197 }
198
199 pub const fn rpc_gas_cap(mut self, rpc_gas_cap: u64) -> Self {
201 self.rpc_gas_cap = rpc_gas_cap;
202 self
203 }
204
205 pub const fn rpc_max_simulate_blocks(mut self, max_blocks: u64) -> Self {
207 self.rpc_max_simulate_blocks = max_blocks;
208 self
209 }
210
211 pub const fn compute_state_root_for_eth_simulate(mut self, enabled: bool) -> Self {
213 self.compute_state_root_for_eth_simulate = enabled;
214 self
215 }
216
217 pub const fn eth_proof_window(mut self, window: u64) -> Self {
219 self.eth_proof_window = window;
220 self
221 }
222
223 pub const fn proof_permits(mut self, permits: usize) -> Self {
225 self.proof_permits = permits;
226 self
227 }
228
229 pub const fn max_batch_size(mut self, max_batch_size: usize) -> Self {
231 self.max_batch_size = max_batch_size;
232 self
233 }
234
235 pub const fn pending_block_kind(mut self, pending_block_kind: PendingBlockKind) -> Self {
237 self.pending_block_kind = pending_block_kind;
238 self
239 }
240
241 pub fn raw_tx_forwarder(mut self, tx_forwarder: Option<Url>) -> Self {
243 if let Some(tx_forwarder) = tx_forwarder {
244 self.raw_tx_forwarder.tx_forwarder = Some(tx_forwarder);
245 }
246 self
247 }
248
249 pub const fn send_raw_transaction_sync_timeout(mut self, timeout: Duration) -> Self {
251 self.send_raw_transaction_sync_timeout = timeout;
252 self
253 }
254
255 pub const fn rpc_evm_memory_limit(mut self, memory_limit: u64) -> Self {
257 self.rpc_evm_memory_limit = memory_limit;
258 self
259 }
260
261 pub const fn force_blob_sidecar_upcasting(mut self, force: bool) -> Self {
263 self.force_blob_sidecar_upcasting = force;
264 self
265 }
266}
267
268#[derive(Debug, Clone, PartialEq, Eq)]
270pub struct EthFilterConfig {
271 pub max_blocks_per_filter: Option<u64>,
275 pub max_logs_per_response: Option<usize>,
279 pub stale_filter_ttl: Duration,
284}
285
286impl EthFilterConfig {
287 pub const fn max_blocks_per_filter(mut self, num: u64) -> Self {
289 self.max_blocks_per_filter = Some(num);
290 self
291 }
292
293 pub const fn max_logs_per_response(mut self, num: usize) -> Self {
296 self.max_logs_per_response = Some(num);
297 self
298 }
299
300 pub const fn stale_filter_ttl(mut self, duration: Duration) -> Self {
302 self.stale_filter_ttl = duration;
303 self
304 }
305}
306
307impl Default for EthFilterConfig {
308 fn default() -> Self {
309 Self {
310 max_blocks_per_filter: None,
311 max_logs_per_response: None,
312 stale_filter_ttl: DEFAULT_STALE_FILTER_TTL,
314 }
315 }
316}