invoices: refactor - add method to handle expected cancelation errors

This commit is contained in:
carla 2021-04-23 08:19:57 +02:00
parent 039e9f439c
commit 7536dd8179
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -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 {