Skip to content

Commit

Permalink
all: use the built-in slices library (#9842)
Browse files Browse the repository at this point in the history
In the current go 1.21 version used in the project, slices are no longer
an experimental feature and have entered the standard library

Co-authored-by: alex.sharov <AskAlexSharov@gmail.com>
  • Loading branch information
carehabit and AskAlexSharov authored Apr 26, 2024
1 parent a5270bc commit 9001183
Show file tree
Hide file tree
Showing 46 changed files with 59 additions and 60 deletions.
2 changes: 1 addition & 1 deletion cl/beacon/beaconhttp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"fmt"
"net/http"
"reflect"
"slices"
"strings"

"github.com/ledgerwatch/erigon-lib/types/ssz"
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice/fork_graph"
"github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"
)

var _ error = EndpointError{}
Expand Down
2 changes: 1 addition & 1 deletion cl/beacon/handler/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"net/http"
"slices"
"strconv"
"strings"
"sync"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/log/v3"
"github.com/pkg/errors"
"golang.org/x/exp/slices"
)

var stringsBuilderPool = sync.Pool{
Expand Down
3 changes: 1 addition & 2 deletions cl/cltypes/beacon_block_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package cltypes

import (
_ "embed"
"encoding/json"
"math/big"
"testing"

_ "embed"

"github.com/holiman/uint256"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cl/clparams"
Expand Down
3 changes: 1 addition & 2 deletions cl/phase1/forkchoice/forkchoice.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package forkchoice

import (
"slices"
"sort"
"sync"
"sync/atomic"

"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon/cl/beacon/beaconevents"
"github.com/ledgerwatch/erigon/cl/beacon/synced_data"
"github.com/ledgerwatch/erigon/cl/clparams"
Expand Down
7 changes: 4 additions & 3 deletions cl/phase1/network/services/aggregate_and_proof_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package services
import (
"context"
"fmt"
"slices"
"sync"
"time"

"github.com/Giulio2002/bls"
"github.com/ledgerwatch/log/v3"
"github.com/pkg/errors"

"github.com/ledgerwatch/erigon/cl/aggregation"
"github.com/ledgerwatch/erigon/cl/beacon/synced_data"
"github.com/ledgerwatch/erigon/cl/clparams"
Expand All @@ -16,9 +20,6 @@ import (
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice"
"github.com/ledgerwatch/erigon/cl/utils"
"github.com/ledgerwatch/log/v3"
"github.com/pkg/errors"
"golang.org/x/exp/slices"
)

type aggregateJob struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice"
"github.com/stretchr/testify/require"
gomock "go.uber.org/mock/gomock"
"go.uber.org/mock/gomock"
)

func getAggregateAndProofAndState(t *testing.T) (*cltypes.SignedAggregateAndProof, *state.CachingBeaconState) {
Expand Down
7 changes: 3 additions & 4 deletions cl/phase1/network/services/blob_sidecar_service_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package services

import (
context "context"
"context"
_ "embed"
"testing"

"github.com/ledgerwatch/erigon-lib/common"
Expand All @@ -14,9 +15,7 @@ import (
"github.com/ledgerwatch/erigon/cl/utils"
"github.com/ledgerwatch/erigon/cl/utils/eth_clock"
"github.com/stretchr/testify/require"
gomock "go.uber.org/mock/gomock"

_ "embed"
"go.uber.org/mock/gomock"
)

//go:embed test_data/blob_sidecar_service_blob.ssz_snappy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"errors"
"fmt"
"slices"
"sync"

"github.com/Giulio2002/bls"

"github.com/ledgerwatch/erigon/cl/beacon/synced_data"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes"
Expand All @@ -15,7 +17,6 @@ import (
"github.com/ledgerwatch/erigon/cl/utils"
"github.com/ledgerwatch/erigon/cl/utils/eth_clock"
"github.com/ledgerwatch/erigon/cl/validator/sync_contribution_pool"
"golang.org/x/exp/slices"
)

type seenSyncCommitteeMessage struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ledgerwatch/erigon/cl/utils/eth_clock"
syncpoolmock "github.com/ledgerwatch/erigon/cl/validator/sync_contribution_pool/mock_services"
"github.com/stretchr/testify/require"
gomock "go.uber.org/mock/gomock"
"go.uber.org/mock/gomock"
)

func setupSyncCommitteesServiceTest(t *testing.T, ctrl *gomock.Controller) (SyncCommitteeMessagesService, *synced_data.SyncedDataManager, *eth_clock.MockEthereumClock) {
Expand Down
8 changes: 4 additions & 4 deletions cl/phase1/network/services/sync_contribution_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import (
"encoding/binary"
"errors"
"fmt"
"slices"
"sync"

"github.com/Giulio2002/bls"

"github.com/ledgerwatch/erigon-lib/common"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cl/beacon/beaconevents"
"github.com/ledgerwatch/erigon/cl/beacon/synced_data"
"github.com/ledgerwatch/erigon/cl/clparams"
Expand All @@ -19,10 +23,6 @@ import (
"github.com/ledgerwatch/erigon/cl/utils"
"github.com/ledgerwatch/erigon/cl/utils/eth_clock"
"github.com/ledgerwatch/erigon/cl/validator/sync_contribution_pool"
"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon-lib/common"
libcommon "github.com/ledgerwatch/erigon-lib/common"
)

type seenSyncCommitteeContribution struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ledgerwatch/erigon/cl/utils/eth_clock"
syncpoolmock "github.com/ledgerwatch/erigon/cl/validator/sync_contribution_pool/mock_services"
"github.com/stretchr/testify/require"
gomock "go.uber.org/mock/gomock"
"go.uber.org/mock/gomock"
)

func setupSyncContributionServiceTest(t *testing.T, ctrl *gomock.Controller) (SyncContributionService, *synced_data.SyncedDataManager, *eth_clock.MockEthereumClock) {
Expand Down
2 changes: 1 addition & 1 deletion cl/transition/impl/eth2/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"bytes"
"errors"
"fmt"
"slices"
"time"

"github.com/ledgerwatch/erigon-lib/metrics"

"github.com/ledgerwatch/erigon/cl/abstract"

"github.com/ledgerwatch/erigon/cl/transition/impl/eth2/statechange"
"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
Expand Down
2 changes: 1 addition & 1 deletion cmd/hack/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"path/filepath"
"runtime/pprof"
"slices"
"sort"
"strings"
"time"
Expand All @@ -23,7 +24,6 @@ import (
"github.com/RoaringBitmap/roaring/roaring64"
"github.com/holiman/uint256"
"github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"

libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"os"
"slices"
"strings"
"sync"
"time"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/ledgerwatch/log/v3"
"github.com/ledgerwatch/secp256k1"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"

chain2 "github.com/ledgerwatch/erigon-lib/chain"
common2 "github.com/ledgerwatch/erigon-lib/common"
Expand Down
2 changes: 1 addition & 1 deletion cmd/snapshots/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"strconv"
"strings"
"time"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/c2h5oh/datasize"
"github.com/ledgerwatch/log/v3"
"github.com/urfave/cli/v2"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"

"github.com/ledgerwatch/erigon-lib/chain/snapcfg"
Expand Down
3 changes: 1 addition & 2 deletions cmd/snapshots/torrents/torrents.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
gosync "sync"
"time"

"golang.org/x/exp/slices"

"github.com/ledgerwatch/log/v3"

"github.com/anacrolix/torrent/metainfo"
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ package core
import (
"encoding/json"
"fmt"
"slices"
"time"

"github.com/ledgerwatch/log/v3"
"golang.org/x/crypto/sha3"
"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
Expand Down
2 changes: 1 addition & 1 deletion core/forkid/forkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"math"
"math/big"
"reflect"
"slices"
"strings"

"github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
Expand Down
2 changes: 1 addition & 1 deletion core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
"encoding/json"
"fmt"
"math/big"
"slices"
"sync"

"github.com/c2h5oh/datasize"
"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/config3"
"github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon-lib/chain/networkname"
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/chain/snapcfg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
_ "embed"
"encoding/json"
"path/filepath"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -14,7 +15,6 @@ import (
"github.com/ledgerwatch/erigon-snapshot/webseed"
"github.com/pelletier/go-toml/v2"
"github.com/tidwall/btree"
"golang.org/x/exp/slices"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/commitment/bin_patricia_hashed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package commitment
import (
"encoding/hex"
"fmt"
"slices"
"testing"

"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon-lib/common/length"
)
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/commitment/patricia_state_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"slices"
"testing"

"github.com/holiman/uint256"
"golang.org/x/crypto/sha3"
"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/length"
Expand Down
3 changes: 2 additions & 1 deletion erigon-lib/common/sorted.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package common

import (
"slices"

"golang.org/x/exp/constraints"
"golang.org/x/exp/slices"
)

func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K {
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"path/filepath"
"reflect"
"runtime"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -47,7 +48,6 @@ import (
"github.com/c2h5oh/datasize"
"github.com/ledgerwatch/log/v3"
"github.com/tidwall/btree"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
"golang.org/x/sync/semaphore"
"golang.org/x/time/rate"
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/downloader/rclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"slices"
"strconv"
"strings"
"sync"
"sync/atomic"
"syscall"
"time"

"golang.org/x/exp/slices"
"golang.org/x/time/rate"

"github.com/c2h5oh/datasize"
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/downloader/snaptype/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"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"
)

var (
Expand Down
Loading

0 comments on commit 9001183

Please sign in to comment.