chore: all: use golang.org/x/exp/maps.(Keys, Values) where necessary (#13349)
Uses golang.org/x/exp/maps.(Keys, Values) to sort out flagged potential non-determinism issues due to map iteration which is randomized in maps. These were flagged by cosmos/gosec in * https://github.com/cosmos/cosmos-sdk/security/code-scanning/724 * https://github.com/cosmos/cosmos-sdk/security/code-scanning/725 * https://github.com/cosmos/cosmos-sdk/security/code-scanning/726 * https://github.com/cosmos/cosmos-sdk/security/code-scanning/727 * https://github.com/cosmos/cosmos-sdk/security/code-scanning/728 * https://github.com/cosmos/cosmos-sdk/security/code-scanning/729 * https://github.com/cosmos/cosmos-sdk/security/code-scanning/782 * https://github.com/cosmos/cosmos-sdk/security/code-scanning/813 * https://github.com/cosmos/cosmos-sdk/security/code-scanning/814 * https://github.com/cosmos/cosmos-sdk/security/code-scanning/816 which complained about potential non-determinism in map iteration in which we only want appends in map iteration loops, this change instead uses golang.org/x/exp/maps.Keys to retrieve the keys then sort.Strings which simplifies the helper code. This change fixes issues in: * orm/model/ormdb: non-determinism in ExportJSON * store/internal/proofs * types/module * x/auth/keeper * x/bank * x/genutil/client/cli Fixes #13348
This commit is contained in:
+10
-11
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@@ -118,7 +119,8 @@ func (bm BasicManager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *
|
||||
// TODO: Remove clientCtx argument.
|
||||
// REF: https://github.com/cosmos/cosmos-sdk/issues/6571
|
||||
func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command) {
|
||||
for _, b := range bm {
|
||||
values := maps.Values(bm)
|
||||
for _, b := range values {
|
||||
if cmd := b.GetTxCmd(); cmd != nil {
|
||||
rootTxCmd.AddCommand(cmd)
|
||||
}
|
||||
@@ -130,7 +132,8 @@ func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command) {
|
||||
// TODO: Remove clientCtx argument.
|
||||
// REF: https://github.com/cosmos/cosmos-sdk/issues/6571
|
||||
func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) {
|
||||
for _, b := range bm {
|
||||
values := maps.Values(bm)
|
||||
for _, b := range values {
|
||||
if cmd := b.GetQueryCmd(); cmd != nil {
|
||||
rootQueryCmd.AddCommand(cmd)
|
||||
}
|
||||
@@ -271,14 +274,16 @@ func (m *Manager) SetOrderMigrations(moduleNames ...string) {
|
||||
|
||||
// RegisterInvariants registers all module invariants
|
||||
func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) {
|
||||
for _, module := range m.Modules {
|
||||
modules := maps.Values(m.Modules)
|
||||
for _, module := range modules {
|
||||
module.RegisterInvariants(ir)
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterServices registers all module services
|
||||
func (m *Manager) RegisterServices(cfg Configurator) {
|
||||
for _, module := range m.Modules {
|
||||
modules := maps.Values(m.Modules)
|
||||
for _, module := range modules {
|
||||
module.RegisterServices(cfg)
|
||||
}
|
||||
}
|
||||
@@ -511,13 +516,7 @@ func (m *Manager) GetVersionMap() VersionMap {
|
||||
|
||||
// ModuleNames returns list of all module names, without any particular order.
|
||||
func (m *Manager) ModuleNames() []string {
|
||||
ms := make([]string, len(m.Modules))
|
||||
i := 0
|
||||
for m := range m.Modules {
|
||||
ms[i] = m
|
||||
i++
|
||||
}
|
||||
return ms
|
||||
return maps.Keys(m.Modules)
|
||||
}
|
||||
|
||||
// DefaultMigrationsOrder returns a default migrations order: ascending alphabetical by module name,
|
||||
|
||||
Reference in New Issue
Block a user