Skip to content

Commit

Permalink
feat: add wasm hooks v8
Browse files Browse the repository at this point in the history
  • Loading branch information
kienn6034 committed Mar 14, 2024
1 parent b838b6e commit 9c240e7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 40 deletions.
91 changes: 52 additions & 39 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/proto"
ibchooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8"
ibchookskeeper "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/keeper"
ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/types"
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
Expand Down Expand Up @@ -326,6 +328,7 @@ func NewEveApp(
capabilitytypes.StoreKey, ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey,
wasm08types.StoreKey, wasmtypes.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, tokenfactorytypes.StoreKey,
ibchookstypes.StoreKey,
)

tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -636,10 +639,53 @@ func NewEveApp(
// register slashing module StakingHooks to the consumer keeper
app.ConsumerKeeper = *app.ConsumerKeeper.SetHooks(app.SlashingKeeper.Hooks())

// Create Interchain Accounts Stack
// SendPacket, since it is originating from the application to core IBC:
// icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket
var icaControllerStack porttypes.IBCModule
// integration point for custom authentication modules
// see https://medium.com/the-interchain-foundation/ibc-go-v6-changes-to-interchain-accounts-and-how-it-impacts-your-chain-806c185300d7
var noAuthzModule porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(noAuthzModule, app.ICAControllerKeeper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)

// RecvPacket, message that originates from core IBC and goes down to app, the flow is:
// channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket
var icaHostStack porttypes.IBCModule
icaHostStack = icahost.NewIBCModule(app.ICAHostKeeper)
icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper)

// Transfer stack
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)

// Create fee enabled wasm ibc Stack
var wasmStack porttypes.IBCModule
wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper)
wasmStack = ibcfee.NewIBCMiddleware(wasmStack, app.IBCFeeKeeper)

// Create static IBC router, add app routes, then set and seal it
ibcRouter := porttypes.NewRouter().
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(wasmtypes.ModuleName, wasmStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(ccvconsumertypes.ModuleName, consumerModule)

app.IBCKeeper.SetRouter(ibcRouter)

app.IBCHooksKeeper = ibchookskeeper.NewKeeper(
keys[ibchookstypes.StoreKey],
)

ics20WasmHooks := ibchooks.NewWasmHooks(&app.IBCHooksKeeper, nil, sdk.GetConfig().GetBech32AccountAddrPrefix())
hooksICS4Wrapper := ibchooks.NewICS4Middleware(app.IBCKeeper.ChannelKeeper, ics20WasmHooks)

// IBC Fee Module keeper
app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
appCodec, keys[ibcfeetypes.StoreKey],
app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware
hooksICS4Wrapper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper,
)
Expand Down Expand Up @@ -710,44 +756,6 @@ func NewEveApp(
wasmOpts...,
)

// Create Transfer Stack
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)

// Create Interchain Accounts Stack
// SendPacket, since it is originating from the application to core IBC:
// icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket
var icaControllerStack porttypes.IBCModule
// integration point for custom authentication modules
// see https://medium.com/the-interchain-foundation/ibc-go-v6-changes-to-interchain-accounts-and-how-it-impacts-your-chain-806c185300d7
var noAuthzModule porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(noAuthzModule, app.ICAControllerKeeper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)

// RecvPacket, message that originates from core IBC and goes down to app, the flow is:
// channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket
var icaHostStack porttypes.IBCModule
icaHostStack = icahost.NewIBCModule(app.ICAHostKeeper)
icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper)

// Create fee enabled wasm ibc Stack
var wasmStack porttypes.IBCModule
wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper)
wasmStack = ibcfee.NewIBCMiddleware(wasmStack, app.IBCFeeKeeper)

// Create static IBC router, add app routes, then set and seal it
ibcRouter := porttypes.NewRouter().
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(wasmtypes.ModuleName, wasmStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(ccvconsumertypes.ModuleName, consumerModule)

app.IBCKeeper.SetRouter(ibcRouter)

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
// we prefer to be more strict in what arguments the modules expect.
skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))
Expand Down Expand Up @@ -838,6 +846,7 @@ func NewEveApp(
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
ibchookstypes.ModuleName,
wasm08types.ModuleName,
wasmtypes.ModuleName,
tokenfactorytypes.ModuleName,
Expand All @@ -857,6 +866,7 @@ func NewEveApp(
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
ibchookstypes.ModuleName,
wasm08types.ModuleName,
wasmtypes.ModuleName,
tokenfactorytypes.ModuleName,
Expand Down Expand Up @@ -898,8 +908,11 @@ func NewEveApp(
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,

ibchookstypes.ModuleName,
wasm08types.ModuleName,
// wasm after ibc transfer

wasmtypes.ModuleName,
tokenfactorytypes.ModuleName,
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ require (
cosmossdk.io/x/upgrade v0.1.1
github.com/cometbft/cometbft v0.38.5
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/ibc-apps/modules/ibc-hooks/v8 v8.0.0-00010101000000-000000000000
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240307202658-3f7320cd66dc
github.com/cosmos/ibc-go/v8 v8.1.0
Expand Down Expand Up @@ -218,10 +219,10 @@ replace (
// core v0.12 was tagged wrong (sdk51)
cosmossdk.io/core => cosmossdk.io/core v0.11.0
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/cosmos/ibc-go/modules/light-clients/08-wasm => github.com/notional-labs/ibc-go/modules/light-clients/08-wasm v0.0.0-20240314043527-f53cabfd50c0
// github.com/cosmos/ibc-go/v8 => github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240310203317-cf4b9b9ad758

github.com/cosmos/ibc-apps/modules/ibc-hooks/v8 => github.com/kienn6034/ibc-apps/modules/ibc-hooks/v8 v8.0.0-20240306102635-57b349e8fd83
github.com/cosmos/ibc-go/modules/light-clients/08-wasm => github.com/notional-labs/ibc-go/modules/light-clients/08-wasm v0.0.0-20240314043527-f53cabfd50c0
github.com/cosmos/interchain-security => /Users/hoank/resource/notional/interchain-security

// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kienn6034/ibc-apps/modules/ibc-hooks/v8 v8.0.0-20240306102635-57b349e8fd83 h1:kWaZJTdaH8CKRWqlDe73AHedySuwJYzif0qmPSJvEbY=
github.com/kienn6034/ibc-apps/modules/ibc-hooks/v8 v8.0.0-20240306102635-57b349e8fd83/go.mod h1:iNDPfR5e9QDRlcxa4AM5C2VeO678BhUfnfaLBNu2aFQ=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
Expand Down

0 comments on commit 9c240e7

Please sign in to comment.