all: update golang/x/ext and fix slice sorting fallout (#27909)

The Go authors updated golang/x/ext to change the function signature of the slices sort method. 
It's an entire shitshow now because x/ext is not tagged, so everyone's codebase just 
picked a new version that some other dep depends on, causing our code to fail building.

This PR updates the dep on our code too and does all the refactorings to follow upstream...
This commit is contained in:
Péter Szilágyi
2023-08-12 00:04:12 +02:00
committed by GitHub
parent 0ce331f56a
commit be65b47645
38 changed files with 144 additions and 113 deletions
+4 -4
View File
@@ -217,14 +217,14 @@ func nodeEqual(n1 *enode.Node, n2 *enode.Node) bool {
}
func sortByID(nodes []*enode.Node) {
slices.SortFunc(nodes, func(a, b *enode.Node) bool {
return string(a.ID().Bytes()) < string(b.ID().Bytes())
slices.SortFunc(nodes, func(a, b *enode.Node) int {
return bytes.Compare(a.ID().Bytes(), b.ID().Bytes())
})
}
func sortedByDistanceTo(distbase enode.ID, slice []*node) bool {
return slices.IsSortedFunc(slice, func(a, b *node) bool {
return enode.DistCmp(distbase, a.ID(), b.ID()) < 0
return slices.IsSortedFunc(slice, func(a, b *node) int {
return enode.DistCmp(distbase, a.ID(), b.ID())
})
}
+2 -2
View File
@@ -302,8 +302,8 @@ func (tn *preminedTestnet) closest(n int) (nodes []*enode.Node) {
nodes = append(nodes, tn.node(d, i))
}
}
slices.SortFunc(nodes, func(a, b *enode.Node) bool {
return enode.DistCmp(tn.target.id(), a.ID(), b.ID()) < 0
slices.SortFunc(nodes, func(a, b *enode.Node) int {
return enode.DistCmp(tn.target.id(), a.ID(), b.ID())
})
return nodes[:n]
}
+2 -2
View File
@@ -61,8 +61,8 @@ func TestUDPv5_lookupE2E(t *testing.T) {
for i := range nodes {
expectedResult[i] = nodes[i].Self()
}
slices.SortFunc(expectedResult, func(a, b *enode.Node) bool {
return enode.DistCmp(target.ID(), a.ID(), b.ID()) < 0
slices.SortFunc(expectedResult, func(a, b *enode.Node) int {
return enode.DistCmp(target.ID(), a.ID(), b.ID())
})
// Do the lookup.
+2 -2
View File
@@ -214,8 +214,8 @@ func (t *Tree) build(entries []entry) entry {
}
func sortByID(nodes []*enode.Node) []*enode.Node {
slices.SortFunc(nodes, func(a, b *enode.Node) bool {
return bytes.Compare(a.ID().Bytes(), b.ID().Bytes()) < 0
slices.SortFunc(nodes, func(a, b *enode.Node) int {
return bytes.Compare(a.ID().Bytes(), b.ID().Bytes())
})
return nodes
}
+1 -1
View File
@@ -386,7 +386,7 @@ func countMatchingProtocols(protocols []Protocol, caps []Cap) int {
// matchProtocols creates structures for matching named subprotocols.
func matchProtocols(protocols []Protocol, caps []Cap, rw MsgReadWriter) map[string]*protoRW {
slices.SortFunc(caps, Cap.Less)
slices.SortFunc(caps, Cap.Cmp)
offset := baseProtocolLength
result := make(map[string]*protoRW)
+11 -4
View File
@@ -18,6 +18,7 @@ package p2p
import (
"fmt"
"strings"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
@@ -77,10 +78,16 @@ func (cap Cap) String() string {
return fmt.Sprintf("%s/%d", cap.Name, cap.Version)
}
// Less defines the canonical sorting order of capabilities.
func (cap Cap) Less(other Cap) bool {
// Cmp defines the canonical sorting order of capabilities.
func (cap Cap) Cmp(other Cap) int {
if cap.Name == other.Name {
return cap.Version < other.Version
if cap.Version < other.Version {
return -1
}
if cap.Version > other.Version {
return 1
}
return 0
}
return cap.Name < other.Name
return strings.Compare(cap.Name, other.Name)
}
+1 -1
View File
@@ -510,7 +510,7 @@ func (srv *Server) setupLocalNode() error {
for _, p := range srv.Protocols {
srv.ourHandshake.Caps = append(srv.ourHandshake.Caps, p.cap())
}
slices.SortFunc(srv.ourHandshake.Caps, Cap.Less)
slices.SortFunc(srv.ourHandshake.Caps, Cap.Cmp)
// Create the local node.
db, err := enode.OpenDB(srv.NodeDatabase)