Skip to content

Commit

Permalink
Merge pull request lightningnetwork#8595 from bhandras/sqldb-invoices…
Browse files Browse the repository at this point in the history
…-reset-on-retry

sqldb: reset out of scope containers on potential ExecTx retry
  • Loading branch information
bhandras authored Apr 2, 2024
2 parents 5599b3c + a1a7982 commit 16c8339
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/release-notes/release-notes-0.18.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ bitcoin peers' feefilter values into account](https://github.com/lightningnetwor
start](https://github.com/lightningnetwork/lnd/pull/8568) if native SQL is
enabled but the channeldb already has any KV invoices stored.

* [Fix a bug](https://github.com/lightningnetwork/lnd/pull/8595) when retrying
SQL InvoiceDB transactions due to database errors.

## Code Health

* [Remove database pointers](https://github.com/lightningnetwork/lnd/pull/8117)
Expand Down
6 changes: 5 additions & 1 deletion sqldb/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,11 @@ func (i *InvoiceStore) LookupInvoice(ctx context.Context,
func (i *InvoiceStore) FetchPendingInvoices(ctx context.Context) (
map[lntypes.Hash]invpkg.Invoice, error) {

invoices := make(map[lntypes.Hash]invpkg.Invoice)
var invoices map[lntypes.Hash]invpkg.Invoice

readTxOpt := NewInvoiceQueryReadTx()
err := i.db.ExecTx(ctx, &readTxOpt, func(db InvoiceQueries) error {
invoices = make(map[lntypes.Hash]invpkg.Invoice)
limit := queryPaginationLimit

return queryWithLimit(func(offset int) (int, error) {
Expand Down Expand Up @@ -671,6 +672,7 @@ func (i *InvoiceStore) InvoicesSettledSince(ctx context.Context, idx uint64) (

readTxOpt := NewInvoiceQueryReadTx()
err := i.db.ExecTx(ctx, &readTxOpt, func(db InvoiceQueries) error {
invoices = nil
settleIdx := idx
limit := queryPaginationLimit

Expand Down Expand Up @@ -784,6 +786,7 @@ func (i *InvoiceStore) InvoicesAddedSince(ctx context.Context, idx uint64) (

readTxOpt := NewInvoiceQueryReadTx()
err := i.db.ExecTx(ctx, &readTxOpt, func(db InvoiceQueries) error {
result = nil
addIdx := idx
limit := queryPaginationLimit

Expand Down Expand Up @@ -840,6 +843,7 @@ func (i *InvoiceStore) QueryInvoices(ctx context.Context,

readTxOpt := NewInvoiceQueryReadTx()
err := i.db.ExecTx(ctx, &readTxOpt, func(db InvoiceQueries) error {
invoices = nil
limit := queryPaginationLimit

return queryWithLimit(func(offset int) (int, error) {
Expand Down

0 comments on commit 16c8339

Please sign in to comment.