Skip to content

node: closeChannel→record_pending is non-atomic — a crash in the gap strands a fully-drawn channel's remainder with no recovery scan #839

Closed

Description

@thiras

Surfaced by a full-repository review (2026-06-09).

Finding

send_close confirms the closeChannel receipt landed, then separately does getChannel + record_pending (record_pending_after_close, crates/node/src/payment_settlement.rs:638-679). If the process crashes — or getChannel/record_pending fails — between the landed close and the durable pending-settle write, no local record exists that settlement is owed.

Impact

For a fully-drawn channel (clientRefund == 0 — the exact case the pending-settle feature targets), the provider's un-withdrawn remainder is stranded; recovery is manual operator settleChannel. The code documents the window and escalates to error!, but there is no boot-time reconciliation that scans on-chain Closing channels this node provides.

This is the seller-side analog of the buyer-side orphan-deposit gap tracked in #763 item 1.

Fix

Add a bootstrap reconciliation scan of provider channels in Closing status (the ChannelOpened backfill in payment_settlement.rs already demonstrates the filter pattern) that rebuilds the pending-settle set on start.

Refs

Activity

  1. added
    kind:bug
    prio:medium
    on Jun 9, 2026
  2. added
    rust
    on Jun 9, 2026
  3. github-actions commented on Jun 9, 2026

    @github-actions

    🎯 Triage report

    A correctness gap in payment_settlement.rs makes the closeChannel → record_pending flow non-atomic on the seller side: if the node crashes (or the getChannel/record_pending call fails) after the close transaction lands on-chain but before the local pending-settle record is durably written, no record exists that settlement is owed. For the specific case of a fully-drawn channel (clientRefund == 0), the provider's remainder is permanently stranded until an operator manually invokes settleChannel. The code already emits error! at the gap but provides no automated recovery. The proposed fix — a bootstrap reconciliation scan for provider channels in Closing status using the existing ChannelOpened filter pattern — is well-defined and scoped.

    📊 Assessment

    Dimension Value Reasoning
    Type Bug Correctness gap: provider funds can be durably stranded with no automated recovery path
    Labels bug, medium, technical, rust Pre-existing bug+medium are correct; added technical+rust for routing
    Coding agent Suitable Exact file/line anchor (payment_settlement.rs:638-679), concrete fix pattern (reuse ChannelOpened_filter already in the same file), clear success criterion (boot-time reconciliation repopulates pending-settle set)

    🔗 Similar issues

    💡 Notes and suggestions

    Affected code path: send_close → record_pending_after_close in crates/node/src/payment_settlement.rs:638-679. The gap is the two sequential async steps after the closeChannel receipt is confirmed: getChannel RPC call, then record_pending write.

    Fix shape:

    • Add a startup reconciliation function (analogous to the ChannelOpened log-backfill in payment_settlement.rs) that:
      1. Queries on-chain for PaymentChannel entries where provider == self_address and status is Closing.
      2. For each such channel, checks whether a local pending-settle record already exists.
      3. If not, inserts one — effectively rehydrating any entries dropped in the crash window.
    • Wire this scan into the existing bootstrap sequence so it runs before the settle sweep starts.

    Scope boundary: Only the seller-side Closing status matters here (buyer-side is #763). The ChannelOpened event filter in the same file is the direct template.

    Testing: Consider adding a test in crates/node/tests/anvil_settlement_e2e.rs (feature anvil-e2e) that simulates a crash after closeChannel mines but before record_pending writes, then restarts and verifies the reconciliation scan picks up the channel and drives it to settlement.

    Priority note: medium seems right — the manual settleChannel escape hatch means funds aren't permanently lost, but the window is real in production and requires operator awareness to exercise.

    Generated by Agentic Triage for issue #839 · sonnet46 563.2K · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. self-assigned this
    on Jun 13, 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:mediumrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions