From 133257548215c12868372cb165e554bdf3e38b5a Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 19 May 2020 20:31:26 -0700 Subject: [PATCH] channeldb/invoices: ignore error when no settles exist This fixes a bug that would cause no backlog to be delivered at all. --- channeldb/invoice_test.go | 7 +++++++ channeldb/invoices.go | 15 +++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/channeldb/invoice_test.go b/channeldb/invoice_test.go index 26807894..a35c9fae 100644 --- a/channeldb/invoice_test.go +++ b/channeldb/invoice_test.go @@ -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. diff --git a/channeldb/invoices.go b/channeldb/invoices.go index 23c10dc6..c7eb819e 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -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