invoices: add hash to update context

This commit is contained in:
Joost Jager 2020-02-04 15:15:48 +01:00
parent ab59f47a0b
commit a339065fdc
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 7 additions and 5 deletions

@ -693,8 +693,7 @@ func (i *InvoiceRegistry) cancelSingleHtlc(hash lntypes.Hash,
// processKeySend just-in-time inserts an invoice if this htlc is a keysend // processKeySend just-in-time inserts an invoice if this htlc is a keysend
// htlc. // htlc.
func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx, func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx) error {
hash lntypes.Hash) error {
// Retrieve keysend record if present. // Retrieve keysend record if present.
preimageSlice, ok := ctx.customRecords[record.KeySendType] preimageSlice, ok := ctx.customRecords[record.KeySendType]
@ -704,7 +703,7 @@ func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx,
// Cancel htlc is preimage is invalid. // Cancel htlc is preimage is invalid.
preimage, err := lntypes.MakePreimage(preimageSlice) preimage, err := lntypes.MakePreimage(preimageSlice)
if err != nil || preimage.Hash() != hash { if err != nil || preimage.Hash() != ctx.hash {
return errors.New("invalid keysend preimage") return errors.New("invalid keysend preimage")
} }
@ -751,7 +750,7 @@ func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx,
// Insert invoice into database. Ignore duplicates, because this // Insert invoice into database. Ignore duplicates, because this
// may be a replay. // may be a replay.
_, err = i.AddInvoice(invoice, hash) _, err = i.AddInvoice(invoice, ctx.hash)
if err != nil && err != channeldb.ErrDuplicateInvoice { if err != nil && err != channeldb.ErrDuplicateInvoice {
return err return err
} }
@ -789,6 +788,7 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
// Create the update context containing the relevant details of the // Create the update context containing the relevant details of the
// incoming htlc. // incoming htlc.
updateCtx := invoiceUpdateCtx{ updateCtx := invoiceUpdateCtx{
hash: rHash,
circuitKey: circuitKey, circuitKey: circuitKey,
amtPaid: amtPaid, amtPaid: amtPaid,
expiry: expiry, expiry: expiry,
@ -802,7 +802,7 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
// AddInvoice obtains its own lock. This is no problem, because the // AddInvoice obtains its own lock. This is no problem, because the
// operation is idempotent. // operation is idempotent.
if i.cfg.AcceptKeySend { if i.cfg.AcceptKeySend {
err := i.processKeySend(updateCtx, rHash) err := i.processKeySend(updateCtx)
if err != nil { if err != nil {
debugLog(fmt.Sprintf("keysend error: %v", err)) debugLog(fmt.Sprintf("keysend error: %v", err))

@ -4,6 +4,7 @@ import (
"errors" "errors"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record" "github.com/lightningnetwork/lnd/record"
) )
@ -169,6 +170,7 @@ func (u ResolutionResult) String() string {
// invoiceUpdateCtx is an object that describes the context for the invoice // invoiceUpdateCtx is an object that describes the context for the invoice
// update to be carried out. // update to be carried out.
type invoiceUpdateCtx struct { type invoiceUpdateCtx struct {
hash lntypes.Hash
circuitKey channeldb.CircuitKey circuitKey channeldb.CircuitKey
amtPaid lnwire.MilliSatoshi amtPaid lnwire.MilliSatoshi
expiry uint32 expiry uint32