Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding runtime Environment #7587

Draft
wants to merge 4 commits into
base: marko/gomod_change
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types"
Expand Down Expand Up @@ -65,19 +64,16 @@ func (k Keeper) registerInterchainAccount(ctx context.Context, connectionID, por

k.setPort(ctx, portID)

sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223
msg := channeltypes.NewMsgChannelOpenInit(portID, version, ordering, []string{connectionID}, icatypes.HostPortID, authtypes.NewModuleAddress(icatypes.ModuleName).String())
handler := k.msgRouter.Handler(msg)
res, err := handler(sdkCtx, msg)
res, err := k.Environment.MsgRouterService.Invoke(ctx, msg)
if err != nil {
return "", err
}

firstMsgResponse := res.MsgResponses[0]
channelOpenInitResponse, ok := firstMsgResponse.GetCachedValue().(*channeltypes.MsgChannelOpenInitResponse)
chanOpenInitResp, ok := res.(*channeltypes.MsgChannelOpenInitResponse)
if !ok {
return "", errorsmod.Wrapf(ibcerrors.ErrInvalidType, "failed to convert %T message response to %T", firstMsgResponse.GetCachedValue(), &channeltypes.MsgChannelOpenInitResponse{})
return "", errorsmod.Wrapf(ibcerrors.ErrInvalidType, "failed to convert %T message response to %T", res, &channeltypes.MsgChannelOpenInitResponse{})
}

return channelOpenInitResponse.ChannelId, nil
return chanOpenInitResp.ChannelId, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"strings"

"cosmossdk.io/core/appmodule"
corestore "cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
Expand All @@ -28,6 +29,8 @@ import (

// Keeper defines the IBC interchain accounts controller keeper
type Keeper struct {
appmodule.Environment

storeService corestore.KVStoreService
cdc codec.Codec
legacySubspace icatypes.ParamSubspace
Expand All @@ -43,7 +46,7 @@ type Keeper struct {

// NewKeeper creates a new interchain accounts controller Keeper instance
func NewKeeper(
cdc codec.Codec, storeService corestore.KVStoreService, legacySubspace icatypes.ParamSubspace,
cdc codec.Codec, env appmodule.Environment, storeService corestore.KVStoreService, legacySubspace icatypes.ParamSubspace,
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper,
msgRouter icatypes.MessageRouter, authority string,
) Keeper {
Expand All @@ -52,6 +55,7 @@ func NewKeeper(
}

return Keeper{
Environment: env,
storeService: storeService,
cdc: cdc,
legacySubspace: legacySubspace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

testifysuite "github.com/stretchr/testify/suite"

"cosmossdk.io/log"
govtypes "cosmossdk.io/x/gov/types"

"github.com/cosmos/cosmos-sdk/runtime"
Expand Down Expand Up @@ -119,6 +120,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
{"success", func() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()),
runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)),
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
Expand All @@ -130,6 +132,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
{"failure: empty authority", func() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()),
runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)),
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package keeper_test
import (
"fmt"

"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/runtime"

icacontrollerkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
icacontrollertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
)

Expand All @@ -29,6 +32,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
func() {
suite.chainA.GetSimApp().ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
suite.chainA.Codec,
runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()),
runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(icacontrollertypes.StoreKey)),
nil, // assign a nil legacy param subspace
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package simulation_test

import (
codecaddress "github.com/cosmos/cosmos-sdk/codec/address"
"math/rand"
"testing"

"github.com/stretchr/testify/require"

codecaddress "github.com/cosmos/cosmos-sdk/codec/address"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
Expand Down
6 changes: 4 additions & 2 deletions modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,13 @@ func NewSimApp(

// ICA Controller keeper
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName),
appCodec,
runtime.NewEnvironment(runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), logger.With(log.ModuleKey, "x/icacontroller"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter())),
runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper,
app.MsgServiceRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)

// ICA Host keeper
Expand Down
4 changes: 3 additions & 1 deletion modules/core/simulation/proposals_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package simulation_test

