diff --git a/crates/rpc/rpc-builder/src/auth.rs b/crates/rpc/rpc-builder/src/auth.rs index 80f880a4f8..8f8e56d97c 100644 --- a/crates/rpc/rpc-builder/src/auth.rs +++ b/crates/rpc/rpc-builder/src/auth.rs @@ -1,6 +1,7 @@ use crate::{ constants, error::{RpcError, ServerKind}, + eth::DEFAULT_MAX_LOGS_IN_RESPONSE, }; use hyper::header::AUTHORIZATION; pub use jsonrpsee::server::ServerBuilder; @@ -49,7 +50,7 @@ where // spawn a new cache task let eth_cache = EthStateCache::spawn_with(client.clone(), Default::default(), executor); let eth_api = EthApi::new(client.clone(), pool.clone(), network, eth_cache.clone()); - let eth_filter = EthFilter::new(client, pool, eth_cache.clone()); + let eth_filter = EthFilter::new(client, pool, eth_cache.clone(), DEFAULT_MAX_LOGS_IN_RESPONSE); launch_with_eth_api(eth_api, eth_filter, engine_api, socket_addr, secret).await } diff --git a/crates/rpc/rpc-builder/src/eth.rs b/crates/rpc/rpc-builder/src/eth.rs index 43b3e7c03d..00f21188b2 100644 --- a/crates/rpc/rpc-builder/src/eth.rs +++ b/crates/rpc/rpc-builder/src/eth.rs @@ -4,6 +4,9 @@ use reth_rpc::{ }; use serde::{Deserialize, Serialize}; +/// The default maximum of logs in a single response. +pub(crate) const DEFAULT_MAX_LOGS_IN_RESPONSE: usize = 2_000; + /// All handlers for the `eth` namespace #[derive(Debug, Clone)] pub struct EthHandlers { @@ -22,13 +25,18 @@ pub struct EthHandlers { pub struct EthConfig { /// Settings for the caching layer pub cache: EthStateCacheConfig, - /// The maximum number of tracing calls that can be executed in concurrently. pub max_tracing_requests: usize, + /// Maximum number of logs that can be returned in a single response in `eth_getLogs` calls. + pub max_logs_per_response: usize, } impl Default for EthConfig { fn default() -> Self { - Self { cache: EthStateCacheConfig::default(), max_tracing_requests: 10 } + Self { + cache: EthStateCacheConfig::default(), + max_tracing_requests: 10, + max_logs_per_response: DEFAULT_MAX_LOGS_IN_RESPONSE, + } } } diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 178f7005e4..387b36290d 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -798,7 +798,12 @@ where self.network.clone(), cache.clone(), ); - let filter = EthFilter::new(self.client.clone(), self.pool.clone(), cache.clone()); + let filter = EthFilter::new( + self.client.clone(), + self.pool.clone(), + cache.clone(), + self.config.eth.max_logs_per_response, + ); let pubsub = EthPubSub::new( self.client.clone(), diff --git a/crates/rpc/rpc/src/eth/filter.rs b/crates/rpc/rpc/src/eth/filter.rs index aafa5587fd..57322c4759 100644 --- a/crates/rpc/rpc/src/eth/filter.rs +++ b/crates/rpc/rpc/src/eth/filter.rs @@ -21,9 +21,6 @@ use std::{collections::HashMap, sync::Arc, time::Instant}; use tokio::sync::Mutex; use tracing::trace; -/// The default maximum of logs in a single response. -const DEFAULT_MAX_LOGS_IN_RESPONSE: usize = 2_000; - /// `Eth` filter RPC implementation. #[derive(Debug, Clone)] pub struct EthFilter { @@ -33,13 +30,23 @@ pub struct EthFilter { impl EthFilter { /// Creates a new, shareable instance. - pub fn new(client: Client, pool: Pool, eth_cache: EthStateCache) -> Self { + /// + /// This uses the given pool to get notified about new transactions, the client to interact with + /// the blockchain, the cache to fetch cacheable data, like the logs and the + /// max_logs_per_response to limit the amount of logs returned in a single response + /// `eth_getLogs` + pub fn new( + client: Client, + pool: Pool, + eth_cache: EthStateCache, + max_logs_per_response: usize, + ) -> Self { let inner = EthFilterInner { client, active_filters: Default::default(), pool, id_provider: Arc::new(EthSubscriptionIdProvider::default()), - max_logs_in_response: DEFAULT_MAX_LOGS_IN_RESPONSE, + max_logs_per_response, eth_cache, }; Self { inner: Arc::new(inner) } @@ -188,7 +195,7 @@ struct EthFilterInner { /// Provides ids to identify filters id_provider: Arc, /// Maximum number of logs that can be returned in a response - max_logs_in_response: usize, + max_logs_per_response: usize, /// The async cache frontend for eth related data eth_cache: EthStateCache, } @@ -303,9 +310,9 @@ where ); // size check - if all_logs.len() > self.max_logs_in_response { + if all_logs.len() > self.max_logs_per_response { return Err(FilterError::QueryExceedsMaxResults( - self.max_logs_in_response, + self.max_logs_per_response, )) } }