From f0c59f5b3831ff0827aa13ba38ec429e871f8a39 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 13 Aug 2024 23:30:33 +0200 Subject: [PATCH 1/7] refactor: remove x/exp dep --- baseapp/baseapp.go | 2 +- go.mod | 2 +- runtime/v2/app.go | 2 +- runtime/v2/go.mod | 2 +- runtime/v2/manager.go | 2 +- server/v2/api/grpc/server.go | 2 +- server/v2/go.mod | 2 +- server/v2/stf/core_event_service.go | 2 +- server/v2/stf/go.mod | 2 +- store/v2/commitment/store.go | 2 +- store/v2/go.mod | 2 +- tests/systemtests/cli.go | 2 +- tests/systemtests/go.mod | 2 +- tests/systemtests/system.go | 2 +- tools/confix/cmd/diff.go | 2 +- tools/confix/cmd/migrate.go | 2 +- tools/confix/go.mod | 2 +- types/events.go | 2 +- types/module/module.go | 2 +- x/auth/ante/unorderedtx/manager.go | 3 +-- x/auth/go.mod | 2 +- x/bank/depinject.go | 3 +-- x/bank/go.mod | 2 +- x/epochs/depinject.go | 3 +-- x/epochs/go.mod | 2 +- x/epochs/keeper/abci_test.go | 2 +- x/genutil/client/cli/migrate.go | 2 +- x/gov/depinject.go | 3 +-- x/gov/go.mod | 3 ++- x/group/go.mod | 2 +- x/group/keeper/invariants.go | 3 +-- x/staking/depinject.go | 3 +-- x/staking/go.mod | 2 +- 33 files changed, 34 insertions(+), 39 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index a6a60a6d376f..98c6986aaca2 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "maps" "math" "sort" "strconv" @@ -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" diff --git a/go.mod b/go.mod index 818e8abc6acf..e3928d34c716 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 ba46e001fcb3..ea3cc7add2d9 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 4893d6a83f2b..f15526ee5840 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 a773f52a1dfc..9529812febd9 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -5,11 +5,11 @@ import ( "encoding/json" "errors" "fmt" + "maps" "reflect" "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" diff --git a/server/v2/api/grpc/server.go b/server/v2/api/grpc/server.go index 006a970e09b9..8279e20bba47 100644 --- a/server/v2/api/grpc/server.go +++ b/server/v2/api/grpc/server.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" "io" + "maps" "net" "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" diff --git a/server/v2/go.mod b/server/v2/go.mod index d17ddcd62367..306b88d4e7c8 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..ba7f162bc9b2 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" 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..e7ba01535e35 100644 --- a/store/v2/commitment/store.go +++ b/store/v2/commitment/store.go @@ -4,11 +4,11 @@ import ( "errors" "fmt" "io" + "maps" "math" "sort" protoio "github.com/cosmos/gogoproto/io" - "golang.org/x/exp/maps" corelog "cosmossdk.io/core/log" corestore "cosmossdk.io/core/store" diff --git a/store/v2/go.mod b/store/v2/go.mod index 96c9555197b2..55c4b2bd8170 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-20231006140011-7918f672742d // indirect golang.org/x/sys v0.23.0 // indirect golang.org/x/text v0.17.0 // indirect google.golang.org/protobuf v1.34.2 // indirect 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 e889dfccbda9..0623de000d3e 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 bc8f4351b33d..ef0afb698747 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" diff --git a/tools/confix/cmd/diff.go b/tools/confix/cmd/diff.go index f6d71bcaa5c5..bc305bdcfdbd 100644 --- a/tools/confix/cmd/diff.go +++ b/tools/confix/cmd/diff.go @@ -3,11 +3,11 @@ package cmd import ( "errors" "fmt" + "maps" "path/filepath" "strings" "github.com/spf13/cobra" - "golang.org/x/exp/maps" "cosmossdk.io/tools/confix" diff --git a/tools/confix/cmd/migrate.go b/tools/confix/cmd/migrate.go index a7122161d14e..c2613533e955 100644 --- a/tools/confix/cmd/migrate.go +++ b/tools/confix/cmd/migrate.go @@ -4,11 +4,11 @@ import ( "context" "errors" "fmt" + "maps" "path/filepath" "strings" "github.com/spf13/cobra" - "golang.org/x/exp/maps" "cosmossdk.io/tools/confix" diff --git a/tools/confix/go.mod b/tools/confix/go.mod index 0be9e2190e26..ee1c453e0b25 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..e62e3d330712 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" ) diff --git a/types/module/module.go b/types/module/module.go index 06be7817eb14..7f6d25b686d8 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -24,12 +24,12 @@ import ( "encoding/json" "errors" "fmt" + "maps" "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" diff --git a/x/auth/ante/unorderedtx/manager.go b/x/auth/ante/unorderedtx/manager.go index 97bf4d5cd7f1..0fea9a2622d5 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" "sync" "time" - - "golang.org/x/exp/maps" ) const ( diff --git a/x/auth/go.mod b/x/auth/go.mod index edbd5f65086c..b260291b7509 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..e1370c99cd37 100644 --- a/x/bank/depinject.go +++ b/x/bank/depinject.go @@ -2,10 +2,9 @@ package bank import ( "fmt" + "maps" "sort" - "golang.org/x/exp/maps" - modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" diff --git a/x/bank/go.mod b/x/bank/go.mod index 1c611ee920f7..43856d9513ea 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..c0f00384cfc4 100644 --- a/x/epochs/depinject.go +++ b/x/epochs/depinject.go @@ -2,10 +2,9 @@ package epochs import ( "fmt" + "maps" "sort" - "golang.org/x/exp/maps" - modulev1 "cosmossdk.io/api/cosmos/epochs/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" diff --git a/x/epochs/go.mod b/x/epochs/go.mod index a434f7bd6e34..e98a595f56be 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..1f5f13e7c1fe 100644 --- a/x/epochs/keeper/abci_test.go +++ b/x/epochs/keeper/abci_test.go @@ -1,12 +1,12 @@ package keeper_test import ( + "maps" "sort" "testing" "time" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" "cosmossdk.io/core/header" "cosmossdk.io/x/epochs/types" diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index 1ee0fc07f0ca..be975eb7a0c4 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" + "maps" "sort" "strings" "time" "github.com/spf13/cobra" - "golang.org/x/exp/maps" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" diff --git a/x/gov/depinject.go b/x/gov/depinject.go index 72f9b4767169..32beccff2c0b 100644 --- a/x/gov/depinject.go +++ b/x/gov/depinject.go @@ -2,12 +2,11 @@ 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" diff --git a/x/gov/go.mod b/x/gov/go.mod index d8385bf72b69..f77aa2c861c1 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -28,13 +28,14 @@ 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 gotest.tools/v3 v3.5.1 ) +require golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect + require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect diff --git a/x/group/go.mod b/x/group/go.mod index 5e19356ec97f..8628eb432b8b 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..e015fb592ba4 100644 --- a/x/group/keeper/invariants.go +++ b/x/group/keeper/invariants.go @@ -2,11 +2,10 @@ package keeper import ( "fmt" + "maps" "math" "sort" - "golang.org/x/exp/maps" - storetypes "cosmossdk.io/core/store" "cosmossdk.io/x/group" "cosmossdk.io/x/group/errors" diff --git a/x/staking/depinject.go b/x/staking/depinject.go index a4dfc2630d52..c619b20a0f91 100644 --- a/x/staking/depinject.go +++ b/x/staking/depinject.go @@ -2,10 +2,9 @@ package staking import ( "fmt" + "maps" "sort" - "golang.org/x/exp/maps" - modulev1 "cosmossdk.io/api/cosmos/staking/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" diff --git a/x/staking/go.mod b/x/staking/go.mod index 581deec093f1..1d814fbec6db 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 => ../../. From 73d50f5eb5c6703965cfd35bb06663c444174af5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 15 Aug 2024 18:48:11 +0200 Subject: [PATCH 2/7] wip --- baseapp/baseapp.go | 6 +++--- server/v2/stf/core_event_service.go | 10 ++-------- types/events.go | 4 ++-- types/module/module.go | 8 ++++++-- x/auth/ante/unorderedtx/manager.go | 6 +++--- x/genutil/client/cli/migrate.go | 12 ++++++++---- x/staking/depinject.go | 8 ++++---- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 98c6986aaca2..0fa11bf1661f 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -6,7 +6,7 @@ import ( "fmt" "maps" "math" - "sort" + "slices" "strconv" "sync" @@ -341,8 +341,8 @@ func (app *BaseApp) MountTransientStores(keys map[string]*storetypes.TransientSt // commit multi-store. func (app *BaseApp) MountMemoryStores(keys map[string]*storetypes.MemoryStoreKey) { skeys := maps.Keys(keys) - sort.Strings(skeys) - for _, key := range skeys { + slices.Sorted(skeys) + for key := range skeys { memKey := keys[key] app.MountStore(memKey, storetypes.StoreTypeMemory) } diff --git a/server/v2/stf/core_event_service.go b/server/v2/stf/core_event_service.go index ba7f162bc9b2..7426dcd4d169 100644 --- a/server/v2/stf/core_event_service.go +++ b/server/v2/stf/core_event_service.go @@ -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) @@ -71,10 +65,10 @@ 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) + slices.Sorted(keys) attrs := make([]event.Attribute, 0, len(attrMap)) - for _, k := range keys { + for k := range keys { v := attrMap[k] attrs = append(attrs, event.Attribute{ Key: k, diff --git a/types/events.go b/types/events.go index e62e3d330712..df64d83dc807 100644 --- a/types/events.go +++ b/types/events.go @@ -101,10 +101,10 @@ 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) + slices.Sorted(keys) attrs := make([]abci.EventAttribute, 0, len(attrMap)) - for _, k := range keys { + for k := range keys { v := attrMap[k] attrs = append(attrs, abci.EventAttribute{ Key: k, diff --git a/types/module/module.go b/types/module/module.go index 7f6d25b686d8..536804cd0336 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -24,7 +24,6 @@ import ( "encoding/json" "errors" "fmt" - "maps" "sort" abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" @@ -832,7 +831,12 @@ 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) + moduleNames := make([]string, 0, len(m.Modules)) + for k := range m.Modules { + moduleNames = append(moduleNames, k) + } + + return moduleNames } // 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 0fea9a2622d5..960b646a4dd0 100644 --- a/x/auth/ante/unorderedtx/manager.go +++ b/x/auth/ante/unorderedtx/manager.go @@ -11,7 +11,7 @@ import ( "maps" "os" "path/filepath" - "sort" + "slices" "sync" "time" ) @@ -162,10 +162,10 @@ func (m *Manager) exportSnapshot(height uint64, snapshotWriter func([]byte) erro 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 }) + slices.SortedFunc(keys, func(i, j TxHash) int { return bytes.Compare(i[:], j[:]) }) timestamp := time.Unix(int64(height), 0) - for _, txHash := range keys { + for txHash := range keys { timeoutTime := m.txHashes[txHash] if timestamp.After(timeoutTime) { // skip expired txs that have yet to be purged diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index be975eb7a0c4..83ef60f3389c 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -4,8 +4,7 @@ import ( "encoding/json" "fmt" "maps" - "sort" - "strings" + "slices" "time" "github.com/spf13/cobra" @@ -52,8 +51,13 @@ 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, ", ")) + slices.Sorted(versions) + var versionsStr string + for v := range versions { + versionsStr += v + ", " + } + + return fmt.Errorf("unknown migration function for version: %s (supported versions %s)", target, versionsStr) } importGenesis := args[1] diff --git a/x/staking/depinject.go b/x/staking/depinject.go index c619b20a0f91..b80c6aeecbbb 100644 --- a/x/staking/depinject.go +++ b/x/staking/depinject.go @@ -91,6 +91,10 @@ func InvokeSetStakingHooks( return nil } + if len(stakingHooks) == 0 { + return nil + } + modNames := maps.Keys(stakingHooks) order := config.HooksOrder if len(order) == 0 { @@ -102,10 +106,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] From a40ae2953130d77ba7bb7df224e6597a8e2f6d62 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 16 Aug 2024 12:22:09 +0200 Subject: [PATCH 3/7] fixes --- baseapp/baseapp.go | 5 ++--- server/v2/stf/core_event_service.go | 6 ++---- types/events.go | 6 ++---- types/module/module.go | 9 +++------ x/auth/ante/unorderedtx/manager.go | 6 ++---- x/feegrant/module/depinject.go | 23 ----------------------- x/feegrant/module/module.go | 22 ++++++++++++++++++++++ x/genutil/client/cli/migrate.go | 9 ++------- x/gov/go.mod | 3 +-- x/staking/depinject.go | 3 ++- 10 files changed, 38 insertions(+), 54 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 0fa11bf1661f..75f3b6a6a811 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -340,9 +340,8 @@ 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) - slices.Sorted(skeys) - for key := range skeys { + skeys := slices.Sorted(maps.Keys(keys)) + for _, key := range skeys { memKey := keys[key] app.MountStore(memKey, storetypes.StoreTypeMemory) } diff --git a/server/v2/stf/core_event_service.go b/server/v2/stf/core_event_service.go index 7426dcd4d169..48b2507b433d 100644 --- a/server/v2/stf/core_event_service.go +++ b/server/v2/stf/core_event_service.go @@ -64,11 +64,9 @@ func TypedEventToEvent(tev transaction.Msg) (event.Event, error) { } // sort the keys to ensure the order is always the same - keys := maps.Keys(attrMap) - slices.Sorted(keys) - + keys := slices.Sorted(maps.Keys(attrMap)) attrs := make([]event.Attribute, 0, len(attrMap)) - for k := range keys { + for _, k := range keys { v := attrMap[k] attrs = append(attrs, event.Attribute{ Key: k, diff --git a/types/events.go b/types/events.go index df64d83dc807..55568c385897 100644 --- a/types/events.go +++ b/types/events.go @@ -100,11 +100,9 @@ func TypedEventToEvent(tev proto.Message) (Event, error) { } // sort the keys to ensure the order is always the same - keys := maps.Keys(attrMap) - slices.Sorted(keys) - + keys := slices.Sorted(maps.Keys(attrMap)) attrs := make([]abci.EventAttribute, 0, len(attrMap)) - for k := range keys { + for _, k := range keys { v := attrMap[k] attrs = append(attrs, abci.EventAttribute{ Key: k, diff --git a/types/module/module.go b/types/module/module.go index 536804cd0336..e24bc4f64f30 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -24,6 +24,8 @@ import ( "encoding/json" "errors" "fmt" + "maps" + "slices" "sort" abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" @@ -831,12 +833,7 @@ func (m *Manager) GetVersionMap() appmodule.VersionMap { // ModuleNames returns list of all module names, without any particular order. func (m *Manager) ModuleNames() []string { - moduleNames := make([]string, 0, len(m.Modules)) - for k := range m.Modules { - moduleNames = append(moduleNames, k) - } - - return moduleNames + 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 960b646a4dd0..8b5a91ed2a01 100644 --- a/x/auth/ante/unorderedtx/manager.go +++ b/x/auth/ante/unorderedtx/manager.go @@ -161,11 +161,9 @@ func (m *Manager) exportSnapshot(height uint64, snapshotWriter func([]byte) erro var buf bytes.Buffer w := bufio.NewWriter(&buf) - keys := maps.Keys(m.txHashes) - slices.SortedFunc(keys, func(i, j TxHash) int { return bytes.Compare(i[:], j[:]) }) - + 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 { + for _, txHash := range keys { timeoutTime := m.txHashes[txHash] if timestamp.After(timeoutTime) { // skip expired txs that have yet to be purged 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 83ef60f3389c..08eb01ced8c9 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -5,6 +5,7 @@ import ( "fmt" "maps" "slices" + "strings" "time" "github.com/spf13/cobra" @@ -51,13 +52,7 @@ func MigrateHandler(cmd *cobra.Command, args []string, migrations types.Migratio migrationFunc, ok := migrations[target] if !ok || migrationFunc == nil { versions := maps.Keys(migrations) - slices.Sorted(versions) - var versionsStr string - for v := range versions { - versionsStr += v + ", " - } - - return fmt.Errorf("unknown migration function for version: %s (supported versions %s)", target, versionsStr) + 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/go.mod b/x/gov/go.mod index f77aa2c861c1..49ea8a8f19fd 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -34,8 +34,6 @@ require ( gotest.tools/v3 v3.5.1 ) -require golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect - require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect @@ -159,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/staking/depinject.go b/x/staking/depinject.go index b80c6aeecbbb..4adee385d4d1 100644 --- a/x/staking/depinject.go +++ b/x/staking/depinject.go @@ -3,6 +3,7 @@ package staking import ( "fmt" "maps" + "slices" "sort" modulev1 "cosmossdk.io/api/cosmos/staking/module/v1" @@ -95,7 +96,7 @@ func InvokeSetStakingHooks( return nil } - modNames := maps.Keys(stakingHooks) + modNames := slices.Collect(maps.Keys(stakingHooks)) order := config.HooksOrder if len(order) == 0 { order = modNames From b070c575ba29e2e3a63b9d63776a0d8d471999f5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 16 Aug 2024 12:38:39 +0200 Subject: [PATCH 4/7] updates --- runtime/v2/manager.go | 3 ++- scripts/dep-assert.sh | 6 ++++++ server/v2/api/grpc/server.go | 3 ++- store/v2/commitment/store.go | 6 ++---- tests/systemtests/system.go | 2 +- tools/confix/cmd/diff.go | 3 ++- x/bank/depinject.go | 3 ++- x/epochs/depinject.go | 9 +++------ x/epochs/keeper/abci_test.go | 13 +++++++++---- x/gov/depinject.go | 8 ++------ x/group/keeper/invariants.go | 13 +++++++++---- 11 files changed, 40 insertions(+), 29 deletions(-) diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 9529812febd9..bd7e4e79cf46 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -7,6 +7,7 @@ import ( "fmt" "maps" "reflect" + "slices" "sort" gogoproto "github.com/cosmos/gogoproto/proto" @@ -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.Collect(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 8279e20bba47..b66be16da602 100644 --- a/server/v2/api/grpc/server.go +++ b/server/v2/api/grpc/server.go @@ -7,6 +7,7 @@ import ( "io" "maps" "net" + "slices" "strconv" "github.com/cosmos/gogoproto/proto" @@ -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/store/v2/commitment/store.go b/store/v2/commitment/store.go index e7ba01535e35..da0440987524 100644 --- a/store/v2/commitment/store.go +++ b/store/v2/commitment/store.go @@ -6,7 +6,7 @@ import ( "io" "maps" "math" - "sort" + "slices" protoio "github.com/cosmos/gogoproto/io" @@ -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/tests/systemtests/system.go b/tests/systemtests/system.go index ef0afb698747..486efbfef00b 100644 --- a/tests/systemtests/system.go +++ b/tests/systemtests/system.go @@ -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 bc305bdcfdbd..89226a112236 100644 --- a/tools/confix/cmd/diff.go +++ b/tools/confix/cmd/diff.go @@ -5,6 +5,7 @@ import ( "fmt" "maps" "path/filepath" + "slices" "strings" "github.com/spf13/cobra" @@ -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/x/bank/depinject.go b/x/bank/depinject.go index e1370c99cd37..ecc05abf4732 100644 --- a/x/bank/depinject.go +++ b/x/bank/depinject.go @@ -3,6 +3,7 @@ package bank import ( "fmt" "maps" + "slices" "sort" modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" @@ -102,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/epochs/depinject.go b/x/epochs/depinject.go index c0f00384cfc4..24640e7c641f 100644 --- a/x/epochs/depinject.go +++ b/x/epochs/depinject.go @@ -3,7 +3,7 @@ package epochs import ( "fmt" "maps" - "sort" + "slices" modulev1 "cosmossdk.io/api/cosmos/epochs/module/v1" "cosmossdk.io/core/appmodule" @@ -55,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/keeper/abci_test.go b/x/epochs/keeper/abci_test.go index 1f5f13e7c1fe..7a864d8ebf41 100644 --- a/x/epochs/keeper/abci_test.go +++ b/x/epochs/keeper/abci_test.go @@ -2,7 +2,7 @@ package keeper_test import ( "maps" - "sort" + "slices" "testing" "time" @@ -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/gov/depinject.go b/x/gov/depinject.go index 32beccff2c0b..46af43b1c782 100644 --- a/x/gov/depinject.go +++ b/x/gov/depinject.go @@ -4,7 +4,6 @@ import ( "fmt" "maps" "slices" - "sort" "strings" modulev1 "cosmossdk.io/api/cosmos/gov/module/v1" @@ -121,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/group/keeper/invariants.go b/x/group/keeper/invariants.go index e015fb592ba4..33034b5d7506 100644 --- a/x/group/keeper/invariants.go +++ b/x/group/keeper/invariants.go @@ -4,7 +4,7 @@ import ( "fmt" "maps" "math" - "sort" + "slices" storetypes "cosmossdk.io/core/store" "cosmossdk.io/x/group" @@ -57,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 { From cb7dfa5781d4106bb81ff4509a3a9b19c6485720 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 16 Aug 2024 12:39:07 +0200 Subject: [PATCH 5/7] updates --- tools/confix/cmd/migrate.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/confix/cmd/migrate.go b/tools/confix/cmd/migrate.go index c2613533e955..7e6c01e03401 100644 --- a/tools/confix/cmd/migrate.go +++ b/tools/confix/cmd/migrate.go @@ -6,6 +6,7 @@ import ( "fmt" "maps" "path/filepath" + "slices" "strings" "github.com/spf13/cobra" @@ -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) From 942d088b12a46f1029d5f07f24fdb013cfa3e5ad Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 16 Aug 2024 13:02:01 +0200 Subject: [PATCH 6/7] lint --- tests/systemtests/system.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/systemtests/system.go b/tests/systemtests/system.go index 486efbfef00b..8505d20d7868 100644 --- a/tests/systemtests/system.go +++ b/tests/systemtests/system.go @@ -247,7 +247,7 @@ func (s *SystemUnderTest) AwaitUpgradeInfo(t *testing.T) { case err == nil: found = true case !os.IsNotExist(err): - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } }) time.Sleep(s.blockTime / 2) From 1bae7ea8a01473181b51f6035348e29d365b2b80 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 16 Aug 2024 20:35:07 +0200 Subject: [PATCH 7/7] deterministic manager --- runtime/v2/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index d6c015b3057d..7b8d555f21df 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -42,7 +42,7 @@ func NewModuleManager[T transaction.Tx]( modules map[string]appmodulev2.AppModule, ) *MM[T] { // good defaults for the module manager order - modulesName := slices.Collect(maps.Keys(modules)) + modulesName := slices.Sorted(maps.Keys(modules)) if len(config.PreBlockers) == 0 { config.PreBlockers = modulesName }