paymentsdb: sort FetchInFlightPayments result by sequence number
What changed, and why it matters
This change fixes a minor non-deterministic ordering bug in the database layer that returns in-flight Lightning payments. Because Go randomizes map iteration order, the list of payments could come back in a different order each time. The patch sorts the results by an internal sequence number so the order is stable. The commit message explicitly states the only current caller processes each payment independently, so existing behavior is unaffected.
No immediate security action required. Treat as normal code-quality/robustness patch. Monitor whether future callers begin to rely on ordering assumptions.
Security signals we found
Non-deterministic iteration order from map-to-slice conversion
Sorting added to produce deterministic output
Commit message states no existing behavior is affected
Evidence from the diff
In payments/db/sql_store.go, FetchInFlightPayments previously built a slice by iterating over a Go map, yielding non-deterministic order due to map randomization. The patch imports sort and sorts the resulting slice by MPPayment.SequenceNum. The commit message notes the sole caller, resumePayments in router.go, handles each payment independently, so ordering has no functional effect today. This is a robustness/correctness improvement rather than a security fix.
Changed components
payments/db/sql_store.goFetchInFlightPaymentsInspect captured patch +7 / −1
diff --git a/payments/db/sql_store.go b/payments/db/sql_store.go
index 2589f3e..9644266 100644
--- a/payments/db/sql_store.go
+++ b/payments/db/sql_store.go
@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"math"
+ "sort"
"strconv"
"time"
@@ -1060,11 +1061,16 @@ func (s *SQLStore) FetchInFlightPayments(ctx context.Context) ([]*MPPayment,
return err
}
- // Convert map to slice.
+ // Convert map to slice and sort by sequence number to
+ // produce a deterministic ordering.
mpPayments = make([]*MPPayment, 0, len(processedPayments))
for _, payment := range processedPayments {
mpPayments = append(mpPayments, payment)
}
+ sort.Slice(mpPayments, func(i, j int) bool {
+ return mpPayments[i].SequenceNum <
+ mpPayments[j].SequenceNum
+ })
return nil
}, func() {
Why this scored 18/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.