Skip to content

Commit c621b8e

Browse files
committed
Merge branch 'main' into integration-tests
2 parents 7cc53e5 + 2a74b92 commit c621b8e

File tree

6 files changed

+102
-23
lines changed

6 files changed

+102
-23
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ jobs:
6969
components: clippy
7070

7171
- name: Clippy Check
72-
uses: giraffate/clippy-action@v1
73-
with:
74-
reporter: "github-pr-check"
75-
github_token: ${{ secrets.GITHUB_TOKEN }}
76-
clippy_flags: --all-targets --all-features -- -D warnings -D clippy::pedantic
72+
run: cargo clippy --all-targets --all-features -- -D warnings -D clippy::pedantic
7773

7874
typos-cli:
7975
name: typos

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
- name: Install stable toolchain
2626
uses: actions-rust-lang/setup-rust-toolchain@v1
2727

28+
- name: Install Foundry
29+
uses: foundry-rs/foundry-toolchain@v1
30+
2831
- name: Cache cargo-nextest binary
2932
id: cache-cargo-nextest
3033
uses: actions/cache@v4
@@ -39,7 +42,7 @@ jobs:
3942
tool: cargo-nextest
4043

4144
- name: Cargo test
42-
run: cargo nextest run --locked --all-targets --all-features --no-tests=pass
45+
run: cargo nextest run --locked --all-targets --all-features --no-tests=pass --no-fail-fast
4346

4447
# https://github.com/rust-lang/cargo/issues/6669
4548
- name: Run doc tests

src/block_scanner.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use std::{marker::PhantomData, time::Duration};
1+
#![allow(unused)]
2+
3+
use std::{future, marker::PhantomData, time::Duration};
24

35
use tokio::sync::mpsc::{self, Receiver, Sender};
46
use tokio_stream::wrappers::ReceiverStream;
@@ -16,7 +18,7 @@ use alloy::{
1618
};
1719

1820
// copied form https://github.com/taikoxyz/taiko-mono/blob/f4b3a0e830e42e2fee54829326389709dd422098/packages/taiko-client/pkg/chain_iterator/block_batch_iterator.go#L19
19-
const DEFAULT_BLOCKS_READ_PER_EPOCH: u64 = 1000;
21+
const DEFAULT_BLOCKS_READ_PER_EPOCH: usize = 1000;
2022
const DEFAULT_RETRY_INTERVAL: Duration = Duration::from_secs(12);
2123
const DEFAULT_BLOCK_CONFIRMATIONS: u64 = 0;
2224
const BACK_OFF_MAX_RETRIES: u64 = 5;
@@ -41,7 +43,7 @@ impl std::fmt::Display for BlockScannerError {
4143
BlockScannerError::ErrEOF => write!(f, "end of block batch iterator"),
4244
BlockScannerError::ErrContinue => write!(f, "continue"),
4345
BlockScannerError::TerminalError(height) => {
44-
write!(f, "terminal error at block height {}", height)
46+
write!(f, "terminal error at block height {height}")
4547
}
4648
}
4749
}
@@ -53,7 +55,7 @@ pub type OnBlocksFunc<N> =
5355
fn(<N as Network>::BlockResponse, UpdateCurrentFunc, EndIterFunc) -> anyhow::Result<()>;
5456

