← Back to Pull requests

invoices: settle after complete HTLC collection #11555

Closed
unknown closed this pull request without merging on Nov 12, 2026 22:16 UTC
View on GitHub
unknown unknown commented on Nov 11, 2026 11:10 UTC
Author

Summary

Keep ordinary MPP, keysend and hold invoices pending until their released
payment HTLCs have final outcomes. Mark an invoice settled only after the
complete payment has been collected off chain or through confirmed on-chain
claims. A full payment can be accepted and its preimage released while
collection is still outstanding. This keeps merchants from treating that
release as final receipt, including through disconnects, restarts and force
closes.

Change Description

  • Add PENDING_SETTLE invoice and HTLC states. Wait for all released payment

  • HTLCs to finish. If any fails, cancel the invoice while preserving the
    collected amount and payment history. Cancellation does not refund collected
    shards.
  • Reconcile missed outcomes after restart and retry failed invoice writes.

  • Recorded outcomes override channel inference. Untrusted or unresolved
    channel state leaves the HTLC pending. Persist on-chain outcomes without
    requiring optional off-chain outcome history.
  • Persist forwarding-package replay state before releasing a preimage.

  • Defer settlement indexes until final collection, preserve an existing
    settlement index when duplicate HTLCs finish, and retain released ordinary
    invoice history during startup cleanup and canceled-invoice deletion, even
    when every released HTLC failed.
  • Expose pending states, distinct HTLC FAILED outcomes and an ordinary

  • invoice preimage_released flag through RPC. Keep AMP settlement finality
    unchanged.

    Regression coverage includes accounting and recovery on KV, SQLite and
    PostgreSQL, the MPP restart scenario, and existing on-chain resolution controls.

    flowchart TD
        %% Only final collection evidence completes payment; unresolved HTLCs keep it pending.
        A["Full payment accepted; preimage released"] --> B["PENDING_SETTLE"]
        B --> C["Record final channel or resolver outcome"]
        C --> D{"Any released payment HTLC unresolved?"}
        D -->|Yes| B
        D -->|No| E{"Every released payment HTLC collected?"}
        E -->|Yes| F["SETTLED"]
        E -->|No| G["CANCELED; retain release history and collected amount"]
    

    Notes

    Invoice finality consumes existing channel and resolver outcomes. Incoming
    resolver admission, preimage lookup and expiry behavior follow the existing
    implementation on master.

    AMP settlement finality and AMP-specific mixed-outcome accounting are deferred.
    The small closed-AMP-set admission guard protects ordinary MPP payments on the
    same link; it does not extend AMP settlement finality.

    Existing OPEN and ACCEPTED invoices can continue through the upgrade.
    Legacy SETTLED payments retain their old state; their finality is not
    retroactively reconciled and missing historical outcomes are not recreated.
    Clients must handle PENDING_SETTLE, HTLC FAILED and provisional aggregate
    amounts. An ordinary CANCELED invoice can have released its preimage; check
    preimage_released and final HTLC outcomes before deciding on counterpart
    refunds or hash reuse. The flag records lnd's release decision, not proof of
    peer receipt or global secret privacy when false. It is not supported for AMP.
    Late duplicate HTLCs can remain pending beneath a settled parent.

    Before downgrading, inspect all invoice pages and their HTLCs across every
    parent state, and let pending work finalize. --pending_only misses pending
    children beneath settled parents. Downgrade is unsupported once a released
    failure has been stored as HtlcStateFailed, exposed as FAILED through RPC.
    Include failed children in the inspection; a terminal parent alone does not
    establish downgrade safety.

    Related to #7463.

    Diff: 461 lines (+345 / -116) across 5 files Reviewer: Roasbeef Review duration: 2106m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 461 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.367
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #11555"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18% · Safe to merge
    18%