Skip to content

Commit 84d00f0

Browse files
committed
ref: clippy
1 parent 32fa1de commit 84d00f0

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

src/block_range_scanner.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use alloy::{
8888
use thiserror::Error;
8989
use tracing::{debug, error, info, warn};
9090

91-
pub const DEFAULT_BLOCKS_READ_PER_EPOCH: u32 = 1000;
91+
pub const DEFAULT_BLOCKS_READ_PER_EPOCH: usize = 1000;
9292
// copied form https://github.com/taikoxyz/taiko-mono/blob/f4b3a0e830e42e2fee54829326389709dd422098/packages/taiko-client/pkg/chain_iterator/block_batch_iterator.go#L19
9393
pub const DEFAULT_BLOCK_CONFIRMATIONS: u64 = 0;
9494
// const BACK_OFF_MAX_RETRIES: u64 = 5;
@@ -201,7 +201,7 @@ impl BlockHashAndNumber {
201201

202202
#[derive(Clone)]
203203
struct Config {
204-
blocks_read_per_epoch: u32,
204+
blocks_read_per_epoch: usize,
205205
reorg_rewind_depth: u64,
206206
#[allow(
207207
dead_code,
@@ -211,7 +211,7 @@ struct Config {
211211
}
212212

213213
pub struct BlockRangeScanner {
214-
blocks_read_per_epoch: u32,
214+
blocks_read_per_epoch: usize,
215215
reorg_rewind_depth: u64,
216216
block_confirmations: u64,
217217
}
@@ -233,7 +233,7 @@ impl BlockRangeScanner {
233233
}
234234

235235
#[must_use]
236-
pub fn with_blocks_read_per_epoch(mut self, blocks_read_per_epoch: u32) -> Self {
236+
pub fn with_blocks_read_per_epoch(mut self, blocks_read_per_epoch: usize) -> Self {
237237
self.blocks_read_per_epoch = blocks_read_per_epoch;
238238
self
239239
}
@@ -620,8 +620,7 @@ impl<N: Network> Service<N> {
620620

621621
// we're iterating in reverse
622622
let stream_end = *block_range.start();
623-
// SAFETY: u32 can always be cast as usize
624-
let range_iter = block_range.rev().step_by(blocks_read_per_epoch as usize);
623+
let range_iter = block_range.rev().step_by(blocks_read_per_epoch);
625624

626625
for batch_end in range_iter {
627626
let batch_start =

src/event_scanner.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl EventScanner {
8686

8787
/// Configures how many blocks are read per epoch during a historical sync.
8888
#[must_use]
89-
pub fn with_blocks_read_per_epoch(mut self, blocks_read_per_epoch: u32) -> Self {
89+
pub fn with_blocks_read_per_epoch(mut self, blocks_read_per_epoch: usize) -> Self {
9090
self.block_range_scanner =
9191
self.block_range_scanner.with_blocks_read_per_epoch(blocks_read_per_epoch);
9292
self
@@ -190,6 +190,11 @@ impl<N: Network> ConnectedEventScanner<N> {
190190
Ok(())
191191
}
192192

193+
/// Scans the latest blocks and returns the specified number of events.
194+
///
195+
/// # Errors
196+
///
197+
/// Returns an error if the scanner fails to start
193198
pub async fn scan_latest(
194199
self,
195200
count: usize,
@@ -226,8 +231,8 @@ impl<N: Network> ConnectedEventScanner<N> {
226231
match sub.recv().await {
227232
Ok(BlockRangeMessage::Data(range)) => {
228233
let logs = Self::get_logs(range, &filter, &log_filter, &provider).await;
229-
if let Ok(logs) = &logs
230-
&& logs.is_empty()
234+
if let Ok(logs) = &logs &&
235+
logs.is_empty()
231236
{
232237
continue;
233238
}
@@ -268,7 +273,7 @@ impl<N: Network> ConnectedEventScanner<N> {
268273
let mut sub = range_tx.subscribe();
269274

270275
tokio::spawn(async move {
271-
let mut events = Vec::with_capacity(count as usize);
276+
let mut events = Vec::with_capacity(count);
272277
loop {
273278
match sub.recv().await {
274279
Ok(BlockRangeMessage::Data(range)) => {

tests/historic_to_live/basic.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use alloy::{eips::BlockNumberOrTag, network::Ethereum, primitives::U256, sol_types::SolEvent};
2-
use event_scanner::types::ScannerStatus;
3-
use event_scanner::{event_filter::EventFilter, event_scanner::EventScanner};
2+
use event_scanner::{event_filter::EventFilter, event_scanner::EventScanner, types::ScannerStatus};
43

5-
use crate::common::{TestCounter, build_provider, deploy_counter, spawn_anvil};
6-
use crate::{assert_next_logs, assert_next_status};
4+
use crate::{
5+
assert_next_logs, assert_next_status,
6+
common::{TestCounter, build_provider, deploy_counter, spawn_anvil},
7+
};
78

89
#[tokio::test]
910
async fn replays_historical_then_switches_to_live() -> anyhow::Result<()> {

tests/latest_events/basic.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,23 @@ async fn collect_events(
2121
loop {
2222
match stream.next().await {
2323
Some(EventScannerMessage::Data(logs)) => return logs,
24-
Some(EventScannerMessage::Error(_)) => continue,
25-
Some(EventScannerMessage::Status(_)) => continue,
2624
None => return vec![],
25+
_ => {}
2726
}
2827
}
2928
}
3029

3130
fn assert_ordering(
32-
logs: Vec<Log>,
31+
logs: &[Log],
3332
expected_first_count: u64,
34-
expected_hashes: Vec<FixedBytes<32>>,
33+
expected_hashes: &[FixedBytes<32>],
3534
expected_address: &Address,
3635
) {
3736
let mut expected_count = U256::from(expected_first_count);
3837
for (log, &expected_hash) in logs.iter().zip(expected_hashes.iter()) {
39-
let event = log.log_decode::<TestCounter::CountIncreased>().expect(
40-
format!("expected sig: 'TestCounter::CountIncreased', got: {:?}", log.topic0())
41-
.as_str(),
42-
);
38+
let event = log.log_decode::<TestCounter::CountIncreased>().unwrap_or_else(|_| {
39+
panic!("expected sig: 'TestCounter::CountIncreased', got: {:?}", log.topic0())
40+
});
4341
assert_eq!(&event.address(), expected_address);
4442
assert_eq!(event.transaction_hash.unwrap(), expected_hash);
4543
assert_eq!(expected_count, event.inner.newCount);
@@ -70,9 +68,9 @@ async fn scan_latest_exact_count_returns_last_events_in_order() -> anyhow::Resul
7068

7169
// Verify exact events (address, signature, tx hashes)
7270
let expected_first_count = 4;
73-
let expected_hashes = tx_hashes[3..8].to_vec();
71+
let expected_hashes = &tx_hashes[3..8];
7472

75-
assert_ordering(logs, expected_first_count, expected_hashes, contract.address());
73+
assert_ordering(&logs, expected_first_count, expected_hashes, contract.address());
7674

7775
Ok(())
7876
}
@@ -100,7 +98,7 @@ async fn scan_latest_fewer_available_than_count_returns_all() -> anyhow::Result<
10098
// Verify exact events
10199
let expected_first_count = 1;
102100

103-
assert_ordering(logs, expected_first_count, tx_hashes, contract.address());
101+
assert_ordering(&logs, expected_first_count, &tx_hashes, contract.address());
104102

105103
Ok(())
106104
}
@@ -155,10 +153,10 @@ async fn scan_latest_respects_range_subset() -> anyhow::Result<()> {
155153
// Expect last 4 emitted events exactly (the 2 empty blocks contain no events)
156154
assert_eq!(logs.len(), 2);
157155

158-
let expected_hashes = tx_hashes[4..6].to_vec(); // counts 5..6
156+
let expected_hashes = &tx_hashes[4..6]; // counts 5..6
159157
let expected_first_count = 5;
160158

161-
assert_ordering(logs, expected_first_count, expected_hashes, contract.address());
159+
assert_ordering(&logs, expected_first_count, expected_hashes, contract.address());
162160

163161
Ok(())
164162
}
@@ -193,9 +191,9 @@ async fn scan_latest_multiple_listeners_to_same_event_receive_same_results() ->
193191
// since logs are equal, asserting for one, asserts for both
194192
assert_eq!(5, logs1.len());
195193

196-
let expected_hashes = tx_hashes[2..7].to_vec();
194+
let expected_hashes = &tx_hashes[2..7];
197195
let expected_first_count = 3;
198-
assert_ordering(logs1, expected_first_count, expected_hashes, contract.address());
196+
assert_ordering(&logs1, expected_first_count, expected_hashes, contract.address());
199197

200198
Ok(())
201199
}
@@ -243,7 +241,7 @@ async fn scan_latest_different_filters_receive_different_results() -> anyhow::Re
243241

244242
// Validate increases: expect counts 3,4,5 and the corresponding tx hashes from inc_hashes[2..5]
245243
let expected_hashes_inc = inc_hashes[2..5].to_vec();
246-
assert_ordering(logs_inc, 3, expected_hashes_inc, contract.address());
244+
assert_ordering(&logs_inc, 3, &expected_hashes_inc, contract.address());
247245

248246
// Validate decreases: expect counts 4,3 (after two decreases)
249247
let mut expected_count_dec = U256::from(4);
@@ -397,7 +395,7 @@ async fn scan_latest_large_gaps_and_empty_ranges() -> anyhow::Result<()> {
397395

398396
assert_eq!(logs.len(), 3);
399397
// Expect counts 1,2,3 and hashes in order
400-
assert_ordering(logs, 1, hashes, contract.address());
398+
assert_ordering(&logs, 1, &hashes, contract.address());
401399

402400
Ok(())
403401
}

0 commit comments

Comments
 (0)