refactor: remove x/exp dep (#21281)

This commit is contained in:
Julien Robert 2024-08-19 13:14:34 +00:00 committed by GitHub
parent 294b608022
commit 6f30de3a41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 115 additions and 122 deletions

View File

@ -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)

2
go.mod
View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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
)

View File

@ -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 {

View File

@ -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

View File

@ -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=

View File

@ -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"
)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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]

View File

@ -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,

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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]})

View File

@ -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(),
)
}

View File

@ -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(),
)
}

View File

@ -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]

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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]

View File

@ -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 => ../../.