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

Wasmd v0.27.0-rc0 integration #361

Merged
merged 2 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SIMAPP = ./app

# for dockerized protobuf tools
DOCKER := $(shell which docker)
BUF_IMAGE=bufbuild/buf@sha256:9dc5d6645f8f8a2d5aaafc8957fbbb5ea64eada98a84cb09654e8f49d6f73b3e
BUF_IMAGE=bufbuild/buf@sha256:3cb1f8a4b48bd5ad8f09168f10f607ddc318af202f5c057d52a45216793d85e5 # v1.4.0
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(BUF_IMAGE)
HTTPS_GIT := https://github.com/confiog/tgrade.git

Expand Down
14 changes: 8 additions & 6 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import (
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
channelkeeper "github.com/cosmos/ibc-go/v2/modules/core/04-channel/keeper"
ibcante "github.com/cosmos/ibc-go/v2/modules/core/ante"

poetypes "github.com/confio/tgrade/x/poe/types"
ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante"
ibcCoreKeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

"github.com/confio/tgrade/x/globalfee"
"github.com/confio/tgrade/x/poe"
poekeeper "github.com/confio/tgrade/x/poe/keeper"
poetypes "github.com/confio/tgrade/x/poe/types"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
Expand All @@ -29,7 +28,7 @@ type HandlerOptions struct {
SignModeHandler authsigning.SignModeHandler
SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params) error

IBCChannelkeeper channelkeeper.Keeper
IBCCoreKeeper *ibcCoreKeeper.Keeper
alpe marked this conversation as resolved.
Show resolved Hide resolved
WasmConfig *wasmtypes.WasmConfig
TXCounterStoreKey sdk.StoreKey
GlobalFeeSubspace paramtypes.Subspace
Expand Down Expand Up @@ -62,6 +61,9 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.ContractSource == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "contract source is required for ante builder")
}
if options.IBCCoreKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "ibc core keeper is required for ante builder")
}

