You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
incentive: watcher bring-up race — bootstrap returns before .watch() filters install, dropping events in the gap #762
kind:bugSomething does not behave as documentedkind:testTest coverage, flakes, fixtures or the e2e harnessprio:mediumScheduledrustDependabot: a Cargo update; use area: labels for Rust code otherwise
PaymentChannelService::bootstrap returns as soon as the watcher task is spawned, but that task then installs four sequential.watch() (eth_newFilter) streams in run_watcher_once (ChannelOpened, ChannelToppedUp, ChannelSettled, ChannelCloseInitiated). .watch() only delivers logs from blocks after the filter exists, so a ChannelOpened (or other event) emitted in the window between bootstrap returning and the filters being installed is never observed — the channel is never registered and its vouchers are rejected with WrongChannel.
In production this is rare: a real client opens a channel, waits for confirmations, then connects — human-scale latency that dwarfs the sub-ms filter-install window. But it is a genuine bring-up race, not a guarantee.
Where it surfaced
PR #752 (anvil e2e settlement harness) has to bridge this race with a fixed sleep(2s) before the first openChannel, because the test mines events milliseconds after bootstrap. A fixed sleep is the classic flaky-test smell; the only reason it's safe today is the large margin (the sleep plus the intervening mint/approve roundtrips). Review thread: #752 (comment)
Proposed fix
Make watcher startup capture a start block and backfill, rather than relying on .watch() alone:
On bootstrap, record the current head S.
Install the .watch() filters; note the block F at which they take over.
get_logs for ChannelOpened (provider == self) over [S, F], registering each (dedup on the overlap block so an event seen by both paths isn't double-applied).
This eliminates the race deterministically and would let #752 replace its readiness sleep with a deterministic wait.
This is the same root cause and same fix as the first checkbox in #751 ("Opened-during-downtime backfill") — both stem from .watch() being forward-only, and a start-block get_logs backfill closes both the downtime gap and this bring-up race. Filing separately per request; these should be implemented together (or this folded into #751) to avoid duplicate work. Whoever picks up #751's backfill item should close this too.
Scope
Deferred post-PoC robustness; does not block #752 (the test's bounded sleep + clean 60s poll-timeout failure mode is acceptable interim). Production-side change to payment_settlement.rs.
PaymentChannelService::bootstrap has a TOCTOU race: it returns before the four eth_newFilter watch streams are installed in run_watcher_once, creating a window where on-chain events (ChannelOpened, etc.) are silently dropped. In production the window is sub-millisecond vs. human-scale latency, so this is benign in the field today but causes a real flaky-test smell in the anvil e2e harness (#752's sleep(2s) workaround). The author explicitly scopes this as a post-PoC robustness fix and notes it shares root cause and fix with #751's "Opened-during-downtime backfill" checkbox — the two should be implemented together.
📊 Assessment
Dimension
Value
Reasoning
Type
Bug
Genuine correctness gap in payment_settlement.rs: events in the bring-up window are permanently lost
bug — correctness gap; prod-blocking — post-PoC robustness item per issue scope; testing — directly causes flaky-test workaround in #752
Coding agent
Suitable
Algorithm is fully specified (record head S, install filters noting block F, backfill get_logs([S,F]) with dedup on overlap), file is named (payment_settlement.rs), and success criteria are clear: remove the sleep(2s) in #752 and have tests pass deterministically
Root cause:eth_newFilter (alloy.watch()) is strictly forward-looking from the block at filter creation time. The four sequential filter installs in run_watcher_once create an observable gap after bootstrap returns.
Proposed fix (from issue):
Before spawning the watcher task, snapshot current head block S via eth_blockNumber.
In run_watcher_once, install all four .watch() filters as today; record the block F at which the last filter takes effect (can use a second eth_blockNumber call immediately after all four watch() calls return).
Immediately after filter installation, call get_logs for all four event types (or at minimum ChannelOpened / ChannelToppedUp / ChannelSettled / ChannelCloseInitiated, filtered to provider == self) over [S, F].
Process the backfill events through the same handler path as live events. Dedup on block F (events in that exact block may be delivered by both paths).
Test impact: Implementing this allows #752 to replace its sleep(2s) readiness guard with a deterministic wait (e.g., poll until the watcher signals "filters installed and backfill complete"), eliminating the flakiness surface entirely.
Coordination note: Whoever picks up #751's backfill checkbox should close this issue simultaneously, as the implementation is shared. Consider folding this into #751 to avoid split PRs against the same code path.
File:crates/incentive/src/payment_settlement.rs (functions bootstrap and run_watcher_once).
kind:bugSomething does not behave as documentedkind:testTest coverage, flakes, fixtures or the e2e harnessprio:mediumScheduledrustDependabot: a Cargo update; use area: labels for Rust code otherwise
Activity
github-actions commentedon Jun 1, 2026
🎯 Triage report
PaymentChannelService::bootstraphas a TOCTOU race: it returns before the foureth_newFilterwatch streams are installed inrun_watcher_once, creating a window where on-chain events (ChannelOpened, etc.) are silently dropped. In production the window is sub-millisecond vs. human-scale latency, so this is benign in the field today but causes a real flaky-test smell in the anvil e2e harness (#752'ssleep(2s)workaround). The author explicitly scopes this as a post-PoC robustness fix and notes it shares root cause and fix with #751's "Opened-during-downtime backfill" checkbox — the two should be implemented together.📊 Assessment
payment_settlement.rs: events in the bring-up window are permanently lostbug,prod-blocking,testingadded (existing:technical,medium,rust)bug— correctness gap;prod-blocking— post-PoC robustness item per issue scope;testing— directly causes flaky-test workaround in #752S, install filters noting blockF, backfillget_logs([S,F])with dedup on overlap), file is named (payment_settlement.rs), and success criteria are clear: remove thesleep(2s)in #752 and have tests pass deterministically🔗 Similar issues
💡 Notes and suggestions
Root cause:
eth_newFilter(alloy.watch()) is strictly forward-looking from the block at filter creation time. The four sequential filter installs inrun_watcher_oncecreate an observable gap afterbootstrapreturns.Proposed fix (from issue):
Sviaeth_blockNumber.run_watcher_once, install all four.watch()filters as today; record the blockFat which the last filter takes effect (can use a secondeth_blockNumbercall immediately after all fourwatch()calls return).get_logsfor all four event types (or at minimumChannelOpened/ChannelToppedUp/ChannelSettled/ChannelCloseInitiated, filtered toprovider == self) over[S, F].F(events in that exact block may be delivered by both paths).Test impact: Implementing this allows #752 to replace its
sleep(2s)readiness guard with a deterministic wait (e.g., poll until the watcher signals "filters installed and backfill complete"), eliminating the flakiness surface entirely.Coordination note: Whoever picks up #751's backfill checkbox should close this issue simultaneously, as the implementation is shared. Consider folding this into #751 to avoid split PRs against the same code path.
File:
crates/incentive/src/payment_settlement.rs(functionsbootstrapandrun_watcher_once).Add this agentic workflows to your repo
To install this agentic workflow, run
fix(node): address review — propagate backfill failures, test retry c…
fix(node): backfill ChannelOpened to close watcher bring-up race (#762)…
refactor(node): address PR #781 review — sync redeemer mutex + backfi…
test(node): make the #751 downtime-backfill e2e a true discriminator
feat(node): seller-settlement robustness follow-ups (#751) (#781)
fix(node): harden resumable-watcher failure paths from multi-agent re…
feat(node): eth_getLogs resumable watcher, off eth_newFilter (#1106, #…
feat(node): share one eth_blockNumber read across all chain watchers (#…
feat(node): share one eth_blockNumber read across all chain watchers (#…
feat(node): share one eth_blockNumber read across all chain watchers (#…