Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 committed Sep 23, 2023
1 parent 507d742 commit aa27de7
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 38 deletions.
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func ExecuteBlockEphemerally(

stateSyncReceipt := &types.Receipt{}
if chainConfig.Consensus == chain.BorConsensus && len(blockLogs) > 0 {
slices.SortStableFunc(blockLogs, func(i, j *types.Log) int { return cmp2.Compare(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
3 changes: 2 additions & 1 deletion erigon-lib/patricia/patricia.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"math/bits"
"strings"

"github.com/ledgerwatch/erigon-lib/common/cmp"
"github.com/ledgerwatch/erigon-lib/sais"
"golang.org/x/exp/slices"
)
Expand Down Expand Up @@ -699,7 +700,7 @@ func (mf2 *MatchFinder2) FindLongestMatches(data []byte) []Match {
return mf2.matches
}
//sort.Sort(&mf2.matches)
slices.SortFunc(mf2.matches, func(i, j Match) bool { return i.Start < j.Start })
slices.SortFunc(mf2.matches, func(i, j Match) int { return cmp.Less(i.Start, j.Start) })

lastEnd := mf2.matches[0].End
j := 1
Expand Down
6 changes: 4 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -55,7 +56,6 @@ import (

"github.com/holiman/uint256"
"github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/protobuf/types/known/emptypb"
Expand Down Expand Up @@ -1092,7 +1092,9 @@ func (s *Ethereum) NodesInfo(limit int) (*remote.NodesInfoReply, error) {
}

nodesInfo := &remote.NodesInfoReply{NodesInfo: nodes}
slices.SortFunc(nodesInfo.NodesInfo, remote.NodeInfoReplyCmp)
sort.Slice(nodesInfo.NodesInfo, func(i, j int) bool {
return remote.NodeInfoReplyLess(nodesInfo.NodesInfo[i], nodesInfo.NodesInfo[j])
})

return nodesInfo, nil
}
Expand Down
2 changes: 1 addition & 1 deletion turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -2146,7 +2146,7 @@ func (*Merger) FindMergeRanges(currentRanges []Range) (toMerge []Range) {
break
}
}
slices.SortFunc(toMerge, func(i, j Range) int { return cmp.Compare(i.from, j.from) })
slices.SortFunc(toMerge, func(i, j Range) int { return cmp.Less(i.from, j.from) })
return toMerge
}

Expand Down
2 changes: 1 addition & 1 deletion turbo/snapshotsync/freezeblocks/bor_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ func (*BorMerger) FindMergeRanges(currentRanges []Range) (toMerge []Range) {
break
}
}
slices.SortFunc(toMerge, func(i, j Range) int { return cmp.Compare(i.from, j.from) })
slices.SortFunc(toMerge, func(i, j Range) int { return cmp.Less(i.from, j.from) })
return toMerge
}

Expand Down
2 changes: 1 addition & 1 deletion turbo/snapshotsync/snapcfg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func doSort(in preverified) Preverified {
for k, v := range in {
out = append(out, PreverifiedItem{k, v})
}
slices.SortFunc(out, func(i, j PreverifiedItem) int { return cmp.Compare(i.Name, j.Name) })
slices.SortFunc(out, func(i, j PreverifiedItem) int { return cmp.Less(i.Name, j.Name) })
return out
}

Expand Down

0 comments on commit aa27de7

Please sign in to comment.