AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 29 Bitcoin

sqldb+paymentsdb: improve filterpayments efficiency

Public commit record

What the developer wrote

Authored by ziggie

73/100 · Adequate
sqldb+paymentsdb: improve filterpayments efficiency

In this commit, we fix a gap that was introduced when the payment DB
commits were arranged for the main line. The `migration1` package
already had the updated `FilterPayments` query using `COALESCE` for
the index bounds and a separate `FilterPaymentsDesc` query for
reverse-ordered pagination, but the corresponding changes in
`sqldb/sqlc` and the main `sql_store.go` were accidentally left out.

The old `FilterPayments` used OR-based nullable params for the
`created_at` bounds (e.g., `p.created_at >= $3 OR $3 IS NULL`). On
Postgres, mixing nullable text fallbacks in a `COALESCE` with
timestamp columns causes a type mismatch error. The OR-based approach
also prevents the query planner from using the `created_at` index.
We fix this by providing non-nullable `time.Time` params from the Go
side, defaulting to epoch start and year 9999 when no filter is set.

We also drop the `Reverse` param from `FilterPaymentsParams` and
instead introduce a dedicated `FilterPaymentsDesc` query that orders
by `p.id DESC`. This avoids the conditional `CASE WHEN` ordering
trick, which some planners handle poorly.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit fixes a database query used to list Lightning Network payments. The old query could fail on Postgres with a type-mismatch error and was inefficient because it couldn't use a date index. The fix supplies default date bounds from the Go code, removes a problematic 'reverse' ordering trick, and adds a separate descending-order query. It is a correctness/performance bug fix rather than a security vulnerability.

Recommended action

Treat as a routine bug-fix/correctness patch. Review for normal QA; no emergency security response indicated. If running Postgres-backed LND with payment queries, ensure this fix is included to avoid query failures and poor performance.

Security signals we found

01

Database query correctness fix (Postgres type mismatch)

02

Performance/index-usage improvement for payment filtering

03

No input sanitization, authentication, or authorization changes observed

04

No cryptographic or secret-handling changes observed

Risk score

Why this scored 29/100

Our methodology →
Potential impact 8/30
Exploitability 3/25
Stealth signal 2/15
Affected reach 5/15
Confidence 7/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.