5557
pub struct BlockScannerBuilder<N: Network> {
56-
blocks_read_per_epoch: u64,
58+
blocks_read_per_epoch: usize,
5759
start_height: BlockNumberOrTag,
5860
end_height: BlockNumberOrTag,
5961
on_blocks: OnBlocksFunc<N>,
@@ -69,6 +71,7 @@ impl<N: Network> Default for BlockScannerBuilder<N> {
6971
}
7072

7173
impl<N: Network> BlockScannerBuilder<N> {
74+
#[must_use]
7275
pub fn new() -> Self {
7376
Self {
7477
blocks_read_per_epoch: DEFAULT_BLOCKS_READ_PER_EPOCH,
@@ -81,41 +84,53 @@ impl<N: Network> BlockScannerBuilder<N> {
8184
}
8285
}
8386

84-
pub fn with_blocks_read_per_epoch(&mut self, blocks_read_per_epoch: u64) -> &mut Self {
87+
#[must_use]
88+
pub fn with_blocks_read_per_epoch(&mut self, blocks_read_per_epoch: usize) -> &mut Self {
8589
self.blocks_read_per_epoch = blocks_read_per_epoch;
8690
self
8791
}
8892

93+
#[must_use]
8994
pub fn with_start_height(&mut self, start_height: BlockNumberOrTag) -> &mut Self {
9095
self.start_height = start_height;
9196
self
9297
}
9398

99+
#[must_use]
94100
pub fn with_end_height(&mut self, end_height: BlockNumberOrTag) -> &mut Self {
95101
self.end_height = end_height;
96102
self
97103
}
98104

105+
#[must_use]
99106
pub fn with_on_blocks(&mut self, on_blocks: OnBlocksFunc<N>) -> &mut Self {
100107
self.on_blocks = on_blocks;
101108
self
102109
}
103110

111+
#[must_use]
104112
pub fn with_reorg_rewind_depth(&mut self, reorg_rewind_depth: u64) -> &mut Self {
105113
self.reorg_rewind_depth = reorg_rewind_depth;
106114
self
107115
}
108116

117+
#[must_use]
109118
pub fn with_retry_interval(&mut self, retry_interval: Duration) -> &mut Self {
110119
self.retry_interval = retry_interval;
111120
self
112121
}
113122

123+
#[must_use]
114124
pub fn with_block_confirmations(&mut self, block_confirmations: u64) -> &mut Self {
115125
self.block_confirmations = block_confirmations;
116126
self
117127
}
118128

129+
/// Connects to the provider via WebSocket
130+
///
131+
/// # Errors
132+
///
133+
/// Returns an error if the connection fails
119134
pub async fn connect_ws(
120135
self,
121136
connect: WsConnect,
@@ -124,6 +139,11 @@ impl<N: Network> BlockScannerBuilder<N> {
124139
Ok(self.connect_client(client))
125140
}
126141

142+
/// Connects to the provider via IPC
143+
///
144+
/// # Errors
145+
///
146+
/// Returns an error if the connection fails
127147
pub async fn connect_ipc<T>(
128148
self,
129149
connect: IpcConnect<T>,
@@ -135,6 +155,7 @@ impl<N: Network> BlockScannerBuilder<N> {
135155
Ok(self.connect_client(client))
136156
}
137157

158+
#[must_use]
138159
pub fn connect_client(self, client: RpcClient) -> BlockScanner<RootProvider<N>, N> {
139160
let provider = RootProvider::new(client);
140161
self.connect_provider(provider)
@@ -144,7 +165,7 @@ impl<N: Network> BlockScannerBuilder<N> {
144165
where
145166
P: Provider<N>,
146167
{
147-
let (sender, receiver) = mpsc::channel(self.blocks_read_per_epoch.try_into().unwrap());
168+
let (sender, receiver) = mpsc::channel(self.blocks_read_per_epoch);
148169

149170
BlockScanner {
150171
provider,
@@ -170,7 +191,7 @@ pub struct BlockScanner<P: Provider<N>, N: Network> {
170191
provider: P,
171192
sender: Sender<Result<N::BlockResponse, BlockScannerError>>,
172193
receiver: Receiver<Result<N::BlockResponse, BlockScannerError>>,
173-
blocks_read_per_epoch: u64,
194+
blocks_read_per_epoch: usize,
174195
start_height: BlockNumberOrTag,
175196
end_height: BlockNumberOrTag,
176197
current: Header,
@@ -190,6 +211,8 @@ where
190211
pub async fn start(self) -> ReceiverStream<Result<N::BlockResponse, BlockScannerError>> {
191212
let receiver_stream = ReceiverStream::new(self.receiver);
192213

214+
future::ready(()).await;
215+
193216
tokio::spawn(async move {
194217
if self.sender.send(Err(BlockScannerError::ErrEOF {})).await.is_err() {}
195218
});
@@ -205,6 +228,7 @@ mod tests {
205228
use alloy_node_bindings::Anvil;
206229
use tokio_stream::StreamExt;
207230

231+
#[allow(clippy::unnecessary_wraps)]
208232
fn no_op_on_blocks<N: Network>(
209233
_block: <N as Network>::BlockResponse,
210234
_update_current: UpdateCurrentFunc,
@@ -266,7 +290,7 @@ mod tests {
266290
let first = stream.next().await;
267291
match first {
268292
Some(Err(BlockScannerError::ErrEOF)) => {}
269-
other => panic!("expected first stream item to be ErrEOF, got: {:?}", other),
293+
other => panic!("expected first stream item to be ErrEOF, got: {other:?}"),
270294
}
271295
}
272296

src/builder.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,47 @@ impl ScannerBuilder {
2424
}
2525
}
2626

27+
#[must_use]
2728
pub fn start_block(mut self, start_block: u64) -> Self {
2829
self.start_block = Some(start_block);
2930
self
3031
}
3132

33+
#[must_use]
3234
pub fn end_block(mut self, end_block: u64) -> Self {
3335
self.end_block = Some(end_block);
3436
self
3537
}
3638

39+
#[must_use]
3740
pub fn max_blocks_per_filter(mut self, max_blocks: u64) -> Self {
3841
self.max_blocks_per_filter = max_blocks;
3942
self
4043
}
4144

45+
#[must_use]
4246
pub fn add_event_filter(mut self, filter: EventFilter) -> Self {
4347
self.tracked_events.push(filter);
4448
self
4549
}
4650

51+
#[must_use]
4752
pub fn add_event_filters(mut self, filters: Vec<EventFilter>) -> Self {
4853
self.tracked_events.extend(filters);
4954
self
5055
}
5156

57+
#[must_use]
5258
pub fn callback_config(mut self, cfg: CallbackConfig) -> Self {
5359
self.callback_config = cfg;
5460
self
5561
}
5662

63+
/// Builds the scanner
64+
///
65+
/// # Errors
66+
///
67+
/// Returns an error if the scanner fails to build
5768
pub async fn build(self) -> anyhow::Result<Scanner> {
5869
Scanner::new(
5970
self.rpc_url,

src/event_scanner.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use std::time::Duration;
1+
#![allow(unused)]
2+
3+
use std::{future, time::Duration};
24

35
use crate::{
46
block_scanner::{BlockScanner, BlockScannerBuilder, OnBlocksFunc},
@@ -26,6 +28,7 @@ impl<N: Network> Default for EventScannerBuilder<N> {
2628
}
2729

2830
impl<N: Network> EventScannerBuilder<N> {
31+
#[must_use]
2932
pub fn new() -> Self {
3033
Self {
3134
block_scanner: BlockScannerBuilder::new(),
@@ -34,56 +37,71 @@ impl<N: Network> EventScannerBuilder<N> {
3437
}
3538
}
3639

40+
#[must_use]
3741
pub fn with_event_filter(mut self, filter: EventFilter) -> Self {
3842
self.tracked_events.push(filter);
3943
self
4044
}
4145

46+
#[must_use]
4247
pub fn with_event_filters(mut self, filters: Vec<EventFilter>) -> Self {
4348
self.tracked_events.extend(filters);
4449
self
4550
}
4651

52+
#[must_use]
4753
pub fn with_callback_config(mut self, cfg: CallbackConfig) -> Self {
4854
self.callback_config = cfg;
4955
self
5056
}
5157

52-
pub fn with_blocks_read_per_epoch(&mut self, blocks_read_per_epoch: u64) -> &mut Self {
58+
#[must_use]
59+
pub fn with_blocks_read_per_epoch(&mut self, blocks_read_per_epoch: usize) -> &mut Self {
5360
self.block_scanner.with_blocks_read_per_epoch(blocks_read_per_epoch);
5461
self
5562
}
5663

64+
#[must_use]
5765
pub fn with_start_height(&mut self, start_height: BlockNumberOrTag) -> &mut Self {
5866
self.block_scanner.with_start_height(start_height);
5967
self
6068
}
6169

70+
#[must_use]
6271
pub fn with_end_height(&mut self, end_height: BlockNumberOrTag) -> &mut Self {
6372
self.block_scanner.with_end_height(end_height);
6473
self
6574
}
6675

76+
#[must_use]
6777
pub fn with_on_blocks(&mut self, on_blocks: OnBlocksFunc<N>) -> &mut Self {
6878
self.block_scanner.with_on_blocks(on_blocks);
6979
self
7080
}
7181

82+
#[must_use]
7283
pub fn with_reorg_rewind_depth(&mut self, reorg_rewind_depth: u64) -> &mut Self {
7384
self.block_scanner.with_reorg_rewind_depth(reorg_rewind_depth);
7485
self
7586
}
7687

88+
#[must_use]
7789
pub fn with_retry_interval(&mut self, retry_interval: Duration) -> &mut Self {
7890
self.block_scanner.with_retry_interval(retry_interval);
7991
self
8092
}
8193

94+
#[must_use]
8295
pub fn with_block_confirmations(&mut self, block_confirmations: u64) -> &mut Self {
8396
self.block_scanner.with_block_confirmations(block_confirmations);
8497
self
8598
}
8699

100+
/// Connects to the provider via WebSocket
101+
///
102+
/// # Errors
103+
///
104+
/// Returns an error if the connection fails
87105
pub async fn connect_ws(
88106
self,
89107
connect: WsConnect,
@@ -96,6 +114,11 @@ impl<N: Network> EventScannerBuilder<N> {
96114
})
97115
}
98116

117+
/// Connects to the provider via IPC
118+
///
119+
/// # Errors
120+
///
121+
/// Returns an error if the connection fails
99122
pub async fn connect_ipc<T>(
100123
self,
101124
connect: IpcConnect<T>,
@@ -111,6 +134,7 @@ impl<N: Network> EventScannerBuilder<N> {
111134
})
112135
}
113136

137+
#[must_use]
114138
pub fn connect_client(self, client: RpcClient) -> EventScanner<RootProvider<N>, N> {
115139
let block_scanner = self.block_scanner.connect_client(client);
116140
EventScanner {
@@ -120,6 +144,7 @@ impl<N: Network> EventScannerBuilder<N> {
120144
}
121145
}
122146

147+
#[must_use]
123148
pub fn connect_provider(self, provider: RootProvider<N>) -> EventScanner<RootProvider<N>, N> {
124149
let block_scanner = self.block_scanner.connect_provider(provider);
125150
EventScanner {
@@ -137,7 +162,13 @@ pub struct EventScanner<P: Provider<N>, N: Network> {
137162
}
138163

139164
impl<P: Provider<N>, N: Network> EventScanner<P, N> {
165+
/// Starts the scanner
166+
///
167+
/// # Errors
168+
///
169+
/// Returns an error if the scanner fails to start
140170
pub async fn start(&mut self) -> anyhow::Result<()> {
171+
future::ready(()).await;
141172
todo!()
142173
}
143174
}

0 commit comments

Comments
 (0)