Repository navigation
fix(node): reconcile provider-side Closing channels into the settle set (#839) - #892
Conversation
…et (#839) `closeChannel` lands on-chain (channel → `Closing`), then `record_pending` persists the `PendingSettle` obligation in a separate step. A crash — or a `getChannel`/`record_pending` failure — in that gap loses the obligation: the settle sweep only acts on the pending-settle store, so a fully-drawn channel's (`clientRefund == 0`) un-withdrawn remainder is stranded until a manual operator `settleChannel`. The `ChannelOpened` bring-up backfill can't recover it — the channel is `Closing`, not `Open`. Separately, `closeChannel` is callable by either party, so a client-initiated close was never recorded at all (the live `ChannelCloseInitiated` arm was observe-only). Add a boot-time reconciliation: - `pending_settle_for_closing` (pure gate) + `reconcile_closing_channel` (thin RPC wrapper): getChannel → verify provider == self && status == Closing → record_pending with the authoritative on-chain disputeDeadline. Idempotent. - `backfill_closing_channels`: a bring-up scan mirroring backfill_opened_channels over the same `[start, head]` range, querying ChannelCloseInitiated logs and reconciling each. Recovers the crash gap and any close during downtime. - The live `ChannelCloseInitiated` arm now reconciles too (closing the client-initiated-close gap), and on failure re-arms the backfill and resubscribes — mirroring the `opened` arm — so a live failure self-heals within the process rather than relying on the next boot scan. Floor caveat: the closing scan reuses the `ChannelOpened` checkpoint as its start, which advances only on open persistence — a true floor for a downtime gap, but not a per-close completeness guarantee. The live-arm re-arm closes the common case; a crash in the retry window after the checkpoint advanced past the close block still needs a manual settleChannel. Documented at the call site; a separate close-scan checkpoint is a possible follow-up. Tests: unit tests for the pure gate (owned-Closing records, foreign/non-Closing skip); anvil-e2e covering both gaps — a node-initiated close while down recovered by the boot scan (deadline matches on-chain, then settled and dropped), and a client-initiated close against the running service recorded by the live arm. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements closing-reconciliation backfill and live tracking for payment channels to address issue #839. It ensures that any provider-owned channel left in a Closing state on-chain—either due to a crash gap or a client-initiated close—correctly records a pending settlement obligation. This is achieved by adding a new backfill scan (backfill_closing_channels) during startup, updating the live event watcher to reconcile ChannelCloseInitiated events, and adding comprehensive unit and end-to-end tests. There are no review comments, and I have no additional 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.
There was a problem hiding this comment.
Pull request overview
This PR fixes a durability gap in provider-side payment-channel settlement by ensuring channels that reach on-chain Closing state are reconciled into the local pending-settlement set, even if the node crashes or the close is initiated by the client.
Changes:
- Add closing-channel reconciliation logic (
pending_settle_for_closing+reconcile_closing_channel) and a boot-timeChannelCloseInitiatedbackfill to restore missingPendingSettleentries. - Update the live
ChannelCloseInitiatedwatcher arm to reconcile and to re-arm backfill/resubscribe on failure. - Extend the anvil e2e settlement test to cover both the “crash gap” and “client-initiated close” gap; update watcher persist-failure metric documentation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/node/src/payment_settlement.rs |
Adds closing reconciliation (boot backfill + live arm) and unit tests for the pure decision gate. |
crates/node/tests/anvil_settlement_e2e.rs |
Extends e2e coverage to validate closing reconciliation works across restart and for client-initiated closes. |
crates/node/src/metrics.rs |
Updates watcher_persist_failures docs to include close-reconciliation read/write failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 86.02% (was 86.16%, ▼ 0.14%) — 35596/41383 lines
History
|
…r both triggers The close-reconcile arm (#839) now also returns RecoveryPending, but the enum doc and the watcher_loop warning still described only the failed-open-persist case ("holding checkpoint after a failed open-persist") — misleading when the trigger was a close reconciliation, and the "holding checkpoint" wording is open-specific (the close arm only re-arms backfill_from; the checkpoint is open-tied). Make both generic and accurate over both triggers. Per PR #892 review (Copilot). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…allback, test guards Second-round PR #892 review (code-reviewer, pr-test-analyzer, comment-analyzer, silent-failure-hunter). Three actionable fixes: - comment-analyzer (Critical): the `record_pending` failure-leg comment in `record_pending_after_close` still said a lost write "is not re-derivable", contradicting the docstring this PR updated. #839's backfill re-reads on-chain status independent of the local forget, so a still-`Closing` channel IS re-derivable. Reworded the comment and the error log. - silent-failure-hunter (Important): the live close arm's block fallback used `unwrap_or(checkpoint_hw)`. Unlike the `opened` arm (where checkpoint_hw <= failed by block-ordering), the close arm's checkpoint_hw is *open*-advanced and unordered against the close, so on a missing block_number it could re-arm *above* the close block and silently skip it. Fall back to `0` — an idempotent, backoff-paced full re-scan that cannot overshoot. Documented the divergence. - pr-test-analyzer (Suggestion, highest-value): assert `decdn_watcher_persist_failures_total 0` after the live-arm scenario so the test pins recovery to the *direct* reconcile path, not the re-arm+resubscribe failure path the 60s poll could otherwise mask. Also yield_now after drop(service2) to let the async AbortOnDrop wind down before the no-pending precondition. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Fixes #839. The provider node closes a
PaymentChannelin two non-atomic steps —closeChannellands on-chain (channel →Closing), thenrecord_pending_after_closeseparately persists thePendingSettleobligation. A crash (or agetChannel/record_pendingfailure) in that gap loses the obligation. Since the settle sweep only acts on the pending-settle store, a fully-drawn channel's (clientRefund == 0) un-withdrawn remainder is stranded until a manual operatorsettleChannel. TheChannelOpenedbring-up backfill can't recover it (the channel isClosing, notOpen).A second, related gap:
closeChannelis callable by either party, so a client-initiated close on a channel we provide was never recorded at all — the liveChannelCloseInitiatedarm was observe-only.Changes
pending_settle_for_closing(pure decision gate) +reconcile_closing_channel(thin RPC wrapper):getChannel→ verifyprovider == self && status == Closing→record_pendingwith the authoritative on-chaindisputeDeadline. Idempotent overwrite. The pure/RPC split follows the existing convention (pure logic → unit tests, on-chain orchestration → anvil-e2e).backfill_closing_channels: a bring-up scan mirroringbackfill_opened_channelsover the same[start, head]range, queryingChannelCloseInitiatedlogs and reconciling each. Wired intorun_watcher_onceafter the opened backfill, before clearingbackfill_from.ChannelCloseInitiatedarm now reconciles too (closing the client-initiated-close gap), and on failure re-arms the backfill and resubscribes — mirroring theopenedarm — so a live failure self-heals within the process instead of relying on the next boot scan.watcher_persist_failuresmetric doc updated: it now also covers the closing-reconciliation path (agetChannelread or arecord_pendingwrite), so it is no longer store-writes-only.Known limitation (documented, not silently overclaimed)
The closing scan reuses the
ChannelOpenedcheckpoint as its start. That checkpoint advances only on open persistence — a true floor for a downtime gap, but not a per-close completeness guarantee. The live-arm re-arm closes the common case; a crash in the retry window after the checkpoint advanced past the close block still requires a manualsettleChannel. A separate close-scan checkpoint is a reasonable follow-up for belt-and-suspenders durability.Testing
pending_settle_for_closinggate — owned-Closingrecords (deadline + channel_id pass-through), foreign provider skipped,Closed/Openskipped.e2e_onchain_payment_channel_settlement): covers both gaps — a node-initiated close while the service is down, recovered by the boot scan (recovered deadline == on-chaindisputeDeadline, then settled by a third party and the entry dropped); and a client-initiated close against the running service, recorded by the live arm.cargo nextest run -p decdn-node→ 601/601 pass; anvil-e2e passes;clippy --all-targets --features anvil-e2eandfmt --checkclean. Contracts unchanged.🤖 Generated with Claude Code