Repository navigation
feat(node): instrument settleChannel finalization sweep (#810) - #812
Conversation
The seller-side `settleChannel` finalization sweep (`try_settle`) emitted only distinct log strings and incremented no metrics, so settlement health was invisible to metric-based alerting and a transient RPC failure was indistinguishable from a permanent on-chain revert. The existing `settlement_auto_*` counters cover only the `closeChannel` auto-trigger stage, a different point in the lifecycle. Add a settlement-finalization observability surface: - Four `try_settle` outcome counters — `settlement_finalize_ok`, `_transient_send`, `_transient_receipt`, `_reverted` (raw) — plus a structured `outcome` field on each log site. - Three post-revert resolution counters set by `drop_pending_if_finalized` after it re-reads the channel: `_confirmed_closed` (co-settler race), `_restamped` (dispute-extended window), `_confirm_failed` (read error or anomalous status). The unresolved cases fold into `_confirm_failed` so the exact invariant `reverted == confirmed_closed + restamped + confirm_failed` holds, and an anomalous status is degraded-but-observable (warn! tripwire) rather than silently dropped. - A shared `settlement_pending_persist_failures` counter for swallowed pending-store writes in `forget_pending_logged` / `restamp_pending_logged`, mirroring the existing `watcher_persist_failures` pattern. The ok/reverted and status-resolution mappings are extracted into pure helpers (`record_settle_receipt_outcome`, `record_revert_resolution`) so the high-consequence counter-to-outcome wiring is unit-testable without a live provider, mirroring `record_auto_settle_close_outcome`. New tests cover the helper mappings, the persist-failure counting (both sites), the additive revert partition invariant, and zero-export + independent increment of all eight counters. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces several new Prometheus counters to track the outcomes of settleChannel finalization sweeps, including successful settlements, transient RPC errors, reverts, and their subsequent resolutions. It integrates these metrics into the payment settlement loop and adds comprehensive unit tests. The review feedback suggests improving compile-time safety and observability by replacing wildcard matches with explicit enum variant matches and logging the actual status, since PaymentChannel::Status implements Debug.
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
Adds observability to the seller-side settleChannel finalization sweep so operators can distinguish transient JSON-RPC issues from on-chain reverts and monitor settlement health via metrics, aligning with existing flat-counter conventions in the node.
Changes:
- Instruments
try_settlewith four outcome counters and structuredoutcome = "...“log fields. - Adds post-revert “resolution” counters (Closed / Closing / unresolved) plus a persist-failure counter for swallowed pending-store write errors.
- Introduces pure helper mappers for receipt outcome and post-revert status mapping, with targeted unit tests for invariants and counter independence.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/node/src/payment_settlement.rs |
Plumbs Metrics into the settlement sweep, records per-outcome counters, adds structured log fields, and adds unit tests for outcome/resolution mappings and persist-failure counting. |
crates/node/src/metrics.rs |
Defines and wires eight new settlement-finalization counters plus accessor methods, and adds a test asserting zero-export and independent increments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 87.25% (was 87.15%, ▲ +0.10%) — 28306/32441 lines
History
|
alpergundogdu
left a comment
There was a problem hiding this comment.
Review — instrument the settleChannel finalization sweep
Clean, purely-additive observability change. The design I most want to highlight as correct: bumping the raw reverted counter in record_settle_receipt_outcome and then resolving exactly once in record_revert_resolution preserves the exact partition reverted == confirmed_closed + restamped + confirm_failed, and reverted_partitions_exactly_into_resolution_counters drives both helpers in the real call order on one registry to lock that invariant in. Folding the read-error and anomalous-Open cases into confirm_failed (degraded-but-observable, never silently dropped) with a warn! tripwire is the right call. Extracting the two pure mappers so the high-consequence wiring is unit-testable without a live provider is the right instinct.
A couple of small things:
1. Re-check the "no Debug for Status" claim. The _ => arm comment says "Status has no Debug impl to log here", but Gemini's bot review asserts PaymentChannel::Status does derive Debug (alloy sol! enums generally do). If it does, the anomalous-status warn! could include status = ?ch.status and you could drop the catch-all _ in favor of explicit variants — improving the tripwire and making a future Status variant a compile error rather than a silent fold into confirm_failed. Worth a 30-second check against the generated bindings; if Debug is genuinely absent, leave the comment as-is.
2. Counter count (8) — fine, just confirming the rationale. Given iroh_metrics has no label support, one-counter-per-outcome is the established pattern here, and each carries a distinct operator action (transient = self-healing vs. reverted/confirm_failed = investigate), so I don't think this is over-instrumentation. The zero-export test guarding against the _total_total double-suffix trap is a nice touch.
No correctness issues found. LGTM pending CI.
Generated by Claude Code
Summary
Closes #810. The seller-side
settleChannelfinalization sweep (try_settle) previously emitted only distinct log strings and incremented no metrics, so settlement health was invisible to metric-based alerting and a transient JSON-RPC failure was indistinguishable from a permanent on-chain revert. The existingsettlement_auto_*counters cover only thecloseChannelauto-trigger stage — a different point in the lifecycle.This adds a complete settlement-finalization observability surface (8 counters + structured
outcomelog fields), following the establishedsettlement_auto_*(#742) /redemption_failures/watcher_persist_failures(#751) conventions. The metrics backend has no Prometheus-label support, so these are flat one-counter-per-outcomeCounters.Counters
try_settleoutcomes (4):decdn_settlement_finalize_ok_totaldecdn_settlement_finalize_transient_send_totalsettleChannel().send()RPC error — retried next sweepdecdn_settlement_finalize_transient_receipt_totalget_receipt()RPC error — retried next sweepdecdn_settlement_finalize_reverted_totalstatus()==falseon-chain revertPost-revert resolution (3) — set by
drop_pending_if_finalizedafter it re-reads the channel, so operators can tell benign from stuck:decdn_settlement_finalize_confirmed_closed_totalClosed— co-settler finalized first (benign)decdn_settlement_finalize_restamped_totalClosing— dispute extended the window, re-stamped (benign)decdn_settlement_finalize_confirm_failed_totalThe two unresolved cases fold into
confirm_failed, so the exact invariantreverted == confirmed_closed + restamped + confirm_failedholds. The anomalous-status path (anOpenre-read, unreachable for a channel we closed) is counted asconfirm_failedand emits awarn!tripwire rather than being silently dropped.Persist (1):
decdn_settlement_pending_persist_failures_total— swallowed pending-store writes inforget_pending_logged/restamp_pending_logged, mirroringwatcher_persist_failures.Design notes
record_settle_receipt_outcome,record_revert_resolution) so the high-consequence counter-to-outcome wiring is unit-testable without a live provider — mirroring the existingrecord_auto_settle_close_outcome.outcome = "transient_send" | "transient_receipt" | "ok" | "reverted"field is added to eachtry_settlelog site for reliable log-based filtering.Test plan
cargo build+cargo clippy --workspace— cleancargo fmt -- --check— cleancargo nextest run -p decdn-node— 455/455 passNew tests (9): helper mapping for ok/reverted and each
Status, persist-failure counting at both sites + the negative case, the additive revert-partition invariant on a single registry, and zero-export + independent increment of all eight counters.Scope
Limited to the finalization sweep (issue #810's checkboxes). The optional
redemption_failurestransient/permanent split (4th checkbox) is left for a follow-up.🤖 Generated with Claude Code