Skip to content

Commit e5b6a15

Browse files
snowmeadTarekkMA
authored andcommitted
Validate max block range eth_getLogs RPC (#245)
1 parent 7c0d0d7 commit e5b6a15

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

client/rpc/src/eth/filter.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct EthFilter<B: BlockT, C, BE, P> {
4949
filter_pool: FilterPool,
5050
max_stored_filters: usize,
5151
max_past_logs: u32,
52+
max_block_range: u32,
5253
block_data_cache: Arc<EthBlockDataCacheTask<B>>,
5354
_marker: PhantomData<BE>,
5455
}
@@ -61,6 +62,7 @@ impl<B: BlockT, C, BE, P: TransactionPool> EthFilter<B, C, BE, P> {
6162
filter_pool: FilterPool,
6263
max_stored_filters: usize,
6364
max_past_logs: u32,
65+
max_block_range: u32,
6466
block_data_cache: Arc<EthBlockDataCacheTask<B>>,
6567
) -> Self {
6668
Self {
@@ -70,6 +72,7 @@ impl<B: BlockT, C, BE, P: TransactionPool> EthFilter<B, C, BE, P> {
7072
filter_pool,
7173
max_stored_filters,
7274
max_past_logs,
75+
max_block_range,
7376
block_data_cache,
7477
_marker: PhantomData,
7578
}
@@ -504,6 +507,14 @@ where
504507
.map(|s| s.unique_saturated_into())
505508
.unwrap_or(best_number);
506509

510+
let block_range = current_number.saturating_sub(from_number);
511+
if block_range > self.max_block_range.into() {
512+
return Err(internal_err(format!(
513+
"block range is too wide (maximum {})",
514+
self.max_block_range
515+
)));
516+
}
517+
507518
if backend.is_indexed() {
508519
let _ = filter_range_logs_indexed(
509520
client.as_ref(),

template/node/src/eth.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ pub struct EthConfiguration {
4646
#[arg(long, default_value = "10000")]
4747
pub max_past_logs: u32,
4848

49+
/// Maximum block range to query logs from.
50+
#[arg(long, default_value = "1024")]
51+
pub max_block_range: u32,
52+
4953
/// Maximum fee history cache size.
5054
#[arg(long, default_value = "2048")]
5155
pub fee_history_limit: u64,

template/node/src/rpc/eth.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ pub struct EthDeps<B: BlockT, C, P, CT, CIDP> {
5252
pub filter_pool: Option<FilterPool>,
5353
/// Maximum number of logs in a query.
5454
pub max_past_logs: u32,
55+
/// Maximum block range for eth_getLogs.
56+
pub max_block_range: u32,
5557
/// Fee history cache.
5658
pub fee_history_cache: FeeHistoryCache,
5759
/// Maximum fee history cache size.
@@ -113,6 +115,7 @@ where
113115
block_data_cache,
114116
filter_pool,
115117
max_past_logs,
118+
max_block_range,
116119
fee_history_cache,
117120
fee_history_cache_limit,
118121
execute_gas_limit_multiplier,
@@ -157,6 +160,7 @@ where
157160
filter_pool,
158161
500_usize, // max stored filters
159162
max_past_logs,
163+
max_block_range,
160164
block_data_cache.clone(),
161165
)
162166
.into_rpc(),

template/node/src/service.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ where
424424
let is_authority = role.is_authority();
425425
let enable_dev_signer = eth_config.enable_dev_signer;
426426
let max_past_logs = eth_config.max_past_logs;
427+
let max_block_range = eth_config.max_block_range;
427428
let execute_gas_limit_multiplier = eth_config.execute_gas_limit_multiplier;
428429
let filter_pool = filter_pool.clone();
429430
let frontier_backend = frontier_backend.clone();
@@ -470,6 +471,7 @@ where
470471
block_data_cache: block_data_cache.clone(),
471472
filter_pool: filter_pool.clone(),
472473
max_past_logs,
474+
max_block_range,
473475
fee_history_cache: fee_history_cache.clone(),
474476
fee_history_cache_limit,
475477
execute_gas_limit_multiplier,

0 commit comments

Comments
 (0)