mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
invoices: fix slow startup with many expired invoices
This commit intends to fix slow first startup time when there are many invoices that need to be canceled. The slowdown is caused by a combination of adding invoices to the expiry watcher one-by-one and slow cancellation. Due to slow cancellation and the unbuffered channel which we use to pass invoices to the expiry watcher blocks the registry. With this fix we'll instead batch add invoices to the expiry watcher and thereby won't block the registry startup.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
)
|
||||
@@ -123,3 +124,31 @@ func TestInvoiceExpiryWithPendingAndExpiredInvoices(t *testing.T) {
|
||||
test.watcher.Stop()
|
||||
test.checkExpectations()
|
||||
}
|
||||
|
||||
// Tests adding multiple invoices at once.
|
||||
func TestInvoiceExpiryWhenAddingMultipleInvoices(t *testing.T) {
|
||||
t.Parallel()
|
||||
test := newInvoiceExpiryWatcherTest(t, testTime, 5, 5)
|
||||
var invoices []channeldb.InvoiceWithPaymentHash
|
||||
for hash, invoice := range test.testData.expiredInvoices {
|
||||
invoices = append(invoices,
|
||||
channeldb.InvoiceWithPaymentHash{
|
||||
Invoice: *invoice,
|
||||
PaymentHash: hash,
|
||||
},
|
||||
)
|
||||
}
|
||||
for hash, invoice := range test.testData.pendingInvoices {
|
||||
invoices = append(invoices,
|
||||
channeldb.InvoiceWithPaymentHash{
|
||||
Invoice: *invoice,
|
||||
PaymentHash: hash,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
test.watcher.AddInvoices(invoices)
|
||||
time.Sleep(testTimeout)
|
||||
test.watcher.Stop()
|
||||
test.checkExpectations()
|
||||
}
|
||||
|
Reference in New Issue
Block a user