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
2019-01-14 12:03:26 +01:00
parent 2a4c93cdc4
commit 436dd41c77
3 changed files with 20 additions and 16 deletions

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
}