Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,7 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
)

sqlInvoiceDB := invoices.NewSQLStore(
&invoices.SQLStoreConfig{QueryCfg: queryCfg},
invoiceExecutor, clock.NewDefaultClock(),
)

Expand Down
20 changes: 20 additions & 0 deletions docs/release-notes/release-notes-0.21.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,26 @@
is fully populated. This new behaviour can be opted out of via the new
`--db.sync-graph-cache-load` option.

* [Invoice pagination queries no longer use
`OFFSET`](https://github.com/lightningnetwork/lnd/pull/10700). The five
invoice filter queries previously used `LIMIT+OFFSET` for internal batching,
which requires the database to scan and discard all preceding rows on every
page. All pagination is now cursor-based (`WHERE id >= cursor`), making every
page an efficient primary-key range scan regardless of how deep into the
result set the query is.

* [Eliminate N+1 per-invoice queries in the SQL invoice
store](https://github.com/lightningnetwork/lnd/pull/10701). The four
paginated list methods (`FetchPendingInvoices`, `InvoicesSettledSince`,
`InvoicesAddedSince`, `QueryInvoices`) previously issued multiple separate
DB round-trips per invoice row (features, HTLCs, HTLC custom records, AMP
sub-invoices, AMP sub-invoice HTLCs). Each method now collects all invoice
IDs for a page and loads the ancillary data in a small set of `WHERE id IN
(…)` batch queries, reducing the total round-trips per page from `O(n)` to
`O(1)`.
The single-invoice lookup path (`LookupInvoice`, `UpdateInvoice`) is
unchanged.

* [Replace the catch-all `FilterInvoices` SQL query with five focused,
index-friendly queries](https://github.com/lightningnetwork/lnd/pull/10601)
(`FetchPendingInvoices`, `FilterInvoicesBySettleIndex`,
Expand Down
10 changes: 9 additions & 1 deletion invoices/invoiceregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,15 @@ func TestInvoiceRegistry(t *testing.T) {

testClock := clock.NewTestClock(testTime)

return invpkg.NewSQLStore(executor, testClock), testClock
queryCfg := sqldb.DefaultSQLiteConfig()
if !sqlite {
queryCfg = sqldb.DefaultPostgresConfig()
}

return invpkg.NewSQLStore(
&invpkg.SQLStoreConfig{QueryCfg: queryCfg},
executor, testClock,
), testClock
}

for _, test := range testList {
Expand Down
7 changes: 6 additions & 1 deletion invoices/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,14 @@ func TestInvoices(t *testing.T) {
// that we also cover query pagination.
const testPaginationLimit = 3

queryCfg := &sqldb.QueryConfig{
MaxPageSize: testPaginationLimit,
MaxBatchSize: testPaginationLimit,
}

return invpkg.NewSQLStore(
&invpkg.SQLStoreConfig{QueryCfg: queryCfg},
executor, testClock,
invpkg.WithPaginationLimit(testPaginationLimit),
)
}

Expand Down
11 changes: 9 additions & 2 deletions invoices/kv_sql_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ func TestMigrationWithChannelDB(t *testing.T) {

testClock := clock.NewTestClock(time.Unix(1, 0))

return invpkg.NewSQLStore(invoiceExecutor, testClock),
genericExecutor
queryCfg := sqldb.DefaultSQLiteConfig()
if !sqlite {
queryCfg = sqldb.DefaultPostgresConfig()
}

return invpkg.NewSQLStore(
&invpkg.SQLStoreConfig{QueryCfg: queryCfg},
invoiceExecutor, testClock,
), genericExecutor
}

migrationTest := func(t *testing.T, kvStore *channeldb.DB,
Expand Down
10 changes: 9 additions & 1 deletion invoices/sql_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,15 @@ func TestMigrateSingleInvoiceRapid(t *testing.T) {

testClock := clock.NewTestClock(time.Unix(1, 0))

return NewSQLStore(executor, testClock)
queryCfg := sqldb.DefaultSQLiteConfig()
if !sqlite {
queryCfg = sqldb.DefaultPostgresConfig()
}

return NewSQLStore(
&SQLStoreConfig{QueryCfg: queryCfg},
executor, testClock,
)
}

// Define property-based test using rapid.
Expand Down
Loading
Loading