invoices: move log into update context

This commit is contained in:
Joost Jager 2020-02-04 15:17:54 +01:00
parent a339065fdc
commit 51324ac7ae
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 9 additions and 8 deletions

@ -780,11 +780,6 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
mpp := payload.MultiPath() mpp := payload.MultiPath()
debugLog := func(s string) {
log.Debugf("Invoice(%x): %v, amt=%v, expiry=%v, circuit=%v, "+
"mpp=%v", rHash[:], s, amtPaid, expiry, circuitKey, mpp)
}
// 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{
@ -804,7 +799,7 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
if i.cfg.AcceptKeySend { if i.cfg.AcceptKeySend {
err := i.processKeySend(updateCtx) err := i.processKeySend(updateCtx)
if err != nil { if err != nil {
debugLog(fmt.Sprintf("keysend error: %v", err)) updateCtx.log(fmt.Sprintf("keysend error: %v", err))
return NewFailureResolution( return NewFailureResolution(
circuitKey, currentHeight, ResultKeySendError, circuitKey, currentHeight, ResultKeySendError,
@ -852,11 +847,11 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
case nil: case nil:
default: default:
debugLog(err.Error()) updateCtx.log(err.Error())
return nil, err return nil, err
} }
debugLog(result.String()) updateCtx.log(result.String())
if updateSubscribers { if updateSubscribers {
i.notifyClients(rHash, invoice, invoice.State) i.notifyClients(rHash, invoice, invoice.State)

@ -180,6 +180,12 @@ type invoiceUpdateCtx struct {
mpp *record.MPP mpp *record.MPP
} }
// log logs a message specific to this update context.
func (i *invoiceUpdateCtx) log(s string) {
log.Debugf("Invoice(%x): %v, amt=%v, expiry=%v, circuit=%v, mpp=%v",
i.hash[:], s, i.amtPaid, i.expiry, i.circuitKey, i.mpp)
}
// updateInvoice is a callback for DB.UpdateInvoice that contains the invoice // updateInvoice is a callback for DB.UpdateInvoice that contains the invoice
// settlement logic. // settlement logic.
func updateInvoice(ctx *invoiceUpdateCtx, inv *channeldb.Invoice) ( func updateInvoice(ctx *invoiceUpdateCtx, inv *channeldb.Invoice) (