From 65ff756bb123bb901154339d510264e2f8acbf5f Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Wed, 28 Jan 2026 10:40:37 +0100 Subject: [PATCH 1/4] turn off unnecessary features + remove tokio-util --- Cargo.lock | 1 - Cargo.toml | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d17342ba..ac56fd1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1888,7 +1888,6 @@ dependencies = [ "thiserror", "tokio", "tokio-stream", - "tokio-util", "tracing", "tracing-subscriber", ] diff --git a/Cargo.toml b/Cargo.toml index f91e914d..1587146a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,14 +28,13 @@ exclude = [ [dependencies] alloy = "1.1.2" -tokio = { version = "1.48", features = ["full"] } -futures = "0.3.31" +tokio = "1.48" +futures = { version = "0.3.31", default-features = false } anyhow = "1.0" thiserror = "2.0.17" -tokio-stream = "0.1.17" +tokio-stream = { version = "0.1.17", default-features = false } tracing = "0.1" robust-provider = "0.2.0" -tokio-util = "0.7.17" serde = { version = "1.0", features = ["derive"], optional = true } serde_json = { version = "1.0", optional = true } flate2 = { version = "1.1", optional = true } From 1aeb5a3f3ec25dad2df75d4c6220f77a90ccc64e Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Wed, 28 Jan 2026 10:52:04 +0100 Subject: [PATCH 2/4] make anyhow optional --- Cargo.toml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1587146a..ff7e7f7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,14 +27,15 @@ exclude = [ ] [dependencies] -alloy = "1.1.2" +alloy = { version = "1.1.2", default-features = false } tokio = "1.48" futures = { version = "0.3.31", default-features = false } -anyhow = "1.0" thiserror = "2.0.17" tokio-stream = { version = "0.1.17", default-features = false } tracing = "0.1" robust-provider = "0.2.0" + +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 } @@ -68,9 +69,10 @@ path = "bin/generate_dump.rs" required-features = ["bench-utils"] [features] -test-utils = [] +test-utils = ["dep:anyhow"] tracing = [] bench-utils = [ + "dep:anyhow", "dep:serde", "dep:serde_json", "dep:flate2", From 6cf92cdea0fa3ec9c9ca7352203f0d98c78f4007 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Wed, 28 Jan 2026 10:53:19 +0100 Subject: [PATCH 3/4] make tracing optional --- Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ff7e7f7a..dbccfe1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,13 +32,13 @@ tokio = "1.48" futures = { version = "0.3.31", default-features = false } thiserror = "2.0.17" tokio-stream = { version = "0.1.17", default-features = false } -tracing = "0.1" robust-provider = "0.2.0" 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"] } @@ -70,12 +70,13 @@ required-features = ["bench-utils"] [features] test-utils = ["dep:anyhow"] -tracing = [] +tracing = ["dep:tracing"] bench-utils = [ "dep:anyhow", "dep:serde", "dep:serde_json", "dep:flate2", + "dep:tracing", "alloy/node-bindings", ] From c1074427199eb0d4649279ac707fe7fe570aa843 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Wed, 28 Jan 2026 11:07:26 +0100 Subject: [PATCH 4/4] fix tracing issue when tracing feature not enabled + fix example builds --- CONTRIBUTING.md | 10 ++++---- Cargo.toml | 26 +++++++++++++++++++++ README.md | 8 ++----- src/block_range_scanner/common.rs | 4 +--- src/block_range_scanner/rewind_handler.rs | 8 +++---- src/block_range_scanner/scanner.rs | 3 +-- src/event_scanner/modes/sync/from_latest.rs | 2 +- src/macros/tracing.rs | 25 ++++++++------------ 8 files changed, 49 insertions(+), 37 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 427e63ae..da47f4ff 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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: @@ -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. diff --git a/Cargo.toml b/Cargo.toml index dbccfe1c..11b60188 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,6 +68,31 @@ 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 = ["dep:anyhow"] tracing = ["dep:tracing"] @@ -79,6 +104,7 @@ bench-utils = [ "dep:tracing", "alloy/node-bindings", ] +example = ["tracing", "dep:anyhow"] [profile.release] lto = "thin" diff --git a/README.md b/README.md index 9ff853b1..995f26d9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/block_range_scanner/common.rs b/src/block_range_scanner/common.rs index 0bae1332..0a3bc8fb 100644 --- a/src/block_range_scanner/common.rs +++ b/src/block_range_scanner/common.rs @@ -410,12 +410,10 @@ pub(crate) async fn stream_historical_range>( // 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)" ); diff --git a/src/block_range_scanner/rewind_handler.rs b/src/block_range_scanner/rewind_handler.rs index 9dddff61..713a68ed 100644 --- a/src/block_range_scanner/rewind_handler.rs +++ b/src/block_range_scanner/rewind_handler.rs @@ -62,12 +62,10 @@ impl RewindHandler { _ => (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" ); diff --git a/src/block_range_scanner/scanner.rs b/src/block_range_scanner/scanner.rs index e9ab0954..8d3849ea 100644 --- a/src/block_range_scanner/scanner.rs +++ b/src/block_range_scanner/scanner.rs @@ -235,11 +235,10 @@ impl BlockRangeScanner { _ => (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" ); diff --git a/src/event_scanner/modes/sync/from_latest.rs b/src/event_scanner/modes/sync/from_latest.rs index bb7bba5f..f6c768f7 100644 --- a/src/event_scanner/modes/sync/from_latest.rs +++ b/src/event_scanner/modes/sync/from_latest.rs @@ -113,7 +113,7 @@ impl EventScanner { 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( diff --git a/src/macros/tracing.rs b/src/macros/tracing.rs index eec3e53b..65d57e18 100644 --- a/src/macros/tracing.rs +++ b/src/macros/tracing.rs @@ -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)*) }; }