From 17ed788c5b8007e349afe78e845c3412b7ea2808 Mon Sep 17 00:00:00 2001 From: devopsbo3 <69951731+devopsbo3@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:27:53 -0600 Subject: [PATCH] Revert "consensus/clique: use slices package for sorting (#27488)" This reverts commit cd00ee32bac52bcd1783511c9a4981663fb19e88. --- common/types.go | 5 ----- consensus/clique/snapshot.go | 11 +++++++++-- consensus/clique/snapshot_test.go | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/common/types.go b/common/types.go index 31515f52fa..bdfd964237 100644 --- a/common/types.go +++ b/common/types.go @@ -226,11 +226,6 @@ func IsHexAddress(s string) bool { return len(s) == 2*AddressLength && isHex(s) } -// Less compares two addresses. -func (a Address) Less(other Address) bool { - return bytes.Compare(a[:], other[:]) < 0 -} - // Bytes gets the string representation of the underlying address. func (a Address) Bytes() []byte { return a[:] } diff --git a/consensus/clique/snapshot.go b/consensus/clique/snapshot.go index 0f1b9f4b3a..e5efa5108f 100644 --- a/consensus/clique/snapshot.go +++ b/consensus/clique/snapshot.go @@ -19,6 +19,7 @@ package clique import ( "bytes" "encoding/json" + "sort" "time" "github.com/ethereum/go-ethereum/common" @@ -28,7 +29,6 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" - "golang.org/x/exp/slices" ) // Vote represents a single vote that an authorized signer made to modify the @@ -62,6 +62,13 @@ type Snapshot struct { Tally map[common.Address]Tally `json:"tally"` // Current vote tally to avoid recalculating } +// signersAscending implements the sort interface to allow sorting a list of addresses +type signersAscending []common.Address + +func (s signersAscending) Len() int { return len(s) } +func (s signersAscending) Less(i, j int) bool { return bytes.Compare(s[i][:], s[j][:]) < 0 } +func (s signersAscending) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + // newSnapshot creates a new snapshot with the specified startup parameters. This // method does not initialize the set of recent signers, so only ever use if for // the genesis block. @@ -308,7 +315,7 @@ func (s *Snapshot) signers() []common.Address { for sig := range s.Signers { sigs = append(sigs, sig) } - slices.SortFunc(sigs, common.Address.Less) + sort.Sort(signersAscending(sigs)) return sigs } diff --git a/consensus/clique/snapshot_test.go b/consensus/clique/snapshot_test.go index f30900f274..66e667276f 100644 --- a/consensus/clique/snapshot_test.go +++ b/consensus/clique/snapshot_test.go @@ -21,6 +21,7 @@ import ( "crypto/ecdsa" "fmt" "math/big" + "sort" "testing" "github.com/ethereum/go-ethereum/common" @@ -30,7 +31,6 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" - "golang.org/x/exp/slices" ) // testerAccountPool is a pool to maintain currently active tester accounts, @@ -53,7 +53,7 @@ func (ap *testerAccountPool) checkpoint(header *types.Header, signers []string) for i, signer := range signers { auths[i] = ap.address(signer) } - slices.SortFunc(auths, common.Address.Less) + sort.Sort(signersAscending(auths)) for i, auth := range auths { copy(header.Extra[extraVanity+i*common.AddressLength:], auth.Bytes()) }