Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go 21 support #8034

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4e42aae
save
AskAlexSharov Aug 16, 2023
ebacf27
merge devel
AskAlexSharov Aug 17, 2023
e1719bf
merge devel
AskAlexSharov Aug 17, 2023
120f532
merge devel
AskAlexSharov Aug 17, 2023
7d82c4e
merge devel
AskAlexSharov Aug 17, 2023
15aa0fc
merge devel
AskAlexSharov Aug 17, 2023
cbf502e
merge devel
AskAlexSharov Aug 17, 2023
e884ca2
save
AskAlexSharov Aug 17, 2023
2b0205d
save
AskAlexSharov Aug 17, 2023
e5f59ca
save
AskAlexSharov Aug 17, 2023
0cd871a
merge devel
AskAlexSharov Aug 17, 2023
e2ec544
merge devel
AskAlexSharov Aug 17, 2023
7cb83e4
merge devel
AskAlexSharov Aug 17, 2023
cd844aa
save
AskAlexSharov Aug 19, 2023
e303db6
save
AskAlexSharov Aug 19, 2023
ab0fe0f
save
AskAlexSharov Aug 22, 2023
86ac6a7
save
AskAlexSharov Aug 22, 2023
6a03170
save
AskAlexSharov Aug 24, 2023
0582e47
save
AskAlexSharov Aug 24, 2023
8409bc1
save
AskAlexSharov Aug 25, 2023
2d36762
merge devel
AskAlexSharov Aug 25, 2023
2b93b00
save
Giulio2002 Sep 22, 2023
507d742
save
Giulio2002 Sep 22, 2023
aa27de7
save
Giulio2002 Sep 23, 2023
7986029
save
Giulio2002 Sep 23, 2023
7c8bd21
save
Giulio2002 Sep 23, 2023
d2303a2
Update ci.yml
AskAlexSharov Sep 24, 2023
fd88704
Update ci.yml
AskAlexSharov Sep 24, 2023
8ee6f85
Merge branch 'devel' into go_21_support
AskAlexSharov Sep 28, 2023
526f41b
switched ci version
Giulio2002 Sep 29, 2023
f4106fd
switched ci version
Giulio2002 Sep 29, 2023
f6fc059
save
Giulio2002 Sep 29, 2023
e073fca
save
Giulio2002 Sep 29, 2023
e03f31b
save
Giulio2002 Sep 29, 2023
b6ea844
save
Giulio2002 Sep 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: '1.20'
- name: Install dependencies on Linux
if: runner.os == 'Linux'
run: sudo apt update && sudo apt install build-essential
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: '1.20'

- uses: actions/cache@v3
with:
Expand Down
3 changes: 1 addition & 2 deletions cmd/sentinel/sentinel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/ledgerwatch/log/v3"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/p2p/muxer/mplex"
"github.com/libp2p/go-libp2p/p2p/security/noise"
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
"github.com/multiformats/go-multiaddr"
Expand Down Expand Up @@ -99,7 +98,7 @@ func buildOptions(cfg *SentinelConfig, s *Sentinel) ([]libp2p.Option, error) {
libp2p.ListenAddrs(listen),
libp2p.UserAgent("erigon/caplin"),
libp2p.Transport(tcp.NewTCPTransport),
libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport),
libp2p.Muxer("/mplex/6.7.0", DefaultTransport),
libp2p.DefaultMuxers,
}

Expand Down
123 changes: 123 additions & 0 deletions cmd/sentinel/sentinel/multiplex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package sentinel

import (
"context"
"net"
"time"

"github.com/libp2p/go-libp2p/core/network"
multiplex "github.com/libp2p/go-mplex"
)

// DefaultTransport has default settings for Transport
var DefaultTransport = &Transport{}

const ID = "/mplex/6.7.0"

var _ network.Multiplexer = &Transport{}

// Transport implements mux.Multiplexer that constructs
// mplex-backed muxed connections.
type Transport struct{}

func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) {
m, err := multiplex.NewMultiplex(nc, isServer, scope)
if err != nil {
return nil, err
}
return NewMuxedConn(m), nil
}

type conn multiplex.Multiplex

var _ network.MuxedConn = &conn{}

// NewMuxedConn constructs a new Conn from a *mp.Multiplex.
func NewMuxedConn(m *multiplex.Multiplex) network.MuxedConn {
return (*conn)(m)
}

