Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ cargo test --features test-utils
Run examples:

```bash
RUST_LOG=info cargo run --example live_scanning
RUST_LOG=info cargo run --example live_scanningu --features example
# or
RUST_LOG=info cargo run --example historical_scanning
RUST_LOG=info cargo run --example historical_scanning --features example
```

Logging / observability notes:
Expand All @@ -82,16 +82,16 @@ Logging / observability notes:
- If the feature is disabled, internal logging calls compile to **no-ops**.
- Examples install a `tracing_subscriber` and read filters from `RUST_LOG`.

Enable internal logs when running an example:
When running an example with internal logging, simply enable the `example` feature:

```bash
RUST_LOG=event_scanner=debug cargo run --example historical_scanning --features tracing
RUST_LOG=event_scanner=debug cargo run --example historical_scanning --features example
```

You can also combine filters to keep other dependencies quiet:

```bash
RUST_LOG=warn,event_scanner=info cargo run --example historical_scanning --features tracing
RUST_LOG=warn,event_scanner=info cargo run --example historical_scanning --features example
```

Note: Examples start a local `anvil` instance and deploy a demo contract. If you run into issues when using a different node/provider, please report them at https://github.com/OpenZeppelin/Event-Scanner/issues.
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 37 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ exclude = [
]

[dependencies]
alloy = "1.1.2"
tokio = { version = "1.48", features = ["full"] }
futures = "0.3.31"
anyhow = "1.0"
alloy = { version = "1.1.2", default-features = false }
tokio = "1.48"
futures = { version = "0.3.31", default-features = false }
thiserror = "2.0.17"
tokio-stream = "0.1.17"
tracing = "0.1"
tokio-stream = { version = "0.1.17", default-features = false }
robust-provider = "0.2.0"
tokio-util = "0.7.17"

anyhow = { version = "1.0", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }
flate2 = { version = "1.1", optional = true }
tracing = { version = "0.1", optional = true }

[dev-dependencies]
alloy = { version = "1.1.2", features = ["node-bindings"] }
Expand Down Expand Up @@ -68,15 +68,43 @@ name = "generate_dump"
path = "bin/generate_dump.rs"
required-features = ["bench-utils"]

[[example]]
name = "historical_scanning"
path = "examples/historical_scanning.rs"
required-features = ["example"]

[[example]]
name = "latest_events_scanning"
path = "examples/latest_events_scanning.rs"
required-features = ["example"]

[[example]]
name = "live_scanning"
path = "examples/live_scanning.rs"
required-features = ["example"]

[[example]]
name = "sync_from_block_scanning"
path = "examples/sync_from_block_scanning.rs"
required-features = ["example"]

[[example]]
name = "sync_from_latest_scanning"
path = "examples/sync_from_latest_scanning.rs"
required-features = ["example"]

[features]
test-utils = []
tracing = []
test-utils = ["dep:anyhow"]
tracing = ["dep:tracing"]
bench-utils = [
"dep:anyhow",
"dep:serde",
"dep:serde_json",
"dep:flate2",
"dep:tracing",
"alloy/node-bindings",
]
example = ["tracing", "dep:anyhow"]

[profile.release]
lto = "thin"
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,10 @@ Notes:
Run an example with:

```bash
RUST_LOG=info cargo run --example live_scanning
RUST_LOG=info cargo run --example live_scanning --features example
```

To also enable `event-scanner` internal logs in the examples:

```bash
RUST_LOG=event_scanner=debug cargo run --example live_scanning --features tracing
```
This will also enable `event-scanner` internal logs in the example.

All examples spin up a local `anvil` instance, deploy a demo counter contract, and demonstrate using event streams to process events.

Expand Down
4 changes: 1 addition & 3 deletions src/block_range_scanner/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,10 @@ pub(crate) async fn stream_historical_range<N: Network, R: ReorgHandler<N>>(

// no reorg check for finalized blocks
let finalized_batch_end = finalized_block_num.min(end);
let finalized_range_count =
RangeIterator::forward(start, finalized_batch_end, max_block_range).count();
trace!(
start = start,
finalized_batch_end = finalized_batch_end,
batch_count = finalized_range_count,
batch_count = RangeIterator::forward(start, finalized_batch_end, max_block_range).count(),
"Streaming finalized blocks (no reorg check)"
);

Expand Down
8 changes: 3 additions & 5 deletions src/block_range_scanner/rewind_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ impl<N: Network> RewindHandler<N> {
_ => (end_block, start_block),
};

let from_num = from.header().number();
let to_num = to.header().number();
info!(
from_block = from_num,
to_block = to_num,
total_blocks = from_num.saturating_sub(to_num) + 1,
from_block = from.header().number(),
to_block = to.header().number(),
total_blocks = from.header().number().saturating_sub(to.header().number()) + 1,
"Starting rewind stream"
);

Expand Down
3 changes: 1 addition & 2 deletions src/block_range_scanner/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,10 @@ impl<N: Network> BlockRangeScanner<N> {
_ => (start_block_num, end_block_num),
};

let total_blocks = end_block_num.saturating_sub(start_block_num) + 1;
debug!(
from_block = start_block_num,
to_block = end_block_num,
total_blocks = total_blocks,
total_blocks = end_block_num.saturating_sub(start_block_num) + 1,
max_block_range = max_block_range,
"Starting historical block stream"
);
Expand Down
2 changes: 1 addition & 1 deletion src/event_scanner/modes/sync/from_latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<N: Network> EventScanner<SyncFromLatestEvents, N> {
self.block_range_scanner.provider().clone(),
listeners.clone(),
self.config.max_concurrent_fetches,
self.config.count,
count,
broadcast_channel_capacity,
);
let stream_handler = StreamHandler::new(
Expand Down
25 changes: 10 additions & 15 deletions src/macros/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,39 @@
#[allow(unused_macros)]
macro_rules! error {
($($arg:tt)*) => {
if cfg!(feature = "tracing") {
tracing::error!(target: "event_scanner", $($arg)*)
}
#[cfg(feature = "tracing")]
tracing::error!(target: "event_scanner", $($arg)*)
};
}

#[allow(unused_macros)]
macro_rules! warn {
($($arg:tt)*) => {
if cfg!(feature = "tracing") {
tracing::warn!(target: "event_scanner", $($arg)*)
}
#[cfg(feature = "tracing")]
tracing::warn!(target: "event_scanner", $($arg)*)
};
}

#[allow(unused_macros)]
macro_rules! info {
($($arg:tt)*) => {
if cfg!(feature = "tracing") {
tracing::info!(target: "event_scanner", $($arg)*)
}
#[cfg(feature = "tracing")]
tracing::info!(target: "event_scanner", $($arg)*)
};
}

#[allow(unused_macros)]
macro_rules! debug {
($($arg:tt)*) => {
if cfg!(feature = "tracing") {
tracing::debug!(target: "event_scanner", $($arg)*)
}
#[cfg(feature = "tracing")]
tracing::debug!(target: "event_scanner", $($arg)*)
};
}

#[allow(unused_macros)]
macro_rules! trace {
($($arg:tt)*) => {
if cfg!(feature = "tracing") {
tracing::trace!(target: "event_scanner", $($arg)*)
}
#[cfg(feature = "tracing")]
tracing::trace!(target: "event_scanner", $($arg)*)
};
}