Skip to content

Commit

Permalink
Adding ICA Host module (#1564)
Browse files Browse the repository at this point in the history
(cherry picked from commit 09f3184)

# Conflicts:
#	app/upgrades/v9/constants.go
#	app/upgrades/v9/upgrades.go
  • Loading branch information
ValarDragon authored and mergify[bot] committed May 25, 2022
1 parent e0ab1db commit 61c9309
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 4 deletions.
26 changes: 25 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -108,6 +114,7 @@ type AppKeepers struct {
GovKeeper *govkeeper.Keeper
WasmKeeper *wasm.Keeper
TokenFactoryKeeper *tokenfactorykeeper.Keeper
// IBC modules
// transfer module
TransferModule transfer.AppModule

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -503,6 +526,7 @@ func KVStoreKeys() []string {
govtypes.StoreKey,
paramstypes.StoreKey,
ibchost.StoreKey,
icahosttypes.StoreKey,
upgradetypes.StoreKey,
evidencetypes.StoreKey,
ibctransfertypes.StoreKey,
Expand Down
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -154,6 +160,7 @@ func orderBeginBlockers() []string {
stakingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
govtypes.ModuleName,
Expand Down Expand Up @@ -199,6 +206,7 @@ var modulesOrderInitGenesis = []string{
minttypes.ModuleName,
crisistypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
gammtypes.ModuleName,
txfeestypes.ModuleName,
genutiltypes.ModuleName,
Expand Down
8 changes: 7 additions & 1 deletion app/upgrades/v9/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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},
},
}
58 changes: 58 additions & 0 deletions app/upgrades/v9/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -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()
})
}
}
62 changes: 60 additions & 2 deletions app/upgrades/v9/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,76 @@ 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(
mm *module.Manager,
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)
}
}

0 comments on commit 61c9309

Please sign in to comment.