What changed, and why it matters
This commit is a simple rename of a Go type and its constructor from KVPaymentsDB/NewKVPaymentsDB to KVStore/NewKVStore across five files. It changes no logic, no behavior, and no security-sensitive code. It is purely a code-style/consistency refactor to match naming already used elsewhere in the project.
No security action needed. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a mechanical identifier rename: type KVPaymentsDB -> KVStore, constructor NewKVPaymentsDB -> NewKVStore, and all receiver methods, comments, and test names updated accordingly. There are no functional changes, no new imports, no altered control flow, and no data format or serialization changes. The change is consistent with the graph package naming convention as noted in the commit message.
Changed components
payments/db/kv_store.gopayments/db/kv_store_test.gopayments/db/test_kvdb.goconfig_builder.gorouting/control_tower_test.goInspect captured patch +52 / −52
diff --git a/config_builder.go b/config_builder.go
index af4a06e..aecd5c1 100644
--- a/config_builder.go
+++ b/config_builder.go
@@ -1225,7 +1225,7 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
cfg.KeepFailedPaymentAttempts,
),
}
- kvPaymentsDB, err := paymentsdb.NewKVPaymentsDB(
+ kvPaymentsDB, err := paymentsdb.NewKVStore(
dbs.ChanStateDB,
paymentsDBOptions...,
)
diff --git a/payments/db/kv_store.go b/payments/db/kv_store.go
index 343f77e..bde4b2e 100644
--- a/payments/db/kv_store.go
+++ b/payments/db/kv_store.go
@@ -118,8 +118,8 @@ var (
paymentsIndexBucket = []byte("payments-index-bucket")
)
-// KVPaymentsDB implements persistence for payments and payment attempts.
-type KVPaymentsDB struct {
+// KVStore implements persistence for payments and payment attempts.
+type KVStore struct {
// Sequence management for the kv store.
seqMu sync.Mutex
currSeq uint64
@@ -140,9 +140,9 @@ func defaultKVStoreOptions() *StoreOptions {
}
}
-// NewKVPaymentsDB creates a new KVStore for payments.
-func NewKVPaymentsDB(db kvdb.Backend,
- options ...OptionModifier) (*KVPaymentsDB, error) {
+// NewKVStore creates a new KVStore for payments.
+func NewKVStore(db kvdb.Backend,
+ options ...OptionModifier) (*KVStore, error) {
opts := defaultKVStoreOptions()
for _, applyOption := range options {
@@ -155,7 +155,7 @@ func NewKVPaymentsDB(db kvdb.Backend,
}
}
- return &KVPaymentsDB{
+ return &KVStore{
db: db,
keepFailedPaymentAttempts: opts.KeepFailedPaymentAttempts,
}, nil
@@ -190,7 +190,7 @@ func initKVStore(db kvdb.Backend) error {
// making sure it does not already exist as an in-flight payment. When this
// method returns successfully, the payment is guaranteed to be in the InFlight
// state.
-func (p *KVPaymentsDB) InitPayment(paymentHash lntypes.Hash,
+func (p *KVStore) InitPayment(paymentHash lntypes.Hash,
info *PaymentCreationInfo) error {
// Obtain a new sequence number for this payment. This is used
@@ -293,8 +293,8 @@ func (p *KVPaymentsDB) InitPayment(paymentHash lntypes.Hash,
}
// DeleteFailedAttempts deletes all failed htlcs for a payment if configured
-// by the KVPaymentsDB db.
-func (p *KVPaymentsDB) DeleteFailedAttempts(hash lntypes.Hash) error {
+// by the KVStore db.
+func (p *KVStore) DeleteFailedAttempts(hash lntypes.Hash) error {
if !p.keepFailedPaymentAttempts {
const failedHtlcsOnly = true
err := p.DeletePayment(hash, failedHtlcsOnly)
@@ -361,7 +361,7 @@ func deserializePaymentIndex(r io.Reader) (lntypes.Hash, error) {
// RegisterAttempt atomically records the provided HTLCAttemptInfo to the
// DB.
-func (p *KVPaymentsDB) RegisterAttempt(paymentHash lntypes.Hash,
+func (p *KVStore) RegisterAttempt(paymentHash lntypes.Hash,
attempt *HTLCAttemptInfo) (*MPPayment, error) {
// Serialize the information before opening the db transaction.
@@ -511,7 +511,7 @@ func (p *KVPaymentsDB) RegisterAttempt(paymentHash lntypes.Hash,
// After invoking this method, InitPayment should always return an error to
// prevent us from making duplicate payments to the same payment hash. The
// provided preimage is atomically saved to the DB for record keeping.
-func (p *KVPaymentsDB) SettleAttempt(hash lntypes.Hash,
+func (p *KVStore) SettleAttempt(hash lntypes.Hash,
attemptID uint64, settleInfo *HTLCSettleInfo) (*MPPayment, error) {
var b bytes.Buffer
@@ -524,7 +524,7 @@ func (p *KVPaymentsDB) SettleAttempt(hash lntypes.Hash,
}
// FailAttempt marks the given payment attempt failed.
-func (p *KVPaymentsDB) FailAttempt(hash lntypes.Hash,
+func (p *KVStore) FailAttempt(hash lntypes.Hash,
attemptID uint64, failInfo *HTLCFailInfo) (*MPPayment, error) {
var b bytes.Buffer
@@ -537,7 +537,7 @@ func (p *KVPaymentsDB) FailAttempt(hash lntypes.Hash,
}
// updateHtlcKey updates a database key for the specified htlc.
-func (p *KVPaymentsDB) updateHtlcKey(paymentHash lntypes.Hash,
+func (p *KVStore) updateHtlcKey(paymentHash lntypes.Hash,
attemptID uint64, key, value []byte) (*MPPayment, error) {
aid := make([]byte, 8)
@@ -609,7 +609,7 @@ func (p *KVPaymentsDB) updateHtlcKey(paymentHash lntypes.Hash,
// payment failed. After invoking this method, InitPayment should return nil on
// its next call for this payment hash, allowing the switch to make a
// subsequent payment.
-func (p *KVPaymentsDB) Fail(paymentHash lntypes.Hash,
+func (p *KVStore) Fail(paymentHash lntypes.Hash,
reason FailureReason) (*MPPayment, error) {
var (
@@ -633,7 +633,7 @@ func (p *KVPaymentsDB) Fail(paymentHash lntypes.Hash,
// We mark the payment as failed as long as it is known. This
// lets the last attempt to fail with a terminal write its
- // failure to the KVPaymentsDB without synchronizing with
+ // failure to the KVStore without synchronizing with
// other attempts.
_, err = fetchPaymentStatus(bucket)
if errors.Is(err, ErrPaymentNotInitiated) {
@@ -666,7 +666,7 @@ func (p *KVPaymentsDB) Fail(paymentHash lntypes.Hash,
}
// FetchPayment returns information about a payment from the database.
-func (p *KVPaymentsDB) FetchPayment(paymentHash lntypes.Hash) (
+func (p *KVStore) FetchPayment(paymentHash lntypes.Hash) (
*MPPayment, error) {
var payment *MPPayment
@@ -761,7 +761,7 @@ func fetchPaymentBucketUpdate(tx kvdb.RwTx, paymentHash lntypes.Hash) (
// nextPaymentSequence returns the next sequence number to store for a new
// payment.
-func (p *KVPaymentsDB) nextPaymentSequence() ([]byte, error) {
+func (p *KVStore) nextPaymentSequence() ([]byte, error) {
p.seqMu.Lock()
defer p.seqMu.Unlock()
@@ -822,7 +822,7 @@ func fetchPaymentStatus(bucket kvdb.RBucket) (PaymentStatus, error) {
}
// FetchInFlightPayments returns all payments with status InFlight.
-func (p *KVPaymentsDB) FetchInFlightPayments() ([]*MPPayment, error) {
+func (p *KVStore) FetchInFlightPayments() ([]*MPPayment, error) {
var (
inFlights []*MPPayment
start = time.Now()
@@ -895,7 +895,7 @@ func htlcBucketKey(prefix, id []byte) []byte {
}
// FetchPayments returns all sent payments found in the DB.
-func (p *KVPaymentsDB) FetchPayments() ([]*MPPayment, error) {
+func (p *KVStore) FetchPayments() ([]*MPPayment, error) {
var payments []*MPPayment
err := kvdb.View(p.db, func(tx kvdb.RTx) error {
@@ -1135,7 +1135,7 @@ 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(_ context.Context,
+func (p *KVStore) QueryPayments(_ context.Context,
query Query) (Response, error) {
var resp Response
@@ -1356,7 +1356,7 @@ func fetchPaymentWithSequenceNumber(tx kvdb.RTx, paymentHash lntypes.Hash,
// DeletePayment deletes a payment from the DB given its payment hash. If
// failedHtlcsOnly is set, only failed HTLC attempts of the payment will be
// deleted.
-func (p *KVPaymentsDB) DeletePayment(paymentHash lntypes.Hash,
+func (p *KVStore) DeletePayment(paymentHash lntypes.Hash,
failedHtlcsOnly bool) error {
return kvdb.Update(p.db, func(tx kvdb.RwTx) error {
@@ -1453,7 +1453,7 @@ func (p *KVPaymentsDB) DeletePayment(paymentHash lntypes.Hash,
// failedHtlcsOnly is set, the payment itself won't be deleted, only failed HTLC
// attempts. The method returns the number of deleted payments, which is always
// 0 if failedHtlcsOnly is set.
-func (p *KVPaymentsDB) DeletePayments(failedOnly,
+func (p *KVStore) DeletePayments(failedOnly,
failedHtlcsOnly bool) (int, error) {
var numPayments int
diff --git a/payments/db/kv_store_test.go b/payments/db/kv_store_test.go
index 547273f..b3d7887 100644
--- a/payments/db/kv_store_test.go
+++ b/payments/db/kv_store_test.go
@@ -18,9 +18,9 @@ import (
"github.com/stretchr/testify/require"
)
-// TestKVPaymentsDBDeleteNonInFlight checks that calling DeletePayments only
+// TestKVStoreDeleteNonInFlight checks that calling DeletePayments only
// deletes payments from the database that are not in-flight.
-func TestKVPaymentsDBDeleteNonInFlight(t *testing.T) {
+func TestKVStoreDeleteNonInFlight(t *testing.T) {
t.Parallel()
paymentDB := NewKVTestDB(t)
@@ -249,7 +249,7 @@ type htlcStatus struct {
// fetchPaymentIndexEntry gets the payment hash for the sequence number provided
// from our payment indexes bucket.
-func fetchPaymentIndexEntry(_ *testing.T, p *KVPaymentsDB,
+func fetchPaymentIndexEntry(_ *testing.T, p *KVStore,
sequenceNumber uint64) (*lntypes.Hash, error) {
var hash lntypes.Hash
@@ -287,7 +287,7 @@ func assertPaymentIndex(t *testing.T, p DB, expectedHash lntypes.Hash) {
// Only the kv implementation uses the index so we exit early if the
// payment db is not a kv implementation. This helps us to reuse the
// same test for both implementations.
- kvPaymentDB, ok := p.(*KVPaymentsDB)
+ kvPaymentDB, ok := p.(*KVStore)
if !ok {
return
}
@@ -307,7 +307,7 @@ func assertPaymentIndex(t *testing.T, p DB, expectedHash lntypes.Hash) {
func assertNoIndex(t *testing.T, p DB, seqNr uint64) {
t.Helper()
- kvPaymentDB, ok := p.(*KVPaymentsDB)
+ kvPaymentDB, ok := p.(*KVStore)
if !ok {
return
}
@@ -929,7 +929,7 @@ func TestQueryPayments(t *testing.T) {
paymentDB := NewKVTestDB(t)
// Initialize the payment database.
- paymentDB, err := NewKVPaymentsDB(paymentDB.db)
+ paymentDB, err := NewKVStore(paymentDB.db)
require.NoError(t, err)
// Make a preliminary query to make sure it's ok to
diff --git a/payments/db/test_kvdb.go b/payments/db/test_kvdb.go
index 78c3372..e0ee173 100644
--- a/payments/db/test_kvdb.go
+++ b/payments/db/test_kvdb.go
@@ -16,16 +16,16 @@ func NewTestDB(t *testing.T, opts ...OptionModifier) DB {
t.Cleanup(backendCleanup)
- paymentDB, err := NewKVPaymentsDB(backend, opts...)
+ paymentDB, err := NewKVStore(backend, opts...)
require.NoError(t, err)
return paymentDB
}
// NewKVTestDB is a helper function that creates an BBolt database for testing
-// and there is no need to convert the interface to the KVPaymentsDB because for
+// and there is no need to convert the interface to the KVStore because for
// some unit tests we still need access to the kvdb interface.
-func NewKVTestDB(t *testing.T, opts ...OptionModifier) *KVPaymentsDB {
+func NewKVTestDB(t *testing.T, opts ...OptionModifier) *KVStore {
backend, backendCleanup, err := kvdb.GetTestBackend(
t.TempDir(), "kvPaymentDB",
)
@@ -33,7 +33,7 @@ func NewKVTestDB(t *testing.T, opts ...OptionModifier) *KVPaymentsDB {
t.Cleanup(backendCleanup)
- paymentDB, err := NewKVPaymentsDB(backend, opts...)
+ paymentDB, err := NewKVStore(backend, opts...)
require.NoError(t, err)
return paymentDB
diff --git a/routing/control_tower_test.go b/routing/control_tower_test.go
index 3e01065..de0aacf 100644
--- a/routing/control_tower_test.go
+++ b/routing/control_tower_test.go
@@ -50,7 +50,7 @@ func TestControlTowerSubscribeUnknown(t *testing.T) {
db := initDB(t)
- paymentDB, err := paymentsdb.NewKVPaymentsDB(
+ paymentDB, err := paymentsdb.NewKVStore(
db,
paymentsdb.WithKeepFailedPaymentAttempts(true),
)
@@ -70,7 +70,7 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
db := initDB(t)
- paymentDB, err := paymentsdb.NewKVPaymentsDB(db)
+ paymentDB, err := paymentsdb.NewKVStore(db)
require.NoError(t, err)
pControl := NewControlTower(paymentDB)
@@ -174,33 +174,33 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
}
}
-// TestKVPaymentsDBSubscribeFail tests that payment updates for a
+// TestKVStoreSubscribeFail tests that payment updates for a
// failed payment are properly sent to subscribers.
-func TestKVPaymentsDBSubscribeFail(t *testing.T) {
+func TestKVStoreSubscribeFail(t *testing.T) {
t.Parallel()
t.Run("register attempt, keep failed payments", func(t *testing.T) {
- testKVPaymentsDBSubscribeFail(t, true, true)
+ testKVStoreSubscribeFail(t, true, true)
})
t.Run("register attempt, delete failed payments", func(t *testing.T) {
- testKVPaymentsDBSubscribeFail(t, true, false)
+ testKVStoreSubscribeFail(t, true, false)
})
t.Run("no register attempt, keep failed payments", func(t *testing.T) {
- testKVPaymentsDBSubscribeFail(t, false, true)
+ testKVStoreSubscribeFail(t, false, true)
})
t.Run("no register attempt, delete failed payments", func(t *testing.T) {
- testKVPaymentsDBSubscribeFail(t, false, false)
+ testKVStoreSubscribeFail(t, false, false)
})
}
-// TestKVPaymentsDBSubscribeAllSuccess tests that multiple payments are
+// TestKVStoreSubscribeAllSuccess tests that multiple payments are
// properly sent to subscribers of TrackPayments.
-func TestKVPaymentsDBSubscribeAllSuccess(t *testing.T) {
+func TestKVStoreSubscribeAllSuccess(t *testing.T) {
t.Parallel()
db := initDB(t)
- paymentDB, err := paymentsdb.NewKVPaymentsDB(
+ paymentDB, err := paymentsdb.NewKVStore(
db,
paymentsdb.WithKeepFailedPaymentAttempts(true),
)
@@ -318,14 +318,14 @@ func TestKVPaymentsDBSubscribeAllSuccess(t *testing.T) {
require.Equal(t, attempt2.Route, htlc2.Route, "unexpected htlc route.")
}
-// TestKVPaymentsDBSubscribeAllImmediate tests whether already inflight
+// TestKVStoreSubscribeAllImmediate tests whether already inflight
// payments are reported at the start of the SubscribeAllPayments subscription.
-func TestKVPaymentsDBSubscribeAllImmediate(t *testing.T) {
+func TestKVStoreSubscribeAllImmediate(t *testing.T) {
t.Parallel()
db := initDB(t)
- paymentDB, err := paymentsdb.NewKVPaymentsDB(
+ paymentDB, err := paymentsdb.NewKVStore(
db,
paymentsdb.WithKeepFailedPaymentAttempts(true),
)
@@ -367,14 +367,14 @@ func TestKVPaymentsDBSubscribeAllImmediate(t *testing.T) {
}
}
-// TestKVPaymentsDBUnsubscribeSuccess tests that when unsubscribed, there are
+// TestKVStoreUnsubscribeSuccess tests that when unsubscribed, there are
// no more notifications to that specific subscription.
-func TestKVPaymentsDBUnsubscribeSuccess(t *testing.T) {
+func TestKVStoreUnsubscribeSuccess(t *testing.T) {
t.Parallel()
db := initDB(t)
- paymentDB, err := paymentsdb.NewKVPaymentsDB(
+ paymentDB, err := paymentsdb.NewKVStore(
db,
paymentsdb.WithKeepFailedPaymentAttempts(true),
)
@@ -444,12 +444,12 @@ func TestKVPaymentsDBUnsubscribeSuccess(t *testing.T) {
require.Len(t, subscription2.Updates(), 0)
}
-func testKVPaymentsDBSubscribeFail(t *testing.T, registerAttempt,
+func testKVStoreSubscribeFail(t *testing.T, registerAttempt,
keepFailedPaymentAttempts bool) {
db := initDB(t)
- paymentDB, err := paymentsdb.NewKVPaymentsDB(
+ paymentDB, err := paymentsdb.NewKVStore(
db,
paymentsdb.WithKeepFailedPaymentAttempts(
keepFailedPaymentAttempts,
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.