Skip to content

Commit

Permalink
fix(storage/event): add upper limit for blocks scanned
Browse files Browse the repository at this point in the history
  • Loading branch information
kkovaacs committed Jan 22, 2024
1 parent 9c2a39d commit e7a70e9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/storage/src/connection/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use pathfinder_common::{

pub const PAGE_SIZE_LIMIT: usize = 1_024;
pub const KEY_FILTER_LIMIT: usize = 16;
const MAX_BLOCKS_TO_SCAN: usize = 200;

#[derive(Debug)]
pub struct EventFilter {
Expand Down Expand Up @@ -107,6 +108,7 @@ pub(super) fn get_events(
let key_filter_is_empty = filter.keys.iter().flatten().count() == 0;

let mut emitted_events = Vec::new();
let mut blocks_scanned: usize = 0;

for block_number in from_block..=to_block {
if emitted_events.len() > filter.page_size {
Expand Down Expand Up @@ -141,6 +143,11 @@ pub(super) fn get_events(
break;
};

blocks_scanned += 1;
if blocks_scanned > MAX_BLOCKS_TO_SCAN {
return Err(EventFilterError::TooManyMatches);
}

let transaction_data = tx.transaction_data_for_block(crate::BlockId::Number(
BlockNumber::new_or_panic(block_number),
))?;
Expand Down

0 comments on commit e7a70e9

Please sign in to comment.