From 6dcec862aa86a5b0c2203964bbdadc2307b46acc Mon Sep 17 00:00:00 2001 From: eugene Date: Wed, 11 May 2022 13:46:48 -0400 Subject: [PATCH 1/2] invoices: remove redundant code HTLCSet already removes any HTLCs that are not in the desired state, so doing it again on the same set is redundant. --- invoices/update.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/invoices/update.go b/invoices/update.go index e1a2469ac..c16fe808d 100644 --- a/invoices/update.go +++ b/invoices/update.go @@ -196,13 +196,6 @@ func updateMpp(ctx *invoiceUpdateCtx, // Check whether total amt matches other htlcs in the set. var newSetTotal lnwire.MilliSatoshi for _, htlc := range htlcSet { - // Only consider accepted mpp htlcs. It is possible that there - // are htlcs registered in the invoice database that previously - // timed out and are in the canceled state now. - if htlc.State != channeldb.HtlcStateAccepted { - continue - } - if ctx.mpp.TotalMsat() != htlc.MppTotalAmt { return nil, ctx.failRes(ResultHtlcSetTotalMismatch), nil } From d76278bc1e6491d75b6adf93e4f41934fc387521 Mon Sep 17 00:00:00 2001 From: eugene Date: Wed, 11 May 2022 13:47:41 -0400 Subject: [PATCH 2/2] invoices: properly set Preimage for settle resolutions This fixes a nil-pointer-dereference that would occur if this was called for a settled AMP invoice. Terms.PaymentPreimage is always false for AMP invoices. --- invoices/update.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/invoices/update.go b/invoices/update.go index c16fe808d..ddcad6fa9 100644 --- a/invoices/update.go +++ b/invoices/update.go @@ -108,8 +108,16 @@ func updateInvoice(ctx *invoiceUpdateCtx, inv *channeldb.Invoice) ( return nil, ctx.acceptRes(resultReplayToAccepted), nil case channeldb.HtlcStateSettled: + pre := inv.Terms.PaymentPreimage + + // Terms.PaymentPreimage will be nil for AMP invoices. + // Set it to the HTLC's AMP Preimage instead. + if pre == nil { + pre = htlc.AMP.Preimage + } + return nil, ctx.settleRes( - *inv.Terms.PaymentPreimage, + *pre, ResultReplayToSettled, ), nil