Skip to content

feat(node): instrument settleChannel finalization sweep (#810) - #812

Merged
thiras merged 1 commit into
mainfrom
feat/810-settle-finalize-metrics
Jun 6, 2026
Merged

thiras merged 1 commit into
mainfrom
feat/810-settle-finalize-metrics

Conversation

@thiras

@thiras thiras commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #810. The seller-side settleChannel finalization 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 existing settlement_auto_* counters cover only the closeChannel auto-trigger stage — a different point in the lifecycle.

This adds a complete settlement-finalization observability surface (8 counters + structured outcome log fields), following the established settlement_auto_* (#742) / redemption_failures / watcher_persist_failures (#751) conventions. The metrics backend has no Prometheus-label support, so these are flat one-counter-per-outcome Counters.

Counters

try_settle outcomes (4):

Counter Meaning
decdn_settlement_finalize_ok_total settle landed; remainder routed through FeeRouter (no-op when fully drawn)
decdn_settlement_finalize_transient_send_total settleChannel().send() RPC error — retried next sweep
decdn_settlement_finalize_transient_receipt_total get_receipt() RPC error — retried next sweep
decdn_settlement_finalize_reverted_total raw status()==false on-chain revert

Post-revert resolution (3) — set by drop_pending_if_finalized after it re-reads the channel, so operators can tell benign from stuck:

Counter Meaning
decdn_settlement_finalize_confirmed_closed_total Closed — co-settler finalized first (benign)
decdn_settlement_finalize_restamped_total Closing — dispute extended the window, re-stamped (benign)
decdn_settlement_finalize_confirm_failed_total read error or anomalous status — the genuinely-degraded signal

The two unresolved cases fold into confirm_failed, so the exact invariant reverted == confirmed_closed + restamped + confirm_failed holds. The anomalous-status path (an Open re-read, unreachable for a channel we closed) is counted as confirm_failed and emits a warn! tripwire rather than being silently dropped.

Persist (1): decdn_settlement_pending_persist_failures_total — swallowed pending-store writes in forget_pending_logged / restamp_pending_logged, mirroring watcher_persist_failures.

Design notes

  • 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 the existing record_auto_settle_close_outcome.
  • A structured outcome = "transient_send" | "transient_receipt" | "ok" | "reverted" field is added to each try_settle log site for reliable log-based filtering.

Test plan

  • cargo build + cargo clippy --workspace — clean
  • cargo fmt -- --check — clean
  • cargo nextest run -p decdn-node — 455/455 pass

New 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_failures transient/permanent split (4th checkbox) is left for a follow-up.

🤖 Generated with Claude Code

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]>
Copilot AI review requested due to automatic review settings June 4, 2026 15:09

@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 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.

Comment thread crates/node/src/payment_settlement.rs Resolved
Comment thread crates/node/src/payment_settlement.rs Resolved

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

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_settle with four outcome counters and structured outcome = "...“ 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.

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

Coverage report

Total: 87.25% (was 87.15%, ▲ +0.10%) — 28306/32441 lines

File Coverage Lines Δ
crates/node/src/metrics.rs 87.76% 595/678 ▲ +1.52%
crates/node/src/payment_settlement.rs 51.21% 828/1617 ▲ +4.67%
History
Commit Total Δ vs base
dcb7f06 (HEAD) 87.25% ▲ +0.10%

@alpergundogdu alpergundogdu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@thiras
thiras merged commit c0352ee into main Jun 6, 2026
20 checks passed
@thiras
thiras deleted the feat/810-settle-finalize-metrics branch June 6, 2026 11:25
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.

node: settleChannel finalization sweep has no metrics and no structured outcome field — transient RPC vs on-chain revert indistinguishable in metrics

3 participants