1//! Configuration for `eth` namespace APIs.
23use std::time::Duration;
45use crate::{
6EthStateCacheConfig, FeeHistoryCacheConfig, GasPriceOracleConfig, RPC_DEFAULT_GAS_CAP,
7};
8use reth_rpc_server_types::constants::{
9 default_max_tracing_requests, DEFAULT_ETH_PROOF_WINDOW, DEFAULT_MAX_BLOCKS_PER_FILTER,
10 DEFAULT_MAX_LOGS_PER_RESPONSE, DEFAULT_MAX_SIMULATE_BLOCKS, DEFAULT_MAX_TRACE_FILTER_BLOCKS,
11 DEFAULT_PROOF_PERMITS,
12};
13use serde::{Deserialize, Serialize};
1415/// Default value for stale filter ttl
16pub const DEFAULT_STALE_FILTER_TTL: Duration = Duration::from_secs(5 * 60);
1718/// Additional config values for the eth namespace.
19#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
20pub struct EthConfig {
21/// Settings for the caching layer
22pub cache: EthStateCacheConfig,
23/// Settings for the gas price oracle
24pub gas_oracle: GasPriceOracleConfig,
25/// The maximum number of blocks into the past for generating state proofs.
26pub eth_proof_window: u64,
27/// The maximum number of tracing calls that can be executed in concurrently.
28pub max_tracing_requests: usize,
29/// Maximum number of blocks for `trace_filter` requests.
30pub max_trace_filter_blocks: u64,
31/// Maximum number of blocks that could be scanned per filter request in `eth_getLogs` calls.
32pub max_blocks_per_filter: u64,
33/// Maximum number of logs that can be returned in a single response in `eth_getLogs` calls.
34pub max_logs_per_response: usize,
35/// Gas limit for `eth_call` and call tracing RPC methods.
36 ///
37 /// Defaults to [`RPC_DEFAULT_GAS_CAP`]
38pub rpc_gas_cap: u64,
39/// Max number of blocks for `eth_simulateV1`.
40pub rpc_max_simulate_blocks: u64,
41///
42 /// Sets TTL for stale filters
43pub stale_filter_ttl: Duration,
44/// Settings for the fee history cache
45pub fee_history_cache: FeeHistoryCacheConfig,
46/// The maximum number of getproof calls that can be executed concurrently.
47pub proof_permits: usize,
48}
4950impl EthConfig {
51/// Returns the filter config for the `eth_filter` handler.
52pub fn filter_config(&self) -> EthFilterConfig {
53EthFilterConfig::default()
54 .max_blocks_per_filter(self.max_blocks_per_filter)
55 .max_logs_per_response(self.max_logs_per_response)
56 .stale_filter_ttl(self.stale_filter_ttl)
57 }
58}
5960impl Defaultfor EthConfig {
61fn default() -> Self {
62Self {
63 cache: EthStateCacheConfig::default(),
64 gas_oracle: GasPriceOracleConfig::default(),
65 eth_proof_window: DEFAULT_ETH_PROOF_WINDOW,
66 max_tracing_requests: default_max_tracing_requests(),
67 max_trace_filter_blocks: DEFAULT_MAX_TRACE_FILTER_BLOCKS,
68 max_blocks_per_filter: DEFAULT_MAX_BLOCKS_PER_FILTER,
69 max_logs_per_response: DEFAULT_MAX_LOGS_PER_RESPONSE,
70 rpc_gas_cap: RPC_DEFAULT_GAS_CAP.into(),
71 rpc_max_simulate_blocks: DEFAULT_MAX_SIMULATE_BLOCKS,
72 stale_filter_ttl: DEFAULT_STALE_FILTER_TTL,
73 fee_history_cache: FeeHistoryCacheConfig::default(),
74 proof_permits: DEFAULT_PROOF_PERMITS,
75 }
76 }
77}
7879impl EthConfig {
80/// Configures the caching layer settings
81pub const fn state_cache(mut self, cache: EthStateCacheConfig) -> Self {
82self.cache = cache;
83self84}
8586/// Configures the gas price oracle settings
87pub const fn gpo_config(mut self, gas_oracle_config: GasPriceOracleConfig) -> Self {
88self.gas_oracle = gas_oracle_config;
89self90}
9192/// Configures the maximum number of tracing requests
93pub const fn max_tracing_requests(mut self, max_requests: usize) -> Self {
94self.max_tracing_requests = max_requests;
95self96}
9798/// Configures the maximum block length to scan per `eth_getLogs` request
99pub const fn max_blocks_per_filter(mut self, max_blocks: u64) -> Self {
100self.max_blocks_per_filter = max_blocks;
101self102}
103104/// Configures the maximum number of blocks for `trace_filter` requests
105pub const fn max_trace_filter_blocks(mut self, max_blocks: u64) -> Self {
106self.max_trace_filter_blocks = max_blocks;
107self108}
109110/// Configures the maximum number of logs per response
111pub const fn max_logs_per_response(mut self, max_logs: usize) -> Self {
112self.max_logs_per_response = max_logs;
113self114}
115116/// Configures the maximum gas limit for `eth_call` and call tracing RPC methods
117pub const fn rpc_gas_cap(mut self, rpc_gas_cap: u64) -> Self {
118self.rpc_gas_cap = rpc_gas_cap;
119self120}
121122/// Configures the maximum gas limit for `eth_call` and call tracing RPC methods
123pub const fn rpc_max_simulate_blocks(mut self, max_blocks: u64) -> Self {
124self.rpc_max_simulate_blocks = max_blocks;
125self126}
127128/// Configures the maximum proof window for historical proof generation.
129pub const fn eth_proof_window(mut self, window: u64) -> Self {
130self.eth_proof_window = window;
131self132}
133134/// Configures the number of getproof requests
135pub const fn proof_permits(mut self, permits: usize) -> Self {
136self.proof_permits = permits;
137self138}
139}
140141/// Config for the filter
142#[derive(Debug, Clone, PartialEq, Eq)]
143pub struct EthFilterConfig {
144/// Maximum number of blocks that a filter can scan for logs.
145 ///
146 /// If `None` then no limit is enforced.
147pub max_blocks_per_filter: Option<u64>,
148/// Maximum number of logs that can be returned in a single response in `eth_getLogs` calls.
149 ///
150 /// If `None` then no limit is enforced.
151pub max_logs_per_response: Option<usize>,
152/// How long a filter remains valid after the last poll.
153 ///
154 /// A filter is considered stale if it has not been polled for longer than this duration and
155 /// will be removed.
156pub stale_filter_ttl: Duration,
157}
158159impl EthFilterConfig {
160/// Sets the maximum number of blocks that a filter can scan for logs.
161pub const fn max_blocks_per_filter(mut self, num: u64) -> Self {
162self.max_blocks_per_filter = Some(num);
163self164}
165166/// Sets the maximum number of logs that can be returned in a single response in `eth_getLogs`
167 /// calls.
168pub const fn max_logs_per_response(mut self, num: usize) -> Self {
169self.max_logs_per_response = Some(num);
170self171}
172173/// Sets how long a filter remains valid after the last poll before it will be removed.
174pub const fn stale_filter_ttl(mut self, duration: Duration) -> Self {
175self.stale_filter_ttl = duration;
176self177}
178}
179180impl Defaultfor EthFilterConfig {
181fn default() -> Self {
182Self {
183 max_blocks_per_filter: None,
184 max_logs_per_response: None,
185// 5min
186stale_filter_ttl: Duration::from_secs(5 * 60),
187 }
188 }
189}