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.
This commit is contained in:
1 file changed
+7
-1
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user