Skip to content

Commit 5ca4cd2

Browse files
committed
use block read limit
1 parent d28c351 commit 5ca4cd2

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async fn run_scanner(
7070
) -> Result<(), Box<dyn std::error::Error>> {
7171
// Configure scanner with custom batch size (optional)
7272
let mut scanner = EventScanner::live()
73-
.max_reads(500) // Process up to 500 blocks per batch
73+
.block_read_limit(500) // Process up to 500 blocks per batch
7474
.connect_ws::<Ethereum>(ws_url).await?;
7575

7676
let filter = EventFilter::new()
@@ -101,22 +101,22 @@ async fn run_scanner(
101101
```rust
102102
// Live streaming mode
103103
let scanner = EventScanner::live()
104-
.max_reads(500) // Optional: set max blocks per read (default: 1000)
104+
.block_read_limit(500) // Optional: set max blocks per read (default: 1000)
105105
.connect_ws::<Ethereum>(ws_url).await?;
106106

107107
// Historical scanning mode
108108
let scanner = EventScanner::historic()
109-
.max_reads(500)
109+
.block_read_limit(500)
110110
.connect_ws::<Ethereum>(ws_url).await?;
111111

112112
// Sync mode (historical + live)
113113
let scanner = EventScanner::sync()
114-
.max_reads(500)
114+
.block_read_limit(500)
115115
.connect_ws::<Ethereum>(ws_url).await?;
116116

117117
// Latest mode (recent blocks only)
118118
let scanner = EventScanner::latest()
119-
.max_reads(500)
119+
.block_read_limit(500)
120120
.connect_ws::<Ethereum>(ws_url).await?;
121121
```
122122

@@ -127,7 +127,7 @@ let scanner = EventScanner::latest()
127127
- `EventScanner::latest()` – Processes a specific number of events then optionally switches to live scanning mode
128128

129129
**Global Configuration Options:**
130-
- `max_reads(usize)` – Sets the maximum number of blocks to process per read operation. This prevents RPC provider errors from overly large block range queries.
130+
- `block_read_limit(usize)` – Sets the maximum number of blocks to process per read operation. This prevents RPC provider errors from overly large block range queries.
131131
- Connect with `connect_ws::<Ethereum>(url)`, `connect_ipc::<Ethereum>(path)`, or `connect_provider(provider)`.
132132

133133
**Mode-specific APIs:**
@@ -177,7 +177,7 @@ The flexibility provided by `EventFilter` allows you to build sophisticated even
177177
- **Latest mode**`EventScanner::latest()` creates a scanner that processes a set number of events.
178178

179179
**Configuration Tips:**
180-
- Set `max_reads` based on your RPC provider's limits (e.g., Alchemy, Infura may limit queries to 2000 blocks)
180+
- Set `block_read_limit` based on your RPC provider's limits (e.g., Alchemy, Infura may limit queries to 2000 blocks)
181181
- For live mode, if the WebSocket subscription lags significantly (e.g., >2000 blocks), ranges are automatically capped to prevent RPC errors
182182
- Each mode has its own configuration options for start block, end block, confirmations, etc. where it makes sense
183183
- The modes come with sensible defaults for example not specify a start block for historic mode automatically sets the start block to the earliest one

src/event_lib/modes/historic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ mod tests {
133133

134134
#[test]
135135
fn test_historic_scanner_builder_pattern() {
136-
let config = HistoricScannerConfig::new().from_block(100u64).to_block(200u64).max_reads(50);
136+
let config =
137+
HistoricScannerConfig::new().from_block(100u64).to_block(200u64).block_read_limit(50);
137138

138139
assert!(matches!(config.from_block, BlockNumberOrTag::Number(100)));
139140
assert!(matches!(config.to_block, BlockNumberOrTag::Number(200)));
@@ -143,7 +144,7 @@ mod tests {
143144
#[test]
144145
fn test_historic_scanner_builder_pattern_chaining() {
145146
let config = HistoricScannerConfig::new()
146-
.max_reads(25)
147+
.block_read_limit(25)
147148
.from_block(BlockNumberOrTag::Number(50))
148149
.to_block(BlockNumberOrTag::Number(150));
149150

src/event_lib/modes/latest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ mod tests {
216216
.to_block(200)
217217
.block_confirmations(10)
218218
.then_live()
219-
.max_reads(50);
219+
.block_read_limit(50);
220220

221221
assert_eq!(config.count, 5);
222222
assert!(matches!(config.from_block, BlockNumberOrTag::Number(100)));
@@ -229,7 +229,7 @@ mod tests {
229229
#[test]
230230
fn test_latest_scanner_builder_pattern_chaining() {
231231
let config = LatestScannerConfig::new()
232-
.max_reads(25)
232+
.block_read_limit(25)
233233
.block_confirmations(5)
234234
.count(3)
235235
.from_block(BlockNumberOrTag::Number(50))

src/event_lib/modes/live.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,23 @@ mod tests {
119119

120120
#[test]
121121
fn test_live_scanner_builder_pattern() {
122-
let config = LiveScannerConfig::new().block_confirmations(10).max_reads(50);
122+
let config = LiveScannerConfig::new().block_confirmations(10).block_read_limit(50);
123123

124124
assert_eq!(config.block_confirmations, 10);
125125
assert_eq!(config.base.block_range_scanner.max_read_per_epoch, 50);
126126
}
127127

128128
#[test]
129129
fn test_live_scanner_builder_pattern_chaining() {
130-
let config = LiveScannerConfig::new().max_reads(25).block_confirmations(5);
130+
let config = LiveScannerConfig::new().block_read_limit(25).block_confirmations(5);
131131

132132
assert_eq!(config.base.block_range_scanner.max_read_per_epoch, 25);
133133
assert_eq!(config.block_confirmations, 5);
134134
}
135135

136136
#[test]
137137
fn test_live_scanner_builder_with_zero_confirmations() {
138-
let config = LiveScannerConfig::new().block_confirmations(0).max_reads(100);
138+
let config = LiveScannerConfig::new().block_confirmations(0).block_read_limit(100);
139139

140140
assert_eq!(config.block_confirmations, 0);
141141
assert_eq!(config.base.block_range_scanner.max_read_per_epoch, 100);

src/event_lib/modes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub trait BaseConfigBuilder: Sized {
4949
fn base_mut(&mut self) -> &mut BaseConfig;
5050

5151
#[must_use]
52-
fn max_reads(mut self, max: usize) -> Self {
52+
fn block_read_limit(mut self, max: usize) -> Self {
5353
self.base_mut().block_range_scanner.max_read_per_epoch = max;
5454
self
5555
}

src/event_lib/modes/sync.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ mod tests {
133133

134134
#[test]
135135
fn test_sync_scanner_builder_pattern() {
136-
let config = SyncScannerConfig::new().from_block(100).block_confirmations(10).max_reads(50);
136+
let config = SyncScannerConfig::new().from_block(100).block_confirmations(10).block_read_limit(50);
137137

138138
assert!(matches!(config.from_block, BlockNumberOrTag::Number(100)));
139139
assert_eq!(config.block_confirmations, 10);
@@ -143,7 +143,7 @@ mod tests {
143143
#[test]
144144
fn test_sync_scanner_builder_pattern_chaining() {
145145
let config = SyncScannerConfig::new()
146-
.max_reads(25)
146+
.block_read_limit(25)
147147
.block_confirmations(5)
148148
.from_block(BlockNumberOrTag::Number(50));
149149

@@ -157,7 +157,7 @@ mod tests {
157157
let config = SyncScannerConfig::new()
158158
.from_block(BlockNumberOrTag::Earliest)
159159
.block_confirmations(20)
160-
.max_reads(100);
160+
.block_read_limit(100);
161161

162162
assert!(matches!(config.from_block, BlockNumberOrTag::Earliest));
163163
assert_eq!(config.block_confirmations, 20);
@@ -166,7 +166,7 @@ mod tests {
166166

167167
#[test]
168168
fn test_sync_scanner_builder_with_zero_confirmations() {
169-
let config = SyncScannerConfig::new().from_block(0).block_confirmations(0).max_reads(75);
169+
let config = SyncScannerConfig::new().from_block(0).block_confirmations(0).block_read_limit(75);
170170

171171
assert!(matches!(config.from_block, BlockNumberOrTag::Number(0)));
172172
assert_eq!(config.block_confirmations, 0);

0 commit comments

Comments
 (0)