From 17488055f8c1ac13abce0d8edbe3e3e9c20ebcc0 Mon Sep 17 00:00:00 2001 From: Arnaud Mimart <33665250+amimart@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:55:06 +0200 Subject: [PATCH] feat(app): update application init --- app/app.go | 64 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/app/app.go b/app/app.go index 9e99b2096..237de3489 100644 --- a/app/app.go +++ b/app/app.go @@ -4,28 +4,25 @@ import ( "context" "encoding/json" "fmt" + ibccallbacks "github.com/cosmos/ibc-go/modules/apps/callbacks" "io" "io/fs" "net/http" "os" "path/filepath" - "slices" "sort" "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + abci "github.com/cometbft/cometbft/abci/types" + tmos "github.com/cometbft/cometbft/libs/os" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/proto" "github.com/ignite/cli/ignite/pkg/openapiconsole" "github.com/prometheus/client_golang/prometheus" "github.com/spf13/cast" - "google.golang.org/protobuf/reflect/protodesc" - "google.golang.org/protobuf/types/descriptorpb" - - abci "github.com/cometbft/cometbft/abci/types" - tmos "github.com/cometbft/cometbft/libs/os" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" @@ -486,13 +483,14 @@ func New( ) // Set legacy router for backwards compatibility with gov v1beta1 - app.GovKeeper.SetLegacyRouter(govRouter) + govKeeper.SetLegacyRouter(govRouter) app.GovKeeper = *govKeeper.SetHooks( govtypes.NewMultiGovHooks( // register the governance hooks ), ) + // Create IBC Keeper app.IBCKeeper = ibckeeper.NewKeeper( appCodec, @@ -504,6 +502,16 @@ func New( authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) + // IBC Fee Module keeper + app.IBCFeeKeeper = ibcfeekeeper.NewKeeper( + appCodec, keys[ibcfeetypes.StoreKey], + app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware + app.IBCKeeper.ChannelKeeper, + app.IBCKeeper.PortKeeper, + app.AccountKeeper, + app.BankKeeper, + ) + // Create Transfer Keepers app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, @@ -518,16 +526,6 @@ func New( authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - // IBC Fee Module keeper - app.IBCFeeKeeper = ibcfeekeeper.NewKeeper( - appCodec, keys[ibcfeetypes.StoreKey], - app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware - app.IBCKeeper.ChannelKeeper, - app.IBCKeeper.PortKeeper, - app.AccountKeeper, - app.BankKeeper, - ) - app.ICAHostKeeper = icahostkeeper.NewKeeper( appCodec, keys[icahosttypes.StoreKey], @@ -540,6 +538,8 @@ func New( app.MsgServiceRouter(), authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) + // set grpc router for ica host + app.ICAHostKeeper.WithQueryRouter(app.GRPCQueryRouter()) app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( appCodec, @@ -611,31 +611,43 @@ func New( wasmOpts..., ) - // Create Transfer Stack - var transferStack ibcporttypes.IBCModule - transferStack = transfer.NewIBCModule(app.TransferKeeper) - transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper) + // Create fee enabled wasm ibc Stack + var wasmStack ibcporttypes.IBCModule + wasmStackIBCHandler := wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper) + wasmStack = ibcfee.NewIBCMiddleware(wasmStackIBCHandler, 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 ibcporttypes.IBCModule + // integration point for custom authentication modules //nolint:lll // see https://medium.com/the-interchain-foundation/ibc-go-v6-changes-to-interchain-accounts-and-how-it-impacts-your-chain-806c185300d7 var noAuthzModule ibcporttypes.IBCModule icaControllerStack = icacontroller.NewIBCMiddleware(noAuthzModule, app.ICAControllerKeeper) + icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, app.ICAControllerKeeper) + icaControllerStack = ibccallbacks.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper, wasmStackIBCHandler, wasm.DefaultMaxIBCCallbackGas) + icaICS4Wrapper := icaControllerStack.(ibcporttypes.ICS4Wrapper) icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper) + // Since the callbacks middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper + app.ICAControllerKeeper.WithICS4Wrapper(icaICS4Wrapper) + // RecvPacket, message that originates from core IBC and goes down to app, the flow is: // channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket var icaHostStack ibcporttypes.IBCModule icaHostStack = icahost.NewIBCModule(app.ICAHostKeeper) icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper) - // Create fee enabled wasm ibc Stack - var wasmStack ibcporttypes.IBCModule - wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper) - wasmStack = ibcfee.NewIBCMiddleware(wasmStack, app.IBCFeeKeeper) + // Create Transfer Stack + var transferStack ibcporttypes.IBCModule + transferStack = transfer.NewIBCModule(app.TransferKeeper) + transferStack = ibccallbacks.NewIBCMiddleware(transferStack, app.IBCFeeKeeper, wasmStackIBCHandler, wasm.DefaultMaxIBCCallbackGas) + transferICS4Wrapper := transferStack.(ibcporttypes.ICS4Wrapper) + transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper) + // Since the callbacks middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper + app.TransferKeeper.WithICS4Wrapper(transferICS4Wrapper) // Create static IBC router, add transfer route, then set and seal it ibcRouter := ibcporttypes.NewRouter()