From d030e2cbb8ec6949a34b9304f9dab237e234521a Mon Sep 17 00:00:00 2001 From: Jim W Date: Thu, 5 Oct 2023 10:17:15 -0400 Subject: [PATCH] switch from exp/slices pkg to the stable (#10852) * switch from using the exp_slices pkg to the stable slices pkg * Update core/services/vrf/v2/listener_v2.go Co-authored-by: Jordan Krage * use compare instead of naive responses * add cmp pkg --------- Co-authored-by: Jordan Krage --- common/txmgr/types/tx.go | 2 +- core/chains/cosmos/config.go | 2 +- core/chains/cosmos/cosmostxm/txm.go | 12 ++++++++---- core/chains/evm/config/toml/config.go | 2 +- core/chains/evm/config/toml/defaults.go | 7 +++---- core/chains/evm/gas/arbitrum_estimator.go | 2 +- core/chains/evm/gas/l2_suggested_estimator.go | 2 +- core/chains/evm/gas/rollups/l1_gas_price_oracle.go | 2 +- core/chains/evm/headtracker/head_tracker_test.go | 2 +- core/chains/solana/config.go | 2 +- core/chains/starknet/config.go | 2 +- core/internal/testutils/evmtest/evmtest.go | 2 +- core/services/gateway/common/utils.go | 3 +-- core/services/job/orm.go | 3 +-- core/services/ocr2/plugins/functions/plugin.go | 2 +- core/services/vrf/v2/listener_v2.go | 7 ++++--- 16 files changed, 28 insertions(+), 26 deletions(-) diff --git a/common/txmgr/types/tx.go b/common/txmgr/types/tx.go index 37834d92e0f..d95f07afabc 100644 --- a/common/txmgr/types/tx.go +++ b/common/txmgr/types/tx.go @@ -5,12 +5,12 @@ import ( "encoding/json" "fmt" "math/big" + "slices" "strings" "time" "github.com/google/uuid" "github.com/pkg/errors" - "golang.org/x/exp/slices" "gopkg.in/guregu/null.v4" feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types" diff --git a/core/chains/cosmos/config.go b/core/chains/cosmos/config.go index fda791d0dc2..8b4c8c13f32 100644 --- a/core/chains/cosmos/config.go +++ b/core/chains/cosmos/config.go @@ -3,13 +3,13 @@ package cosmos import ( "fmt" "net/url" + "slices" "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/pelletier/go-toml/v2" "github.com/shopspring/decimal" "go.uber.org/multierr" - "golang.org/x/exp/slices" coscfg "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/config" "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/db" diff --git a/core/chains/cosmos/cosmostxm/txm.go b/core/chains/cosmos/cosmostxm/txm.go index de741e8934f..48d5c2a13ce 100644 --- a/core/chains/cosmos/cosmostxm/txm.go +++ b/core/chains/cosmos/cosmostxm/txm.go @@ -1,14 +1,15 @@ package cosmostxm import ( + "cmp" "context" "encoding/hex" + "slices" "strings" "time" "github.com/gogo/protobuf/proto" "github.com/pkg/errors" - "golang.org/x/exp/slices" "github.com/smartcontractkit/sqlx" @@ -176,12 +177,15 @@ func (e *msgValidator) add(msg adapters.Msg) { } func (e *msgValidator) sortValid() { - slices.SortFunc(e.valid, func(a, b adapters.Msg) bool { + slices.SortFunc(e.valid, func(a, b adapters.Msg) int { ac, bc := a.CreatedAt, b.CreatedAt if ac.Equal(bc) { - return a.ID < b.ID + return cmp.Compare(a.ID, b.ID) } - return ac.Before(bc) + if ac.After(bc) { + return 1 + } + return -1 // ac.Before(bc) }) } diff --git a/core/chains/evm/config/toml/config.go b/core/chains/evm/config/toml/config.go index 8097f752dc5..cf2cde460e5 100644 --- a/core/chains/evm/config/toml/config.go +++ b/core/chains/evm/config/toml/config.go @@ -3,13 +3,13 @@ package toml import ( "fmt" "net/url" + "slices" "strconv" "github.com/ethereum/go-ethereum/core/txpool" "github.com/pelletier/go-toml/v2" "github.com/shopspring/decimal" "go.uber.org/multierr" - "golang.org/x/exp/slices" "gopkg.in/guregu/null.v4" relaytypes "github.com/smartcontractkit/chainlink-relay/pkg/types" diff --git a/core/chains/evm/config/toml/defaults.go b/core/chains/evm/config/toml/defaults.go index 239a97f585b..68513383585 100644 --- a/core/chains/evm/config/toml/defaults.go +++ b/core/chains/evm/config/toml/defaults.go @@ -5,10 +5,9 @@ import ( "embed" "log" "path/filepath" + "slices" "strings" - "golang.org/x/exp/slices" - "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/utils" configutils "github.com/smartcontractkit/chainlink/v2/core/utils/config" @@ -62,8 +61,8 @@ func init() { defaults[id] = config.Chain defaultNames[id] = strings.ReplaceAll(strings.TrimSuffix(fe.Name(), ".toml"), "_", " ") } - slices.SortFunc(DefaultIDs, func(a, b *utils.Big) bool { - return a.Cmp(b) < 0 + slices.SortFunc(DefaultIDs, func(a, b *utils.Big) int { + return a.Cmp(b) }) } diff --git a/core/chains/evm/gas/arbitrum_estimator.go b/core/chains/evm/gas/arbitrum_estimator.go index 01a0e6d29b3..9c76b76dbae 100644 --- a/core/chains/evm/gas/arbitrum_estimator.go +++ b/core/chains/evm/gas/arbitrum_estimator.go @@ -5,13 +5,13 @@ import ( "fmt" "math" "math/big" + "slices" "sync" "time" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" - "golang.org/x/exp/slices" feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types" "github.com/smartcontractkit/chainlink/v2/core/assets" diff --git a/core/chains/evm/gas/l2_suggested_estimator.go b/core/chains/evm/gas/l2_suggested_estimator.go index de3081180bc..1782e349302 100644 --- a/core/chains/evm/gas/l2_suggested_estimator.go +++ b/core/chains/evm/gas/l2_suggested_estimator.go @@ -2,12 +2,12 @@ package gas import ( "context" + "slices" "sync" "time" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" - "golang.org/x/exp/slices" feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types" "github.com/smartcontractkit/chainlink/v2/core/assets" diff --git a/core/chains/evm/gas/rollups/l1_gas_price_oracle.go b/core/chains/evm/gas/rollups/l1_gas_price_oracle.go index 5b0025333cb..8cf10325d47 100644 --- a/core/chains/evm/gas/rollups/l1_gas_price_oracle.go +++ b/core/chains/evm/gas/rollups/l1_gas_price_oracle.go @@ -5,12 +5,12 @@ import ( "errors" "fmt" "math/big" + "slices" "sync" "time" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" - "golang.org/x/exp/slices" "github.com/smartcontractkit/chainlink/v2/core/assets" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" diff --git a/core/chains/evm/headtracker/head_tracker_test.go b/core/chains/evm/headtracker/head_tracker_test.go index cb438e4c263..c0f40c2213d 100644 --- a/core/chains/evm/headtracker/head_tracker_test.go +++ b/core/chains/evm/headtracker/head_tracker_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "math/big" + "slices" "sync" "testing" "time" @@ -17,7 +18,6 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "golang.org/x/exp/maps" - "golang.org/x/exp/slices" commonmocks "github.com/smartcontractkit/chainlink/v2/common/types/mocks" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" diff --git a/core/chains/solana/config.go b/core/chains/solana/config.go index b6e4a077f9e..772d660a164 100644 --- a/core/chains/solana/config.go +++ b/core/chains/solana/config.go @@ -3,12 +3,12 @@ package solana import ( "fmt" "net/url" + "slices" "time" "github.com/gagliardetto/solana-go/rpc" "github.com/pelletier/go-toml/v2" "go.uber.org/multierr" - "golang.org/x/exp/slices" relaytypes "github.com/smartcontractkit/chainlink-relay/pkg/types" diff --git a/core/chains/starknet/config.go b/core/chains/starknet/config.go index 33b2a8d257a..f659cb7af15 100644 --- a/core/chains/starknet/config.go +++ b/core/chains/starknet/config.go @@ -3,11 +3,11 @@ package starknet import ( "fmt" "net/url" + "slices" "time" "github.com/pelletier/go-toml/v2" "go.uber.org/multierr" - "golang.org/x/exp/slices" "github.com/smartcontractkit/chainlink-relay/pkg/types" diff --git a/core/internal/testutils/evmtest/evmtest.go b/core/internal/testutils/evmtest/evmtest.go index 2a86101d0d8..3a08c815166 100644 --- a/core/internal/testutils/evmtest/evmtest.go +++ b/core/internal/testutils/evmtest/evmtest.go @@ -3,6 +3,7 @@ package evmtest import ( "fmt" "math/big" + "slices" "sync" "sync/atomic" "testing" @@ -12,7 +13,6 @@ import ( "github.com/smartcontractkit/sqlx" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" "gopkg.in/guregu/null.v4" "github.com/smartcontractkit/chainlink-relay/pkg/types" diff --git a/core/services/gateway/common/utils.go b/core/services/gateway/common/utils.go index 2e5033432bb..59c67bdcfa1 100644 --- a/core/services/gateway/common/utils.go +++ b/core/services/gateway/common/utils.go @@ -3,8 +3,7 @@ package common import ( "crypto/ecdsa" "encoding/binary" - - "golang.org/x/exp/slices" + "slices" "github.com/smartcontractkit/chainlink/v2/core/utils" ) diff --git a/core/services/job/orm.go b/core/services/job/orm.go index 369ce039ad4..6fb8a532964 100644 --- a/core/services/job/orm.go +++ b/core/services/job/orm.go @@ -6,10 +6,9 @@ import ( "encoding/json" "fmt" "reflect" + "slices" "time" - "golang.org/x/exp/slices" - "github.com/ethereum/go-ethereum/common" "github.com/google/uuid" "github.com/jackc/pgconn" diff --git a/core/services/ocr2/plugins/functions/plugin.go b/core/services/ocr2/plugins/functions/plugin.go index 6cc7da97d00..750b5ad3960 100644 --- a/core/services/ocr2/plugins/functions/plugin.go +++ b/core/services/ocr2/plugins/functions/plugin.go @@ -3,12 +3,12 @@ package functions import ( "encoding/json" "math/big" + "slices" "time" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" "github.com/smartcontractkit/sqlx" - "golang.org/x/exp/slices" "github.com/smartcontractkit/libocr/commontypes" libocr2 "github.com/smartcontractkit/libocr/offchainreporting2plus" diff --git a/core/services/vrf/v2/listener_v2.go b/core/services/vrf/v2/listener_v2.go index 7998de557a6..31e76b48fdb 100644 --- a/core/services/vrf/v2/listener_v2.go +++ b/core/services/vrf/v2/listener_v2.go @@ -1,11 +1,13 @@ package v2 import ( + "cmp" "context" "database/sql" "fmt" "math" "math/big" + "slices" "strings" "sync" "time" @@ -20,7 +22,6 @@ import ( heaps "github.com/theodesp/go-heaps" "github.com/theodesp/go-heaps/pairing" "go.uber.org/multierr" - "golang.org/x/exp/slices" txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types" @@ -503,8 +504,8 @@ func (lsn *listenerV2) processPendingVRFRequests(ctx context.Context) { // first. This allows us to break out of the processing loop as early as possible // in the event that a subscription is too underfunded to have it's // requests processed. - slices.SortFunc(reqs, func(a, b pendingRequest) bool { - return a.req.CallbackGasLimit() < b.req.CallbackGasLimit() + slices.SortFunc(reqs, func(a, b pendingRequest) int { + return cmp.Compare(a.req.CallbackGasLimit(), b.req.CallbackGasLimit()) }) p := lsn.processRequestsPerSub(ctx, sID, startLinkBalance, startEthBalance, reqs, subIsActive)