Skip to content

Commit 5e8d30b

Browse files
committed
feat: cosmwasm
Signed-off-by: Artur Troian <[email protected]>
1 parent 26cf5ae commit 5e8d30b

File tree

5 files changed

+189
-56
lines changed

5 files changed

+189
-56
lines changed

app/app.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path/filepath"
99
"time"
1010

11+
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
1112
"github.com/gorilla/mux"
1213
"github.com/rakyll/statik/fs"
1314
"github.com/spf13/cast"
@@ -27,6 +28,7 @@ import (
2728
evidencetypes "cosmossdk.io/x/evidence/types"
2829
"cosmossdk.io/x/feegrant"
2930
upgradetypes "cosmossdk.io/x/upgrade/types"
31+
"github.com/CosmWasm/wasmd/x/wasm"
3032
dbm "github.com/cosmos/cosmos-db"
3133
"github.com/cosmos/cosmos-sdk/baseapp"
3234
"github.com/cosmos/cosmos-sdk/client"
@@ -56,6 +58,7 @@ import (
5658
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
5759
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
5860
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
61+
ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
5962
transfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
6063
ibchost "github.com/cosmos/ibc-go/v10/modules/core/exported"
6164
ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"
@@ -142,6 +145,19 @@ func NewApp(
142145
invCheckPeriod: invCheckPeriod,
143146
}
144147

148+
wasmDir := filepath.Join(homePath, "wasm")
149+
ibcWasmConfig := ibcwasmtypes.WasmConfig{
150+
DataDir: filepath.Join(homePath, "ibc_08-wasm"),
151+
SupportedCapabilities: []string{"iterator", "stargate", "abort"},
152+
ContractDebugMode: false,
153+
}
154+
wasmConfig, err := wasm.ReadNodeConfig(appOpts)
155+
// Uncomment this for debugging contracts. In the future this could be made into a param passed by the tests
156+
// wasmConfig.ContractDebugMode = true
157+
if err != nil {
158+
panic(fmt.Sprintf("error while reading wasm config: %s", err))
159+
}
160+
145161
app.InitSpecialKeepers(
146162
app.cdc,
147163
aminoCdc,
@@ -288,6 +304,8 @@ func orderBeginBlockers(_ []string) []string {
288304
ibctm.ModuleName,
289305
ibchost.ModuleName,
290306
feegrant.ModuleName,
307+
// wasm after ibc transfer
308+
wasmtypes.ModuleName,
291309
}
292310
}
293311

@@ -317,6 +335,8 @@ func OrderEndBlockers(_ []string) []string {
317335
transfertypes.ModuleName,
318336
ibchost.ModuleName,
319337
feegrant.ModuleName,
338+
// wasm after ibc transfer
339+
wasmtypes.ModuleName,
320340
}
321341
}
322342

app/modules.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"cosmossdk.io/x/evidence"
55
feegrantmodule "cosmossdk.io/x/feegrant/module"
66
"cosmossdk.io/x/upgrade"
7+
"github.com/CosmWasm/wasmd/x/wasm"
78
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
89
"github.com/cosmos/cosmos-sdk/types/module"
910
"github.com/cosmos/cosmos-sdk/x/auth"
@@ -190,6 +191,15 @@ func appModules(
190191
app.cdc,
191192
app.Keepers.Akash.Cert,
192193
),
194+
wasm.NewAppModule(
195+
app.cdc,
196+
app.Keepers.External.Wasm,
197+
app.Keepers.Cosmos.Staking,
198+
app.Keepers.Cosmos.Acct,
199+
app.Keepers.Cosmos.Bank,
200+
app.MsgServiceRouter(),
201+
nil,
202+
),
193203
}
194204
}
195205

