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_BLOCKS_PER_FILTER,
12 DEFAULT_MAX_LOGS_PER_RESPONSE, DEFAULT_MAX_SIMULATE_BLOCKS, DEFAULT_MAX_TRACE_FILTER_BLOCKS,
13 DEFAULT_PROOF_PERMITS, RPC_DEFAULT_SEND_RAW_TX_SYNC_TIMEOUT_SECS,
14};
15use serde::{Deserialize, Serialize};
16
17pub const DEFAULT_STALE_FILTER_TTL: Duration = Duration::from_secs(5 * 60);
19
20#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Default)]
22#[serde(rename_all = "lowercase")]
23pub enum PendingBlockKind {
24 Empty,
26 None,
28 #[default]
30 Full,
31}
32
33impl std::str::FromStr for PendingBlockKind {
34 type Err = String;
35
36 fn from_str(s: &str) -> Result<Self, Self::Err> {
37 match s.to_lowercase().as_str() {
38 "empty" => Ok(Self::Empty),
39 "none" => Ok(Self::None),
40 "full" => Ok(Self::Full),
41 _ => Err(format!(
42 "Invalid pending block kind: {s}. Valid options are: empty, none, full"
43 )),
44 }
45 }
46}
47
48impl PendingBlockKind {
49 pub const fn is_none(&self) -> bool {
51 matches!(self, Self::None)
52 }
53
54 pub const fn is_empty(&self) -> bool {
56 matches!(self, Self::Empty)
57 }
58}
59
60#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
62pub struct EthConfig {
63 pub cache: EthStateCacheConfig,
65 pub gas_oracle: GasPriceOracleConfig,
67 pub eth_proof_window: u64,
69 pub max_tracing_requests: usize,
71 pub max_trace_filter_blocks: u64,
73 pub max_blocks_per_filter: u64,
75 pub max_logs_per_response: usize,
77 pub rpc_gas_cap: u64,
81 pub rpc_max_simulate_blocks: u64,
83 pub stale_filter_ttl: Duration,
86 pub fee_history_cache: FeeHistoryCacheConfig,
88 pub proof_permits: usize,
90 pub max_batch_size: usize,
92 pub pending_block_kind: PendingBlockKind,
94 pub raw_tx_forwarder: ForwardConfig,
96 pub send_raw_transaction_sync_timeout: Duration,
98}
99
100impl EthConfig {
101 pub fn filter_config(&self) -> EthFilterConfig {
103 EthFilterConfig::default()
104 .max_blocks_per_filter(self.max_blocks_per_filter)
105 .max_logs_per_response(self.max_logs_per_response)
106 .stale_filter_ttl(self.stale_filter_ttl)
107 }
108}
109
110impl Default for EthConfig {
111 fn default() -> Self {
112 Self {
113 cache: EthStateCacheConfig::default(),
114 gas_oracle: GasPriceOracleConfig::default(),
115 eth_proof_window: DEFAULT_ETH_PROOF_WINDOW,
116 max_tracing_requests: default_max_tracing_requests(),
117 max_trace_filter_blocks: DEFAULT_MAX_TRACE_FILTER_BLOCKS,
118 max_blocks_per_filter: DEFAULT_MAX_BLOCKS_PER_FILTER,
119 max_logs_per_response: DEFAULT_MAX_LOGS_PER_RESPONSE,
120 rpc_gas_cap: RPC_DEFAULT_GAS_CAP.into(),
121 rpc_max_simulate_blocks: DEFAULT_MAX_SIMULATE_BLOCKS,
122 stale_filter_ttl: DEFAULT_STALE_FILTER_TTL,
123 fee_history_cache: FeeHistoryCacheConfig::default(),
124 proof_permits: DEFAULT_PROOF_PERMITS,
125 max_batch_size: 1,
126 pending_block_kind: PendingBlockKind::Full,
127 raw_tx_forwarder: ForwardConfig::default(),
128 send_raw_transaction_sync_timeout: RPC_DEFAULT_SEND_RAW_TX_SYNC_TIMEOUT_SECS,
129 }
130 }
131}
132
133impl EthConfig {
134 pub const fn state_cache(mut self, cache: EthStateCacheConfig) -> Self {
136 self.cache = cache;
137 self
138 }
139
140 pub const fn gpo_config(mut self, gas_oracle_config: GasPriceOracleConfig) -> Self {
142 self.gas_oracle = gas_oracle_config;
143 self
144 }
145
146 pub const fn max_tracing_requests(mut self, max_requests: usize) -> Self {
148 self.max_tracing_requests = max_requests;
149 self
150 }
151
152 pub const fn max_blocks_per_filter(mut self, max_blocks: u64) -> Self {
154 self.max_blocks_per_filter = max_blocks;
155 self
156 }
157
158 pub const fn max_trace_filter_blocks(mut self, max_blocks: u64) -> Self {
160 self.max_trace_filter_blocks = max_blocks;
161 self
162 }
163
164 pub const fn max_logs_per_response(mut self, max_logs: usize) -> Self {
166 self.max_logs_per_response = max_logs;
167 self
168 }
169
170 pub const fn rpc_gas_cap(mut self, rpc_gas_cap: u64) -> Self {
172 self.rpc_gas_cap = rpc_gas_cap;
173 self
174 }
175
176 pub const fn rpc_max_simulate_blocks(mut self, max_blocks: u64) -> Self {
178 self.rpc_max_simulate_blocks = max_blocks;
179 self
180 }
181
182 pub const fn eth_proof_window(mut self, window: u64) -> Self {
184 self.eth_proof_window = window;
185 self
186 }
187
188 pub const fn proof_permits(mut self, permits: usize) -> Self {
190 self.proof_permits = permits;
191 self
192 }
193
194 pub const fn max_batch_size(mut self, max_batch_size: usize) -> Self {
196 self.max_batch_size = max_batch_size;
197 self
198 }
199
200 pub const fn pending_block_kind(mut self, pending_block_kind: PendingBlockKind) -> Self {
202 self.pending_block_kind = pending_block_kind;
203 self
204 }
205
206 pub fn raw_tx_forwarder(mut self, tx_forwarder: Option<Url>) -> Self {
208 if let Some(tx_forwarder) = tx_forwarder {
209 self.raw_tx_forwarder.tx_forwarder = Some(tx_forwarder);
210 }
211 self
212 }
213
214 pub const fn send_raw_transaction_sync_timeout(mut self, timeout: Duration) -> Self {
216 self.send_raw_transaction_sync_timeout = timeout;
217 self
218 }
219}
220
221#[derive(Debug, Clone, PartialEq, Eq)]
223pub struct EthFilterConfig {
224 pub max_blocks_per_filter: Option<u64>,
228 pub max_logs_per_response: Option<usize>,
232 pub stale_filter_ttl: Duration,
237}
238
239impl EthFilterConfig {
240 pub const fn max_blocks_per_filter(mut self, num: u64) -> Self {
242 self.max_blocks_per_filter = Some(num);
243 self
244 }
245
246 pub const fn max_logs_per_response(mut self, num: usize) -> Self {
249 self.max_logs_per_response = Some(num);
250 self
251 }
252
253 pub const fn stale_filter_ttl(mut self, duration: Duration) -> Self {
255 self.stale_filter_ttl = duration;
256 self
257 }
258}
259
260impl Default for EthFilterConfig {
261 fn default() -> Self {
262 Self {
263 max_blocks_per_filter: None,
264 max_logs_per_response: None,
265 stale_filter_ttl: Duration::from_secs(5 * 60),
267 }
268 }
269}