Skip to content

Commit 1bb567e

Browse files
committed
feat(nibiru): changes for Nibiru geth v1.13
1 parent c5ba367 commit 1bb567e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+512
-161
lines changed

accounts/keystore/account_cache.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/ethereum/go-ethereum/accounts"
3232
"github.com/ethereum/go-ethereum/common"
3333
"github.com/ethereum/go-ethereum/log"
34-
"golang.org/x/exp/slices"
3534
)
3635

3736
// Minimum amount of time between cache reloads. This limit applies if the platform does
@@ -194,7 +193,16 @@ func (ac *accountCache) find(a accounts.Account) (accounts.Account, error) {
194193
default:
195194
err := &AmbiguousAddrError{Addr: a.Address, Matches: make([]accounts.Account, len(matches))}
196195
copy(err.Matches, matches)
197-
slices.SortFunc(err.Matches, byURL)
196+
197+
// Note: Favor `sort.Slice` form the std lib since it's stable across
198+
// different Go versions.
199+
// ```
200+
// slices.SortFunc(err.Matches, byURL)
201+
// ```
202+
sort.Slice(err.Matches, func(i, j int) bool {
203+
return byURL(err.Matches[i], err.Matches[j]) < 0
204+
})
205+
198206
return accounts.Account{}, err
199207
}
200208
}

accounts/keystore/account_cache_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import (
2323
"os"
2424
"path/filepath"
2525
"reflect"
26+
"sort"
2627
"testing"
2728
"time"
2829

2930
"github.com/cespare/cp"
3031
"github.com/davecgh/go-spew/spew"
3132
"github.com/ethereum/go-ethereum/accounts"
3233
"github.com/ethereum/go-ethereum/common"
33-
"golang.org/x/exp/slices"
3434
)
3535

