mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
invoices: refactor - add method to handle expected cancelation errors
This commit is contained in:
parent
039e9f439c
commit
7536dd8179
1 changed files with 17 additions and 8 deletions
|
@ -193,15 +193,24 @@ func (ew *InvoiceExpiryWatcher) cancelNextExpiredInvoice() {
|
||||||
// field would never be used. Enabling cancellation for accepted
|
// field would never be used. Enabling cancellation for accepted
|
||||||
// keysend invoices creates a safety mechanism that can prevents
|
// keysend invoices creates a safety mechanism that can prevents
|
||||||
// channel force-closes.
|
// channel force-closes.
|
||||||
err := ew.cancelInvoice(top.PaymentHash, top.Keysend)
|
ew.expireInvoice(top.PaymentHash, top.Keysend)
|
||||||
if err != nil && err != channeldb.ErrInvoiceAlreadySettled &&
|
ew.timestampExpiryQueue.Pop()
|
||||||
err != channeldb.ErrInvoiceAlreadyCanceled {
|
}
|
||||||
|
|
||||||
log.Errorf("Unable to cancel invoice: %v",
|
|
||||||
top.PaymentHash)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue