Skip to content

fix(node): use simple nonce management so a reverting reclaimExpired can't wedge the tx lane (#904) - #905

Merged
thiras merged 1 commit into
mainfrom
fix/904-reclaim-nonce-leak
Jun 14, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/904-reclaim-nonce-leak

Conversation

@thiras

@thiras thiras commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #904.

The buyer and seller PaymentChannel providers were built with ProviderBuilder::new(), whose default CachedNonceManager advances a locally-cached nonce when it prepares a transaction. When a send then fails — e.g. reclaimExpired on a channel not yet expired in block.timestamp under host-clock-vs-chain skew, whose eth_estimateGas reverts — .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() (which has no default timeout) hangs effectively unbounded, wedging the wallet's tx lane until process restart.

This matters because the reclaim path expects reclaimExpired to revert and be retried (BuyerChannelState::is_expired_at doc; try_reclaim; the open_or_reuse_channel reclaim-before-reopen bail path), so the leak is a real failure mode, not misuse.

Fix

Switch both wallet providers to alloy's SimpleNonceManager via .with_simple_nonce_management() — what alloy's own connect_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 extra eth_getTransactionCount per 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 reclaimExpired handling.

Test

New anvil e2e regression (scenario E in anvil_settlement_e2e.rs, anvil-e2e feature): opens a not-yet-expired channel against the registered node, drives a reclaimExpired that must revert (asserts the send is Err), then asserts the next buyer openChannel lands 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 — clean
  • cargo nextest run -p decdn-node — 637/637 pass
  • cargo test -p decdn-node --features anvil-e2e — 4/4 pass (~8s)

Follow-up (out of scope)

try_reclaim warn-and-returns on every failure with no escalation; a persistently failing reclaim strands a refundable deposit with no error!/metric (unlike the seller's record_pending_after_close). Pre-existing — filed separately.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 reclaimExpired does 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.

Comment on lines +1680 to +1684
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)"
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Jun 14, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 85.73% (was 85.74%, ▼ 0.01%) — 36981/43137 lines

File Coverage Lines Δ
crates/node/src/runtime/mod.rs 48.95% 882/1802 ▼ 0.05%
History
Commit Total Δ vs base
e2bc12d 85.73% ● 0.00%
3a7e0c4 (HEAD) 85.73% ▼ 0.01%

…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]>
@thiras
thiras force-pushed the fix/904-reclaim-nonce-leak branch from e2bc12d to 3a7e0c4 Compare June 14, 2026 17:21
@thiras
thiras merged commit c7d8e53 into main Jun 14, 2026
19 checks passed
@thiras
thiras deleted the fix/904-reclaim-nonce-leak branch June 14, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buyer/seller PaymentChannel: reverting reclaimExpired leaks alloy cached nonce, can wedge subsequent txs

2 participants