From 216de55dff8de52a686f65c1245e3f9acbc426b7 Mon Sep 17 00:00:00 2001 From: ziggie Date: Tue, 24 Feb 2026 10:01:06 +0100 Subject: [PATCH] paymentsdb: sort FetchInFlightPayments result by sequence number The SQL implementation collects payments into a map before converting to a slice, resulting in non-deterministic iteration order due to Go's intentional map randomisation. Sort the result by SequenceNum to produce a deterministic, insertion-ordered output. Note that the current sole caller (resumePayments in router.go) processes each payment independently, so this ordering does not affect any existing behaviour. --- payments/db/sql_store.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/payments/db/sql_store.go b/payments/db/sql_store.go index 2589f3e79..9644266f8 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() {