Skip to content

Commit

Permalink
Added upgrade handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Dec 8, 2022
1 parent a7e0e79 commit fea81c7
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
27 changes: 26 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -80,6 +81,7 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibcica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts"
ibcicacontrollertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
ibcicahost "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host"
ibcicahostkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/keeper"
ibcicahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
Expand All @@ -103,6 +105,7 @@ import (
tmdb "github.com/tendermint/tm-db"

hubparams "github.com/sentinel-official/hub/params"
hubupgrades "github.com/sentinel-official/hub/upgrades"
deposittypes "github.com/sentinel-official/hub/x/deposit/types"
custommint "github.com/sentinel-official/hub/x/mint"
custommintkeeper "github.com/sentinel-official/hub/x/mint/keeper"
Expand Down Expand Up @@ -461,7 +464,7 @@ func NewApp(
authtypes.FeeCollectorName,
)

wasmDir := filepath.Join(homePath, "data")
wasmDir := filepath.Join(homePath, "wasm")

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
Expand Down Expand Up @@ -663,6 +666,28 @@ func NewApp(
}
}

app.upgradeKeeper.SetUpgradeHandler(
hubupgrades.Name,
hubupgrades.Handler(app.moduleManager, app.configurator, app.wasmKeeper),
)

upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

if upgradeInfo.Name == hubupgrades.Name && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
ibcicacontrollertypes.StoreKey,
ibcicahosttypes.StoreKey,
wasmtypes.ModuleName,
},
}

app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand Down
57 changes: 57 additions & 0 deletions upgrades/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package upgrades

import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
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"
distributiontypes "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"
ibcica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts"
ibcicacontrollertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
ibcicahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
ibcicatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
)

func Handler(mm *module.Manager, configurator module.Configurator, wasmKeeper wasmkeeper.Keeper) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
controllerParams := ibcicacontrollertypes.Params{}
hostParams := ibcicahosttypes.Params{
HostEnabled: true,
AllowMessages: []string{
sdk.MsgTypeURL(&authz.MsgExec{}),
sdk.MsgTypeURL(&authz.MsgGrant{}),
sdk.MsgTypeURL(&authz.MsgRevoke{}),
sdk.MsgTypeURL(&banktypes.MsgSend{}),
sdk.MsgTypeURL(&distributiontypes.MsgFundCommunityPool{}),
sdk.MsgTypeURL(&distributiontypes.MsgSetWithdrawAddress{}),
sdk.MsgTypeURL(&distributiontypes.MsgWithdrawDelegatorReward{}),
sdk.MsgTypeURL(&distributiontypes.MsgWithdrawValidatorCommission{}),
sdk.MsgTypeURL(&govtypes.MsgVote{}),
sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}),
sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}),
},
}

icaModule, ok := mm.Modules[ibcicatypes.ModuleName].(ibcica.AppModule)
if !ok {
panic("mm.Modules[ibcicatypes.ModuleName] is not of type ibcica.AppModule")
}

icaModule.InitModule(ctx, controllerParams, hostParams)

wasmParams := wasmKeeper.GetParams(ctx)
wasmParams.CodeUploadAccess = wasmtypes.AllowNobody
wasmKeeper.SetParams(ctx, wasmParams)

fromVM[ibcicatypes.ModuleName] = mm.Modules[ibcicatypes.ModuleName].ConsensusVersion()

return mm.RunMigrations(ctx, configurator, fromVM)
}
}
5 changes: 5 additions & 0 deletions upgrades/keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package upgrades

const (
Name = "upgrade-4"
)

0 comments on commit fea81c7

Please sign in to comment.