channeldb: move idempotency up the call tree

As a preparation for subscribing to single invoices, InvoiceRegistry
needs to become aware of settling a settled invoice.
This commit is contained in:
Joost Jager committed 2019-02-01 09:42:56 +01:00
1 parent 2a4c93cdc4
commit 436dd41c77
3 files changed
+20 -16

No files matched your search

+8
View File
@@ -378,6 +378,14 @@ func (i *InvoiceRegistry) SettleInvoice(rHash lntypes.Hash,
// If this isn't a debug invoice, then we'll attempt to settle an
// invoice matching this rHash on disk (if one exists).
invoice, err := i.cdb.SettleInvoice(rHash, amtPaid)
// Implement idempotency by returning success if the invoice was already
// settled.
if err == channeldb.ErrInvoiceAlreadySettled {
log.Debugf("Invoice %v already settled", rHash)
return nil
}
if err != nil {
return err
}