From 974b34bde6f832d6885b1b07b9135b991f4fe133 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 30 Apr 2024 17:50:12 +0100 Subject: [PATCH] invoices: add `SkipAmountCheck` field to `invoiceUpdateCtx` type This commit introduces the `SkipAmountCheck` field to the `invoiceUpdateCtx` type. This field serves as a flag to determine whether to bypass the amount verification during the invoice settlement process. It is set based on the client's input, allowing the invoice to be settled even if the HTLC amount is less than the stated invoice amount. --- invoices/update.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/invoices/update.go b/invoices/update.go index ed60c278c..855d774bd 100644 --- a/invoices/update.go +++ b/invoices/update.go @@ -23,6 +23,10 @@ type invoiceUpdateCtx struct { mpp *record.MPP amp *record.AMP metadata []byte + + // SkipAmountCheck is a flag that indicates whether the amount check + // should be skipped during the invoice settlement process. + SkipAmountCheck bool } // invoiceRef returns an identifier that can be used to lookup or update the @@ -189,13 +193,13 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc, } // Don't accept zero-valued sets. - if ctx.mpp.TotalMsat() == 0 { + if !ctx.SkipAmountCheck && ctx.mpp.TotalMsat() == 0 { return nil, ctx.failRes(ResultHtlcSetTotalTooLow), nil } // Check that the total amt of the htlc set is high enough. In case this // is a zero-valued invoice, it will always be enough. - if ctx.mpp.TotalMsat() < inv.Terms.Value { + if !ctx.SkipAmountCheck && ctx.mpp.TotalMsat() < inv.Terms.Value { return nil, ctx.failRes(ResultHtlcSetTotalTooLow), nil } @@ -204,7 +208,7 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc, // Check whether total amt matches other htlcs in the set. var newSetTotal lnwire.MilliSatoshi for _, htlc := range htlcSet { - if ctx.mpp.TotalMsat() != htlc.MppTotalAmt { + if !ctx.SkipAmountCheck && ctx.mpp.TotalMsat() != htlc.MppTotalAmt { //nolint:lll return nil, ctx.failRes(ResultHtlcSetTotalMismatch), nil } @@ -239,7 +243,7 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc, // If the invoice cannot be settled yet, only record the htlc. setComplete := newSetTotal >= ctx.mpp.TotalMsat() - if !setComplete { + if !ctx.SkipAmountCheck && !setComplete { return &update, ctx.acceptRes(resultPartialAccepted), nil }