From 6f30de3a41d37a4359751f9d9e508b28fc620697 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 19 Aug 2024 13:14:34 +0000 Subject: [PATCH] refactor: remove x/exp dep (#21281) --- baseapp/baseapp.go | 7 +++---- go.mod | 2 +- runtime/v2/app.go | 2 +- runtime/v2/go.mod | 2 +- runtime/v2/manager.go | 5 +++-- scripts/dep-assert.sh | 6 ++++++ server/v2/api/grpc/server.go | 5 +++-- server/v2/go.mod | 2 +- server/v2/stf/core_event_service.go | 12 ++---------- server/v2/stf/go.mod | 2 +- store/v2/commitment/store.go | 8 +++----- store/v2/go.mod | 2 +- store/v2/go.sum | 4 ++-- tests/systemtests/cli.go | 2 +- tests/systemtests/go.mod | 2 +- tests/systemtests/system.go | 4 ++-- tools/confix/cmd/diff.go | 5 +++-- tools/confix/cmd/migrate.go | 5 +++-- tools/confix/go.mod | 2 +- types/events.go | 6 ++---- types/module/module.go | 5 +++-- x/auth/ante/unorderedtx/manager.go | 9 +++------ x/auth/go.mod | 2 +- x/bank/depinject.go | 6 +++--- x/bank/go.mod | 2 +- x/epochs/depinject.go | 12 ++++-------- x/epochs/go.mod | 2 +- x/epochs/keeper/abci_test.go | 15 ++++++++++----- x/feegrant/module/depinject.go | 23 ----------------------- x/feegrant/module/module.go | 22 ++++++++++++++++++++++ x/genutil/client/cli/migrate.go | 7 +++---- x/gov/depinject.go | 11 +++-------- x/gov/go.mod | 2 +- x/group/go.mod | 2 +- x/group/keeper/invariants.go | 16 ++++++++++------ x/staking/depinject.go | 14 +++++++------- x/staking/go.mod | 2 +- 37 files changed, 115 insertions(+), 122 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index a6a60a6d376f..75f3b6a6a811 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -4,8 +4,9 @@ import ( "context" "errors" "fmt" + "maps" "math" - "sort" + "slices" "strconv" "sync" @@ -14,7 +15,6 @@ import ( "github.com/cometbft/cometbft/crypto/tmhash" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/proto" - "golang.org/x/exp/maps" "google.golang.org/protobuf/reflect/protoreflect" "cosmossdk.io/core/header" @@ -340,8 +340,7 @@ func (app *BaseApp) MountTransientStores(keys map[string]*storetypes.TransientSt // MountMemoryStores mounts all in-memory KVStores with the BaseApp's internal // commit multi-store. func (app *BaseApp) MountMemoryStores(keys map[string]*storetypes.MemoryStoreKey) { - skeys := maps.Keys(keys) - sort.Strings(skeys) + skeys := slices.Sorted(maps.Keys(keys)) for _, key := range skeys { memKey := keys[key] app.MountStore(memKey, storetypes.StoreTypeMemory) diff --git a/go.mod b/go.mod index a41a5adf64fe..380330c50c45 100644 --- a/go.mod +++ b/go.mod @@ -57,7 +57,6 @@ require ( github.com/tendermint/go-amino v0.16.0 gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b golang.org/x/crypto v0.26.0 - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc golang.org/x/sync v0.8.0 google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 google.golang.org/grpc v1.65.0 @@ -164,6 +163,7 @@ require ( go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sys v0.24.0 // indirect diff --git a/runtime/v2/app.go b/runtime/v2/app.go index 08f2498255c5..ff888039be57 100644 --- a/runtime/v2/app.go +++ b/runtime/v2/app.go @@ -3,9 +3,9 @@ package runtime import ( "encoding/json" "errors" + "slices" gogoproto "github.com/cosmos/gogoproto/proto" - "golang.org/x/exp/slices" runtimev2 "cosmossdk.io/api/cosmos/app/runtime/v2" "cosmossdk.io/core/legacy" diff --git a/runtime/v2/go.mod b/runtime/v2/go.mod index e7f197f94489..4831b66fe920 100644 --- a/runtime/v2/go.mod +++ b/runtime/v2/go.mod @@ -24,7 +24,6 @@ require ( cosmossdk.io/x/tx v0.13.3 github.com/cosmos/gogoproto v1.7.0 github.com/spf13/viper v1.19.0 - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 ) @@ -91,6 +90,7 @@ require ( github.com/tidwall/btree v1.7.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.24.0 // indirect diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 9fe4c5fb80dd..bdeaf02afe36 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -5,11 +5,12 @@ import ( "encoding/json" "errors" "fmt" + "maps" "reflect" + "slices" "sort" gogoproto "github.com/cosmos/gogoproto/proto" - "golang.org/x/exp/maps" "google.golang.org/grpc" proto "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" @@ -41,7 +42,7 @@ func NewModuleManager[T transaction.Tx]( modules map[string]appmodulev2.AppModule, ) *MM[T] { // good defaults for the module manager order - modulesName := maps.Keys(modules) + modulesName := slices.Sorted(maps.Keys(modules)) if len(config.PreBlockers) == 0 { config.PreBlockers = modulesName } diff --git a/scripts/dep-assert.sh b/scripts/dep-assert.sh index 2f4dfd0dbf64..2599115a19cd 100755 --- a/scripts/dep-assert.sh +++ b/scripts/dep-assert.sh @@ -22,6 +22,7 @@ done # no runtime/v2 or server/v2 imports in x/ modules RUNTIMEV2_REGEX="cosmossdk.io/runtime/v2" SEVERV2_REGEX="cosmossdk.io/server/v2" +XEXP_REGEX="golang.org/x/exp" find ./x/ -type f -name 'go.mod' -print0 | while IFS= read -r -d '' file do d=$(dirname "$file") @@ -34,4 +35,9 @@ do echo "${d} has a dependency on server/v2!" exit 1 fi + + if cd "$CWD/$d" && go list -test -f '{{ .Imports }}' ./... | grep -q -E "${XEXP_REGEX}"; then + echo "${d} has a dependency on golang.org/x/exp" + exit 1 + fi done \ No newline at end of file diff --git a/server/v2/api/grpc/server.go b/server/v2/api/grpc/server.go index 006a970e09b9..b66be16da602 100644 --- a/server/v2/api/grpc/server.go +++ b/server/v2/api/grpc/server.go @@ -5,13 +5,14 @@ import ( "errors" "fmt" "io" + "maps" "net" + "slices" "strconv" "github.com/cosmos/gogoproto/proto" "github.com/spf13/pflag" "github.com/spf13/viper" - "golang.org/x/exp/maps" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -65,7 +66,7 @@ func (s *Server[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logge ) // Reflection allows external clients to see what services and methods the gRPC server exposes. - gogoreflection.Register(grpcSrv, maps.Keys(methodsMap), logger.With("sub-module", "grpc-reflection")) + gogoreflection.Register(grpcSrv, slices.Collect(maps.Keys(methodsMap)), logger.With("sub-module", "grpc-reflection")) s.grpcSrv = grpcSrv s.config = cfg diff --git a/server/v2/go.mod b/server/v2/go.mod index 5e5cedf830db..607ca7384469 100644 --- a/server/v2/go.mod +++ b/server/v2/go.mod @@ -38,7 +38,6 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.9.0 - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc golang.org/x/sync v0.8.0 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 @@ -102,6 +101,7 @@ require ( github.com/tidwall/btree v1.7.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sys v0.24.0 // indirect diff --git a/server/v2/stf/core_event_service.go b/server/v2/stf/core_event_service.go index a27eddd35cd5..48b2507b433d 100644 --- a/server/v2/stf/core_event_service.go +++ b/server/v2/stf/core_event_service.go @@ -4,11 +4,11 @@ import ( "bytes" "context" "encoding/json" + "maps" "slices" "github.com/cosmos/gogoproto/jsonpb" gogoproto "github.com/cosmos/gogoproto/proto" - "golang.org/x/exp/maps" "cosmossdk.io/core/event" transaction "cosmossdk.io/core/transaction" @@ -49,12 +49,6 @@ func (em *eventManager) EmitKV(eventType string, attrs ...event.Attribute) error return nil } -// EmitNonConsensus emits an typed event that is defined in the protobuf file. -// These events will not be added to consensus. -func (em *eventManager) EmitNonConsensus(event transaction.Msg) error { - return em.Emit(event) -} - // TypedEventToEvent takes typed event and converts to Event object func TypedEventToEvent(tev transaction.Msg) (event.Event, error) { evtType := gogoproto.MessageName(tev) @@ -70,9 +64,7 @@ func TypedEventToEvent(tev transaction.Msg) (event.Event, error) { } // sort the keys to ensure the order is always the same - keys := maps.Keys(attrMap) - slices.Sort(keys) - + keys := slices.Sorted(maps.Keys(attrMap)) attrs := make([]event.Attribute, 0, len(attrMap)) for _, k := range keys { v := attrMap[k] diff --git a/server/v2/stf/go.mod b/server/v2/stf/go.mod index a11fe22895ee..50cb2a8821ac 100644 --- a/server/v2/stf/go.mod +++ b/server/v2/stf/go.mod @@ -9,13 +9,13 @@ require ( github.com/cosmos/gogoproto v1.7.0 github.com/stretchr/testify v1.9.0 github.com/tidwall/btree v1.7.0 - golang.org/x/exp v0.0.0-20231006140011-7918f672742d ) require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/store/v2/commitment/store.go b/store/v2/commitment/store.go index 68c83e1c3de1..da0440987524 100644 --- a/store/v2/commitment/store.go +++ b/store/v2/commitment/store.go @@ -4,11 +4,11 @@ import ( "errors" "fmt" "io" + "maps" "math" - "sort" + "slices" protoio "github.com/cosmos/gogoproto/io" - "golang.org/x/exp/maps" corelog "cosmossdk.io/core/log" corestore "cosmossdk.io/core/store" @@ -111,9 +111,7 @@ func (c *CommitStore) LoadVersion(targetVersion uint64) error { func (c *CommitStore) LoadVersionAndUpgrade(targetVersion uint64, upgrades *corestore.StoreUpgrades) error { // deterministic iteration order for upgrades (as the underlying store may change and // upgrades make store changes where the execution order may matter) - storeKeys := maps.Keys(c.multiTrees) - sort.Strings(storeKeys) - + storeKeys := slices.Sorted(maps.Keys(c.multiTrees)) removeTree := func(storeKey string) error { if oldTree, ok := c.multiTrees[storeKey]; ok { if err := oldTree.Close(); err != nil { diff --git a/store/v2/go.mod b/store/v2/go.mod index 9f2dc4f4c507..1a446e696501 100644 --- a/store/v2/go.mod +++ b/store/v2/go.mod @@ -20,7 +20,6 @@ require ( github.com/stretchr/testify v1.9.0 github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d go.uber.org/mock v0.4.0 - golang.org/x/exp v0.0.0-20231006140011-7918f672742d golang.org/x/sync v0.8.0 ) @@ -59,6 +58,7 @@ require ( github.com/rs/zerolog v1.33.0 // indirect github.com/tidwall/btree v1.7.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/sys v0.24.0 // indirect golang.org/x/text v0.17.0 // indirect google.golang.org/protobuf v1.34.2 // indirect diff --git a/store/v2/go.sum b/store/v2/go.sum index 8af3e61c137d..5c023c9b2bcb 100644 --- a/store/v2/go.sum +++ b/store/v2/go.sum @@ -228,8 +228,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= -golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= -golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= 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/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/tests/systemtests/cli.go b/tests/systemtests/cli.go index bae6c55eaf73..697cc6b85225 100644 --- a/tests/systemtests/cli.go +++ b/tests/systemtests/cli.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "slices" "strings" "testing" "time" @@ -15,7 +16,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tidwall/gjson" - "golang.org/x/exp/slices" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/tests/systemtests/go.mod b/tests/systemtests/go.mod index a4d405ded4df..c2bff18e7ff0 100644 --- a/tests/systemtests/go.mod +++ b/tests/systemtests/go.mod @@ -29,7 +29,6 @@ require ( github.com/creachadair/tomledit v0.0.26 github.com/tidwall/gjson v1.14.2 github.com/tidwall/sjson v1.2.5 - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc ) require ( @@ -147,6 +146,7 @@ require ( go.etcd.io/bbolt v1.3.8 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.24.0 // indirect diff --git a/tests/systemtests/system.go b/tests/systemtests/system.go index 1c39cc150df5..8505d20d7868 100644 --- a/tests/systemtests/system.go +++ b/tests/systemtests/system.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "io" + "maps" "os" "os/exec" "path/filepath" @@ -23,7 +24,6 @@ import ( tmtypes "github.com/cometbft/cometbft/types" "github.com/stretchr/testify/require" "github.com/tidwall/sjson" - "golang.org/x/exp/maps" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" @@ -336,7 +336,7 @@ func (s *SystemUnderTest) withEachPid(cb func(p *os.Process)) { pids := maps.Keys(s.pids) s.pidsLock.RUnlock() - for _, pid := range pids { + for pid := range pids { p, err := os.FindProcess(pid) if err != nil { continue diff --git a/tools/confix/cmd/diff.go b/tools/confix/cmd/diff.go index f6d71bcaa5c5..89226a112236 100644 --- a/tools/confix/cmd/diff.go +++ b/tools/confix/cmd/diff.go @@ -3,11 +3,12 @@ package cmd import ( "errors" "fmt" + "maps" "path/filepath" + "slices" "strings" "github.com/spf13/cobra" - "golang.org/x/exp/maps" "cosmossdk.io/tools/confix" @@ -43,7 +44,7 @@ func DiffCommand() *cobra.Command { targetVersion := args[0] if _, ok := confix.Migrations[targetVersion]; !ok { - return fmt.Errorf("unknown version %q, supported versions are: %q", targetVersion, maps.Keys(confix.Migrations)) + return fmt.Errorf("unknown version %q, supported versions are: %q", targetVersion, slices.Collect(maps.Keys(confix.Migrations))) } targetVersionFile, err := confix.LoadLocalConfig(targetVersion, configType) diff --git a/tools/confix/cmd/migrate.go b/tools/confix/cmd/migrate.go index a7122161d14e..7e6c01e03401 100644 --- a/tools/confix/cmd/migrate.go +++ b/tools/confix/cmd/migrate.go @@ -4,11 +4,12 @@ import ( "context" "errors" "fmt" + "maps" "path/filepath" + "slices" "strings" "github.com/spf13/cobra" - "golang.org/x/exp/maps" "cosmossdk.io/tools/confix" @@ -60,7 +61,7 @@ In case of any error in updating the file, no output is written.`, targetVersion := args[0] plan, ok := confix.Migrations[targetVersion] if !ok { - return fmt.Errorf("unknown version %q, supported versions are: %q", targetVersion, maps.Keys(confix.Migrations)) + return fmt.Errorf("unknown version %q, supported versions are: %q", targetVersion, slices.Collect(maps.Keys(confix.Migrations))) } rawFile, err := confix.LoadConfig(configPath) diff --git a/tools/confix/go.mod b/tools/confix/go.mod index a9268468fbb5..23b8e71db64d 100644 --- a/tools/confix/go.mod +++ b/tools/confix/go.mod @@ -9,7 +9,6 @@ require ( github.com/pelletier/go-toml/v2 v2.2.2 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc gotest.tools/v3 v3.5.1 ) @@ -140,6 +139,7 @@ require ( go.etcd.io/bbolt v1.3.8 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.24.0 // indirect diff --git a/types/events.go b/types/events.go index 748b35ce63d4..55568c385897 100644 --- a/types/events.go +++ b/types/events.go @@ -3,6 +3,7 @@ package types import ( "encoding/json" "fmt" + "maps" "reflect" "slices" "strings" @@ -10,7 +11,6 @@ import ( abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" "github.com/cosmos/gogoproto/jsonpb" "github.com/cosmos/gogoproto/proto" - "golang.org/x/exp/maps" "github.com/cosmos/cosmos-sdk/codec" ) @@ -100,9 +100,7 @@ func TypedEventToEvent(tev proto.Message) (Event, error) { } // sort the keys to ensure the order is always the same - keys := maps.Keys(attrMap) - slices.Sort(keys) - + keys := slices.Sorted(maps.Keys(attrMap)) attrs := make([]abci.EventAttribute, 0, len(attrMap)) for _, k := range keys { v := attrMap[k] diff --git a/types/module/module.go b/types/module/module.go index 06be7817eb14..e24bc4f64f30 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -24,12 +24,13 @@ import ( "encoding/json" "errors" "fmt" + "maps" + "slices" "sort" abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" - "golang.org/x/exp/maps" "google.golang.org/grpc" "cosmossdk.io/core/appmodule" @@ -832,7 +833,7 @@ func (m *Manager) GetVersionMap() appmodule.VersionMap { // ModuleNames returns list of all module names, without any particular order. func (m *Manager) ModuleNames() []string { - return maps.Keys(m.Modules) + return slices.Collect(maps.Keys(m.Modules)) } // DefaultMigrationsOrder returns a default migrations order: ascending alphabetical by module name, diff --git a/x/auth/ante/unorderedtx/manager.go b/x/auth/ante/unorderedtx/manager.go index 97bf4d5cd7f1..8b5a91ed2a01 100644 --- a/x/auth/ante/unorderedtx/manager.go +++ b/x/auth/ante/unorderedtx/manager.go @@ -8,13 +8,12 @@ import ( "errors" "fmt" "io" + "maps" "os" "path/filepath" - "sort" + "slices" "sync" "time" - - "golang.org/x/exp/maps" ) const ( @@ -162,9 +161,7 @@ func (m *Manager) exportSnapshot(height uint64, snapshotWriter func([]byte) erro var buf bytes.Buffer w := bufio.NewWriter(&buf) - keys := maps.Keys(m.txHashes) - sort.Slice(keys, func(i, j int) bool { return bytes.Compare(keys[i][:], keys[j][:]) < 0 }) - + keys := slices.SortedFunc(maps.Keys(m.txHashes), func(i, j TxHash) int { return bytes.Compare(i[:], j[:]) }) timestamp := time.Unix(int64(height), 0) for _, txHash := range keys { timeoutTime := m.txHashes[txHash] diff --git a/x/auth/go.mod b/x/auth/go.mod index 19dda15d6834..47250dfc23ae 100644 --- a/x/auth/go.mod +++ b/x/auth/go.mod @@ -25,7 +25,6 @@ require ( github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.9.0 - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 @@ -156,6 +155,7 @@ require ( go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect diff --git a/x/bank/depinject.go b/x/bank/depinject.go index 1d6f7dd3e533..ecc05abf4732 100644 --- a/x/bank/depinject.go +++ b/x/bank/depinject.go @@ -2,10 +2,10 @@ package bank import ( "fmt" + "maps" + "slices" "sort" - "golang.org/x/exp/maps" - modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" @@ -103,7 +103,7 @@ func InvokeSetSendRestrictions( return nil } - modules := maps.Keys(restrictions) + modules := slices.Collect(maps.Keys(restrictions)) order := config.RestrictionsOrder if len(order) == 0 { order = modules diff --git a/x/bank/go.mod b/x/bank/go.mod index bf0f89bb211e..a3704a5eeaa5 100644 --- a/x/bank/go.mod +++ b/x/bank/go.mod @@ -149,7 +149,7 @@ require ( go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect diff --git a/x/epochs/depinject.go b/x/epochs/depinject.go index f09f9f95d9f8..24640e7c641f 100644 --- a/x/epochs/depinject.go +++ b/x/epochs/depinject.go @@ -2,9 +2,8 @@ package epochs import ( "fmt" - "sort" - - "golang.org/x/exp/maps" + "maps" + "slices" modulev1 "cosmossdk.io/api/cosmos/epochs/module/v1" "cosmossdk.io/core/appmodule" @@ -56,12 +55,9 @@ func InvokeSetHooks(keeper *keeper.Keeper, hooks map[string]types.EpochHooksWrap // Default ordering is lexical by module name. // Explicit ordering can be added to the module config if required. - modNames := maps.Keys(hooks) - order := modNames - sort.Strings(order) - + modNames := slices.Sorted(maps.Keys(hooks)) var multiHooks types.MultiEpochHooks - for _, modName := range order { + for _, modName := range modNames { hook, ok := hooks[modName] if !ok { return fmt.Errorf("can't find epoch hooks for module %s", modName) diff --git a/x/epochs/go.mod b/x/epochs/go.mod index 1081adf465f4..559f1f9b9419 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -146,7 +146,7 @@ require ( go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect diff --git a/x/epochs/keeper/abci_test.go b/x/epochs/keeper/abci_test.go index e3d5f84ff55d..7a864d8ebf41 100644 --- a/x/epochs/keeper/abci_test.go +++ b/x/epochs/keeper/abci_test.go @@ -1,12 +1,12 @@ package keeper_test import ( - "sort" + "maps" + "slices" "testing" "time" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" "cosmossdk.io/core/header" "cosmossdk.io/x/epochs/types" @@ -89,9 +89,14 @@ func (suite *KeeperTestSuite) TestEpochInfoBeginBlockChanges() { suite.Require().NoError(err) // get sorted heights - heights := maps.Keys(test.blockHeightTimePairs) - sort.Slice(heights, func(i, j int) bool { return heights[i] < heights[j] }) - + heights := slices.SortedFunc(maps.Keys(test.blockHeightTimePairs), func(i, j int) int { + if test.blockHeightTimePairs[i].Before(test.blockHeightTimePairs[j]) { + return -1 + } else if test.blockHeightTimePairs[i].After(test.blockHeightTimePairs[j]) { + return 1 + } + return 0 + }) for _, h := range heights { // for each height in order, run begin block suite.Ctx = suite.Ctx.WithHeaderInfo(header.Info{Height: int64(h), Time: test.blockHeightTimePairs[h]}) diff --git a/x/feegrant/module/depinject.go b/x/feegrant/module/depinject.go index 3fb6afa68984..018b09d3d593 100644 --- a/x/feegrant/module/depinject.go +++ b/x/feegrant/module/depinject.go @@ -7,12 +7,9 @@ import ( "cosmossdk.io/depinject/appconfig" "cosmossdk.io/x/feegrant" "cosmossdk.io/x/feegrant/keeper" - "cosmossdk.io/x/feegrant/simulation" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/types/module" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) var _ depinject.OnePerModuleType = AppModule{} @@ -41,23 +38,3 @@ func ProvideModule(in FeegrantInputs) (keeper.Keeper, appmodule.AppModule) { m := NewAppModule(in.Cdc, in.AccountKeeper, in.BankKeeper, k, in.Registry) return k, m } - -// AppModuleSimulation functions - -// GenerateGenesisState creates a randomized GenState of the feegrant module. -func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - simulation.RandomizedGenState(simState) -} - -// RegisterStoreDecoder registers a decoder for feegrant module's types -func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { - sdr[feegrant.StoreKey] = simulation.NewDecodeStore(am.cdc) -} - -// WeightedOperations returns all the feegrant module operations with their respective weights. -func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - return simulation.WeightedOperations( - am.registry, simState.AppParams, simState.Cdc, simState.TxConfig, - am.accountKeeper, am.bankKeeper, am.keeper, am.accountKeeper.AddressCodec(), - ) -} diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 134160422723..163c91cef1ef 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -16,11 +16,13 @@ import ( "cosmossdk.io/x/feegrant" "cosmossdk.io/x/feegrant/client/cli" "cosmossdk.io/x/feegrant/keeper" + "cosmossdk.io/x/feegrant/simulation" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) var ( @@ -152,3 +154,23 @@ func (AppModule) ConsensusVersion() uint64 { return 2 } func (am AppModule) EndBlock(ctx context.Context) error { return EndBlocker(ctx, am.keeper) } + +// AppModuleSimulation functions + +// GenerateGenesisState creates a randomized GenState of the feegrant module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// RegisterStoreDecoder registers a decoder for feegrant module's types +func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { + sdr[feegrant.StoreKey] = simulation.NewDecodeStore(am.cdc) +} + +// WeightedOperations returns all the feegrant module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return simulation.WeightedOperations( + am.registry, simState.AppParams, simState.Cdc, simState.TxConfig, + am.accountKeeper, am.bankKeeper, am.keeper, am.accountKeeper.AddressCodec(), + ) +} diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index 1ee0fc07f0ca..08eb01ced8c9 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -3,12 +3,12 @@ package cli import ( "encoding/json" "fmt" - "sort" + "maps" + "slices" "strings" "time" "github.com/spf13/cobra" - "golang.org/x/exp/maps" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -52,8 +52,7 @@ func MigrateHandler(cmd *cobra.Command, args []string, migrations types.Migratio migrationFunc, ok := migrations[target] if !ok || migrationFunc == nil { versions := maps.Keys(migrations) - sort.Strings(versions) - return fmt.Errorf("unknown migration function for version: %s (supported versions %s)", target, strings.Join(versions, ", ")) + return fmt.Errorf("unknown migration function for version: %s (supported versions %s)", target, strings.Join(slices.Sorted(versions), ", ")) } importGenesis := args[1] diff --git a/x/gov/depinject.go b/x/gov/depinject.go index 72f9b4767169..46af43b1c782 100644 --- a/x/gov/depinject.go +++ b/x/gov/depinject.go @@ -2,12 +2,10 @@ package gov import ( "fmt" + "maps" "slices" - "sort" "strings" - "golang.org/x/exp/maps" - modulev1 "cosmossdk.io/api/cosmos/gov/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" @@ -122,12 +120,9 @@ func InvokeSetHooks(keeper *keeper.Keeper, govHooks map[string]govtypes.GovHooks // Default ordering is lexical by module name. // Explicit ordering can be added to the module config if required. - modNames := maps.Keys(govHooks) - order := modNames - sort.Strings(order) - + modNames := slices.Sorted(maps.Keys(govHooks)) var multiHooks govtypes.MultiGovHooks - for _, modName := range order { + for _, modName := range modNames { hook, ok := govHooks[modName] if !ok { return fmt.Errorf("can't find staking hooks for module %s", modName) diff --git a/x/gov/go.mod b/x/gov/go.mod index a0b3c9ca9954..e41756b00731 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -28,7 +28,6 @@ require ( github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.9.0 - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 @@ -158,6 +157,7 @@ require ( go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 diff --git a/x/group/go.mod b/x/group/go.mod index 1f67ec61ef22..a1df92725fb7 100644 --- a/x/group/go.mod +++ b/x/group/go.mod @@ -31,7 +31,6 @@ require ( github.com/manifoldco/promptui v0.9.0 github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 @@ -165,6 +164,7 @@ require ( go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect diff --git a/x/group/keeper/invariants.go b/x/group/keeper/invariants.go index d3f47201a208..33034b5d7506 100644 --- a/x/group/keeper/invariants.go +++ b/x/group/keeper/invariants.go @@ -2,10 +2,9 @@ package keeper import ( "fmt" + "maps" "math" - "sort" - - "golang.org/x/exp/maps" + "slices" storetypes "cosmossdk.io/core/store" "cosmossdk.io/x/group" @@ -58,9 +57,14 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, storeService storetypes.KV groups[groupInfo.Id] = groupInfo } - groupByIDs := maps.Keys(groups) - sort.Slice(groupByIDs, func(i, j int) bool { - return groupByIDs[i] < groupByIDs[j] + groupByIDs := slices.Collect(maps.Keys(groups)) + slices.SortFunc(groupByIDs, func(i, j uint64) int { + if groupByIDs[i] < groupByIDs[j] { + return -1 + } else if groupByIDs[i] > groupByIDs[j] { + return 1 + } + return 0 }) for _, groupID := range groupByIDs { diff --git a/x/staking/depinject.go b/x/staking/depinject.go index a4dfc2630d52..4adee385d4d1 100644 --- a/x/staking/depinject.go +++ b/x/staking/depinject.go @@ -2,10 +2,10 @@ package staking import ( "fmt" + "maps" + "slices" "sort" - "golang.org/x/exp/maps" - modulev1 "cosmossdk.io/api/cosmos/staking/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" @@ -92,7 +92,11 @@ func InvokeSetStakingHooks( return nil } - modNames := maps.Keys(stakingHooks) + if len(stakingHooks) == 0 { + return nil + } + + modNames := slices.Collect(maps.Keys(stakingHooks)) order := config.HooksOrder if len(order) == 0 { order = modNames @@ -103,10 +107,6 @@ func InvokeSetStakingHooks( return fmt.Errorf("len(hooks_order: %v) != len(hooks modules: %v)", order, modNames) } - if len(modNames) == 0 { - return nil - } - var multiHooks types.MultiStakingHooks for _, modName := range order { hook, ok := stakingHooks[modName] diff --git a/x/staking/go.mod b/x/staking/go.mod index 0b2c17eeae9a..170146613aa8 100644 --- a/x/staking/go.mod +++ b/x/staking/go.mod @@ -23,7 +23,6 @@ require ( github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.9.0 - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 @@ -173,6 +172,7 @@ require ( require ( cosmossdk.io/schema v0.1.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect ) replace github.com/cosmos/cosmos-sdk => ../../.