eth/fetcher: using slices.SortFunc

This commit is contained in:
cuiweixie 2025-09-20 13:32:08 +08:00
parent 684f0db4a2
commit 726528e83e

View file

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"math" "math"
mrand "math/rand" mrand "math/rand"
"slices"
"sort" "sort"
"time" "time"
@ -1014,8 +1015,8 @@ func (f *TxFetcher) forEachAnnounce(announces map[common.Hash]*txMetadataWithSeq
for hash, entry := range announces { for hash, entry := range announces {
list = append(list, announcement{hash: hash, meta: entry.txMetadata, seq: entry.seq}) list = append(list, announcement{hash: hash, meta: entry.txMetadata, seq: entry.seq})
} }
sort.Slice(list, func(i, j int) bool { slices.SortFunc(list, func(a, b announcement) int {
return list[i].seq < list[j].seq return int(a.seq) - int(b.seq)
}) })
for i := range list { for i := range list {
if !do(list[i].hash, list[i].meta) { if !do(list[i].hash, list[i].meta) {