forked from cerc-io/plugeth
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:
@@ -81,8 +81,8 @@ type kv struct {
|
||||
t bool
|
||||
}
|
||||
|
||||
func (k *kv) less(other *kv) bool {
|
||||
return bytes.Compare(k.k, other.k) < 0
|
||||
func (k *kv) cmp(other *kv) int {
|
||||
return bytes.Compare(k.k, other.k)
|
||||
}
|
||||
|
||||
func TestIteratorLargeData(t *testing.T) {
|
||||
|
||||
+16
-16
@@ -173,7 +173,7 @@ func TestRangeProof(t *testing.T) {
|
||||
for _, kv := range vals {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
for i := 0; i < 500; i++ {
|
||||
start := mrand.Intn(len(entries))
|
||||
end := mrand.Intn(len(entries)-start) + start + 1
|
||||
@@ -206,7 +206,7 @@ func TestRangeProofWithNonExistentProof(t *testing.T) {
|
||||
for _, kv := range vals {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
for i := 0; i < 500; i++ {
|
||||
start := mrand.Intn(len(entries))
|
||||
end := mrand.Intn(len(entries)-start) + start + 1
|
||||
@@ -278,7 +278,7 @@ func TestRangeProofWithInvalidNonExistentProof(t *testing.T) {
|
||||
for _, kv := range vals {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
// Case 1
|
||||
start, end := 100, 200
|
||||
@@ -335,7 +335,7 @@ func TestOneElementRangeProof(t *testing.T) {
|
||||
for _, kv := range vals {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
// One element with existent edge proof, both edge proofs
|
||||
// point to the SAME key.
|
||||
@@ -422,7 +422,7 @@ func TestAllElementsProof(t *testing.T) {
|
||||
for _, kv := range vals {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
var k [][]byte
|
||||
var v [][]byte
|
||||
@@ -474,7 +474,7 @@ func TestSingleSideRangeProof(t *testing.T) {
|
||||
trie.MustUpdate(value.k, value.v)
|
||||
entries = append(entries, value)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
var cases = []int{0, 1, 50, 100, 1000, 2000, len(entries) - 1}
|
||||
for _, pos := range cases {
|
||||
@@ -509,7 +509,7 @@ func TestReverseSingleSideRangeProof(t *testing.T) {
|
||||
trie.MustUpdate(value.k, value.v)
|
||||
entries = append(entries, value)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
var cases = []int{0, 1, 50, 100, 1000, 2000, len(entries) - 1}
|
||||
for _, pos := range cases {
|
||||
@@ -543,7 +543,7 @@ func TestBadRangeProof(t *testing.T) {
|
||||
for _, kv := range vals {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
for i := 0; i < 500; i++ {
|
||||
start := mrand.Intn(len(entries))
|
||||
@@ -646,7 +646,7 @@ func TestSameSideProofs(t *testing.T) {
|
||||
for _, kv := range vals {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
pos := 1000
|
||||
first := decreaseKey(common.CopyBytes(entries[pos].k))
|
||||
@@ -690,7 +690,7 @@ func TestHasRightElement(t *testing.T) {
|
||||
trie.MustUpdate(value.k, value.v)
|
||||
entries = append(entries, value)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
var cases = []struct {
|
||||
start int
|
||||
@@ -762,7 +762,7 @@ func TestEmptyRangeProof(t *testing.T) {
|
||||
for _, kv := range vals {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
var cases = []struct {
|
||||
pos int
|
||||
@@ -797,7 +797,7 @@ func TestBloatedProof(t *testing.T) {
|
||||
for _, kv := range kvs {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
var keys [][]byte
|
||||
var vals [][]byte
|
||||
|
||||
@@ -831,7 +831,7 @@ func TestEmptyValueRangeProof(t *testing.T) {
|
||||
for _, kv := range values {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
// Create a new entry with a slightly modified key
|
||||
mid := len(entries) / 2
|
||||
@@ -875,7 +875,7 @@ func TestAllElementsEmptyValueRangeProof(t *testing.T) {
|
||||
for _, kv := range values {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
// Create a new entry with a slightly modified key
|
||||
mid := len(entries) / 2
|
||||
@@ -981,7 +981,7 @@ func benchmarkVerifyRangeProof(b *testing.B, size int) {
|
||||
for _, kv := range vals {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
start := 2
|
||||
end := start + size
|
||||
@@ -1018,7 +1018,7 @@ func benchmarkVerifyRangeNoProof(b *testing.B, size int) {
|
||||
for _, kv := range vals {
|
||||
entries = append(entries, kv)
|
||||
}
|
||||
slices.SortFunc(entries, (*kv).less)
|
||||
slices.SortFunc(entries, (*kv).cmp)
|
||||
|
||||
var keys [][]byte
|
||||
var values [][]byte
|
||||
|
||||
@@ -262,20 +262,20 @@ func newHistory(root common.Hash, parent common.Hash, block uint64, states *trie
|
||||
for addr := range states.Accounts {
|
||||
accountList = append(accountList, addr)
|
||||
}
|
||||
slices.SortFunc(accountList, func(a, b common.Address) bool { return a.Less(b) })
|
||||
slices.SortFunc(accountList, common.Address.Cmp)
|
||||
|
||||
for addr, slots := range states.Storages {
|
||||
slist := make([]common.Hash, 0, len(slots))
|
||||
for slotHash := range slots {
|
||||
slist = append(slist, slotHash)
|
||||
}
|
||||
slices.SortFunc(slist, func(a, b common.Hash) bool { return a.Less(b) })
|
||||
slices.SortFunc(slist, common.Hash.Cmp)
|
||||
storageList[addr] = slist
|
||||
}
|
||||
for addr := range states.Incomplete {
|
||||
incomplete = append(incomplete, addr)
|
||||
}
|
||||
slices.SortFunc(incomplete, func(a, b common.Address) bool { return a.Less(b) })
|
||||
slices.SortFunc(incomplete, common.Address.Cmp)
|
||||
|
||||
return &history{
|
||||
meta: &meta{
|
||||
|
||||
@@ -117,7 +117,7 @@ func hash(states map[common.Hash][]byte) (common.Hash, []byte) {
|
||||
for hash := range states {
|
||||
hs = append(hs, hash)
|
||||
}
|
||||
slices.SortFunc(hs, func(a, b common.Hash) bool { return a.Less(b) })
|
||||
slices.SortFunc(hs, common.Hash.Cmp)
|
||||
|
||||
var input []byte
|
||||
for _, hash := range hs {
|
||||
|
||||
@@ -18,10 +18,10 @@ package trienode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
// Node is a wrapper which contains the encoded blob of the trie node and its
|
||||
@@ -83,9 +83,7 @@ func (set *NodeSet) ForEachWithOrder(callback func(path string, n *Node)) {
|
||||
paths = append(paths, path)
|
||||
}
|
||||
// Bottom-up, the longest path first
|
||||
slices.SortFunc(paths, func(a, b string) bool {
|
||||
return a > b // Sort in reverse order
|
||||
})
|
||||
sort.Sort(sort.Reverse(sort.StringSlice(paths)))
|
||||
for _, path := range paths {
|
||||
callback(path, set.Nodes[path])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user