3636
var (
@@ -205,7 +205,10 @@ func TestCacheAddDeleteOrder(t *testing.T) {
205205
// Check that the account list is sorted by filename.
206206
wantAccounts := make([]accounts.Account, len(accs))
207207
copy(wantAccounts, accs)
208-
slices.SortFunc(wantAccounts, byURL)
208+
sort.Slice(wantAccounts, func(i, j int) bool {
209+
return byURL(wantAccounts[i], wantAccounts[j]) < 0
210+
})
211+
209212
list := cache.accounts()
210213
if !reflect.DeepEqual(list, wantAccounts) {
211214
t.Fatalf("got accounts: %s\nwant %s", spew.Sdump(accs), spew.Sdump(wantAccounts))

accounts/keystore/keystore_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"math/rand"
2121
"os"
2222
"runtime"
23+
"sort"
2324
"strings"
2425
"sync"
2526
"sync/atomic"
@@ -30,7 +31,6 @@ import (
3031
"github.com/ethereum/go-ethereum/common"
3132
"github.com/ethereum/go-ethereum/crypto"
3233
"github.com/ethereum/go-ethereum/event"
33-
"golang.org/x/exp/slices"
3434
)
3535

3636
var testSigData = make([]byte, 32)
@@ -431,7 +431,10 @@ func checkAccounts(t *testing.T, live map[common.Address]accounts.Account, walle
431431
for _, account := range live {
432432
liveList = append(liveList, account)
433433
}
434-
slices.SortFunc(liveList, byURL)
434+
sort.Slice(liveList, func(i, j int) bool {
435+
return byURL(liveList[i], liveList[j]) < 0
436+
})
437+
435438
for j, wallet := range wallets {
436439
if accs := wallet.Accounts(); len(accs) != 1 {
437440
t.Errorf("wallet %d: contains invalid number of accounts: have %d, want 1", j, len(accs))

build/update-license.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ import (
4646
"path/filepath"
4747
"regexp"
4848
"runtime"
49+
"sort"
4950
"strconv"
5051
"strings"
5152
"sync"
5253
"text/template"
5354
"time"
54-
55-
"golang.org/x/exp/slices"
5655
)
5756

5857
var (
@@ -292,7 +291,8 @@ func writeAuthors(files []string) {
292291
}
293292
}
294293
// Write sorted list of authors back to the file.
295-
slices.SortFunc(list, func(a, b string) bool {
294+
sort.Slice(list, func(i, j int) bool {
295+
a, b := list[i], list[j]
296296
return strings.ToLower(a) < strings.ToLower(b)
297297
})
298298
content := new(bytes.Buffer)

cmd/devp2p/dns_route53.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"sort"
2324
"strconv"
2425
"strings"
2526
"time"
@@ -32,7 +33,6 @@ import (
3233
"github.com/ethereum/go-ethereum/log"
3334
"github.com/ethereum/go-ethereum/p2p/dnsdisc"
3435
"github.com/urfave/cli/v2"
35-
"golang.org/x/exp/slices"
3636
)
3737

3838
const (
@@ -288,7 +288,8 @@ func makeDeletionChanges(records map[string]recordSet, keep map[string]string) [
288288
// sortChanges ensures DNS changes are in leaf-added -> root-changed -> leaf-deleted order.
289289
func sortChanges(changes []types.Change) {
290290
score := map[string]int{"CREATE": 1, "UPSERT": 2, "DELETE": 3}
291-
slices.SortFunc(changes, func(a, b types.Change) int {
291+
292+
cmpChange := func(a, b types.Change) int {
292293
if a.Action == b.Action {
293294
return strings.Compare(*a.ResourceRecordSet.Name, *b.ResourceRecordSet.Name)
294295
}
@@ -299,6 +300,9 @@ func sortChanges(changes []types.Change) {
299300
return 1
300301
}
301302
return 0
303+
}
304+
sort.Slice(changes, func(i, j int) bool {
305+
return cmpChange(changes[i], changes[j]) < 0
302306
})
303307
}
304308

cmd/devp2p/internal/ethtest/chain.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"github.com/ethereum/go-ethereum/eth/protocols/eth"
4141
"github.com/ethereum/go-ethereum/params"
4242
"github.com/ethereum/go-ethereum/rlp"
43-
"golang.org/x/exp/slices"
4443
)
4544

4645
// Chain is a lightweight blockchain-like store which can read a hivechain
@@ -108,8 +107,8 @@ func (c *Chain) AccountsInHashOrder() []state.DumpAccount {
108107
}
109108
i++
110109
}
111-
slices.SortFunc(list, func(x, y state.DumpAccount) int {
112-
return bytes.Compare(x.AddressHash, y.AddressHash)
110+
sort.Slice(list, func(i, j int) bool {
111+
return bytes.Compare(list[i].AddressHash, list[j].AddressHash) < 0
113112
})
114113
return list
115114
}
@@ -127,7 +126,9 @@ func (c *Chain) CodeHashes() []common.Hash {
127126
hashes = append(hashes, h)
128127
seen[h] = struct{}{}
129128
}
130-
slices.SortFunc(hashes, (common.Hash).Cmp)
129+
sort.Slice(hashes, func(i, j int) bool {
130+
return hashes[i].Cmp(hashes[j]) < 0
131+
})
131132
return hashes
132133
}
133134

cmd/devp2p/nodeset.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"os"
24+
"sort"
2425
"time"
2526

2627
"github.com/ethereum/go-ethereum/common"
2728
"github.com/ethereum/go-ethereum/p2p/enode"
28-
"golang.org/x/exp/slices"
2929
)
3030

3131
const jsonIndent = " "
@@ -77,8 +77,8 @@ func (ns nodeSet) nodes() []*enode.Node {
7777
result = append(result, n.N)
7878
}
7979
// Sort by ID.
80-
slices.SortFunc(result, func(a, b *enode.Node) int {
81-
return bytes.Compare(a.ID().Bytes(), b.ID().Bytes())
80+
sort.Slice(result, func(i, j int) bool {
81+
return bytes.Compare(result[i].ID().Bytes(), result[j].ID().Bytes()) < 0
8282
})
8383
return result
8484
}
@@ -103,14 +103,19 @@ func (ns nodeSet) topN(n int) nodeSet {
103103
for _, v := range ns {
104104
byscore = append(byscore, v)
105105
}
106-
slices.SortFunc(byscore, func(a, b nodeJSON) int {
106+
107+
cmpScore := func(a, b nodeJSON) int {
107108
if a.Score > b.Score {
108-
return -1
109+
return 1
109110
}
110111
if a.Score < b.Score {
111-
return 1
112+
return -1
112113
}
113114
return 0
115+
}
116+
// NOTE: Sorts in descending order ( > 0)
117+
sort.Slice(byscore, func(i, j int) bool {
118+
return cmpScore(byscore[i], byscore[j]) > 0
114119
})
115120
result := make(nodeSet, n)
116121
for _, v := range byscore[:n] {

common/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ func (a Address) Bytes() []byte { return a[:] }
248248
// Big converts an address to a big integer.
249249
func (a Address) Big() *big.Int { return new(big.Int).SetBytes(a[:]) }
250250

251+
// Hash converts an address to a hash by left-padding the address bytes with zeros.
252+
//
253+
// Note: This is different from BigToHash(a.Big()) because the intermediate conversion
254+
// to *big.Int uses a minimal byte representation, potentially stripping leading
255+
// zero bytes from the address before padding occurs in BytesToHash.
256+
// This implementation directly uses the full 20 address bytes for consistent padding.
257+
func (a Address) Hash() Hash { return BytesToHash(a.Bytes()) }
258+
251259
// Hex returns an EIP55-compliant hex string representation of the address.
252260
func (a Address) Hex() string {
253261
return string(a.checksumHex())

consensus/clique/snapshot.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package clique
1919
import (
2020
"bytes"
2121
"encoding/json"
22+
"sort"
2223
"time"
2324

2425
"github.com/ethereum/go-ethereum/common"
@@ -28,7 +29,6 @@ import (
2829
"github.com/ethereum/go-ethereum/ethdb"
2930
"github.com/ethereum/go-ethereum/log"
3031
"github.com/ethereum/go-ethereum/params"
31-
"golang.org/x/exp/slices"
3232
)
3333

3434
// Vote represents a single vote that an authorized signer made to modify the
@@ -308,7 +308,9 @@ func (s *Snapshot) signers() []common.Address {
308308
for sig := range s.Signers {
309309
sigs = append(sigs, sig)
310310
}
311-
slices.SortFunc(sigs, common.Address.Cmp)
311+
sort.Slice(sigs, func(i, j int) bool {
312+
return sigs[i].Cmp(sigs[j]) < 0
313+
})
312314
return sigs
313315
}
314316

consensus/clique/snapshot_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"crypto/ecdsa"
2222
"fmt"
2323
"math/big"
24+
"sort"
2425
"testing"
2526

2627
"github.com/ethereum/go-ethereum/common"
@@ -30,7 +31,6 @@ import (
3031
"github.com/ethereum/go-ethereum/core/vm"
3132
"github.com/ethereum/go-ethereum/crypto"
3233
"github.com/ethereum/go-ethereum/params"
33-
"golang.org/x/exp/slices"
3434
)
3535

3636
// testerAccountPool is a pool to maintain currently active tester accounts,
@@ -53,7 +53,9 @@ func (ap *testerAccountPool) checkpoint(header *types.Header, signers []string)
5353
for i, signer := range signers {
5454
auths[i] = ap.address(signer)
5555
}
56-
slices.SortFunc(auths, common.Address.Cmp)
56+
sort.Slice(auths, func(i, j int) bool {
57+
return auths[i].Cmp(auths[j]) < 0
58+
})
5759
for i, auth := range auths {
5860
copy(header.Extra[extraVanity+i*common.AddressLength:], auth.Bytes())
5961
}

0 commit comments

Comments
 (0)