From 61c930946b46682b57453b899f47737cd66a1b7d Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Wed, 25 May 2022 03:04:43 +0200 Subject: [PATCH] Adding ICA Host module (#1564) (cherry picked from commit 09f3184b47bcaf498fcabd46d4ea60a2cdde4e8b) # Conflicts: # app/upgrades/v9/constants.go # app/upgrades/v9/upgrades.go --- app/keepers/keepers.go | 26 +++++++++++++- app/modules.go | 8 +++++ app/upgrades/v9/constants.go | 8 ++++- app/upgrades/v9/upgrade_test.go | 58 ++++++++++++++++++++++++++++++ app/upgrades/v9/upgrades.go | 62 +++++++++++++++++++++++++++++++-- 5 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 app/upgrades/v9/upgrade_test.go diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index ba60ea78d9e..3eca80b162c 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -32,6 +32,10 @@ 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" + + 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" ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" ibcclient "github.com/cosmos/ibc-go/v3/modules/core/02-client" @@ -82,6 +86,7 @@ type AppKeepers struct { // make scoped keepers public for test purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedICAHostKeeper capabilitykeeper.ScopedKeeper ScopedTransferKeeper capabilitykeeper.ScopedKeeper ScopedWasmKeeper capabilitykeeper.ScopedKeeper @@ -93,6 +98,7 @@ type AppKeepers struct { DistrKeeper *distrkeeper.Keeper SlashingKeeper *slashingkeeper.Keeper IBCKeeper *ibckeeper.Keeper + ICAHostKeeper *icahostkeeper.Keeper TransferKeeper *ibctransferkeeper.Keeper Bech32IBCKeeper *bech32ibckeeper.Keeper Bech32ICS20Keeper *bech32ics20keeper.Keeper @@ -108,6 +114,7 @@ type AppKeepers struct { GovKeeper *govkeeper.Keeper WasmKeeper *wasm.Keeper TokenFactoryKeeper *tokenfactorykeeper.Keeper + // IBC modules // transfer module TransferModule transfer.AppModule @@ -206,9 +213,22 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appKeepers.TransferModule = transfer.NewAppModule(*appKeepers.TransferKeeper) transferIBCModule := transfer.NewIBCModule(*appKeepers.TransferKeeper) + icaHostKeeper := icahostkeeper.NewKeeper( + appCodec, appKeepers.keys[icahosttypes.StoreKey], + appKeepers.GetSubspace(icahosttypes.SubModuleName), + appKeepers.IBCKeeper.ChannelKeeper, + &appKeepers.IBCKeeper.PortKeeper, + appKeepers.AccountKeeper, + appKeepers.ScopedICAHostKeeper, + bApp.MsgServiceRouter(), + ) + 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(ibctransfertypes.ModuleName, transferIBCModule) + ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule). + AddRoute(ibctransfertypes.ModuleName, transferIBCModule) // Note: the sealing is done after creating wasmd and wiring that up appKeepers.Bech32IBCKeeper = bech32ibckeeper.NewKeeper( @@ -389,6 +409,7 @@ func (appKeepers *AppKeepers) InitSpecialKeepers( // add capability keeper and ScopeToModule for ibc module 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.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) appKeepers.ScopedWasmKeeper = appKeepers.CapabilityKeeper.ScopeToModule(wasm.ModuleName) appKeepers.CapabilityKeeper.Seal() @@ -424,6 +445,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(icahosttypes.SubModuleName) paramsKeeper.Subspace(incentivestypes.ModuleName) paramsKeeper.Subspace(poolincentivestypes.ModuleName) paramsKeeper.Subspace(superfluidtypes.ModuleName) @@ -492,6 +514,7 @@ func (appKeepers *AppKeepers) SetupHooks() { ) } +// TODO: We need to automate this, by bundling with a module struct... func KVStoreKeys() []string { return []string{ authtypes.StoreKey, @@ -503,6 +526,7 @@ func KVStoreKeys() []string { govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, + icahosttypes.StoreKey, upgradetypes.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, diff --git a/app/modules.go b/app/modules.go index 5deda9358ba..44018b44189 100644 --- a/app/modules.go +++ b/app/modules.go @@ -5,6 +5,9 @@ import ( ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v3/modules/core" ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host" + + ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts" + icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" "github.com/osmosis-labs/bech32-ibc/x/bech32ibc" bech32ibctypes "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/types" "github.com/osmosis-labs/bech32-ibc/x/bech32ics20" @@ -64,9 +67,11 @@ import ( ) // moduleAccountPermissions defines module account permissions +// TODO: Having to input nil's here is unacceptable, we need a way to automatically derive this. var moduleAccountPermissions = map[string][]string{ authtypes.FeeCollectorName: nil, distrtypes.ModuleName: nil, + icatypes.ModuleName: nil, minttypes.ModuleName: {authtypes.Minter, authtypes.Burner}, minttypes.DeveloperVestingModuleAcctName: nil, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, @@ -114,6 +119,7 @@ func appModules( evidence.NewAppModule(*app.EvidenceKeeper), authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), + ica.NewAppModule(nil, app.ICAHostKeeper), params.NewAppModule(*app.ParamsKeeper), app.TransferModule, gamm.NewAppModule(appCodec, *app.GAMMKeeper, app.AccountKeeper, app.BankKeeper), @@ -154,6 +160,7 @@ func orderBeginBlockers() []string { stakingtypes.ModuleName, ibchost.ModuleName, ibctransfertypes.ModuleName, + icatypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, @@ -199,6 +206,7 @@ var modulesOrderInitGenesis = []string{ minttypes.ModuleName, crisistypes.ModuleName, ibchost.ModuleName, + icatypes.ModuleName, gammtypes.ModuleName, txfeestypes.ModuleName, genutiltypes.ModuleName, diff --git a/app/upgrades/v9/constants.go b/app/upgrades/v9/constants.go index c808503e0a1..49b5bdea0b2 100644 --- a/app/upgrades/v9/constants.go +++ b/app/upgrades/v9/constants.go @@ -5,7 +5,13 @@ import ( store "github.com/cosmos/cosmos-sdk/store/types" +<<<<<<< HEAD tokenfactorytypes "github.com/osmosis-labs/osmosis/v9/x/tokenfactory/types" +======= + icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types" + + tokenfactorytypes "github.com/osmosis-labs/osmosis/v7/x/tokenfactory/types" +>>>>>>> 09f3184 (Adding ICA Host module (#1564)) ) // UpgradeName defines the on-chain upgrade name for the Osmosis v9 upgrade. @@ -19,7 +25,7 @@ var Upgrade = upgrades.Upgrade{ UpgradeName: UpgradeName, CreateUpgradeHandler: CreateUpgradeHandler, StoreUpgrades: store.StoreUpgrades{ - Added: []string{tokenfactorytypes.ModuleName}, + Added: []string{tokenfactorytypes.ModuleName, icahosttypes.StoreKey}, Deleted: []string{ClaimsModuleName}, }, } diff --git a/app/upgrades/v9/upgrade_test.go b/app/upgrades/v9/upgrade_test.go new file mode 100644 index 00000000000..2fa4fbcec6f --- /dev/null +++ b/app/upgrades/v9/upgrade_test.go @@ -0,0 +1,58 @@ +package v9_test + +import ( + "fmt" + + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + abci "github.com/tendermint/tendermint/abci/types" +) + +const dummyUpgradeHeight = 5 + +func (suite *UpgradeTestSuite) TestUpgradePayments() { + testCases := []struct { + msg string + pre_update func() + update func() + post_update func() + expPass bool + }{ + { + "Test that upgrade does not panic", + func() { + // Create pool 1 + suite.PrepareBalancerPool() + }, + func() { + // run upgrade + // TODO: Refactor this all into a helper fn + suite.Ctx = suite.Ctx.WithBlockHeight(dummyUpgradeHeight - 1) + plan := upgradetypes.Plan{Name: "v9", Height: dummyUpgradeHeight} + err := suite.App.UpgradeKeeper.ScheduleUpgrade(suite.Ctx, plan) + suite.Require().NoError(err) + plan, exists := suite.App.UpgradeKeeper.GetUpgradePlan(suite.Ctx) + suite.Require().True(exists) + + suite.Ctx = suite.Ctx.WithBlockHeight(dummyUpgradeHeight) + suite.Require().NotPanics(func() { + beginBlockRequest := abci.RequestBeginBlock{} + suite.App.BeginBlocker(suite.Ctx, beginBlockRequest) + }) + }, + func() { + + }, + true, + }, + } + + for _, tc := range testCases { + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() // reset + + tc.pre_update() + tc.update() + tc.post_update() + }) + } +} diff --git a/app/upgrades/v9/upgrades.go b/app/upgrades/v9/upgrades.go index 7684dc485d6..7c9e651a68e 100644 --- a/app/upgrades/v9/upgrades.go +++ b/app/upgrades/v9/upgrades.go @@ -3,9 +3,25 @@ package v9 import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/authz" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +<<<<<<< HEAD "github.com/osmosis-labs/osmosis/v9/app/keepers" +======= + gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types" + + ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts" + icacontrollertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types" + 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" + + "github.com/osmosis-labs/osmosis/v7/app/keepers" +>>>>>>> 09f3184 (Adding ICA Host module (#1564)) ) func CreateUpgradeHandler( @@ -13,8 +29,50 @@ func CreateUpgradeHandler( configurator module.Configurator, keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { ExecuteProp214(ctx, keepers.GAMMKeeper) - return mm.RunMigrations(ctx, configurator, vm) + + // Add Interchain Accounts host module + // set the ICS27 consensus version so InitGenesis is not run + fromVM[icatypes.ModuleName] = mm.Modules[icatypes.ModuleName].ConsensusVersion() + + // create ICS27 Controller submodule params, controller module not enabled. + controllerParams := icacontrollertypes.Params{} + + // create ICS27 Host submodule params + hostParams := icahosttypes.Params{ + HostEnabled: true, + AllowMessages: []string{ + sdk.MsgTypeURL(&banktypes.MsgSend{}), + sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}), + sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}), + sdk.MsgTypeURL(&distrtypes.MsgWithdrawDelegatorReward{}), + sdk.MsgTypeURL(&distrtypes.MsgSetWithdrawAddress{}), + sdk.MsgTypeURL(&distrtypes.MsgWithdrawValidatorCommission{}), + sdk.MsgTypeURL(&distrtypes.MsgFundCommunityPool{}), + sdk.MsgTypeURL(&govtypes.MsgVote{}), + sdk.MsgTypeURL(&authz.MsgExec{}), + sdk.MsgTypeURL(&authz.MsgGrant{}), + sdk.MsgTypeURL(&authz.MsgRevoke{}), + sdk.MsgTypeURL(&gammtypes.MsgJoinPool{}), + sdk.MsgTypeURL(&gammtypes.MsgExitPool{}), + sdk.MsgTypeURL(&gammtypes.MsgSwapExactAmountIn{}), + sdk.MsgTypeURL(&gammtypes.MsgSwapExactAmountOut{}), + sdk.MsgTypeURL(&gammtypes.MsgJoinSwapExternAmountIn{}), + sdk.MsgTypeURL(&gammtypes.MsgJoinSwapShareAmountOut{}), + sdk.MsgTypeURL(&gammtypes.MsgExitSwapExternAmountOut{}), + sdk.MsgTypeURL(&gammtypes.MsgExitSwapShareAmountIn{}), + }, + } + + // initialize ICS27 module + icamodule, correctTypecast := mm.Modules[icatypes.ModuleName].(ica.AppModule) + if !correctTypecast { + panic("mm.Modules[icatypes.ModuleName] is not of type ica.AppModule") + } + icamodule.InitModule(ctx, controllerParams, hostParams) + return mm.RunMigrations(ctx, configurator, fromVM) } }