From 09609b2339c8e44d0e61ec44f2f940831811c8b7 Mon Sep 17 00:00:00 2001 From: Eng Zer Jun Date: Tue, 26 Nov 2024 00:14:51 +0800 Subject: [PATCH 1/2] refactor: replace experimental `maps` and `slices` with stdlib The experimental functions are now available in the standard library in Go 1.21 [1] and Go 1.23 [2]. [1]: https://go.dev/doc/go1.21#slices [2]: https://go.dev/doc/go1.23#new-unique-package Signed-off-by: Eng Zer Jun --- agreement/agreementtest/simulate_test.go | 2 +- agreement/autopsy.go | 2 +- agreement/common_test.go | 2 +- cmd/algokey/keyreg.go | 5 +++-- cmd/goal/account.go | 2 +- cmd/tealdbg/local.go | 2 +- crypto/merklearray/merkle.go | 2 +- crypto/merkletrie/cache.go | 8 +++---- crypto/merkletrie/committer.go | 2 +- crypto/merkletrie/committer_test.go | 2 +- crypto/merkletrie/node.go | 2 +- daemon/algod/api/server/v2/account.go | 2 +- .../algod/api/server/v2/test/handlers_test.go | 2 +- daemon/algod/api/server/v2/utils.go | 16 +++++++------- data/basics/teal.go | 2 +- data/basics/userBalance.go | 2 +- data/transactions/application.go | 2 +- data/transactions/logic/crypto_test.go | 2 +- data/transactions/logic/eval.go | 3 +-- data/transactions/logic/opcodes.go | 7 +++--- data/transactions/logic/opcodes_test.go | 2 +- data/transactions/teal.go | 4 ++-- data/transactions/transaction.go | 2 +- ledger/apply/application_test.go | 2 +- ledger/apply/mockBalances_test.go | 3 ++- ledger/eval/cow.go | 5 ++--- ledger/eval/txntracer.go | 4 ++-- ledger/ledger_test.go | 2 +- ledger/ledgercore/statedelta.go | 22 +++++++++---------- ledger/simulation/simulation_eval_test.go | 3 +-- netdeploy/network.go | 5 +++-- network/p2p/peerstore/peerstore.go | 2 +- network/phonebook/phonebook.go | 2 +- stateproof/builder.go | 7 +++--- test/reflectionhelpers/helpers.go | 3 +-- util/metrics/opencensus.go | 2 +- util/metrics/tagcounter.go | 2 +- 37 files changed, 68 insertions(+), 73 deletions(-) diff --git a/agreement/agreementtest/simulate_test.go b/agreement/agreementtest/simulate_test.go index 6c071ed8a8..02ba048cb7 100644 --- a/agreement/agreementtest/simulate_test.go +++ b/agreement/agreementtest/simulate_test.go @@ -19,6 +19,7 @@ package agreementtest import ( "context" "fmt" + "maps" "math/rand" "os" "strconv" @@ -27,7 +28,6 @@ import ( "github.com/algorand/go-deadlock" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" "github.com/algorand/go-algorand/agreement" "github.com/algorand/go-algorand/config" diff --git a/agreement/autopsy.go b/agreement/autopsy.go index 82df84473a..dd9fe81420 100644 --- a/agreement/autopsy.go +++ b/agreement/autopsy.go @@ -20,11 +20,11 @@ import ( "fmt" "io" "os" + "slices" "github.com/algorand/go-algorand/data/basics" "github.com/algorand/go-algorand/logging" "github.com/algorand/go-algorand/protocol" - "golang.org/x/exp/slices" ) // An Autopsy is a trace of the ordered input events and output diff --git a/agreement/common_test.go b/agreement/common_test.go index ca8983705e..f468bae4a1 100644 --- a/agreement/common_test.go +++ b/agreement/common_test.go @@ -19,12 +19,12 @@ package agreement import ( "context" "fmt" + "maps" "math/rand" "testing" "github.com/algorand/go-deadlock" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/crypto" diff --git a/cmd/algokey/keyreg.go b/cmd/algokey/keyreg.go index 43b072f4d0..4b034cef50 100644 --- a/cmd/algokey/keyreg.go +++ b/cmd/algokey/keyreg.go @@ -20,11 +20,12 @@ import ( "encoding/base64" "errors" "fmt" + "maps" "os" + "slices" "strings" "github.com/spf13/cobra" - "golang.org/x/exp/maps" "github.com/algorand/go-algorand/crypto" "github.com/algorand/go-algorand/data/account" @@ -95,7 +96,7 @@ func init() { "betanet": mustConvertB64ToDigest("mFgazF+2uRS1tMiL9dsj01hJGySEmPN28B/TjjvpVW0="), "devnet": mustConvertB64ToDigest("sC3P7e2SdbqKJK0tbiCdK9tdSpbe6XeCGKdoNzmlj0E="), } - validNetworkList = maps.Keys(validNetworks) + validNetworkList = slices.Collect(maps.Keys(validNetworks)) } func mustConvertB64ToDigest(b64 string) (digest crypto.Digest) { diff --git a/cmd/goal/account.go b/cmd/goal/account.go index 67d382bf45..b92d58f962 100644 --- a/cmd/goal/account.go +++ b/cmd/goal/account.go @@ -24,12 +24,12 @@ import ( "net/http" "os" "path/filepath" + "slices" "sort" "strings" "time" "github.com/spf13/cobra" - "golang.org/x/exp/slices" "github.com/algorand/go-algorand/cmd/util/datadir" "github.com/algorand/go-algorand/config" diff --git a/cmd/tealdbg/local.go b/cmd/tealdbg/local.go index 6f61fb2da3..332b581cfb 100644 --- a/cmd/tealdbg/local.go +++ b/cmd/tealdbg/local.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "log" + "slices" "time" "github.com/algorand/go-algorand/config" @@ -28,7 +29,6 @@ import ( "github.com/algorand/go-algorand/data/transactions/logic" "github.com/algorand/go-algorand/ledger/apply" "github.com/algorand/go-algorand/protocol" - "golang.org/x/exp/slices" ) func protoFromString(protoString string) (name string, proto config.ConsensusParams, err error) { diff --git a/crypto/merklearray/merkle.go b/crypto/merklearray/merkle.go index e540586b53..af74ad416f 100644 --- a/crypto/merklearray/merkle.go +++ b/crypto/merklearray/merkle.go @@ -21,10 +21,10 @@ import ( "errors" "fmt" "hash" + "slices" "sort" "github.com/algorand/go-algorand/crypto" - "golang.org/x/exp/slices" ) const ( diff --git a/crypto/merkletrie/cache.go b/crypto/merkletrie/cache.go index d4d60b2c39..1491517e07 100644 --- a/crypto/merkletrie/cache.go +++ b/crypto/merkletrie/cache.go @@ -21,9 +21,8 @@ import ( "encoding/binary" "errors" "fmt" - - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" + "maps" + "slices" ) // storedNodeIdentifier is the "equivalent" of a node-ptr, but oriented around persisting the @@ -448,8 +447,7 @@ func (mtc *merkleTrieCache) reallocatePendingPages(stats *CommitStats) (pagesToC } // create a sorted list of created pages - sortedCreatedPages := maps.Keys(createdPages) - slices.Sort(sortedCreatedPages) + sortedCreatedPages := slices.Sorted(maps.Keys(createdPages)) mtc.reallocatedPages = make(map[uint64]map[storedNodeIdentifier]*node) diff --git a/crypto/merkletrie/committer.go b/crypto/merkletrie/committer.go index 66dd2c65c8..bbfb54966e 100644 --- a/crypto/merkletrie/committer.go +++ b/crypto/merkletrie/committer.go @@ -16,7 +16,7 @@ package merkletrie -import "golang.org/x/exp/slices" +import "slices" // Committer is the interface supporting serializing tries into persistent storage. type Committer interface { diff --git a/crypto/merkletrie/committer_test.go b/crypto/merkletrie/committer_test.go index 3dc6c39d2a..6260379aad 100644 --- a/crypto/merkletrie/committer_test.go +++ b/crypto/merkletrie/committer_test.go @@ -18,10 +18,10 @@ package merkletrie import ( "encoding/binary" + "slices" "testing" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" "github.com/algorand/go-algorand/crypto" "github.com/algorand/go-algorand/test/partitiontest" diff --git a/crypto/merkletrie/node.go b/crypto/merkletrie/node.go index f63d2b12ab..327a6eba65 100644 --- a/crypto/merkletrie/node.go +++ b/crypto/merkletrie/node.go @@ -19,11 +19,11 @@ package merkletrie import ( "bytes" "encoding/binary" + "slices" "sort" "unsafe" "github.com/algorand/go-algorand/crypto" - "golang.org/x/exp/slices" ) type childEntry struct { diff --git a/daemon/algod/api/server/v2/account.go b/daemon/algod/api/server/v2/account.go index 10ec183919..dc6e3cd14d 100644 --- a/daemon/algod/api/server/v2/account.go +++ b/daemon/algod/api/server/v2/account.go @@ -20,6 +20,7 @@ import ( "encoding/base64" "errors" "math" + "slices" "sort" "github.com/algorand/go-algorand/config" @@ -27,7 +28,6 @@ import ( "github.com/algorand/go-algorand/crypto/merklesignature" "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model" "github.com/algorand/go-algorand/data/basics" - "golang.org/x/exp/slices" ) // AssetHolding converts between basics.AssetHolding and model.AssetHolding diff --git a/daemon/algod/api/server/v2/test/handlers_test.go b/daemon/algod/api/server/v2/test/handlers_test.go index bc4799dc13..4b97f8f3a4 100644 --- a/daemon/algod/api/server/v2/test/handlers_test.go +++ b/daemon/algod/api/server/v2/test/handlers_test.go @@ -28,6 +28,7 @@ import ( "net/http" "net/http/httptest" "reflect" + "slices" "strings" "testing" "time" @@ -37,7 +38,6 @@ import ( "github.com/algorand/go-algorand/daemon/algod/api/server" "github.com/algorand/go-algorand/ledger/eval" "github.com/algorand/go-algorand/ledger/ledgercore" - "golang.org/x/exp/slices" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" diff --git a/daemon/algod/api/server/v2/utils.go b/daemon/algod/api/server/v2/utils.go index 6f36784ee4..58120f46d8 100644 --- a/daemon/algod/api/server/v2/utils.go +++ b/daemon/algod/api/server/v2/utils.go @@ -20,15 +20,15 @@ import ( "encoding/base64" "errors" "fmt" + "maps" "net/http" + "slices" "strings" "unicode" "unicode/utf8" "github.com/algorand/go-codec/codec" "github.com/labstack/echo/v4" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" "github.com/algorand/go-algorand/crypto" "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model" @@ -494,23 +494,23 @@ func convertUnnamedResourcesAccessed(resources *simulation.ResourceTracker) *mod return nil } return &model.SimulateUnnamedResourcesAccessed{ - Accounts: sliceOrNil(stringSlice(maps.Keys(resources.Accounts))), - Assets: sliceOrNil(uint64Slice(maps.Keys(resources.Assets))), - Apps: sliceOrNil(uint64Slice(maps.Keys(resources.Apps))), - Boxes: sliceOrNil(convertSlice(maps.Keys(resources.Boxes), func(box logic.BoxRef) model.BoxReference { + Accounts: sliceOrNil(stringSlice(slices.Collect(maps.Keys(resources.Accounts)))), + Assets: sliceOrNil(uint64Slice(slices.Collect(maps.Keys(resources.Assets)))), + Apps: sliceOrNil(uint64Slice(slices.Collect(maps.Keys(resources.Apps)))), + Boxes: sliceOrNil(convertSlice(slices.Collect(maps.Keys(resources.Boxes)), func(box logic.BoxRef) model.BoxReference { return model.BoxReference{ App: uint64(box.App), Name: []byte(box.Name), } })), ExtraBoxRefs: omitEmpty(uint64(resources.NumEmptyBoxRefs)), - AssetHoldings: sliceOrNil(convertSlice(maps.Keys(resources.AssetHoldings), func(holding ledgercore.AccountAsset) model.AssetHoldingReference { + AssetHoldings: sliceOrNil(convertSlice(slices.Collect(maps.Keys(resources.AssetHoldings)), func(holding ledgercore.AccountAsset) model.AssetHoldingReference { return model.AssetHoldingReference{ Account: holding.Address.String(), Asset: uint64(holding.Asset), } })), - AppLocals: sliceOrNil(convertSlice(maps.Keys(resources.AppLocals), func(local ledgercore.AccountApp) model.ApplicationLocalReference { + AppLocals: sliceOrNil(convertSlice(slices.Collect(maps.Keys(resources.AppLocals)), func(local ledgercore.AccountApp) model.ApplicationLocalReference { return model.ApplicationLocalReference{ Account: local.Address.String(), App: uint64(local.App), diff --git a/data/basics/teal.go b/data/basics/teal.go index f3156ae4b8..7268c8aadf 100644 --- a/data/basics/teal.go +++ b/data/basics/teal.go @@ -19,9 +19,9 @@ package basics import ( "encoding/hex" "fmt" + "maps" "github.com/algorand/go-algorand/config" - "golang.org/x/exp/maps" ) // DeltaAction is an enum of actions that may be performed when applying a diff --git a/data/basics/userBalance.go b/data/basics/userBalance.go index d8f86aea54..3bccd3f4ed 100644 --- a/data/basics/userBalance.go +++ b/data/basics/userBalance.go @@ -20,13 +20,13 @@ import ( "encoding/binary" "fmt" "reflect" + "slices" "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/crypto" "github.com/algorand/go-algorand/crypto/merklesignature" "github.com/algorand/go-algorand/logging" "github.com/algorand/go-algorand/protocol" - "golang.org/x/exp/slices" ) // Status is the delegation status of an account's MicroAlgos diff --git a/data/transactions/application.go b/data/transactions/application.go index 48a5788c04..1cff14760d 100644 --- a/data/transactions/application.go +++ b/data/transactions/application.go @@ -18,9 +18,9 @@ package transactions import ( "fmt" + "slices" "github.com/algorand/go-algorand/data/basics" - "golang.org/x/exp/slices" ) const ( diff --git a/data/transactions/logic/crypto_test.go b/data/transactions/logic/crypto_test.go index c528424ef6..70283be7e3 100644 --- a/data/transactions/logic/crypto_test.go +++ b/data/transactions/logic/crypto_test.go @@ -25,11 +25,11 @@ import ( "encoding/hex" "fmt" "math/big" + "slices" "strconv" "testing" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" "github.com/algorand/go-algorand/crypto" "github.com/algorand/go-algorand/crypto/secp256k1" diff --git a/data/transactions/logic/eval.go b/data/transactions/logic/eval.go index d599d56119..ae8614e824 100644 --- a/data/transactions/logic/eval.go +++ b/data/transactions/logic/eval.go @@ -28,11 +28,10 @@ import ( "math/big" "math/bits" "runtime" + "slices" "strconv" "strings" - "golang.org/x/exp/slices" - "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/crypto" "github.com/algorand/go-algorand/data/basics" diff --git a/data/transactions/logic/opcodes.go b/data/transactions/logic/opcodes.go index f3f8bfe37d..0171be5078 100644 --- a/data/transactions/logic/opcodes.go +++ b/data/transactions/logic/opcodes.go @@ -19,12 +19,12 @@ package logic import ( "cmp" "fmt" + "maps" + "slices" "strconv" "strings" "github.com/algorand/go-algorand/data/basics" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" ) // LogicVersion defines default assembler and max eval versions @@ -839,10 +839,9 @@ func OpcodesByVersion(version uint64) []OpSpec { } } result := maps.Values(subv) - slices.SortFunc(result, func(a, b OpSpec) int { + return slices.SortedFunc(result, func(a, b OpSpec) int { return cmp.Compare(a.Opcode, b.Opcode) }) - return result } // direct opcode bytes diff --git a/data/transactions/logic/opcodes_test.go b/data/transactions/logic/opcodes_test.go index 57a2d5eb76..a39be85106 100644 --- a/data/transactions/logic/opcodes_test.go +++ b/data/transactions/logic/opcodes_test.go @@ -19,11 +19,11 @@ package logic import ( "fmt" "reflect" + "slices" "testing" "github.com/algorand/go-algorand/test/partitiontest" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" ) func TestOpSpecs(t *testing.T) { diff --git a/data/transactions/teal.go b/data/transactions/teal.go index bdb68b525d..fa25a71520 100644 --- a/data/transactions/teal.go +++ b/data/transactions/teal.go @@ -18,11 +18,11 @@ package transactions import ( "bytes" + "maps" + "slices" "github.com/algorand/go-algorand/data/basics" "github.com/algorand/go-algorand/protocol" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" ) // EvalDelta stores StateDeltas for an application's global key/value store, as diff --git a/data/transactions/transaction.go b/data/transactions/transaction.go index 4a6d5b6603..a8226654b5 100644 --- a/data/transactions/transaction.go +++ b/data/transactions/transaction.go @@ -21,13 +21,13 @@ import ( "encoding/binary" "errors" "fmt" + "slices" "sync" "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/crypto" "github.com/algorand/go-algorand/data/basics" "github.com/algorand/go-algorand/protocol" - "golang.org/x/exp/slices" ) // Txid is a hash used to uniquely identify individual transactions diff --git a/ledger/apply/application_test.go b/ledger/apply/application_test.go index dfc298bf84..77efd5b075 100644 --- a/ledger/apply/application_test.go +++ b/ledger/apply/application_test.go @@ -18,11 +18,11 @@ package apply import ( "fmt" + "maps" "math/rand" "testing" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/crypto" diff --git a/ledger/apply/mockBalances_test.go b/ledger/apply/mockBalances_test.go index 43af5fa11d..a02a2108fd 100644 --- a/ledger/apply/mockBalances_test.go +++ b/ledger/apply/mockBalances_test.go @@ -17,13 +17,14 @@ package apply import ( + "maps" + "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/data/basics" "github.com/algorand/go-algorand/data/transactions" "github.com/algorand/go-algorand/data/transactions/logic" "github.com/algorand/go-algorand/ledger/ledgercore" "github.com/algorand/go-algorand/protocol" - "golang.org/x/exp/maps" ) type mockBalances struct { diff --git a/ledger/eval/cow.go b/ledger/eval/cow.go index 9511af7ce7..046fb46598 100644 --- a/ledger/eval/cow.go +++ b/ledger/eval/cow.go @@ -28,7 +28,6 @@ import ( "github.com/algorand/go-algorand/data/transactions" "github.com/algorand/go-algorand/ledger/ledgercore" "github.com/algorand/go-algorand/protocol" - "golang.org/x/exp/maps" ) // ___________________ @@ -352,9 +351,9 @@ func (cb *roundCowState) reset() { cb.proto = config.ConsensusParams{} cb.mods.Reset() cb.txnCount = 0 - maps.Clear(cb.sdeltas) + clear(cb.sdeltas) cb.compatibilityMode = false - maps.Clear(cb.compatibilityGetKeyCache) + clear(cb.compatibilityGetKeyCache) cb.prevTotals = ledgercore.AccountTotals{} cb.feesCollected = basics.MicroAlgos{} } diff --git a/ledger/eval/txntracer.go b/ledger/eval/txntracer.go index 96d307390a..9d19d42e69 100644 --- a/ledger/eval/txntracer.go +++ b/ledger/eval/txntracer.go @@ -18,10 +18,10 @@ package eval import ( "fmt" + "maps" + "slices" "github.com/algorand/go-deadlock" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" "github.com/algorand/go-algorand/crypto" "github.com/algorand/go-algorand/data/basics" diff --git a/ledger/ledger_test.go b/ledger/ledger_test.go index e73d648b4d..9018d5d73b 100644 --- a/ledger/ledger_test.go +++ b/ledger/ledger_test.go @@ -25,11 +25,11 @@ import ( "os" "path/filepath" "runtime" + "slices" "sort" "testing" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" "github.com/algorand/go-algorand/agreement" "github.com/algorand/go-algorand/config" diff --git a/ledger/ledgercore/statedelta.go b/ledger/ledgercore/statedelta.go index 1d2562ca4f..90bf7afeaf 100644 --- a/ledger/ledgercore/statedelta.go +++ b/ledger/ledgercore/statedelta.go @@ -18,11 +18,11 @@ package ledgercore import ( "fmt" + "maps" "github.com/algorand/go-algorand/data/basics" "github.com/algorand/go-algorand/data/bookkeeping" "github.com/algorand/go-algorand/data/transactions" - "golang.org/x/exp/maps" ) const ( @@ -294,24 +294,24 @@ func (ad *AccountDeltas) Dehydrate() { if ad.acctsCache == nil { ad.acctsCache = make(map[basics.Address]int) } - maps.Clear(ad.acctsCache) + clear(ad.acctsCache) if ad.appResourcesCache == nil { ad.appResourcesCache = make(map[AccountApp]int) } - maps.Clear(ad.appResourcesCache) + clear(ad.appResourcesCache) if ad.assetResourcesCache == nil { ad.assetResourcesCache = make(map[AccountAsset]int) } - maps.Clear(ad.assetResourcesCache) + clear(ad.assetResourcesCache) } // Reset resets the StateDelta for re-use with sync.Pool func (sd *StateDelta) Reset() { sd.Accts.reset() - maps.Clear(sd.Txids) - maps.Clear(sd.Txleases) - maps.Clear(sd.Creatables) - maps.Clear(sd.KvMods) + clear(sd.Txids) + clear(sd.Txleases) + clear(sd.Creatables) + clear(sd.KvMods) sd.Totals = AccountTotals{} // these fields are going to be populated on next use but resetting them anyway for safety. @@ -329,9 +329,9 @@ func (ad *AccountDeltas) reset() { ad.AssetResources = ad.AssetResources[:0] // reset the maps - maps.Clear(ad.acctsCache) - maps.Clear(ad.appResourcesCache) - maps.Clear(ad.assetResourcesCache) + clear(ad.acctsCache) + clear(ad.appResourcesCache) + clear(ad.assetResourcesCache) } // notAllocated returns true if any of the fields allocated by MakeAccountDeltas is nil diff --git a/ledger/simulation/simulation_eval_test.go b/ledger/simulation/simulation_eval_test.go index 98ce3bd695..ef81a8a10e 100644 --- a/ledger/simulation/simulation_eval_test.go +++ b/ledger/simulation/simulation_eval_test.go @@ -21,11 +21,10 @@ import ( "encoding/hex" "fmt" "math" + "slices" "strings" "testing" - "golang.org/x/exp/slices" - "github.com/algorand/go-algorand/crypto" "github.com/algorand/go-algorand/data/basics" "github.com/algorand/go-algorand/data/transactions" diff --git a/netdeploy/network.go b/netdeploy/network.go index 6f31673a54..1ca99239f4 100644 --- a/netdeploy/network.go +++ b/netdeploy/network.go @@ -20,8 +20,10 @@ import ( "encoding/json" "fmt" "io" + "maps" "os" "path/filepath" + "slices" "sort" "strings" "time" @@ -34,7 +36,6 @@ import ( "github.com/algorand/go-algorand/nodecontrol" "github.com/algorand/go-algorand/protocol" "github.com/algorand/go-algorand/util" - "golang.org/x/exp/maps" ) const configFileName = "network.json" @@ -365,7 +366,7 @@ func (n Network) GetPeerAddresses(binDir string) []string { } func (n Network) startNodes(binDir string, relayNameToAddress map[string]string, redirectOutput bool) error { - allRelaysAddresses := strings.Join(maps.Values(relayNameToAddress), ";") + allRelaysAddresses := strings.Join(slices.Collect(maps.Values(relayNameToAddress)), ";") nodeConfigToEntry := make(map[string]remote.NodeConfigGoal, len(n.cfg.Template.Nodes)) for _, n := range n.cfg.Template.Nodes { diff --git a/network/p2p/peerstore/peerstore.go b/network/p2p/peerstore/peerstore.go index 5ae9c6aa04..4a4e7e6ddf 100644 --- a/network/p2p/peerstore/peerstore.go +++ b/network/p2p/peerstore/peerstore.go @@ -20,12 +20,12 @@ import ( "fmt" "math" "math/rand" + "slices" "time" "github.com/libp2p/go-libp2p/core/peer" libp2p "github.com/libp2p/go-libp2p/core/peerstore" mempstore "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem" - "golang.org/x/exp/slices" "github.com/algorand/go-algorand/network/phonebook" "github.com/algorand/go-deadlock" diff --git a/network/phonebook/phonebook.go b/network/phonebook/phonebook.go index b3aeafb0fa..100d624c04 100644 --- a/network/phonebook/phonebook.go +++ b/network/phonebook/phonebook.go @@ -19,10 +19,10 @@ package phonebook import ( "math" "math/rand" + "slices" "time" "github.com/algorand/go-deadlock" - "golang.org/x/exp/slices" ) // getAllAddresses when using GetAddresses with getAllAddresses, all the addresses will be retrieved, regardless diff --git a/stateproof/builder.go b/stateproof/builder.go index 317e813602..96ca279a4b 100644 --- a/stateproof/builder.go +++ b/stateproof/builder.go @@ -22,6 +22,8 @@ import ( "encoding/binary" "errors" "fmt" + "maps" + "slices" "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/crypto/stateproof" @@ -34,8 +36,6 @@ import ( "github.com/algorand/go-algorand/network" "github.com/algorand/go-algorand/protocol" "github.com/algorand/go-algorand/stateproof/verify" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" ) var errVotersNotTracked = errors.New("voters not tracked for the given lookback round") @@ -642,8 +642,7 @@ func (spw *Worker) tryBroadcast() { spw.mu.Lock() defer spw.mu.Unlock() - sortedRounds := maps.Keys(spw.provers) - slices.Sort(sortedRounds) + sortedRounds := slices.Sorted(maps.Keys(spw.provers)) for _, rnd := range sortedRounds { // Iterate over the provers in a sequential manner. If the earlist state proof is not ready/rejected diff --git a/test/reflectionhelpers/helpers.go b/test/reflectionhelpers/helpers.go index de11d3c9e9..d3a7122042 100644 --- a/test/reflectionhelpers/helpers.go +++ b/test/reflectionhelpers/helpers.go @@ -19,9 +19,8 @@ package reflectionhelpers import ( "fmt" "reflect" + "slices" "strings" - - "golang.org/x/exp/slices" ) // TypeSegmentKind is a enum for the types of TypeSegment diff --git a/util/metrics/opencensus.go b/util/metrics/opencensus.go index fefb1d054b..d61c6206cd 100644 --- a/util/metrics/opencensus.go +++ b/util/metrics/opencensus.go @@ -21,11 +21,11 @@ package metrics import ( "context" + "slices" "strings" "go.opencensus.io/metric/metricdata" "go.opencensus.io/metric/metricexport" - "golang.org/x/exp/slices" ) type defaultOpencensusGatherer struct { diff --git a/util/metrics/tagcounter.go b/util/metrics/tagcounter.go index c2b5fcb9bb..d12f10ead5 100644 --- a/util/metrics/tagcounter.go +++ b/util/metrics/tagcounter.go @@ -17,12 +17,12 @@ package metrics import ( + "maps" "strconv" "strings" "sync/atomic" "github.com/algorand/go-deadlock" - "golang.org/x/exp/maps" ) // NewTagCounterFiltered makes a set of metrics under rootName for tagged counting. From 4742e344c0b1f24f0903b3486dd8ab6de79400a7 Mon Sep 17 00:00:00 2001 From: Eng Zer Jun Date: Tue, 26 Nov 2024 02:11:42 +0800 Subject: [PATCH 2/2] Rename `result` to `values` Reference: https://github.com/algorand/go-algorand/pull/6179#discussion_r1857106294 Signed-off-by: Eng Zer Jun --- data/transactions/logic/opcodes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/transactions/logic/opcodes.go b/data/transactions/logic/opcodes.go index 0171be5078..419e937874 100644 --- a/data/transactions/logic/opcodes.go +++ b/data/transactions/logic/opcodes.go @@ -838,8 +838,8 @@ func OpcodesByVersion(version uint64) []OpSpec { } } } - result := maps.Values(subv) - return slices.SortedFunc(result, func(a, b OpSpec) int { + values := maps.Values(subv) + return slices.SortedFunc(values, func(a, b OpSpec) int { return cmp.Compare(a.Opcode, b.Opcode) }) }