Skip to content

Commit

Permalink
p2p: use package slices to sort in PeersInfo (ethereum#29957)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gealber authored Jun 9, 2024
1 parent 349fcdd commit 8bda642
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package p2p

import (
"bytes"
"cmp"
"crypto/ecdsa"
"encoding/hex"
"errors"
Expand Down Expand Up @@ -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
}

0 comments on commit 8bda642

Please sign in to comment.