func (c *conn) Close() error {
return c.mplex().Close()
}

func (c *conn) IsClosed() bool {
return c.mplex().IsClosed()
}

// OpenStream creates a new stream.
func (c *conn) OpenStream(ctx context.Context) (network.MuxedStream, error) {
s, err := c.mplex().NewStream(ctx)
if err != nil {
return nil, err
}
return (*stream)(s), nil
}

// AcceptStream accepts a stream opened by the other side.
func (c *conn) AcceptStream() (network.MuxedStream, error) {
s, err := c.mplex().Accept()
if err != nil {
return nil, err
}
return (*stream)(s), nil
}

func (c *conn) mplex() *multiplex.Multiplex {
return (*multiplex.Multiplex)(c)
}

// stream implements network.MuxedStream over mplex.Stream.
type stream multiplex.Stream

var _ network.MuxedStream = &stream{}

func (s *stream) Read(b []byte) (n int, err error) {
n, err = s.mplex().Read(b)
if err == multiplex.ErrStreamReset {
err = network.ErrReset
}

return n, err
}

func (s *stream) Write(b []byte) (n int, err error) {
n, err = s.mplex().Write(b)
if err == multiplex.ErrStreamReset {
err = network.ErrReset
}

return n, err
}

func (s *stream) Close() error {
return s.mplex().Close()
}

func (s *stream) CloseWrite() error {
return s.mplex().CloseWrite()
}

func (s *stream) CloseRead() error {
return s.mplex().CloseRead()
}

func (s *stream) Reset() error {
return s.mplex().Reset()
}

func (s *stream) SetDeadline(t time.Time) error {
return s.mplex().SetDeadline(t)
}

func (s *stream) SetReadDeadline(t time.Time) error {
return s.mplex().SetReadDeadline(t)
}

func (s *stream) SetWriteDeadline(t time.Time) error {
return s.mplex().SetWriteDeadline(t)
}

func (s *stream) mplex() *multiplex.Stream {
return (*multiplex.Stream)(s)
}
6 changes: 3 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"time"

"github.com/ledgerwatch/erigon/metrics"
cmp2 "github.com/ledgerwatch/erigon-lib/common/cmp"
"golang.org/x/crypto/sha3"
"golang.org/x/exp/slices"

