Skip to content

Commit b0f65d4

Browse files
snowmeadRomarQ
authored andcommitted
Validate max block range eth_getLogs RPC (#245)
1 parent 6dae0e5 commit b0f65d4

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
@@ -50,6 +50,7 @@ pub struct EthFilter<B: BlockT, C, BE, A: ChainApi> {
5050
filter_pool: FilterPool,
5151
max_stored_filters: usize,
5252
max_past_logs: u32,
53+
max_block_range: u32,
5354
block_data_cache: Arc<EthBlockDataCacheTask<B>>,
5455
_marker: PhantomData<BE>,
5556
}
@@ -62,6 +63,7 @@ impl<B: BlockT, C, BE, A: ChainApi> EthFilter<B, C, BE, A> {
6263
filter_pool: FilterPool,
6364
max_stored_filters: usize,
6465
max_past_logs: u32,
66+
max_block_range: u32,
6567
block_data_cache: Arc<EthBlockDataCacheTask<B>>,
6668
) -> Self {
6769
Self {
@@ -71,6 +73,7 @@ impl<B: BlockT, C, BE, A: ChainApi> EthFilter<B, C, BE, A> {
7173
filter_pool,
7274
max_stored_filters,
7375
max_past_logs,
76+
max_block_range,
7477
block_data_cache,
7578
_marker: PhantomData,
7679
}
@@ -507,6 +510,14 @@ where
507510
.map(|s| s.unique_saturated_into())
508511
.unwrap_or(best_number);
509512

513+
let block_range = current_number.saturating_sub(from_number);
514+
if block_range > self.max_block_range.into() {
515+
return Err(internal_err(format!(
516+
"block range is too wide (maximum {})",
517+
self.max_block_range
518+
)));
519+
}
520+
510521
if backend.is_indexed() {
511522
let _ = filter_range_logs_indexed(
512523
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
@@ -53,6 +53,8 @@ pub struct EthDeps<B: BlockT, C, P, A: ChainApi, CT, CIDP> {
5353
pub filter_pool: Option<FilterPool>,
5454
/// Maximum number of logs in a query.
5555
pub max_past_logs: u32,
56+
/// Maximum block range for eth_getLogs.
57+
pub max_block_range: u32,
5658
/// Fee history cache.
5759
pub fee_history_cache: FeeHistoryCache,
5860
/// Maximum fee history cache size.
@@ -115,6 +117,7 @@ where
115117
block_data_cache,
116118
filter_pool,
117119
max_past_logs,
120+
max_block_range,
118121
fee_history_cache,
119122
fee_history_cache_limit,
120123
execute_gas_limit_multiplier,
@@ -159,6 +162,7 @@ where
159162
filter_pool,
160163
500_usize, // max stored filters
161164
max_past_logs,
165+
max_block_range,
162166
block_data_cache.clone(),
163167
)
164168
.into_rpc(),

template/node/src/service.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ where
417417
let is_authority = role.is_authority();
418418
let enable_dev_signer = eth_config.enable_dev_signer;
419419
let max_past_logs = eth_config.max_past_logs;
420+
let max_block_range = eth_config.max_block_range;
420421
let execute_gas_limit_multiplier = eth_config.execute_gas_limit_multiplier;
421422
let filter_pool = filter_pool.clone();
422423
let frontier_backend = frontier_backend.clone();
@@ -463,6 +464,7 @@ where
463464
block_data_cache: block_data_cache.clone(),
464465
filter_pool: filter_pool.clone(),
465466
max_past_logs,
467+
max_block_range,
466468
fee_history_cache: fee_history_cache.clone(),
467469
fee_history_cache_limit,
468470
execute_gas_limit_multiplier,

0 commit comments

Comments
 (0)