invoices: refactor - add method to handle expected cancelation errors
This commit is contained in:
parent
039e9f439c
commit
7536dd8179
@ -193,18 +193,27 @@ 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 &&
|
|
||||||
err != channeldb.ErrInvoiceAlreadyCanceled {
|
|
||||||
|
|
||||||
log.Errorf("Unable to cancel invoice: %v",
|
|
||||||
top.PaymentHash)
|
|
||||||
}
|
|
||||||
|
|
||||||
ew.timestampExpiryQueue.Pop()
|
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.
|
// pushInvoices adds invoices to be expired to their relevant queue.
|
||||||
func (ew *InvoiceExpiryWatcher) pushInvoices(invoices []invoiceExpiry) {
|
func (ew *InvoiceExpiryWatcher) pushInvoices(invoices []invoiceExpiry) {
|
||||||
for _, inv := range invoices {
|
for _, inv := range invoices {
|
||||||
|
Loading…
Reference in New Issue
Block a user