Expand All @@ -36,6 +36,7 @@ import (
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/core/vm/evmtypes"
"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/rlp"
"github.com/ledgerwatch/log/v3"
)
Expand Down Expand Up @@ -184,8 +185,7 @@ func ExecuteBlockEphemerally(

stateSyncReceipt := &types.Receipt{}
if chainConfig.Consensus == chain.BorConsensus && len(blockLogs) > 0 {
slices.SortStableFunc(blockLogs, func(i, j *types.Log) bool { return i.Index < j.Index })

slices.SortStableFunc(blockLogs, func(i, j *types.Log) int { return cmp2.Less(i.Index, j.Index) })
if len(blockLogs) > len(logs) {
stateSyncReceipt.Logs = blockLogs[len(logs):] // get state-sync logs from `state.Logs()`

Expand Down
7 changes: 7 additions & 0 deletions erigon-lib/common/cmp/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ func Max[T constraints.Ordered](a, b T) T {
}
return b
}

func Less[T constraints.Ordered](a, b T) int {
if a < b {
return -1
}
return 1
}
19 changes: 10 additions & 9 deletions erigon-lib/compress/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"github.com/c2h5oh/datasize"
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/cmp"
dir2 "github.com/ledgerwatch/erigon-lib/common/dir"
"github.com/ledgerwatch/erigon-lib/etl"
"github.com/ledgerwatch/log/v3"
Expand Down Expand Up @@ -300,11 +301,11 @@ func (db *DictionaryBuilder) Less(i, j int) bool {
return db.items[i].score < db.items[j].score
}

func dictionaryBuilderLess(i, j *Pattern) bool {
func dictionaryBuilderLess(i, j *Pattern) int {
if i.score == j.score {
return bytes.Compare(i.word, j.word) < 0
return bytes.Compare(i.word, j.word)
}
return i.score < j.score
return cmp.Less(i.score, j.score)
}

func (db *DictionaryBuilder) Swap(i, j int) {
Expand Down Expand Up @@ -383,11 +384,11 @@ type Pattern struct {
type PatternList []*Pattern

func (pl PatternList) Len() int { return len(pl) }
func patternListLess(i, j *Pattern) bool {
func patternListLess(i, j *Pattern) int {
if i.uses == j.uses {
return bits.Reverse64(i.code) < bits.Reverse64(j.code)
return cmp.Less(bits.Reverse64(i.code), bits.Reverse64(j.code))
}
return i.uses < j.uses
return cmp.Less(bits.Reverse64(i.uses), bits.Reverse64(j.uses))
}

// PatternHuff is an intermediate node in a huffman tree of patterns
Expand Down Expand Up @@ -555,11 +556,11 @@ type PositionList []*Position

func (pl PositionList) Len() int { return len(pl) }

func positionListLess(i, j *Position) bool {
func positionListLess(i, j *Position) int {
if i.uses == j.uses {
return bits.Reverse64(i.code) < bits.Reverse64(j.code)
return cmp.Less(bits.Reverse64(i.code), bits.Reverse64(j.code))
}
return i.uses < j.uses
return cmp.Less(i.uses, j.uses)
}

type PositionHeap []*PositionHuff
Expand Down
16 changes: 9 additions & 7 deletions erigon-lib/downloader/snaptype/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/anacrolix/torrent/metainfo"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/anacrolix/torrent/metainfo"

"github.com/ledgerwatch/erigon-lib/common/cmp"
"github.com/ledgerwatch/erigon-lib/common/dir"
"golang.org/x/exp/slices"
)
Expand Down Expand Up @@ -209,20 +211,20 @@ func ParseDir(dir string) (res []FileInfo, err error) {
}
res = append(res, meta)
}
slices.SortFunc(res, func(i, j FileInfo) bool {
slices.SortFunc(res, func(i, j FileInfo) int {
if i.Version != j.Version {
return i.Version < j.Version
return cmp.Less(i.Version, j.Version)
}
if i.From != j.From {
return i.From < j.From
return cmp.Less(i.From, j.From)
}
if i.To != j.To {
return i.To < j.To
return cmp.Less(i.To, j.To)
}
if i.T != j.T {
return i.T < j.T
return cmp.Less(i.T, j.T)
}
return i.Ext < j.Ext
return cmp.Less(i.Ext, j.Ext)
})

return res, nil
Expand Down
8 changes: 4 additions & 4 deletions erigon-lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/tidwall/btree v1.6.0
golang.org/x/crypto v0.13.0
golang.org/x/exp v0.0.0-20230711023510-fffb14384f22
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
golang.org/x/sync v0.3.0
golang.org/x/sys v0.12.0
golang.org/x/time v0.3.0
Expand Down Expand Up @@ -104,10 +104,10 @@ require (
go.etcd.io/bbolt v1.3.6 // indirect
go.opentelemetry.io/otel v1.8.0 // indirect
go.opentelemetry.io/otel/trace v1.8.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.22.3 // indirect
Expand Down
16 changes: 8 additions & 8 deletions erigon-lib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20230711023510-fffb14384f22 h1:FqrVOBQxQ8r/UwwXibI0KMolVhvFiGobSfdE33deHJM=
golang.org/x/exp v0.0.0-20230711023510-fffb14384f22/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand All @@ -435,8 +435,8 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -465,8 +465,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -545,8 +545,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 h1:Vve/L0v7CXXuxUmaMGIEK/dEeq7uiqb5qBgQrZzIE7E=
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
7 changes: 4 additions & 3 deletions erigon-lib/gointerfaces/remote/sort_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package remote_test

import (
"sort"
"testing"

"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
"github.com/ledgerwatch/erigon-lib/gointerfaces/types"
"github.com/stretchr/testify/assert"
"golang.org/x/exp/slices"
)

func TestSort(t *testing.T) {
Expand Down Expand Up @@ -48,8 +48,9 @@ func TestSort(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

slices.SortFunc(tt.got.NodesInfo, remote.NodeInfoReplyLess)
sort.Slice(tt.got.NodesInfo, func(i, j int) bool {
return remote.NodeInfoReplyLess(tt.got.NodesInfo[i], tt.got.NodesInfo[j])
})
assert.Equal(t, tt.want, tt.got)
})
}
Expand Down
Loading
Loading