var sigGasConsumer = options.SigGasConsumer
if sigGasConsumer == nil {
Expand All @@ -88,7 +90,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCChannelkeeper),
ibcante.NewAnteDecorator(options.IBCCoreKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
91 changes: 69 additions & 22 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"os"
"path/filepath"

poetypes "github.com/confio/tgrade/x/poe/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand Down Expand Up @@ -58,15 +57,20 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/ibc-go/v2/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v2/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v2/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v2/modules/core"
ibcclient "github.com/cosmos/ibc-go/v2/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"
ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts"
icahost "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
transfer "github.com/cosmos/ibc-go/v3/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v3/modules/core"
ibcclient "github.com/cosmos/ibc-go/v3/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand All @@ -82,6 +86,7 @@ import (
"github.com/confio/tgrade/x/poe"
poekeeper "github.com/confio/tgrade/x/poe/keeper"
poestakingadapter "github.com/confio/tgrade/x/poe/stakingadapter"
poetypes "github.com/confio/tgrade/x/poe/types"
"github.com/confio/tgrade/x/twasm"
twasmkeeper "github.com/confio/tgrade/x/twasm/keeper"

Expand Down Expand Up @@ -137,11 +142,13 @@ var (
vesting.AppModuleBasic{},
twasm.AppModuleBasic{},
globalfee.AppModuleBasic{},
ica.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
twasm.ModuleName: {authtypes.Minter, authtypes.Burner},
poetypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
}
Expand Down Expand Up @@ -179,12 +186,14 @@ type TgradeApp struct {
ibcKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
evidenceKeeper evidencekeeper.Keeper
transferKeeper ibctransferkeeper.Keeper
icaHostKeeper icahostkeeper.Keeper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once wasmd #848 is merged, you can add controller functionality as well

feeGrantKeeper feegrantkeeper.Keeper
authzKeeper authzkeeper.Keeper
twasmKeeper twasmkeeper.Keeper
poeKeeper poekeeper.Keeper

scopedIBCKeeper capabilitykeeper.ScopedKeeper
scopedICAHostKeeper capabilitykeeper.ScopedKeeper
scopedTransferKeeper capabilitykeeper.ScopedKeeper
scopedWasmKeeper capabilitykeeper.ScopedKeeper

Expand Down Expand Up @@ -225,7 +234,7 @@ func NewTgradeApp(
authtypes.StoreKey, banktypes.StoreKey,
paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, wasm.StoreKey, poe.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, wasm.StoreKey, poe.StoreKey, icahosttypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -258,6 +267,7 @@ func NewTgradeApp(
memKeys[capabilitytypes.MemStoreKey],
)
scopedIBCKeeper := app.capabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedICAHostKeeper := app.capabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedTransferKeeper := app.capabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.capabilityKeeper.ScopeToModule(twasm.ModuleName)
app.capabilityKeeper.Seal()
Expand Down Expand Up @@ -327,16 +337,27 @@ func NewTgradeApp(
keys[ibctransfertypes.StoreKey],
app.getSubspace(ibctransfertypes.ModuleName),
app.ibcKeeper.ChannelKeeper,
app.ibcKeeper.ChannelKeeper,
&app.ibcKeeper.PortKeeper,
app.accountKeeper,
app.bankKeeper,
scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.transferKeeper)
transferIBCModule := transfer.NewIBCModule(app.transferKeeper)

// create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
app.icaHostKeeper = icahostkeeper.NewKeeper(
appCodec,
keys[icahosttypes.StoreKey],
app.getSubspace(icahosttypes.SubModuleName),
app.ibcKeeper.ChannelKeeper,
&app.ibcKeeper.PortKeeper,
app.accountKeeper,
scopedICAHostKeeper,
app.MsgServiceRouter(),
)
icaModule := ica.NewAppModule(nil, &app.icaHostKeeper)
icaHostIBCModule := icahost.NewIBCModule(app.icaHostKeeper)

slashingAdapter := poestakingadapter.SlashingAdapter{}
// create evidence keeper with router
Expand Down Expand Up @@ -383,7 +404,13 @@ func NewTgradeApp(
)

govRouter.AddRoute(twasm.RouterKey, twasmkeeper.NewProposalHandler(app.twasmKeeper))
ibcRouter.AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.twasmKeeper, app.ibcKeeper.ChannelKeeper))

// Create static IBC router, add app routes, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.
AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.twasmKeeper, app.ibcKeeper.ChannelKeeper)).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule)
app.ibcKeeper.SetRouter(ibcRouter)

app.poeKeeper = poekeeper.NewKeeper(
Expand Down Expand Up @@ -422,6 +449,7 @@ func NewTgradeApp(
params.NewAppModule(app.paramsKeeper),
transferModule,
globalfee.NewAppModule(app.getSubspace(globalfee.ModuleName)),
icaModule,
crisis.NewAppModule(&app.crisisKeeper, skipGenesisInvariants),
)

Expand All @@ -443,6 +471,8 @@ func NewTgradeApp(
// additional non simd modules
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
poe.ModuleName,
twasm.ModuleName,
globalfee.ModuleName,
Expand All @@ -459,8 +489,9 @@ func NewTgradeApp(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
// additional non simd modules
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
globalfee.ModuleName,
twasm.ModuleName,
poe.ModuleName, // poe after twasm to have valset update at the end
Expand All @@ -485,8 +516,9 @@ func NewTgradeApp(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
// additional non simd modules
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
// wasm after ibc transfer
twasm.ModuleName,
// poe after wasm contract instantiation
Expand Down Expand Up @@ -534,7 +566,7 @@ func NewTgradeApp(
FeegrantKeeper: app.feeGrantKeeper,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
IBCChannelkeeper: app.ibcKeeper.ChannelKeeper,
IBCCoreKeeper: app.ibcKeeper,
WasmConfig: &twasmConfig.WasmConfig,
TXCounterStoreKey: keys[twasm.StoreKey],
GlobalFeeSubspace: app.getSubspace(globalfee.ModuleName),
Expand All @@ -550,6 +582,23 @@ func NewTgradeApp(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

// must be before Loading version
// requires the snapshot store to be created and registered as a BaseAppOption
// see cmd/wasmd/root.go: 206 - 214 approx
if manager := app.SnapshotManager(); manager != nil {
alpe marked this conversation as resolved.
Show resolved Hide resolved
err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.twasmKeeper.Keeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
}
}

app.scopedIBCKeeper = scopedIBCKeeper
app.scopedTransferKeeper = scopedTransferKeeper
app.scopedWasmKeeper = scopedWasmKeeper
app.scopedICAHostKeeper = scopedICAHostKeeper

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(fmt.Sprintf("failed to load latest version: %s", err))
Expand All @@ -562,9 +611,6 @@ func NewTgradeApp(
}
}

app.scopedIBCKeeper = scopedIBCKeeper
app.scopedTransferKeeper = scopedTransferKeeper
app.scopedWasmKeeper = scopedWasmKeeper
return app
}

Expand Down Expand Up @@ -694,6 +740,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(twasm.ModuleName)
paramsKeeper.Subspace(globalfee.ModuleName)
paramsKeeper.Subspace(poe.ModuleName)
Expand Down
6 changes: 3 additions & 3 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
ibcclienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -180,9 +180,9 @@ func TestIBCKeeperLazyInitialization(t *testing.T) {

// when
// https://github.com/cosmos/cosmos-sdk/blob/v0.42.9/x/ibc/core/02-client/keeper/keeper.go#L252
state, found := gapp.ibcKeeper.ClientKeeper.GetSelfConsensusState(ctx, height)
state, err := gapp.ibcKeeper.ClientKeeper.GetSelfConsensusState(ctx, height)
// then
require.True(t, found)
require.NoError(t, err)
assert.Equal(t, []byte("myAppHash"), state.GetRoot().GetHash())
assert.Equal(t, uint64(now.UnixNano()), state.GetTimestamp())
}
4 changes: 2 additions & 2 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/simulation"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctransfertypes "github.com/cosmos/ibc-go/v2/modules/apps/transfer/types"
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand Down
4 changes: 2 additions & 2 deletions app/test_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v2/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
)

type TestSupport struct {
Expand Down
26 changes: 16 additions & 10 deletions cmd/tgrade/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
"github.com/spf13/cast"
"github.com/spf13/cobra"
tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
Expand Down Expand Up @@ -294,18 +295,23 @@ func (ac appCreator) appExport(

// extendUnsafeResetAllCmd - also clear wasm dir
func extendUnsafeResetAllCmd(rootCmd *cobra.Command) {
unsafeResetCmd := server.UnsafeResetAllCmd().Use
for _, cmd := range rootCmd.Commands() {
if cmd.Use == unsafeResetCmd {
serverRunE := cmd.RunE
cmd.RunE = func(cmd *cobra.Command, args []string) error {
if err := serverRunE(cmd, args); err != nil {
return nil
unsafeResetCmd := tmcmd.ResetAllCmd.Use
for _, branchCmd := range rootCmd.Commands() {
if branchCmd.Use != "tendermint" {
continue
}
for _, cmd := range branchCmd.Commands() {
if cmd.Use == unsafeResetCmd {
serverRunE := cmd.RunE
cmd.RunE = func(cmd *cobra.Command, args []string) error {
if err := serverRunE(cmd, args); err != nil {
return nil
}
serverCtx := server.GetServerContextFromCmd(cmd)
return os.RemoveAll(filepath.Join(serverCtx.Config.RootDir, "wasm"))
}
serverCtx := server.GetServerContextFromCmd(cmd)
return os.RemoveAll(filepath.Join(serverCtx.Config.RootDir, "wasm"))
return
}
return
}
}
}
Expand Down
Loading