What changed, and why it matters
This commit is a straightforward internal code cleanup. It adds a context parameter to a database query method so the same interface can be used by both the existing key-value store and a future SQL implementation. The new context is not used for any security purpose in this change, and no behavior of the application changes.
No security action required. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies the paymentDB interface implementation by adding a context.Context parameter to KVPaymentsDB.QueryPayments. The context is passed through from rpcServer.ListPayments but is ignored (named ‘_’) in the KV implementation. The change is preparatory work for a SQL-backed payments DB where SQL drivers require a context. Tests are updated only to pass context.Background(). No functional, security, or behavioral changes are introduced.
Changed components
channeldb/payments_kv_store.gochanneldb/payments_test.gorpcserver.goInspect captured patch +20 / −15
diff --git a/channeldb/payments_kv_store.go b/channeldb/payments_kv_store.go
index 584dc0f..ab98d42 100644
--- a/channeldb/payments_kv_store.go
+++ b/channeldb/payments_kv_store.go
@@ -2,6 +2,7 @@ package channeldb
import (
"bytes"
+ "context"
"encoding/binary"
"errors"
"fmt"
@@ -1206,8 +1207,8 @@ func fetchFailedHtlcKeys(bucket kvdb.RBucket) ([][]byte, error) {
// QueryPayments is a query to the payments database which is restricted
// to a subset of payments by the payments query, containing an offset
// index and a maximum number of returned payments.
-func (p *KVPaymentsDB) QueryPayments(query PaymentsQuery) (PaymentsResponse,
- error) {
+func (p *KVPaymentsDB) QueryPayments(_ context.Context,
+ query PaymentsQuery) (PaymentsResponse, error) {
var resp PaymentsResponse
diff --git a/channeldb/payments_test.go b/channeldb/payments_test.go
index 1d5e814..727bd91 100644
--- a/channeldb/payments_test.go
+++ b/channeldb/payments_test.go
@@ -1,6 +1,7 @@
package channeldb
import (
+ "context"
"fmt"
"math"
"reflect"
@@ -348,20 +349,20 @@ func TestQueryPayments(t *testing.T) {
}
for _, tt := range tests {
- tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
+ ctx := context.Background()
+
db, err := MakeTestDB(t)
- if err != nil {
- t.Fatalf("unable to init db: %v", err)
- }
+ require.NoError(t, err)
+ // Initialize the payment database.
paymentDB := NewKVPaymentsDB(db)
// Make a preliminary query to make sure it's ok to
// query when we have no payments.
- resp, err := paymentDB.QueryPayments(tt.query)
+ resp, err := paymentDB.QueryPayments(ctx, tt.query)
require.NoError(t, err)
require.Len(t, resp.Payments, 0)
@@ -389,10 +390,7 @@ func TestQueryPayments(t *testing.T) {
err = paymentDB.InitPayment(
info.PaymentIdentifier, info,
)
- if err != nil {
- t.Fatalf("unable to initialize "+
- "payment in database: %v", err)
- }
+ require.NoError(t, err)
// Immediately delete the payment with index 2.
if i == 1 {
@@ -401,8 +399,10 @@ func TestQueryPayments(t *testing.T) {
)
require.NoError(t, err)
- deletePayment(t, db, info.PaymentIdentifier,
- pmt.SequenceNum)
+ deletePayment(
+ t, db, info.PaymentIdentifier,
+ pmt.SequenceNum,
+ )
}
// If we are on the last payment entry, add a
@@ -437,7 +437,9 @@ func TestQueryPayments(t *testing.T) {
"want %v.", len(allPayments), 6)
}
- querySlice, err := paymentDB.QueryPayments(tt.query)
+ querySlice, err := paymentDB.QueryPayments(
+ ctx, tt.query,
+ )
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
diff --git a/rpcserver.go b/rpcserver.go
index 08f9cf5..c922b23 100644
--- a/rpcserver.go
+++ b/rpcserver.go
@@ -7528,7 +7528,9 @@ func (r *rpcServer) ListPayments(ctx context.Context,
query.MaxPayments = math.MaxUint64
}
- paymentsQuerySlice, err := r.server.kvPaymentsDB.QueryPayments(query)
+ paymentsQuerySlice, err := r.server.kvPaymentsDB.QueryPayments(
+ ctx, query,
+ )
if err != nil {
return nil, err
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.