import (
codecaddress "github.com/cosmos/cosmos-sdk/codec/address"
"math/rand"
"testing"
"time"

codecaddress "github.com/cosmos/cosmos-sdk/codec/address"

Check failure on line 8 in modules/core/simulation/proposals_test.go

View workflow job for this annotation

GitHub Actions / tests (03)

other declaration of codecaddress

"github.com/stretchr/testify/require"

codecaddress "github.com/cosmos/cosmos-sdk/codec/address"

Check failure on line 12 in modules/core/simulation/proposals_test.go

View workflow job for this annotation

GitHub Actions / tests (03)

codecaddress redeclared in this block

Check failure on line 12 in modules/core/simulation/proposals_test.go

View workflow job for this annotation

GitHub Actions / tests (03)

"github.com/cosmos/cosmos-sdk/codec/address" imported as codecaddress and not used
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
Expand Down
21 changes: 12 additions & 9 deletions modules/light-clients/08-wasm/testing/simapp/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package simapp

import (
"encoding/json"
"fmt"
"io"
"math/rand"
"os"
"path/filepath"
"strconv"

coreaddress "cosmossdk.io/core/address"
"cosmossdk.io/x/accounts/accountstd"
baseaccount "cosmossdk.io/x/accounts/defaults/base"
Expand All @@ -9,17 +17,10 @@ import (
epochstypes "cosmossdk.io/x/epochs/types"
nftkeeper "cosmossdk.io/x/nft/keeper"
txdecode "cosmossdk.io/x/tx/decode"
"encoding/json"
"fmt"
cmtcrypto "github.com/cometbft/cometbft/crypto"
cmted25519 "github.com/cometbft/cometbft/crypto/ed25519"
sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
"io"
"math/rand"
"os"
"path/filepath"
"strconv"

"github.com/cosmos/gogoproto/proto"
"github.com/spf13/cast"
Expand Down Expand Up @@ -559,11 +560,13 @@ func NewSimApp(

// ICA Controller keeper
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName),
appCodec,
runtime.NewEnvironment(runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), logger.With(log.ModuleKey, "x/icacontroller"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter())),
runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper,
app.MsgServiceRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)

// ICA Host keeper
Expand Down
57 changes: 29 additions & 28 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,11 @@ import (
"os"
"path/filepath"

epochskeeper "cosmossdk.io/x/epochs/keeper"
evidencekeeper "cosmossdk.io/x/evidence/keeper"

sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"

abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
cmtcrypto "github.com/cometbft/cometbft/crypto"
cmted25519 "github.com/cometbft/cometbft/crypto/ed25519"
"github.com/cosmos/gogoproto/proto"
"github.com/spf13/cast"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
baseaccount "cosmossdk.io/x/accounts/defaults/base"
"cosmossdk.io/x/circuit"
circuitkeeper "cosmossdk.io/x/circuit/keeper"
circuittypes "cosmossdk.io/x/circuit/types"
"cosmossdk.io/x/epochs"
"cosmossdk.io/x/evidence"
evidencetypes "cosmossdk.io/x/evidence/types"
"cosmossdk.io/x/feegrant"
feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
feegrantmodule "cosmossdk.io/x/feegrant/module"
groupkeeper "cosmossdk.io/x/group/keeper"
groupmodule "cosmossdk.io/x/group/module"
nftkeeper "cosmossdk.io/x/nft/keeper"
nftmodule "cosmossdk.io/x/nft/module"
"cosmossdk.io/x/protocolpool"
"github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx"

"cosmossdk.io/client/v2/autocli"
clienthelpers "cosmossdk.io/client/v2/helpers"
coreaddress "cosmossdk.io/core/address"
Expand All @@ -47,6 +21,7 @@ import (
storetypes "cosmossdk.io/store/types"
"cosmossdk.io/x/accounts"
"cosmossdk.io/x/accounts/accountstd"
baseaccount "cosmossdk.io/x/accounts/defaults/base"
lockup "cosmossdk.io/x/accounts/defaults/lockup"
"cosmossdk.io/x/accounts/defaults/multisig"
"cosmossdk.io/x/authz"
Expand All @@ -55,26 +30,42 @@ import (
"cosmossdk.io/x/bank"
bankkeeper "cosmossdk.io/x/bank/keeper"
banktypes "cosmossdk.io/x/bank/types"
"cosmossdk.io/x/circuit"
circuitkeeper "cosmossdk.io/x/circuit/keeper"
circuittypes "cosmossdk.io/x/circuit/types"
"cosmossdk.io/x/consensus"
consensusparamkeeper "cosmossdk.io/x/consensus/keeper"
consensustypes "cosmossdk.io/x/consensus/types"
distr "cosmossdk.io/x/distribution"
distrkeeper "cosmossdk.io/x/distribution/keeper"
distrtypes "cosmossdk.io/x/distribution/types"
"cosmossdk.io/x/epochs"
epochskeeper "cosmossdk.io/x/epochs/keeper"
epochstypes "cosmossdk.io/x/epochs/types"
"cosmossdk.io/x/evidence"
evidencekeeper "cosmossdk.io/x/evidence/keeper"
evidencetypes "cosmossdk.io/x/evidence/types"
"cosmossdk.io/x/feegrant"
feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
feegrantmodule "cosmossdk.io/x/feegrant/module"
"cosmossdk.io/x/gov"
govkeeper "cosmossdk.io/x/gov/keeper"
govtypes "cosmossdk.io/x/gov/types"
govv1beta1 "cosmossdk.io/x/gov/types/v1beta1"
"cosmossdk.io/x/group"
groupkeeper "cosmossdk.io/x/group/keeper"
groupmodule "cosmossdk.io/x/group/module"
"cosmossdk.io/x/mint"
mintkeeper "cosmossdk.io/x/mint/keeper"
minttypes "cosmossdk.io/x/mint/types"
"cosmossdk.io/x/nft"
nftkeeper "cosmossdk.io/x/nft/keeper"
nftmodule "cosmossdk.io/x/nft/module"
"cosmossdk.io/x/params"
paramskeeper "cosmossdk.io/x/params/keeper"
paramstypes "cosmossdk.io/x/params/types"
paramproposal "cosmossdk.io/x/params/types/proposal"
"cosmossdk.io/x/protocolpool"
poolkeeper "cosmossdk.io/x/protocolpool/keeper"
pooltypes "cosmossdk.io/x/protocolpool/types"
"cosmossdk.io/x/slashing"
Expand Down Expand Up @@ -108,19 +99,27 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/msgservice"
sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"

abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
cmtcrypto "github.com/cometbft/cometbft/crypto"
cmted25519 "github.com/cometbft/cometbft/crypto/ed25519"

ica "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper"
Expand Down Expand Up @@ -319,7 +318,7 @@ func NewSimApp(
// baseAppOptions = append(baseAppOptions, prepareOpt)

// create and set dummy vote extension handler
//voteExtOp := func(bApp *baseapp.BaseApp) {
// voteExtOp := func(bApp *baseapp.BaseApp) {
// voteExtHandler := NewVoteExtensionHandler()
// voteExtHandler.SetHandlers(bApp)
//}
Expand Down Expand Up @@ -539,7 +538,9 @@ func NewSimApp(

// ICA Controller keeper
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName),
appCodec,
runtime.NewEnvironment(runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), logger.With(log.ModuleKey, "x/icacontroller"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter())),
runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper,
app.MsgServiceRouter(),
Expand Down
4 changes: 2 additions & 2 deletions simapp/simd/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package cmd
import (
"strings"

cmtcfg "github.com/cometbft/cometbft/config"

clientconfig "github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"

cmtcfg "github.com/cometbft/cometbft/config"
)

// initCometBFTConfig helps to override default CometBFT Config values.
Expand Down
3 changes: 1 addition & 2 deletions testing/chain.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ibctesting

import (
"cosmossdk.io/core/header"
"fmt"
"testing"
"time"

"github.com/stretchr/testify/require"

"cosmossdk.io/core/header"
errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
banktypes "cosmossdk.io/x/bank/types"
Expand Down Expand Up @@ -199,7 +199,6 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {

// GetContext returns the current context for the application.
func (chain *TestChain) GetContext() sdk.Context {

ctx := chain.App.GetBaseApp().NewUncachedContext(false, chain.ProposedHeader)

// when fetching time from context, the header info time is used, rather than the proposed header.
Expand Down
Loading
Loading