Skip to content

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

Closed

Description

@thiras

Context

Surfaced while writing the #763 buyer-channel reconciliation e2e (PR for #763). Not introduced by that work — it is a pre-existing concern in the on-chain settlement paths.

Problem

The buyer and seller PaymentChannelService providers are built with ProviderBuilder::new() (recommended fillers, incl. the default nonce filler) in crates/node/src/runtime/mod.rs (e.g. :886 seller wallet, :969 buyer wallet) and in the anvil e2e.

When reclaimExpired is submitted for a channel that is not yet expired on-chain, it reverts (ChannelNotExpired, custom error 0xd56b7c97). Observed behavior on anvil: the failed send appears to leave the provider's cached nonce advanced, so the next transaction from that wallet carries a gapped nonce, sits unmined, and its get_receipt() polls until timeout (~780s in the repro), effectively wedging all subsequent buyer transactions until the process restarts.

This matters because the code expects reclaimExpired to revert and be retried:

  • BuyerChannelState::is_expired_at doc (crates/incentive/src/buyer_channel.rs): "a too-early attempt simply reverts and is retried" under host-clock-vs-chain skew.
  • try_reclaim (crates/node/src/buyer_channel.rs) and the open_or_reuse_channel reclaim-before-reopen bail path both send reclaimExpired that can revert.

So under clock skew (or the bail path), a single reverting reclaimExpired could strand the node's buyer transaction lane.

Repro

In the #763 PR an e2e sub-scenario that deliberately triggered a not-yet-reclaimable reclaimExpired via open_or_reuse_channel, immediately followed by another buyer tx, hung for ~780s. Removing that sub-scenario avoided it; the hang is the symptom of the nonce gap.

What to investigate / fix

  1. Confirm whether alloy 2.0.5's default nonce filler (CachedNonceManager) increments the cached nonce during a fill whose eth_estimateGas then reverts (leaking it), vs. a fetch-each-time manager.
  2. If it leaks: decide on a remediation — e.g. a nonce manager that does not advance on a failed send, resetting/refetching the cached nonce after a send error, or pre-checking expiry off-chain before submitting reclaimExpired so a revert is never issued.
  3. Add regression coverage (the reverting-reclaim-then-next-tx sequence) once a fix lands.

Refs

🤖 Generated with Claude Code

Activity

  1. self-assigned this
    on Jun 14, 2026
  2. added
    kind:bug
    prio:high
    rust
    on Jun 14, 2026
  3. github-actions commented on Jun 14, 2026

    @github-actions

    🎯 Triage report

    Pre-existing bug in the PaymentChannelService: alloy's CachedNonceManager advances its cached nonce when filling a transaction (before broadcast), so a reclaimExpired call that reverts on-chain (ChannelNotExpired) leaves the cached nonce incremented — subsequent transactions from the same wallet carry a gapped nonce, sit unmined, and block get_receipt() for the full ~780s poll timeout. Since try_reclaim and open_or_reuse_channel deliberately expect reclaimExpired to revert under clock skew, any clock-skew event today can silently wedge the entire buyer tx lane until process restart.

    📊 Assessment

    Dimension Value Reasoning
    Type Bug Confirmed pre-existing reliability defect; single reverting call can DoS the buyer tx lane
    Labels bug, rust, technical, high Nonce leak can strand the payment lane in production under normal clock skew; high reliability impact
    Coding agent Suitable Code pointers are precise, three concrete remediation paths are enumerated, regression test scope is defined

    🔗 Similar issues

    💡 Notes and suggestions

    Root-cause confirmation (step 1)

    Alloy's CachedNonceManager (alloy-network/src/transaction/signer.rs in alloy-rs/alloy ≥0.5) increments the cached nonce inside fill_transaction before the eth_sendRawTransaction call. If eth_estimateGas (run by the filler pipeline) returns an error, the increment still happens. This is a known limitation documented in alloy issues; fetching each time (NonceManagerLayer::new_with_policy(NoncePolicy::FetchEach)) avoids it at the cost of one extra eth_getTransactionCount RPC per tx.

    Remediation options (most to least surgical):

    1. Off-chain expiry pre-check (preferred, zero RPC overhead): Before calling reclaimExpired, read the channel's expiresAt from the contract state (already available via PaymentChannel::channels()) and compare against the latest block timestamp. Only submit if block.timestamp >= expiresAt. This eliminates the revert entirely and aligns with how the rest of the node avoids known-failing txs. The is_expired_at helper in BuyerChannelState already does the host-clock side; it just needs a chain-timestamp cross-check.

    2. Switch to fetch-each nonce manager: Replace ProviderBuilder::new() with an explicit NonceManagerLayer configured to fetch fresh from chain on every fill. Robust against any future revert path; adds ~1 RPC per tx (~few ms on localhost, negligible on Sepolia vs. payment channel latency). Touch points: crates/node/src/runtime/mod.rs seller (:886) and buyer (:969) wallet construction.

    3. Nonce reset on send error: Wrap calls to send_transaction in an error handler that calls eth_getTransactionCount(wallet, "pending") and resets the manager's cached value. More complex, as alloy doesn't expose a public reset API — would require a custom middleware layer.

    Regression test checklist:

    Code references:

    • crates/node/src/runtime/mod.rs :886 (seller wallet), :969 (buyer wallet) — provider construction
    • crates/node/src/buyer_channel.rs — try_reclaim, open_or_reuse_channel
    • crates/incentive/src/buyer_channel.rs — BuyerChannelState::is_expired_at (clock-side check; needs chain-timestamp companion)

    Generated by Agentic Triage for issue #904 · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. assigned and unassigned on Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugprio:highrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions