p2p: use package slices to sort in PeersInfo (#29957)

This commit is contained in:
Gealber Morales 2024-06-09 22:50:22 +02:00 committed by GitHub
parent 349fcdd22d
commit 8bda642963
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 7 deletions

View File

@ -19,6 +19,7 @@ package p2p
import (
"bytes"
"cmp"
"crypto/ecdsa"
"encoding/hex"
"errors"
@ -1140,12 +1141,9 @@ func (srv *Server) PeersInfo() []*PeerInfo {
}
}
// Sort the result array alphabetically by node identifier
for i := 0; i < len(infos); i++ {
for j := i + 1; j < len(infos); j++ {
if infos[i].ID > infos[j].ID {
infos[i], infos[j] = infos[j], infos[i]
}
}
}
slices.SortFunc(infos, func(a, b *PeerInfo) int {
return cmp.Compare(a.ID, b.ID)
})
return infos
}