Repository navigation
fix(node): use simple nonce management so a reverting reclaimExpired can't wedge the tx lane (#904) - #905
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a nonce-gap failure mode in the node’s on-chain PaymentChannel transaction lane by switching wallet providers from alloy’s cached nonce manager to simple “fetch pending nonce per-send” management, preventing reverting/failed sends from corrupting local nonce state and wedging subsequent transactions.
Changes:
- Switch node runtime seller and buyer wallet providers to
ProviderBuilder::with_simple_nonce_management()to avoid cached-nonce advancement on failed sends. - Update anvil e2e providers to use simple nonce management to mirror production.
- Add an anvil e2e regression scenario ensuring a reverting
reclaimExpireddoes not wedge subsequent buyer transactions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/node/src/runtime/mod.rs | Switch seller/buyer wallet providers to simple nonce management to prevent nonce gaps after reverted/failed sends. |
| crates/node/tests/anvil_settlement_e2e.rs | Mirror nonce management in e2e providers and add a regression scenario for reverting reclaimExpired not wedging the tx lane. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let reclaim_send = pc_buyer_full.reclaimExpired(regress_id).send().await; | ||
| anyhow::ensure!( | ||
| reclaim_send.is_err(), | ||
| "reclaimExpired on a not-yet-expired channel must revert (precondition for the regression)" | ||
| ); |
There was a problem hiding this comment.
Fixed in 3a7e0c4. The precondition now matches the failed send's error string and asserts it contains "revert" (surfacing the full error on mismatch), so an unrelated RPC/signing failure can no longer let the scenario pass without exercising the gas-estimate-revert path. Verified against anvil — the real ChannelNotExpired revert surfaces as "execution reverted" and the scenario still passes.
There was a problem hiding this comment.
Code Review
This pull request switches the Ethereum providers in the runtime and integration tests to use simple nonce management (with_simple_nonce_management()) instead of Alloy's default cached nonce manager. This change prevents transaction lanes from becoming wedged or blocked when a transaction (such as a reverting reclaimExpired call) fails during gas estimation or preparation. Additionally, a new end-to-end integration test has been added to verify that a reverting reclaim transaction does not block subsequent transactions. There are no review comments, and I have no feedback to provide.
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.
Coverage reportTotal: 85.73% (was 85.74%, ▼ 0.01%) — 36981/43137 lines
History
|
…can't wedge the tx lane (#904) The buyer and seller PaymentChannel providers were built with `ProviderBuilder::new()`, whose default `CachedNonceManager` advances a locally-cached nonce when it fills a transaction. When a send's `eth_estimateGas` reverts — e.g. `reclaimExpired` on a channel not yet expired in `block.timestamp` under host-clock-vs-chain skew — `.send()` returns `Err` but the cached nonce stays advanced. The tx never reached the chain, so the next tx from that wallet carries a gapped nonce, sits unmined, and `get_receipt()` polls until timeout (~780s), wedging the buyer lane until restart. The reclaim path *expects* `reclaimExpired` to revert and be retried, so this is a real failure mode. Switch both wallet providers to `with_simple_nonce_management()` (alloy's `SimpleNonceManager`, what its own `connect_anvil*` helpers use): it stores nothing locally and re-fetches the pending nonce on every send, so a reverted/failed send can't corrupt nonce state. This covers every reverting send path (reclaimExpired, openChannel, topUp, approve, settleChannel, closeChannel), at the cost of ~1 extra eth_getTransactionCount per tx — negligible at settlement frequency, and the services send sequentially. Add an anvil e2e regression (scenario E): open a not-yet-expired channel against the registered node, drive a reverting `reclaimExpired`, then assert the next buyer `openChannel` lands within a tight bound. With the fix the suite passes in ~8s; reverting the buyer provider to the cached manager makes only this scenario fail via the 20s wedge timeout. The e2e harness providers also adopt simple nonce management to mirror production. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
e2bc12d to
3a7e0c4
Compare
Problem
Closes #904.
The buyer and seller
PaymentChannelproviders were built withProviderBuilder::new(), whose defaultCachedNonceManageradvances a locally-cached nonce when it prepares a transaction. When a send then fails — e.g.reclaimExpiredon a channel not yet expired inblock.timestampunder host-clock-vs-chain skew, whoseeth_estimateGasreverts —.send()returnsErrbut the cached nonce stays advanced. The tx never reached the chain, so the next tx from that wallet carries a gapped nonce, sits unmined, andget_receipt()(which has no default timeout) hangs effectively unbounded, wedging the wallet's tx lane until process restart.This matters because the reclaim path expects
reclaimExpiredto revert and be retried (BuyerChannelState::is_expired_atdoc;try_reclaim; theopen_or_reuse_channelreclaim-before-reopen bail path), so the leak is a real failure mode, not misuse.Fix
Switch both wallet providers to alloy's
SimpleNonceManagervia.with_simple_nonce_management()— what alloy's ownconnect_anvil*helpers use. It stores nothing locally and re-reads the pending nonce on every send, so a reverted/failed send cannot corrupt nonce state. This covers every reverting send path on the provider (reclaimExpired,openChannel,topUp,approve,settleChannel,closeChannel), at the cost of ~1 extraeth_getTransactionCountper tx — negligible at settlement frequency. The buyer provider is shared across sends and the reclaim sweep runs concurrently with opens, so correctness rests on the per-send pending-nonce refetch (a transient racing collision just gets a fresh nonce next attempt), not on strict serialization.Scope is deliberately the nonce-manager swap only — no off-chain expiry pre-check, no change to the existing revert-tolerant
reclaimExpiredhandling.Test
New anvil e2e regression (scenario E in
anvil_settlement_e2e.rs,anvil-e2efeature): opens a not-yet-expired channel against the registered node, drives areclaimExpiredthat must revert (asserts the send isErr), then asserts the next buyeropenChannellands within a tight 20s bound. The harness providers also adopt simple nonce management to mirror production.Guard verified: with the fix the suite passes in ~8s; reverting the buyer provider to the default cached manager makes only scenario E fail, via the 20s wedge timeout.
Verification
cargo fmt -- --check,cargo clippy -p decdn-node --all-targets --features anvil-e2e— cleancargo nextest run -p decdn-node— 637/637 passcargo test -p decdn-node --features anvil-e2e— 4/4 pass (~8s)Follow-up (out of scope)
try_reclaimwarn-and-returns on every failure with no escalation; a persistently failing reclaim strands a refundable deposit with noerror!/metric (unlike the seller'srecord_pending_after_close). Pre-existing — filed separately.🤖 Generated with Claude Code