lnd: use sql store for payments in normal build
What changed, and why it matters
This commit changes how LND stores payment data in normal production builds, switching from an older key-value database backend to a newer SQL-based backend. It removes build-specific code differences so that both normal and test-native-SQL builds use the same SQL payments store. There is no indication in the commit of a security bug, vulnerability fix, or exploit.
No security action required. Treat as a normal backend migration commit. Operators and reviewers should verify that the SQL payments store migration path and backward compatibility are handled elsewhere in the release notes or related commits.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch unifies payments storage construction by moving the SQLStore instantiation from config_test_native_sql.go into config_builder.go and removing the KVStore-backed getPaymentsStore from config_prod.go. The production build now uses paymentsdb.NewSQLStore with a sqldb.TransactionExecutor, matching the previous test_native_sql behavior. This is a backend migration/refactoring change.
Changed components
lnd database configurationpayments store backend selectionconfig_builder.goconfig_prod.goconfig_test_native_sql.goInspect captured patch +11 / −47
diff --git a/config_builder.go b/config_builder.go
index 1a18f21..647d265 100644
--- a/config_builder.go
+++ b/config_builder.go
@@ -1269,13 +1269,17 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
return nil, nil, err
}
- // Create the payments DB.
- //
- // NOTE: In the regular build, this will construct a kvdb
- // backed payments backend. With the test_native_sql tag, it
- // will build a SQL payments backend.
- sqlPaymentsDB, err := d.getPaymentsStore(
- baseDB, dbs.ChanStateDB.Backend,
+ paymentsExecutor := sqldb.NewTransactionExecutor(
+ baseDB, func(tx *sql.Tx) paymentsdb.SQLQueries {
+ return baseDB.WithTx(tx)
+ },
+ )
+
+ sqlPaymentsDB, err := paymentsdb.NewSQLStore(
+ &paymentsdb.SQLStoreConfig{
+ QueryCfg: queryCfg,
+ },
+ paymentsExecutor,
)
if err != nil {
cleanUp()
diff --git a/config_prod.go b/config_prod.go
index 02b7d2a..60dba8b 100644
--- a/config_prod.go
+++ b/config_prod.go
@@ -6,8 +6,6 @@ import (
"context"
"github.com/lightningnetwork/lnd/kvdb"
- paymentsdb "github.com/lightningnetwork/lnd/payments/db"
- "github.com/lightningnetwork/lnd/sqldb"
"github.com/lightningnetwork/lnd/sqldb/sqlc"
)
@@ -26,12 +24,3 @@ func (d *DefaultDatabaseBuilder) getSQLMigration(ctx context.Context,
return nil, false
}
-
-// getPaymentsStore returns a paymentsdb.DB backed by a paymentsdb.KVStore
-// implementation.
-func (d *DefaultDatabaseBuilder) getPaymentsStore(_ *sqldb.BaseDB,
- kvBackend kvdb.Backend,
- opts ...paymentsdb.OptionModifier) (paymentsdb.DB, error) {
-
- return paymentsdb.NewKVStore(kvBackend, opts...)
-}
diff --git a/config_test_native_sql.go b/config_test_native_sql.go
index efc6ed8..91589fa 100644
--- a/config_test_native_sql.go
+++ b/config_test_native_sql.go
@@ -4,12 +4,8 @@ package lnd
import (
"context"
- "database/sql"
"github.com/lightningnetwork/lnd/kvdb"
- "github.com/lightningnetwork/lnd/lncfg"
- paymentsdb "github.com/lightningnetwork/lnd/payments/db"
- "github.com/lightningnetwork/lnd/sqldb"
"github.com/lightningnetwork/lnd/sqldb/sqlc"
)
@@ -29,28 +25,3 @@ func (d *DefaultDatabaseBuilder) getSQLMigration(_ context.Context,
return nil, false
}
}
-
-// getPaymentsStore returns a paymentsdb.DB backed by a paymentsdb.SQLStore
-// implementation.
-func (d *DefaultDatabaseBuilder) getPaymentsStore(baseDB *sqldb.BaseDB,
- kvBackend kvdb.Backend,
- opts ...paymentsdb.OptionModifier) (paymentsdb.DB, error) {
-
- paymentsExecutor := sqldb.NewTransactionExecutor(
- baseDB, func(tx *sql.Tx) paymentsdb.SQLQueries {
- return baseDB.WithTx(tx)
- },
- )
-
- queryConfig := d.cfg.DB.Sqlite.QueryConfig
- if d.cfg.DB.Backend == lncfg.PostgresBackend {
- queryConfig = d.cfg.DB.Postgres.QueryConfig
- }
-
- return paymentsdb.NewSQLStore(
- &paymentsdb.SQLStoreConfig{
- QueryCfg: &queryConfig,
- },
- paymentsExecutor, opts...,
- )
-}
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.