multi: add explicit hodl invoice flag to invoice
Previously it wasn't possible to store a preimage in the invoice database and signal that a payment should not be settled right away. The only way to hold a payment was to insert the magic UnknownPreimage value in the invoice database. This commit introduces a distinct flag to signal that an invoice is a hold invoice and thereby allows the preimage to be present in the database already. Preparation for (key send) hodl invoices for which we already know the preimage.
This commit is contained in:
11 files changed
+153
-93
No files matched your search
@@ -652,12 +652,6 @@ func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx) error {
|
||||
return errors.New("invalid keysend preimage")
|
||||
}
|
||||
|
||||
// Don't accept zero preimages as those have a special meaning in our
|
||||
// database for hodl invoices.
|
||||
if preimage == channeldb.UnknownPreimage {
|
||||
return errors.New("invalid keysend preimage")
|
||||
}
|
||||
|
||||
// Only allow keysend for non-mpp payments.
|
||||
if ctx.mpp != nil {
|
||||
return errors.New("no mpp keysend supported")
|
||||
@@ -688,7 +682,7 @@ func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx) error {
|
||||
Terms: channeldb.ContractTerm{
|
||||
FinalCltvDelta: finalCltvDelta,
|
||||
Value: amt,
|
||||
PaymentPreimage: preimage,
|
||||
PaymentPreimage: &preimage,
|
||||
Features: features,
|
||||
},
|
||||
}
|
||||
@@ -948,7 +942,7 @@ func (i *InvoiceRegistry) SettleHodlInvoice(preimage lntypes.Preimage) error {
|
||||
return &channeldb.InvoiceUpdateDesc{
|
||||
State: &channeldb.InvoiceStateUpdateDesc{
|
||||
NewState: channeldb.ContractSettled,
|
||||
Preimage: preimage,
|
||||
Preimage: &preimage,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ var (
|
||||
testInvoiceAmt = lnwire.MilliSatoshi(100000)
|
||||
testInvoice = &channeldb.Invoice{
|
||||
Terms: channeldb.ContractTerm{
|
||||
PaymentPreimage: testInvoicePreimage,
|
||||
PaymentPreimage: &testInvoicePreimage,
|
||||
Value: testInvoiceAmt,
|
||||
Expiry: time.Hour,
|
||||
Features: testFeatures,
|
||||
@@ -102,12 +102,12 @@ var (
|
||||
|
||||
testHodlInvoice = &channeldb.Invoice{
|
||||
Terms: channeldb.ContractTerm{
|
||||
PaymentPreimage: channeldb.UnknownPreimage,
|
||||
Value: testInvoiceAmt,
|
||||
Expiry: time.Hour,
|
||||
Features: testFeatures,
|
||||
Value: testInvoiceAmt,
|
||||
Expiry: time.Hour,
|
||||
Features: testFeatures,
|
||||
},
|
||||
CreationDate: testInvoiceCreationDate,
|
||||
HodlInvoice: true,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -225,7 +225,7 @@ func newTestInvoice(t *testing.T, preimage lntypes.Preimage,
|
||||
|
||||
return &channeldb.Invoice{
|
||||
Terms: channeldb.ContractTerm{
|
||||
PaymentPreimage: preimage,
|
||||
PaymentPreimage: &preimage,
|
||||
PaymentAddr: payAddr,
|
||||
Value: testInvoiceAmount,
|
||||
Expiry: expiry,
|
||||
|
||||
+6
-8
@@ -81,7 +81,7 @@ func updateInvoice(ctx *invoiceUpdateCtx, inv *channeldb.Invoice) (
|
||||
|
||||
case channeldb.HtlcStateSettled:
|
||||
return nil, ctx.settleRes(
|
||||
inv.Terms.PaymentPreimage,
|
||||
*inv.Terms.PaymentPreimage,
|
||||
ResultReplayToSettled,
|
||||
), nil
|
||||
|
||||
@@ -187,8 +187,7 @@ func updateMpp(ctx *invoiceUpdateCtx,
|
||||
|
||||
// Check to see if we can settle or this is an hold invoice and
|
||||
// we need to wait for the preimage.
|
||||
holdInvoice := inv.Terms.PaymentPreimage == channeldb.UnknownPreimage
|
||||
if holdInvoice {
|
||||
if inv.HodlInvoice {
|
||||
update.State = &channeldb.InvoiceStateUpdateDesc{
|
||||
NewState: channeldb.ContractAccepted,
|
||||
}
|
||||
@@ -201,7 +200,7 @@ func updateMpp(ctx *invoiceUpdateCtx,
|
||||
}
|
||||
|
||||
return &update, ctx.settleRes(
|
||||
inv.Terms.PaymentPreimage, ResultSettled,
|
||||
*inv.Terms.PaymentPreimage, ResultSettled,
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -269,14 +268,13 @@ func updateLegacy(ctx *invoiceUpdateCtx,
|
||||
|
||||
case channeldb.ContractSettled:
|
||||
return &update, ctx.settleRes(
|
||||
inv.Terms.PaymentPreimage, ResultDuplicateToSettled,
|
||||
*inv.Terms.PaymentPreimage, ResultDuplicateToSettled,
|
||||
), nil
|
||||
}
|
||||
|
||||
// Check to see if we can settle or this is an hold invoice and we need
|
||||
// to wait for the preimage.
|
||||
holdInvoice := inv.Terms.PaymentPreimage == channeldb.UnknownPreimage
|
||||
if holdInvoice {
|
||||
if inv.HodlInvoice {
|
||||
update.State = &channeldb.InvoiceStateUpdateDesc{
|
||||
NewState: channeldb.ContractAccepted,
|
||||
}
|
||||
@@ -290,6 +288,6 @@ func updateLegacy(ctx *invoiceUpdateCtx,
|
||||
}
|
||||
|
||||
return &update, ctx.settleRes(
|
||||
inv.Terms.PaymentPreimage, ResultSettled,
|
||||
*inv.Terms.PaymentPreimage, ResultSettled,
|
||||
), nil
|
||||
}
|
||||
Reference in new issue
Block a user