Skip to content

Commit

Permalink
refactor: remove x/exp dep (#21281)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Aug 19, 2024
1 parent 294b608 commit 6f30de3
Show file tree
Hide file tree
Showing 37 changed files with 115 additions and 122 deletions.
7 changes: 3 additions & 4 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"context"
"errors"
"fmt"
"maps"
"math"
"sort"
"slices"
"strconv"
"sync"

Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/v2/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion runtime/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions runtime/v2/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions scripts/dep-assert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
5 changes: 3 additions & 2 deletions server/v2/api/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions server/v2/stf/core_event_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion server/v2/stf/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
8 changes: 3 additions & 5 deletions store/v2/commitment/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion store/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions store/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion tests/systemtests/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"testing"
"time"

"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"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/systemtests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/systemtests/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"io"
"maps"
"os"
"os/exec"
"path/filepath"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tools/confix/cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions tools/confix/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/confix/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 6f30de3

Please sign in to comment.