channeldb: ensure that we return an invoice on duplicate settles

In this commit, we fix an existing bug related to duplicate invoice
settle.s Before this commit, the second (and later) times an invoice was
settled we would return a nil pointer. This would result in the new
invoiceRegistry panicing as it would go to attempt to notify with a nil
invoice.

We fix this by returning the invoice on disk (unmodified) for each
settle after the initial one.

Fixes #1568.
This commit is contained in:
Olaoluwa Osuntokun 2018-07-17 16:28:08 -07:00
parent 509998db86
commit 5ee368f0f9
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -8,9 +8,9 @@ import (
"io"
"time"
"github.com/btcsuite/btcd/wire"
"github.com/coreos/bbolt"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/btcsuite/btcd/wire"
)
var (
@ -704,7 +704,7 @@ func settleInvoice(invoices, settleIndex *bolt.Bucket, invoiceNum []byte,
// Add idempotency to duplicate settles, return here to avoid
// overwriting the previous info.
if invoice.Terms.Settled {
return nil, nil
return &invoice, nil
}
// Now that we know the invoice hasn't already been settled, we'll