app/types/app.go

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
1515
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
1616
upgradetypes "cosmossdk.io/x/upgrade/types"
17+
"github.com/CosmWasm/wasmd/x/wasm"
18+
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
19+
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
1720
"github.com/cosmos/cosmos-sdk/baseapp"
1821
"github.com/cosmos/cosmos-sdk/codec"
1922
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
@@ -45,23 +48,29 @@ import (
4548
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
4649
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
4750
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
51+
icacontroller "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller"
52+
icacontrollerkeeper "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/keeper"
4853
icacontrollertypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/types"
54+
icahostkeeper "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/host/keeper"
4955
icahosttypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/host/types"
56+
ibccallbacks "github.com/cosmos/ibc-go/v10/modules/apps/callbacks"
5057
"github.com/cosmos/ibc-go/v10/modules/apps/transfer"
5158
ibctransferkeeper "github.com/cosmos/ibc-go/v10/modules/apps/transfer/keeper"
5259
ibctransfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
60+
transferv2 "github.com/cosmos/ibc-go/v10/modules/apps/transfer/v2"
5361
ibcclienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
5462
ibcconnectiontypes "github.com/cosmos/ibc-go/v10/modules/core/03-connection/types"
5563
porttypes "github.com/cosmos/ibc-go/v10/modules/core/05-port/types"
64+
ibcapi "github.com/cosmos/ibc-go/v10/modules/core/api"
5665
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
5766
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"
5867
ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"
59-
emodule "pkg.akt.dev/go/node/escrow/module"
6068

6169
atypes "pkg.akt.dev/go/node/audit/v1"
6270
ctypes "pkg.akt.dev/go/node/cert/v1"
6371
dtypes "pkg.akt.dev/go/node/deployment/v1"
6472
dv1beta "pkg.akt.dev/go/node/deployment/v1beta3"
73+
emodule "pkg.akt.dev/go/node/escrow/module"
6574
agovtypes "pkg.akt.dev/go/node/gov/v1beta3"
6675
mtypes "pkg.akt.dev/go/node/market/v1beta4"
6776
ptypes "pkg.akt.dev/go/node/provider/v1beta4"
@@ -103,6 +112,8 @@ type AppKeepers struct {
103112
IBC *ibckeeper.Keeper
104113
Evidence *evidencekeeper.Keeper
105114
Transfer ibctransferkeeper.Keeper
115+
ICAController icacontrollerkeeper.Keeper
116+
ICAHost icahostkeeper.Keeper
106117
}
107118

108119
Akash struct {
@@ -115,6 +126,10 @@ type AppKeepers struct {
115126
Cert ckeeper.Keeper
116127
}
117128

129+
External struct {
130+
Wasm *wasmkeeper.Keeper
131+
}
132+
118133
Modules struct {
119134
TMLight ibctm.LightClientModule
120135
}
@@ -238,6 +253,9 @@ func (app *App) InitNormalKeepers(
238253
encodingConfig sdkutil.EncodingConfig,
239254
bApp *baseapp.BaseApp,
240255
maccPerms map[string][]string,
256+
wasmDir string,
257+
wasmConfig wasmtypes.NodeConfig,
258+
wasmOpts []wasmkeeper.Option,
241259
blockedAddresses map[string]bool,
242260
invCheckPeriod uint,
243261
) {
@@ -386,14 +404,6 @@ func (app *App) InitNormalKeepers(
386404
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
387405
)
388406

389-
transferIBCModule := transfer.NewIBCModule(app.Keepers.Cosmos.Transfer)
390-
391-
// Create static IBC router, add transfer route, then set and seal it
392-
ibcRouter := porttypes.NewRouter()
393-
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
394-
395-
app.Keepers.Cosmos.IBC.SetRouter(ibcRouter)
396-
397407
/// Light client modules
398408
clientKeeper := app.Keepers.Cosmos.IBC.ClientKeeper
399409
storeProvider := app.Keepers.Cosmos.IBC.ClientKeeper.GetStoreProvider()
@@ -444,6 +454,70 @@ func (app *App) InitNormalKeepers(
444454
cdc,
445455
app.keys[ctypes.StoreKey],
446456
)
457+
458+
// The last arguments can contain custom message handlers, and custom query handlers,
459+
// if we want to allow any custom callbacks
460+
// The last arguments can contain custom message handlers, and custom query handlers,
461+
// if we want to allow any custom callbacks
462+
wasmCapabilities := wasmkeeper.BuiltInCapabilities()
463+
wasmCapabilities = append(wasmCapabilities, "akash")
464+
465+
wasmKeeper := wasmkeeper.NewKeeper(
466+
cdc,
467+
runtime.NewKVStoreService(app.keys[wasmtypes.StoreKey]),
468+
app.Keepers.Cosmos.Acct,
469+
app.Keepers.Cosmos.Bank,
470+
*app.Keepers.Cosmos.Staking,
471+
distrkeeper.NewQuerier(app.Keepers.Cosmos.Distr),
472+
app.Keepers.Cosmos.IBC.ChannelKeeper,
473+
app.Keepers.Cosmos.IBC.ChannelKeeper,
474+
app.Keepers.Cosmos.IBC.ChannelKeeperV2,
475+
app.Keepers.Cosmos.Transfer,
476+
bApp.MsgServiceRouter(),
477+
bApp.GRPCQueryRouter(),
478+
wasmDir,
479+
wasmConfig,
480+
wasmtypes.VMConfig{},
481+
wasmCapabilities,
482+
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
483+
wasmOpts...,
484+
)
485+
app.Keepers.External.Wasm = &wasmKeeper
486+
487+
// Create fee enabled wasm ibc Stack
488+
wasmStackIBCHandler := wasm.NewIBCHandler(app.Keepers.External.Wasm, app.Keepers.Cosmos.IBC.ChannelKeeper, app.Keepers.Cosmos.Transfer, app.Keepers.Cosmos.IBC.ChannelKeeper)
489+
490+
// Create Interchain Accounts Stack
491+
// SendPacket, since it is originating from the application to core IBC:
492+
// icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket
493+
var icaControllerStack porttypes.IBCModule
494+
// integration point for custom authentication modules
495+
// sees https://medium.com/the-interchain-foundation/ibc-go-v6-changes-to-interchain-accounts-and-how-it-impacts-your-chain-806c185300d7
496+
var noAuthzModule porttypes.IBCModule
497+
icaControllerStack = icacontroller.NewIBCMiddlewareWithAuth(noAuthzModule, app.Keepers.Cosmos.ICAController)
498+
// app.ICAAuthModule = icaControllerStack.(ibcmock.IBCModule)
499+
icaControllerStack = icacontroller.NewIBCMiddlewareWithAuth(icaControllerStack, app.Keepers.Cosmos.ICAController)
500+
icaControllerStack = ibccallbacks.NewIBCMiddleware(icaControllerStack, app.Keepers.Cosmos.IBC.ChannelKeeper, wasmStackIBCHandler, wasm.DefaultMaxIBCCallbackGas)
501+
icaICS4Wrapper := icaControllerStack.(porttypes.ICS4Wrapper)
502+
// Since the callback middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper
503+
app.Keepers.Cosmos.ICAController.WithICS4Wrapper(icaICS4Wrapper)
504+
505+
transferIBCModule := transfer.NewIBCModule(app.Keepers.Cosmos.Transfer)
506+
507+
// Create static IBC router, add transfer route, then set and seal it
508+
ibcRouter := porttypes.NewRouter()
509+
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
510+
ibcRouter.AddRoute(wasmtypes.ModuleName, wasmStackIBCHandler)
511+
512+
app.Keepers.Cosmos.IBC.SetRouter(ibcRouter)
513+
514+
ibcRouterV2 := ibcapi.NewRouter()
515+
ibcRouterV2 = ibcRouterV2.
516+
AddRoute(ibctransfertypes.PortID, transferv2.NewIBCModule(app.Keepers.Cosmos.Transfer)).
517+
AddPrefixRoute(wasmkeeper.PortIDPrefixV2, wasmkeeper.NewIBC2Handler(app.Keepers.External.Wasm))
518+
519+
app.Keepers.Cosmos.IBC.SetRouterV2(ibcRouterV2)
520+
447521
}
448522

449523
func (app *App) SetupHooks() {
@@ -517,6 +591,8 @@ func kvStoreKeys() []string {
517591
upgradetypes.StoreKey,
518592
evidencetypes.StoreKey,
519593
ibctransfertypes.StoreKey,
594+
// wasm after ibc transfer
595+
wasmtypes.ModuleName,
520596
}
521597

522598
keys = append(keys, akashKVStoreKeys()...)

0 commit comments

Comments
 (0)