Skip to content

Commit 5e47816

Browse files
Add optional parameter get_logs_filter_max_epoch_gap. (#1768)
* Add optional parameter `get_logs_filter_max_epoch_range`. * Fix name.
1 parent 2b69530 commit 5e47816

File tree

7 files changed

+52
-0
lines changed

7 files changed

+52
-0
lines changed

client/src/configuration.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ build_config! {
229229
(enable_optimistic_execution, (bool), true)
230230
(future_block_buffer_capacity, (usize), 32768)
231231
(get_logs_filter_max_limit, (Option<usize>), None)
232+
(get_logs_filter_max_epoch_range, (Option<u64>), None)
232233
(get_logs_epoch_batch_size, (usize), 32)
233234
(max_trans_count_received_in_catch_up, (u64), 60_000)
234235
(persist_tx_index, (bool), false)
@@ -443,6 +444,7 @@ impl Configuration {
443444
transaction_epoch_bound: self.raw_conf.transaction_epoch_bound,
444445
referee_bound: self.raw_conf.referee_bound,
445446
get_logs_epoch_batch_size: self.raw_conf.get_logs_epoch_batch_size,
447+
get_logs_filter_max_epoch_range: self.raw_conf.get_logs_filter_max_epoch_range
446448
}
447449
}
448450

core/src/consensus/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub struct ConsensusConfig {
9595
/// Larger batch sizes may improve performance but might also prevent
9696
/// consensus from making progress under high RPC load.
9797
pub get_logs_epoch_batch_size: usize,
98+
pub get_logs_filter_max_epoch_range: Option<u64>,
9899
}
99100

100101
#[derive(Debug)]
@@ -981,6 +982,17 @@ impl ConsensusGraph {
981982
});
982983
}
983984

985+
if let Some(max_gap) = self.config.get_logs_filter_max_epoch_range {
986+
// The range includes both ends.
987+
if to_epoch - from_epoch + 1 > max_gap {
988+
return Err(FilterError::EpochNumberGapTooLarge {
989+
from_epoch,
990+
to_epoch,
991+
max_gap,
992+
});
993+
}
994+
}
995+
984996
return Ok((from_epoch..=to_epoch).rev());
985997
}
986998

core/src/sync/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ pub fn initialize_synchronization_graph_with_data_manager(
207207
transaction_epoch_bound: TRANSACTION_DEFAULT_EPOCH_BOUND,
208208
referee_bound: REFEREE_DEFAULT_BOUND,
209209
get_logs_epoch_batch_size: 32,
210+
get_logs_filter_max_epoch_range: None,
210211
},
211212
vm.clone(),
212213
txpool.clone(),

primitives/src/filter.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ pub enum FilterError {
3838
max_epoch: u64,
3939
},
4040

41+
EpochNumberGapTooLarge {
42+
from_epoch: u64,
43+
to_epoch: u64,
44+
max_gap: u64,
45+
},
46+
4147
/// Roots for verifying the requested epochs are unavailable.
4248
UnableToVerify {
4349
epoch: u64,
@@ -89,6 +95,17 @@ impl fmt::Display for FilterError {
8995
"Filter to_epoch is larger than the current best_epoch (to: {}, max: {})",
9096
to_epoch, max_epoch,
9197
},
98+
EpochNumberGapTooLarge {
99+
from_epoch,
100+
to_epoch,
101+
max_gap,
102+
} => {
103+
format! {
104+
"The gap between from_epoch and to_epoch is larger than max_gap \
105+
(from: {}, to: {}, max_gap: {})",
106+
from_epoch, to_epoch, max_gap
107+
}
108+
}
92109
UnableToVerify {
93110
epoch,
94111
latest_verifiable,

run/default.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ jsonrpc_local_http_port=12539
421421
#
422422
# get_logs_epoch_batch_size = 32
423423

424+
# The maximal allowed number of epochs between `from_epoch` and `to_epoch` in the filter to call `cfx_getLogs`.
425+
# If not set, there is no limit on the gap.
426+
# By default it is not set.
427+
#
428+
# get_logs_filter_max_epoch_range = 10000
429+
424430
# Maximum number of transactions allowed for peers to send to a catch-up node.
425431
#
426432
# max_trans_count_received_in_catch_up = 60_000

src/cli.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ args:
163163
long: get-logs-epoch-batch-size
164164
value_name: SIZE
165165
takes_value: true
166+
- get-logs-filter-max-epoch-range:
167+
help: Sets the maximum number of allowed epochs during log filtering.
168+
long: get-logs-filter-max-epoch-range
169+
value_name: SIZE
170+
takes_value: true
166171
- account-provider-refresh-time-ms:
167172
help: Sets the time after which accounts are re-read from disk.
168173
long: account-provider-refresh-time-ms

tests/log_filtering_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ def run_test(self):
215215
assert_equal(logs[ii]["topics"][1], self.address_to_topic(sender))
216216
assert_equal(logs[ii]["topics"][2], self.number_to_topic(NUM_CALLS // 2 + ii))
217217

218+
# get-logs-filter-max-epoch-range should limit the number of epochs queried.
219+
self.stop_node(0)
220+
self.start_node(0, ["--get-logs-filter-max-epoch-range", "16"])
221+
filter = Filter(from_epoch="0x0", to_epoch="0x0f", topics=[BAR_TOPIC])
222+
# should not raise error
223+
self.rpc.get_logs(filter)
224+
filter = Filter(from_epoch="0x0", to_epoch="0x10", topics=[BAR_TOPIC])
225+
assert_raises_rpc_error(None, None, self.rpc.get_logs, filter)
226+
218227
self.log.info("Pass")
219228

220229
def address_to_topic(self, address):

0 commit comments

Comments
 (0)