Repository navigation
fix(node): stop flooding local anvil with eth_getFilterChanges (#1011) - #1012
Conversation
Against a localhost anvil a decdn-node issued ~80 eth_getFilterChanges/sec in steady state. Two factors compounded: alloy auto-detects 127.0.0.1 / localhost as "local" and hard-codes a 250 ms filter poll interval, and a node held ~20 long-lived per-event .watch() filters, each polling on its own tick. Neither shows up on the live Arbitrum Sepolia testnet (alloy polls every 7000 ms there). All three issue fixes land together: 1. with_poll_interval helper sets an explicit filter poll interval on every chain-event provider (all 6 construction sites in runtime/mod.rs), via alloy's interior-mutable RpcClient::set_poll_interval — overriding the 250 ms localhost default. A unit test pins the override (and asserts alloy really does seed 250 ms for a 127.0.0.1 URL). 2. blockchain.event_poll_interval_ms config knob (default 7000 ms, matching alloy's non-local cadence so live-RPC load is unchanged; min 250 ms), wired through the full config-knob convention (schema, resolver + validation, ResolvedBlockchain, config validate summary, DEFAULT_CONFIG) with reject-below-min and default-when-absent tests. 3. Consolidate the per-event filters into one multi-topic Filter per contract address (a topic0 OR-set), demuxed by Log::topic0 + decode_log_data, via a new chain_events::watch_contract_events helper. Cuts ~20 long-lived filters to 6 across the five watchers (chain_staker_set, node_address, payment_settlement, reputation_indexer, chain_origin_directory), independent of poll interval — the only fix that also helps the live testnet. Error/ordering semantics are preserved: the underlying poller swallows transport errors and retries (unchanged), decode failures surface as Err to trip the existing backoff, and origin-directory keeps installing filters before the resync pass so events buffer over the catch-up gap. Verified: cargo build, clippy --all-targets (workspace), fmt, cargo doc, 1306 unit / integration tests, and the anvil-e2e on-chain settlement test (exercises the refactored PaymentChannel watcher end-to-end against a live chain). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (7)
WalkthroughAdds ChangesBlockchain Event Filter Consolidation and Poll Interval Config
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a configurable event_poll_interval_ms and refactors the chain watchers to use a single multi-topic filter per contract address instead of multiple per-event filters, addressing the issue of flooding RPC endpoints with eth_getFilterChanges requests. A critical issue was identified across multiple watcher files (chain_origin_directory.rs, chain_staker_set.rs, node_address.rs, payment_settlement.rs, and reputation_indexer.rs) where the use of decode_log_data fails to decode indexed fields, which will break the watcher logic. It is recommended to use decode_log(&log.inner, true) instead to correctly decode both indexed and non-indexed fields.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR addresses excessive eth_getFilterChanges traffic against local Anvil endpoints by (a) explicitly overriding alloy’s localhost-default filter poll cadence and (b) reducing the number of long-lived log filters by consolidating per-event watches into per-contract multi-topic filters. This fits into the node’s on-chain watcher subsystem (staker set, origin directory, payment settlement, reputation indexer) and the shared config/resolution pipeline.
Changes:
- Add a
blockchain.event_poll_interval_msconfig knob (default 7000ms, min 250ms) and apply it to all node-built providers via awith_poll_intervalhelper. - Collapse watcher subscriptions from many per-event
.watch()filters into single per-contract multi-topic filters viachain_events::watch_contract_events. - Add tests to pin the localhost default behavior (250ms) and validate resolution defaults/minimums for the new config knob.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/tests/sighup_signal.rs | Update test config seed to include event_poll_interval_ms. |
| crates/node/src/runtime/reload.rs | Extend runtime reload test fixtures to include the new resolved field. |
| crates/node/src/runtime/mod.rs | Apply explicit provider poll interval everywhere; add unit test pinning alloy localhost default override. |
| crates/node/src/reputation_indexer.rs | Replace per-event watches with one multi-topic PaymentChannel filter + topic0 demux. |
| crates/node/src/payment_settlement.rs | Replace four per-event watches with one multi-topic PaymentChannel filter + topic0 demux. |
| crates/node/src/lib.rs | Export the new chain_events module. |
| crates/node/src/dht/node_address.rs | Replace two per-event CapacityBond watches with one multi-topic filter + topic0 demux. |
| crates/node/src/dht/chain_staker_set.rs | Replace five per-event CapacityBond watches with one multi-topic filter + topic0 demux. |
| crates/node/src/dht/chain_origin_directory.rs | Replace seven per-event watches across two contracts with two per-contract multi-topic filters + demux. |
| crates/node/src/chain_events.rs | New shared helper to open per-contract multi-topic log streams. |
| crates/common/src/config/types.rs | Add event_poll_interval_ms to the file config schema. |
| crates/common/src/config/resolved.rs | Add event_poll_interval_ms to ResolvedBlockchain. |
| crates/common/src/config/mod.rs | Add defaults/min validation + tests; wire resolved field construction. |
| crates/cli/tests/config_validate.rs | Update resolved-config test fixture to include event_poll_interval_ms. |
| crates/cli/src/commands/config.rs | Print the new resolved value in config validate output; document in DEFAULT_CONFIG template. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
crates/node/src/payment_settlement.rs (1)
1025-1026: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUpdate the recovery comments for the unified event stream.
These comments still describe the old per-event stream model (
openedstream / “two streams”). After consolidation, the recovery rationale should refer to the single ordered channel-event stream.Proposed comment update
- // `opened` stream is block-ordered, so the per-cycle hold below - // suffices against a later same-stream open. + // unified event stream is block/log ordered, so the per-cycle + // hold below suffices against a later open.- // checkpoint past this block (the two streams aren't mutually - // ordered), so a crash before the retry lands leaves the - // residual manual-`settleChannel` gap noted at the backfill - // call site. The re-arm closes the common (no-crash) case. + // checkpoint past this block before this close is observed. + // The re-arm closes the common no-crash retry case.Also applies to: 1129-1132
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/node/src/payment_settlement.rs` around lines 1025 - 1026, Update the recovery comments in payment_settlement.rs to describe the unified single ordered channel-event stream instead of the old per-event “opened”/two-stream model. Edit the comments around the recovery logic in the relevant payment settlement paths, including the blocks near the current opened-stream wording and the later matching comment, so they explain the same recovery guarantee using the consolidated stream terminology. Keep the implementation unchanged; only refresh the comment text to match the current stream model and ordering rationale.crates/node/src/dht/chain_staker_set.rs (1)
342-345: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAlign the metrics comment with the clean-end path.
watcher_loophandlesOk(())by immediately resubscribing without callingstaker_set_watcher_backoff_started(), sodown_secondsdoes not climb when the stream ends.Proposed comment fix
- // entire life of this cycle (however long/quiet); it climbs again only if a - // log fails to decode and the loop enters backoff, or the stream ends. + // entire life of this cycle (however long/quiet); it climbs again only if a + // log fails to decode and the loop enters backoff.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/node/src/dht/chain_staker_set.rs` around lines 342 - 345, Update the metrics comment in watcher_loop to match the clean-end behavior: on Ok(()) the loop immediately resubscribes and does not call staker_set_watcher_backoff_started(), so down_since should remain cleared and decdn_staker_set_watcher_down_seconds should stay at 0 for the normal reconnect path. Adjust the wording near the down_since reset to distinguish clean stream end from decode/backoff failures, using watcher_loop and staker_set_watcher_backoff_started as the key references.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/node/src/dht/chain_origin_directory.rs`:
- Around line 743-755: The origin-event dispatch in chain_origin_directory’s
decode/handler branches is exceeding the 100-column Rust formatting limit. Wrap
the long decode_log_data and on_origin_removed/on_namespace_changed call chains
in the affected match arms, keeping the logic in the same branches and
preserving the existing symbols like OriginAssignment::AssignmentActivated,
OriginAssignment::AssignmentRevoked,
OriginAssignment::BlacklistedAssignmentPruned, decode_log_data,
on_namespace_changed, and on_origin_removed.
In `@crates/node/src/dht/chain_staker_set.rs`:
- Line 309: The `#[allow(clippy::cognitive_complexity)]` justification in
`chain_staker_set.rs` exceeds the Rust 100-column limit; wrap the trailing
comment so it stays under the source width limit while keeping the same
justification on the attribute line.
---
Nitpick comments:
In `@crates/node/src/dht/chain_staker_set.rs`:
- Around line 342-345: Update the metrics comment in watcher_loop to match the
clean-end behavior: on Ok(()) the loop immediately resubscribes and does not
call staker_set_watcher_backoff_started(), so down_since should remain cleared
and decdn_staker_set_watcher_down_seconds should stay at 0 for the normal
reconnect path. Adjust the wording near the down_since reset to distinguish
clean stream end from decode/backoff failures, using watcher_loop and
staker_set_watcher_backoff_started as the key references.
In `@crates/node/src/payment_settlement.rs`:
- Around line 1025-1026: Update the recovery comments in payment_settlement.rs
to describe the unified single ordered channel-event stream instead of the old
per-event “opened”/two-stream model. Edit the comments around the recovery logic
in the relevant payment settlement paths, including the blocks near the current
opened-stream wording and the later matching comment, so they explain the same
recovery guarantee using the consolidated stream terminology. Keep the
implementation unchanged; only refresh the comment text to match the current
stream model and ordering rationale.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2128d766-0557-4108-b2e5-50e37894baff
📒 Files selected for processing (15)
crates/cli/src/commands/config.rscrates/cli/tests/config_validate.rscrates/common/src/config/mod.rscrates/common/src/config/resolved.rscrates/common/src/config/types.rscrates/node/src/chain_events.rscrates/node/src/dht/chain_origin_directory.rscrates/node/src/dht/chain_staker_set.rscrates/node/src/dht/node_address.rscrates/node/src/lib.rscrates/node/src/payment_settlement.rscrates/node/src/reputation_indexer.rscrates/node/src/runtime/mod.rscrates/node/src/runtime/reload.rscrates/node/tests/sighup_signal.rs
Coverage reportTotal: 83.20% (was 83.09%, ▲ +0.11%) — 41947/50417 lines
History
|
- chain_origin_directory: import the OriginAssignment/PublisherRegistry event structs directly so the topic0 dispatch (match guards + decode calls) fits under the 100-col width, and wrap the residual on_origin_removed calls. Pure readability/formatting — dispatch behavior is unchanged. - payment_settlement / reputation_indexer: update comments that still described the old per-event multi-stream + tokio::select model to the unified single-filter stream (the block-ordering guarantee still holds: one filter returns logs in block order). No functional change. CodeRabbit nits. The gemini-code-assist "decode_log_data drops indexed fields" finding is a false positive — decode_log_data forwards log.topics() to decode_raw_log, so indexed fields are decoded (confirmed by the alloy source and the passing anvil-e2e settlement test that matches on the indexed channelId/provider). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment-accuracy and observability follow-ups from the comprehensive review; no functional change to the dispatch. - Stream-termination comments (chain_events + 4 watchers): the alloy poller built by `watch_logs` sets no terminal_error_codes, so the stream also ends on a server "filter not found" response (filter expiry / provider rotation), not "only when the provider is dropped". Restored the accurate wording that the old per-event `.watch()` comments carried; two of the stale lines had begun contradicting accurate retained comments in the same files. - payment_settlement: reworded the ChannelCloseInitiated block-fallback rationale and the advance_checkpoint #751 doc — under the unified single filter, opens and closes are mutually block-ordered, so the old cross-stream overshoot race no longer exists (the `unwrap_or(0)` full-rescan is kept as the simplest provably-safe choice for a no-block log). - All five `_ => {}` catch-all arms now `debug!` the unmatched topic0 instead of silently dropping: unreachable today (the filter's OR-set bounds inputs), but a future OR-set/dispatch drift now leaves a greppable trail. - Added a config boundary test pinning that exactly MIN (250ms) is accepted and an in-range value is preserved through resolution (mirrors the rpc_watchdog boundary test). Declined: an upper bound on event_poll_interval_ms (the sibling rpc_watchdog_interval_sec has a floor and no ceiling — consistency wins). Deferred: provider-free dispatch-routing tests for the 5 watchers (the high-value version needs a classify() extraction or a mock provider; tracked as a follow-up rather than expanding this PR). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Fixes #1011. Against a localhost anvil a
decdn-nodeissued ~80eth_getFilterChanges/sec in steady state, flooding the dev RPC and node logs. Two factors compounded:127.0.0.1/localhostas "local" and hard-codes a 250 ms filter poll interval. Every provider was built bare, inheriting it. On the live Arbitrum Sepolia testnetis_local == false, so alloy polls every 7000 ms and the bug never surfaces there..watch()filters, each issuing its owneth_getFilterChangesper tick (~20 × 4/sec ≈ 80/sec).All three issue fixes land together:
1. Surgical — explicit poll interval (
with_poll_interval)A helper in
runtime/mod.rssets an explicit filter poll interval on every chain-event provider (all 6 construction sites), via alloy's interior-mutableRpcClient::set_poll_interval, overriding the 250 ms localhost default. A unit test pins the override — and asserts alloy really does seed 250 ms for a127.0.0.1URL, validating the root cause.2. Config knob
blockchain.event_poll_interval_msDefault 7000 ms (matches alloy's non-local cadence, so live-RPC load is unchanged), minimum 250 ms. Wired through the full config-knob convention (schema, resolver + validation,
ResolvedBlockchain,config validatesummary,DEFAULT_CONFIG) with reject-below-min and default-when-absent tests. Local dev can lower it (e.g.1000) for snappier event pickup.3. Structural — one multi-topic filter per contract
A new
chain_events::watch_contract_eventshelper collapses the per-event filters into a single multi-topicFilterper contract address (atopic0OR-set), demuxed byLog::topic0+decode_log_data. Cuts ~20 long-lived filters to 6 across the five watchers (chain_staker_set,node_address,payment_settlement,reputation_indexer,chain_origin_directory), independent of poll interval — the only fix that also helps the live testnet.Error/ordering semantics are preserved: the underlying alloy poller swallows transport errors and retries (unchanged from the old typed streams); decode failures surface as
Errto trip the existing backoff; andchain_origin_directorykeeps installing filters before its resync pass so events buffer over the catch-up gap.Acceptance
eth_getFilterChangesrate drops; test added.blockchain.event_poll_interval_ms.Verification
cargo build,cargo clippy --all-targets(workspace),cargo fmt --check,cargo doc— cleancargo nextest run— 1306 tests passcargo nextest run -p decdn-node --features anvil-e2e— the on-chaine2e_onchain_payment_channel_settlementtest exercises the refactored PaymentChannel watcher end-to-end against a live anvil chain ✅🤖 Generated with Claude Code
Summary by CodeRabbit
blockchain.event_poll_interval_mswith documented default (7000ms) and minimum (250ms).decdn config validatenow shows the resolved polling interval.