paymentsdb: benchmark FetchInFlightPayments on Postgres
What changed, and why it matters
This commit adds a new test file that benchmarks a database operation (FetchInFlightPayments) using Postgres. It is purely a performance test/benchmark and does not change any production code, fix bugs, or alter security behavior.
No security action needed. Review as normal test/benchmark code if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff introduces payments/db/fetch_inflight_benchmark_postgres_test.go, a Go benchmark test gated by build tags test_db_postgres && !test_db_sqlite. It sets up a Postgres-backed SQLStore via sqldb test fixtures and seeds benchmark data. No production logic is modified; no security-sensitive code paths are introduced.
Changed components
payments/db/fetch_inflight_benchmark_postgres_test.goInspect captured patch +60 / −0
diff --git a/payments/db/fetch_inflight_benchmark_postgres_test.go b/payments/db/fetch_inflight_benchmark_postgres_test.go
new file mode 100644
index 0000000..9e6f9e9
--- /dev/null
+++ b/payments/db/fetch_inflight_benchmark_postgres_test.go
@@ -0,0 +1,60 @@
+//go:build test_db_postgres && !test_db_sqlite
+
+package paymentsdb
+
+import (
+ "database/sql"
+ "testing"
+
+ "github.com/lightningnetwork/lnd/sqldb"
+)
+
+// postgresFetchInFlightBenchBackend creates Postgres-backed benchmark stores.
+type postgresFetchInFlightBenchBackend struct {
+ fixture *sqldb.TestPgFixture
+}
+
+// newFetchInFlightBenchBackend creates the benchmark backend selected by the
+// active build tags.
+func newFetchInFlightBenchBackend(b *testing.B) fetchInFlightBenchBackend {
+ b.Helper()
+
+ fixture := sqldb.NewTestPgFixture(
+ b, sqldb.DefaultPostgresFixtureLifetime,
+ )
+ b.Cleanup(func() {
+ fixture.TearDown(b)
+ })
+
+ return postgresFetchInFlightBenchBackend{fixture: fixture}
+}
+
+// newStore creates a migrated Postgres SQLStore and seeds it with one benchmark
+// scenario.
+func (backend postgresFetchInFlightBenchBackend) newStore(b *testing.B,
+ scenario fetchInFlightBenchScenario,
+ totalPayments int) (*SQLStore, fetchInFlightBenchSeedStats) {
+
+ b.Helper()
+
+ pgDB := sqldb.NewTestPostgresDB(b, backend.fixture)
+ baseDB := pgDB.BaseDB
+
+ withTx := func(tx *sql.Tx) SQLQueries {
+ return baseDB.WithTx(tx)
+ }
+ queries := sqldb.NewTransactionExecutor(baseDB, withTx)
+
+ store, err := NewSQLStore(&SQLStoreConfig{
+ QueryCfg: sqldb.DefaultPostgresConfig(),
+ }, queries)
+ if err != nil {
+ b.Fatalf("new SQL store: %v", err)
+ }
+
+ stats := seedFetchInFlightBenchDB(
+ b, baseDB.DB, withTx, scenario, totalPayments,
+ )
+
+ return store, stats
+}
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.