What changed, and why it matters
This change fixes a bug in LND's invoice handling for AMP (Atomic Multi-Path) payments. Previously, if someone tried to pay a fresh shard for an AMP set that was already fully paid, the invoice updater could return an internal error that would fail the whole channel link, disrupting other normal payments traveling over the same link. Now, that fresh shard is rejected cleanly as a normal payment failure instead, keeping the channel link and other sibling payments undisturbed. The fix also ensures the already-paid set and accounting remain unchanged.
Reviewers should confirm that ResultInvoiceNotOpen is the correct failure code for this case and does not leak information or cause unintended behavior for the payer. Consider whether the same guard is needed in other invoice update entry points or for non-AMP MPP scenarios. The new test should be run in CI.
Security signals we found
Denial-of-service vector: an internal updater error could force-fail a shared channel link, disrupting unrelated sibling HTLCs
AMP invoice state machine edge case: reusable invoice stays open for other sets but must reject new shards for already-settled sets
Clean failure path introduced: ResultInvoiceNotOpen instead of error-driven link failure
Accounting integrity preserved: settled set, AmtPaid, SettleIndex, and HTLC map unchanged after rejection
Evidence from the diff
In invoices/update.go, updateMpp now checks whether any HTLCs already exist in HtlcStateSettled for the same AMP set ID before accepting a new shard. If the set is already settled, it returns ctx.failRes(ResultInvoiceNotOpen) with no invoice update and no error, preventing an updater error from propagating to the shared channel link. A unit test verifies that a fresh circuit for a paid AMP set is rejected without internal error, that the invoice remains ContractOpen, AmtPaid and SettleIndex are unchanged, and no new HTLC is added.
Changed components
invoices/update.goinvoices/update_invoice_test.goAMP (Atomic Multi-Path) invoice settlement logicHTLC update/failure resolution pathInspect captured patch +49 / −0
### invoices/update.go
@@ -276,6 +276,12 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc,
htlcSet := inv.HTLCSet(setID, HtlcStateAccepted)
+ // AMP invoices remain open after a set settles. Reject fresh shards
+ // for that set before their update can fail the link carrying them.
+ if len(inv.HTLCSet(setID, HtlcStateSettled)) > 0 {
+ return nil, ctx.failRes(ResultInvoiceNotOpen), nil
+ }
+
// Check whether total amt matches other HTLCs in the set.
var newSetTotal lnwire.MilliSatoshi
for _, htlc := range htlcSet {
### invoices/update_invoice_test.go
@@ -1206,6 +1206,49 @@ func TestUpdateLegacyValidatesKeysendRecord(t *testing.T) {
}
}
+// TestUpdateMppRejectsSettledAmpSet checks that a fresh shard for a paid AMP
+// set is rejected without an updater error that would fail the channel link.
+func TestUpdateMppRejectsSettledAmpSet(t *testing.T) {
+ t.Parallel()
+
+ // Arrange a reusable AMP invoice with one paid set and a fresh circuit
+ // for that same set. A partial amount avoids preimage reconstruction,
+ // isolating the closed-set admission guard.
+ settledSetID := [32]byte{1}
+ ctx, invoice := newLegacyUpdateTestContext(t, ContractOpen)
+ ctx.circuitKey = CircuitKey{HtlcID: 2}
+ ctx.amtPaid = 400
+ ctx.mpp = record.NewMPP(1000, invoice.Terms.PaymentAddr)
+ ctx.amp = record.NewAMP([32]byte{3}, settledSetID, 1)
+ invoice.Terms.PaymentPreimage = nil
+ invoice.Terms.Features = lnwire.NewFeatureVector(
+ lnwire.NewRawFeatureVector(lnwire.AMPRequired), lnwire.Features,
+ )
+ invoice.AmtPaid = 1000
+ invoice.Htlcs[CircuitKey{HtlcID: 1}] = &InvoiceHTLC{
+ Amt: 1000,
+ MppTotalAmt: 1000,
+ State: HtlcStateSettled,
+ AMP: &InvoiceHtlcAMPData{
+ Record: *record.NewAMP([32]byte{4}, settledSetID, 0),
+ },
+ }
+
+ // Act through new-shard admission so rejection must be a normal HTLC
+ // resolution rather than an updater error that fails its channel link.
+ update, resolution, err := updateInvoice(ctx, invoice)
+
+ // Assert rejection preserves the paid set and its accounting, while
+ // returning no invoice update and no internal error to the link.
+ require.NoError(t, err)
+ require.Nil(t, update)
+ requireFailResolution(t, resolution, ResultInvoiceNotOpen)
+ require.Equal(t, ContractOpen, invoice.State)
+ require.Equal(t, lnwire.MilliSatoshi(1000), invoice.AmtPaid)
+ require.Zero(t, invoice.SettleIndex)
+ require.Len(t, invoice.Htlcs, 1)
+}
+
// newLegacyUpdateTestContext creates a minimal legacy invoice and update
// context for exercising update selection and settlement outcomes.
func newLegacyUpdateTestContext(t *testing.T,Why this scored 60/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.