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.
This commit is contained in:
eugene 2022-05-11 13:47:41 -04:00
parent 6dcec862aa
commit d76278bc1e
No known key found for this signature in database
GPG key ID: 118759E83439A9B1

View file

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