Skip to content

Commit 987ba9e

Browse files
authored
feat: Add max_block_range to sync::from_latest mode (#162)
1 parent 086d29c commit 987ba9e

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

src/event_scanner/scanner/historic.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ use crate::{
77
};
88

99
impl EventScannerBuilder<Historic> {
10-
#[must_use]
11-
pub fn max_block_range(mut self, max_block_range: u64) -> Self {
12-
self.block_range_scanner.max_block_range = max_block_range;
13-
self
14-
}
15-
1610
#[must_use]
1711
pub fn from_block(mut self, block: impl Into<BlockNumberOrTag>) -> Self {
1812
self.config.from_block = block.into();

src/event_scanner/scanner/latest.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ use crate::{
77
};
88

99
impl EventScannerBuilder<LatestEvents> {
10-
#[must_use]
11-
pub fn max_block_range(mut self, max_block_range: u64) -> Self {
12-
self.block_range_scanner.max_block_range = max_block_range;
13-
self
14-
}
15-
1610
#[must_use]
1711
pub fn block_confirmations(mut self, confirmations: u64) -> Self {
1812
self.config.block_confirmations = confirmations;

src/event_scanner/scanner/live.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ use crate::{
77
};
88

99
impl EventScannerBuilder<Live> {
10-
#[must_use]
11-
pub fn max_block_range(mut self, max_block_range: u64) -> Self {
12-
self.block_range_scanner.max_block_range = max_block_range;
13-
self
14-
}
15-
1610
#[must_use]
1711
pub fn block_confirmations(mut self, confirmations: u64) -> Self {
1812
self.config.block_confirmations = confirmations;

src/event_scanner/scanner/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,29 @@ impl EventScannerBuilder<SyncFromBlock> {
366366
}
367367

368368
impl<M> EventScannerBuilder<M> {
369+
/// Sets the maximum block range per event batch.
370+
///
371+
/// Controls how the scanner splits a large block range into smaller batches for processing.
372+
/// Each batch corresponds to a single RPC call to fetch logs. This prevents timeouts and
373+
/// respects rate limits imposed by node providers.
374+
///
375+
/// # Arguments
376+
///
377+
/// * `max_block_range` - Maximum number of blocks to process per batch.
378+
///
379+
/// # Example
380+
///
381+
/// If scanning events from blocks 1000–1099 (100 blocks total) with `max_block_range(30)`:
382+
/// - Batch 1: blocks 1000–1029 (30 blocks)
383+
/// - Batch 2: blocks 1030–1059 (30 blocks)
384+
/// - Batch 3: blocks 1060–1089 (30 blocks)
385+
/// - Batch 4: blocks 1090–1099 (10 blocks)
386+
#[must_use]
387+
pub fn max_block_range(mut self, max_block_range: u64) -> Self {
388+
self.block_range_scanner.max_block_range = max_block_range;
389+
self
390+
}
391+
369392
/// Connects to the provider via WebSocket.
370393
///
371394
/// Final builder method: consumes the builder and returns the built [`EventScanner`].

src/event_scanner/scanner/sync/from_block.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ use crate::{
99
};
1010

1111
impl EventScannerBuilder<SyncFromBlock> {
12-
#[must_use]
13-
pub fn max_block_range(mut self, max_block_range: u64) -> Self {
14-
self.block_range_scanner.max_block_range = max_block_range;
15-
self
16-
}
17-
1812
#[must_use]
1913
pub fn block_confirmations(mut self, count: u64) -> Self {
2014
self.config.block_confirmations = count;

0 commit comments

Comments
 (0)