channeldb: add context to query method

We add a context for the query method because the query method
is part of the paymentDB interface and for the SQL case
we will need the context for this method because the native
SQL drivers demand one. So we add it for the kv implementation
here as well so we can then make use of the new interface type.
This commit is contained in:
ziggie committed 2025-08-11 16:44:13 +02:00
1 parent 2269859d98
commit db2c50a599
3 files changed
+21 -16

No files matched your search

+3 -2
View File
@@ -2,6 +2,7 @@ package channeldb
import ( import (
"bytes" "bytes"
"context"
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
@@ -1206,8 +1207,8 @@ func fetchFailedHtlcKeys(bucket kvdb.RBucket) ([][]byte, error) {
// QueryPayments is a query to the payments database which is restricted // QueryPayments is a query to the payments database which is restricted
// to a subset of payments by the payments query, containing an offset // to a subset of payments by the payments query, containing an offset
// index and a maximum number of returned payments. // index and a maximum number of returned payments.
func (p *KVPaymentsDB) QueryPayments(query PaymentsQuery) (PaymentsResponse, func (p *KVPaymentsDB) QueryPayments(_ context.Context,
error) { query PaymentsQuery) (PaymentsResponse, error) {
var resp PaymentsResponse var resp PaymentsResponse
+15 -13
View File
@@ -1,6 +1,7 @@
package channeldb package channeldb
import ( import (
"context"
"fmt" "fmt"
"math" "math"
"reflect" "reflect"
@@ -348,20 +349,20 @@ func TestQueryPayments(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
t.Parallel() t.Parallel()
db, err := MakeTestDB(t) ctx := context.Background()
if err != nil {
t.Fatalf("unable to init db: %v", err)
}
db, err := MakeTestDB(t)
require.NoError(t, err)
// Initialize the payment database.
paymentDB := NewKVPaymentsDB(db) paymentDB := NewKVPaymentsDB(db)
// Make a preliminary query to make sure it's ok to // Make a preliminary query to make sure it's ok to
// query when we have no payments. // query when we have no payments.
resp, err := paymentDB.QueryPayments(tt.query) resp, err := paymentDB.QueryPayments(ctx, tt.query)
require.NoError(t, err) require.NoError(t, err)
require.Len(t, resp.Payments, 0) require.Len(t, resp.Payments, 0)
@@ -389,10 +390,7 @@ func TestQueryPayments(t *testing.T) {
err = paymentDB.InitPayment( err = paymentDB.InitPayment(
info.PaymentIdentifier, info, info.PaymentIdentifier, info,
) )
if err != nil { require.NoError(t, err)
t.Fatalf("unable to initialize "+
"payment in database: %v", err)
}
// Immediately delete the payment with index 2. // Immediately delete the payment with index 2.
if i == 1 { if i == 1 {
@@ -401,8 +399,10 @@ func TestQueryPayments(t *testing.T) {
) )
require.NoError(t, err) require.NoError(t, err)
deletePayment(t, db, info.PaymentIdentifier, deletePayment(
pmt.SequenceNum) t, db, info.PaymentIdentifier,
pmt.SequenceNum,
)
} }
// If we are on the last payment entry, add a // If we are on the last payment entry, add a
@@ -437,7 +437,9 @@ func TestQueryPayments(t *testing.T) {
"want %v.", len(allPayments), 6) "want %v.", len(allPayments), 6)
} }
querySlice, err := paymentDB.QueryPayments(tt.query) querySlice, err := paymentDB.QueryPayments(
ctx, tt.query,
)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
+3 -1
View File
@@ -7528,7 +7528,9 @@ func (r *rpcServer) ListPayments(ctx context.Context,
query.MaxPayments = math.MaxUint64 query.MaxPayments = math.MaxUint64
} }
paymentsQuerySlice, err := r.server.kvPaymentsDB.QueryPayments(query) paymentsQuerySlice, err := r.server.kvPaymentsDB.QueryPayments(
ctx, query,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }