Skip to content

Commit 14a56fc

Browse files
committed
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.
1 parent 011ff00 commit 14a56fc

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

invoices/update.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ type invoiceUpdateCtx struct {
2323
mpp *record.MPP
2424
amp *record.AMP
2525
metadata []byte
26+
27+
// SkipAmountCheck is a flag that indicates whether the amount check
28+
// should be skipped during the invoice settlement process.
29+
SkipAmountCheck bool
2630
}
2731

2832
// invoiceRef returns an identifier that can be used to lookup or update the
@@ -189,13 +193,13 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc,
189193
}
190194

191195
// Don't accept zero-valued sets.
192-
if ctx.mpp.TotalMsat() == 0 {
196+
if !ctx.SkipAmountCheck && ctx.mpp.TotalMsat() == 0 {
193197
return nil, ctx.failRes(ResultHtlcSetTotalTooLow), nil
194198
}
195199

196200
// Check that the total amt of the htlc set is high enough. In case this
197201
// is a zero-valued invoice, it will always be enough.
198-
if ctx.mpp.TotalMsat() < inv.Terms.Value {
202+
if !ctx.SkipAmountCheck && ctx.mpp.TotalMsat() < inv.Terms.Value {
199203
return nil, ctx.failRes(ResultHtlcSetTotalTooLow), nil
200204
}
201205

@@ -204,7 +208,7 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc,
204208
// Check whether total amt matches other htlcs in the set.
205209
var newSetTotal lnwire.MilliSatoshi
206210
for _, htlc := range htlcSet {
207-
if ctx.mpp.TotalMsat() != htlc.MppTotalAmt {
211+
if !ctx.SkipAmountCheck && ctx.mpp.TotalMsat() != htlc.MppTotalAmt { //nolint:lll
208212
return nil, ctx.failRes(ResultHtlcSetTotalMismatch), nil
209213
}
210214

@@ -239,7 +243,7 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc,
239243

240244
// If the invoice cannot be settled yet, only record the htlc.
241245
setComplete := newSetTotal >= ctx.mpp.TotalMsat()
242-
if !setComplete {
246+
if !ctx.SkipAmountCheck && !setComplete {
243247
return &update, ctx.acceptRes(resultPartialAccepted), nil
244248
}
245249

0 commit comments

Comments
 (0)