channeldb/invoices: ignore error when no settles exist

This fixes a bug that would cause no backlog to be delivered at all.
This commit is contained in:
Conner Fromknecht committed 2020-05-26 17:50:45 -07:00
1 parent d32c7a4814
commit 1332575482
2 files changed
+12 -10

No files matched your search

+7
View File
@@ -11,6 +11,7 @@ import (
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
"github.com/stretchr/testify/assert"
)
var (
@@ -305,6 +306,9 @@ func TestInvoiceAddTimeSeries(t *testing.T) {
t.Fatalf("unable to make test db: %v", err)
}
_, err = db.InvoicesAddedSince(0)
assert.Nil(t, err)
// We'll start off by creating 20 random invoices, and inserting them
// into the database.
const numInvoices = 20
@@ -372,6 +376,9 @@ func TestInvoiceAddTimeSeries(t *testing.T) {
}
}
_, err = db.InvoicesSettledSince(0)
assert.Nil(t, err)
var settledInvoices []Invoice
var settleIndex uint64 = 1
// We'll now only settle the latter half of each of those invoices.
+5 -10
View File
@@ -488,12 +488,12 @@ func (d *DB) InvoicesAddedSince(sinceAddIndex uint64) ([]Invoice, error) {
err := kvdb.View(d, func(tx kvdb.ReadTx) error {
invoices := tx.ReadBucket(invoiceBucket)
if invoices == nil {
return ErrNoInvoicesCreated
return nil
}
addIndex := invoices.NestedReadBucket(addIndexBucket)
if addIndex == nil {
return ErrNoInvoicesCreated
return nil
}
// We'll now run through each entry in the add index starting
@@ -520,12 +520,7 @@ func (d *DB) InvoicesAddedSince(sinceAddIndex uint64) ([]Invoice, error) {
return nil
})
switch {
// If no invoices have been created, then we'll return the empty set of
// invoices.
case err == ErrNoInvoicesCreated:
case err != nil:
if err != nil {
return nil, err
}
@@ -886,12 +881,12 @@ func (d *DB) InvoicesSettledSince(sinceSettleIndex uint64) ([]Invoice, error) {
err := kvdb.View(d, func(tx kvdb.ReadTx) error {
invoices := tx.ReadBucket(invoiceBucket)
if invoices == nil {
return ErrNoInvoicesCreated
return nil
}
settleIndex := invoices.NestedReadBucket(settleIndexBucket)
if settleIndex == nil {
return ErrNoInvoicesCreated
return nil
}
// We'll now run through each entry in the add index starting