From 7536dd81790a1db628e490e2b9685398a2716ea0 Mon Sep 17 00:00:00 2001 From: carla Date: Fri, 23 Apr 2021 08:19:57 +0200 Subject: [PATCH] invoices: refactor - add method to handle expected cancelation errors --- invoices/invoice_expiry_watcher.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/invoices/invoice_expiry_watcher.go b/invoices/invoice_expiry_watcher.go index 8cf2b4cb..14257581 100644 --- a/invoices/invoice_expiry_watcher.go +++ b/invoices/invoice_expiry_watcher.go @@ -193,18 +193,27 @@ func (ew *InvoiceExpiryWatcher) cancelNextExpiredInvoice() { // field would never be used. Enabling cancellation for accepted // keysend invoices creates a safety mechanism that can prevents // channel force-closes. - err := ew.cancelInvoice(top.PaymentHash, top.Keysend) - if err != nil && err != channeldb.ErrInvoiceAlreadySettled && - err != channeldb.ErrInvoiceAlreadyCanceled { - - log.Errorf("Unable to cancel invoice: %v", - top.PaymentHash) - } - + ew.expireInvoice(top.PaymentHash, top.Keysend) ew.timestampExpiryQueue.Pop() } } +// expireInvoice attempts to expire an invoice and logs an error if we get an +// unexpected error. +func (ew *InvoiceExpiryWatcher) expireInvoice(hash lntypes.Hash, force bool) { + err := ew.cancelInvoice(hash, force) + switch err { + case nil: + + case channeldb.ErrInvoiceAlreadyCanceled: + + case channeldb.ErrInvoiceAlreadySettled: + + default: + log.Errorf("Unable to cancel invoice: %v: %v", hash, err) + } +} + // pushInvoices adds invoices to be expired to their relevant queue. func (ew *InvoiceExpiryWatcher) pushInvoices(invoices []invoiceExpiry) { for _, inv := range invoices {