invoices: add hash to update context
This commit is contained in:
parent
ab59f47a0b
commit
a339065fdc
@ -693,8 +693,7 @@ func (i *InvoiceRegistry) cancelSingleHtlc(hash lntypes.Hash,
|
||||
|
||||
// processKeySend just-in-time inserts an invoice if this htlc is a keysend
|
||||
// htlc.
|
||||
func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx,
|
||||
hash lntypes.Hash) error {
|
||||
func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx) error {
|
||||
|
||||
// Retrieve keysend record if present.
|
||||
preimageSlice, ok := ctx.customRecords[record.KeySendType]
|
||||
@ -704,7 +703,7 @@ func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx,
|
||||
|
||||
// Cancel htlc is preimage is invalid.
|
||||
preimage, err := lntypes.MakePreimage(preimageSlice)
|
||||
if err != nil || preimage.Hash() != hash {
|
||||
if err != nil || preimage.Hash() != ctx.hash {
|
||||
return errors.New("invalid keysend preimage")
|
||||
}
|
||||
|
||||
@ -751,7 +750,7 @@ func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx,
|
||||
|
||||
// Insert invoice into database. Ignore duplicates, because this
|
||||
// may be a replay.
|
||||
_, err = i.AddInvoice(invoice, hash)
|
||||
_, err = i.AddInvoice(invoice, ctx.hash)
|
||||
if err != nil && err != channeldb.ErrDuplicateInvoice {
|
||||
return err
|
||||
}
|
||||
@ -789,6 +788,7 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
|
||||
// Create the update context containing the relevant details of the
|
||||
// incoming htlc.
|
||||
updateCtx := invoiceUpdateCtx{
|
||||
hash: rHash,
|
||||
circuitKey: circuitKey,
|
||||
amtPaid: amtPaid,
|
||||
expiry: expiry,
|
||||
@ -802,7 +802,7 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
|
||||
// AddInvoice obtains its own lock. This is no problem, because the
|
||||
// operation is idempotent.
|
||||
if i.cfg.AcceptKeySend {
|
||||
err := i.processKeySend(updateCtx, rHash)
|
||||
err := i.processKeySend(updateCtx)
|
||||
if err != nil {
|
||||
debugLog(fmt.Sprintf("keysend error: %v", err))
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"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
|
||||
// update to be carried out.
|
||||
type invoiceUpdateCtx struct {
|
||||
hash lntypes.Hash
|
||||
circuitKey channeldb.CircuitKey
|
||||
amtPaid lnwire.MilliSatoshi
|
||||
expiry uint32
|
||||
|
Loading…
Reference in New Issue
Block a user