Skip to content

Commit

Permalink
added ica controller
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslara committed Mar 25, 2024
1 parent 900c0a0 commit 03f586a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
56 changes: 40 additions & 16 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icq "github.com/cosmos/ibc-apps/modules/async-icq/v7"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types"

icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
appparams "github.com/osmosis-labs/osmosis/v23/app/params"
"github.com/osmosis-labs/osmosis/v23/x/cosmwasmpool"
cosmwasmpooltypes "github.com/osmosis-labs/osmosis/v23/x/cosmwasmpool/types"
Expand Down Expand Up @@ -126,11 +128,12 @@ type AppKeepers struct {
ConsensusParamsKeeper *consensusparamkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper
ScopedICQKeeper capabilitykeeper.ScopedKeeper
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper
ScopedICQKeeper capabilitykeeper.ScopedKeeper

// "Normal" keepers
AccountKeeper *authkeeper.AccountKeeper
Expand All @@ -143,6 +146,7 @@ type AppKeepers struct {
IBCKeeper *ibckeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
ICAHostKeeper *icahostkeeper.Keeper
ICAControllerKeeper *icacontrollerkeeper.Keeper
ICQKeeper *icqkeeper.Keeper
TransferKeeper *ibctransferkeeper.Keeper
IBCWasmClientKeeper *ibcwasmkeeper.Keeper
Expand Down Expand Up @@ -292,7 +296,6 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
icaHostKeeper := icahostkeeper.NewKeeper(
appCodec, appKeepers.keys[icahosttypes.StoreKey],
appKeepers.GetSubspace(icahosttypes.SubModuleName),
// UNFORKINGNOTE: I think it is correct to use rate limiting wrapper here
appKeepers.RateLimitingICS4Wrapper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
Expand All @@ -302,13 +305,25 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
)
appKeepers.ICAHostKeeper = &icaHostKeeper

icaHostIBCModule := icahost.NewIBCModule(*appKeepers.ICAHostKeeper)
// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
// The transferIBC module is replaced by rateLimitingTransferModule
AddRoute(ibctransfertypes.ModuleName, appKeepers.TransferStack)
// Note: the sealing is done after creating wasmd and wiring that up
icaControllerKeeper := icacontrollerkeeper.NewKeeper(
appCodec, appKeepers.keys[icacontrollertypes.StoreKey],
appKeepers.GetSubspace(icacontrollertypes.SubModuleName),
appKeepers.RateLimitingICS4Wrapper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedICAControllerKeeper,
bApp.MsgServiceRouter(),
)
appKeepers.ICAControllerKeeper = &icaControllerKeeper

// initialize ICA module with mock module as the authentication module on the controller side
var icaControllerStack porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, *appKeepers.ICAControllerKeeper)

// 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(*appKeepers.ICAHostKeeper)

// ICQ Keeper
icqKeeper := icqkeeper.NewKeeper(
Expand All @@ -326,8 +341,14 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
// Create Async ICQ module
icqModule := icq.NewIBCModule(*appKeepers.ICQKeeper)

// Add icq modules to IBC router
ibcRouter.AddRoute(icqtypes.ModuleName, icqModule)
// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack).
// The transferIBC module is replaced by rateLimitingTransferModule
AddRoute(ibctransfertypes.ModuleName, appKeepers.TransferStack).
// Add icq modules to IBC router
AddRoute(icqtypes.ModuleName, icqModule)
// Note: the sealing is done after creating wasmd and wiring that up

// create evidence keeper with router
Expand Down Expand Up @@ -676,6 +697,7 @@ func (appKeepers *AppKeepers) InitSpecialKeepers(
appKeepers.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, appKeepers.keys[capabilitytypes.StoreKey], appKeepers.memKeys[capabilitytypes.MemStoreKey])
appKeepers.ScopedIBCKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
appKeepers.ScopedICAControllerKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
appKeepers.ScopedWasmKeeper = appKeepers.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)
appKeepers.ScopedICQKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icqtypes.ModuleName)
Expand Down Expand Up @@ -714,6 +736,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())
paramsKeeper.Subspace(incentivestypes.ModuleName)
paramsKeeper.Subspace(lockuptypes.ModuleName)
paramsKeeper.Subspace(poolincentivestypes.ModuleName)
Expand Down Expand Up @@ -827,6 +850,7 @@ func KVStoreKeys() []string {
consensusparamtypes.StoreKey,
ibchost.StoreKey,
icahosttypes.StoreKey,
icacontrollertypes.StoreKey,
upgradetypes.StoreKey,
evidencetypes.StoreKey,
ibctransfertypes.StoreKey,
Expand Down
2 changes: 1 addition & 1 deletion app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func appModules(
authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ibc.NewAppModule(app.IBCKeeper),
ibcwasm.NewAppModule(*app.IBCWasmClientKeeper),
ica.NewAppModule(nil, app.ICAHostKeeper),
ica.NewAppModule(app.ICAControllerKeeper, app.ICAHostKeeper),
params.NewAppModule(*app.ParamsKeeper),
consensus.NewAppModule(appCodec, *app.AppKeepers.ConsensusParamsKeeper),
app.RawIcs20TransferAppModule,
Expand Down
4 changes: 4 additions & 0 deletions app/upgrades/v24/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"

"github.com/osmosis-labs/osmosis/v23/app/keepers"
"github.com/osmosis-labs/osmosis/v23/app/upgrades"
Expand Down Expand Up @@ -46,6 +47,9 @@ func CreateUpgradeHandler(
// https://www.mintscan.io/osmosis/proposals/733
keepers.IncentivesKeeper.SetParam(ctx, incentivestypes.KeyMinValueForDistr, incentivestypes.DefaultMinValueForDistr)

// Enable ICA controllers
keepers.ICAControllerKeeper.SetParams(ctx, icacontrollertypes.DefaultParams())

return migrations, nil
}
}

0 comments on commit 03f586a

Please sign in to comment.