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 2020-05-19 20:31:26 -07:00
parent d32c7a4814
commit 1332575482
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 12 additions and 10 deletions

@ -11,6 +11,7 @@ import (
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record" "github.com/lightningnetwork/lnd/record"
"github.com/stretchr/testify/assert"
) )
var ( var (
@ -305,6 +306,9 @@ func TestInvoiceAddTimeSeries(t *testing.T) {
t.Fatalf("unable to make test db: %v", err) 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 // We'll start off by creating 20 random invoices, and inserting them
// into the database. // into the database.
const numInvoices = 20 const numInvoices = 20
@ -372,6 +376,9 @@ func TestInvoiceAddTimeSeries(t *testing.T) {
} }
} }
_, err = db.InvoicesSettledSince(0)
assert.Nil(t, err)
var settledInvoices []Invoice var settledInvoices []Invoice
var settleIndex uint64 = 1 var settleIndex uint64 = 1
// We'll now only settle the latter half of each of those invoices. // We'll now only settle the latter half of each of those invoices.

@ -488,12 +488,12 @@ func (d *DB) InvoicesAddedSince(sinceAddIndex uint64) ([]Invoice, error) {
err := kvdb.View(d, func(tx kvdb.ReadTx) error { err := kvdb.View(d, func(tx kvdb.ReadTx) error {
invoices := tx.ReadBucket(invoiceBucket) invoices := tx.ReadBucket(invoiceBucket)
if invoices == nil { if invoices == nil {
return ErrNoInvoicesCreated return nil
} }
addIndex := invoices.NestedReadBucket(addIndexBucket) addIndex := invoices.NestedReadBucket(addIndexBucket)
if addIndex == nil { if addIndex == nil {
return ErrNoInvoicesCreated return nil
} }
// We'll now run through each entry in the add index starting // 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 return nil
}) })
switch { if err != nil {
// If no invoices have been created, then we'll return the empty set of
// invoices.
case err == ErrNoInvoicesCreated:
case err != nil:
return nil, err return nil, err
} }
@ -886,12 +881,12 @@ func (d *DB) InvoicesSettledSince(sinceSettleIndex uint64) ([]Invoice, error) {
err := kvdb.View(d, func(tx kvdb.ReadTx) error { err := kvdb.View(d, func(tx kvdb.ReadTx) error {
invoices := tx.ReadBucket(invoiceBucket) invoices := tx.ReadBucket(invoiceBucket)
if invoices == nil { if invoices == nil {
return ErrNoInvoicesCreated return nil
} }
settleIndex := invoices.NestedReadBucket(settleIndexBucket) settleIndex := invoices.NestedReadBucket(settleIndexBucket)
if settleIndex == nil { if settleIndex == nil {
return ErrNoInvoicesCreated return nil
} }
// We'll now run through each entry in the add index starting // We'll now run through each entry in the add index starting