Skip to content

Commit

Permalink
Merge pull request #1109 from scrtlabs/cw1-upgrade-and-migrations
Browse files Browse the repository at this point in the history
v1.4 upgrade handler
  • Loading branch information
assafmo authored Sep 7, 2022
2 parents 33d39c0 + f529309 commit 614bf70
Show file tree
Hide file tree
Showing 27 changed files with 159 additions and 2,003 deletions.
59 changes: 22 additions & 37 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"os"
"path/filepath"

store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/enigmampc/SecretNetwork/app/upgrades"
v1_3 "github.com/enigmampc/SecretNetwork/app/upgrades/v1.3"
v1_4 "github.com/enigmampc/SecretNetwork/app/upgrades/v1.4"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -37,7 +39,6 @@ import (
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
v1_3 "github.com/enigmampc/SecretNetwork/app/upgrades/v1.3"
icaauth "github.com/enigmampc/SecretNetwork/x/mauth"
icaauthtypes "github.com/enigmampc/SecretNetwork/x/mauth/types"

Expand Down Expand Up @@ -136,6 +137,8 @@ var (
allowedReceivingModAcc = map[string]bool{
distrtypes.ModuleName: true,
}

Upgrades = []upgrades.Upgrade{v1_3.Upgrade, v1_4.Upgrade}
)

// Verify app interface at compile time
Expand Down Expand Up @@ -566,31 +569,9 @@ func NewSecretNetworkApp(
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)

// setupUpgradeHandlers() shoulbe be called after app.mm is configured
app.setupUpgradeHandlers(&icaModule)

// add test gRPC service for testing gRPC queries in isolation
// testdata.RegisterTestServiceServer(app.GRPCQueryRouter(), testdata.QueryImpl{}) // TODO: this is testdata !!!

// create the simulation manager and define the order of the modules for deterministic simulations
//
// NOTE: This is not required for apps that don't use the simulator for fuzz testing
// transactions.
// app.sm = module.NewSimulationManager(
// auth.NewAppModule(appCodec, app.accountKeeper, authsims.RandomGenesisAccounts),
// bank.NewAppModule(appCodec, app.bankKeeper, app.accountKeeper),
// capability.NewAppModule(appCodec, *app.capabilityKeeper),
// gov.NewAppModule(appCodec, app.govKeeper, app.accountKeeper, app.bankKeeper),
// mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper),
// staking.NewAppModule(appCodec, app.stakingKeeper, app.accountKeeper, app.bankKeeper),
// distr.NewAppModule(appCodec, app.distrKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper),
// slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper),
// params.NewAppModule(app.paramsKeeper),
// //compute.NewAppModule(app.computeKeeper),
// evidence.NewAppModule(app.evidenceKeeper),
//)

// app.sm.RegisterStoreDecoders()

// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tKeys)
Expand Down Expand Up @@ -751,11 +732,15 @@ func (app *SecretNetworkApp) BlockedAddrs() map[string]bool {
}

func (app *SecretNetworkApp) setupUpgradeHandlers(icamodule *ica.AppModule) {
// this configures a no-op upgrade handler for the v4 upgrade,
// which improves the lockup module's store management.
app.upgradeKeeper.SetUpgradeHandler(
v1_3.UpgradeName, v1_3.CreateUpgradeHandler(
app.mm, icamodule, app.configurator))
for _, upgradeDetails := range Upgrades {
app.upgradeKeeper.SetUpgradeHandler(
upgradeDetails.UpgradeName,
upgradeDetails.CreateUpgradeHandler(
app.mm,
app.configurator,
),
)
}
}

func (app *SecretNetworkApp) setupUpgradeStoreLoaders() {
Expand All @@ -764,14 +749,14 @@ func (app *SecretNetworkApp) setupUpgradeStoreLoaders() {
panic(fmt.Sprintf("Failed to read upgrade info from disk %s", err))
}

if upgradeInfo.Name == v1_3.UpgradeName && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
// @Frey do we do this for Cosmwasm?
storeUpgrades := store.StoreUpgrades{
Added: []string{icahosttypes.StoreKey},
}
if app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
for _, upgradeDetails := range Upgrades {
if upgradeInfo.Name == upgradeDetails.UpgradeName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgradeDetails.StoreUpgrades))
}
}
}

Expand Down
32 changes: 32 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package upgrades

import (
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
abci "github.com/tendermint/tendermint/abci/types"
)

// BaseAppParamManager defines an interrace that BaseApp is expected to fullfil
// that allows upgrade handlers to modify BaseApp parameters.
type BaseAppParamManager interface {
GetConsensusParams(ctx sdk.Context) *abci.ConsensusParams
StoreConsensusParams(ctx sdk.Context, cp *abci.ConsensusParams)
}

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
// must have written, in order for the state migration to go smoothly.
// An upgrade must implement this struct, and then set it in the app.go.
// The app.go will then define the handler.
type Upgrade struct {
// Upgrade version name, for the upgrade handler, e.g. `v1.4`
UpgradeName string

// CreateUpgradeHandler defines the function that creates an upgrade handler
// mm *module.Manager, computeModule *computetypes.AppModule, configurator module.Configurator
CreateUpgradeHandler func(*module.Manager, module.Configurator) upgradetypes.UpgradeHandler

// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}
22 changes: 19 additions & 3 deletions app/upgrades/v1.3/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package v1_3

import (
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icamodule "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/enigmampc/SecretNetwork/app/upgrades"
)

const UpgradeName = "v1.3"

func CreateUpgradeHandler(mm *module.Manager, icamodule *icamodule.AppModule, configurator module.Configurator,
var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{Added: []string{icahosttypes.StoreKey}},
}

func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// Assaf: Set version map for all modules because for some
Expand All @@ -24,7 +32,7 @@ func CreateUpgradeHandler(mm *module.Manager, icamodule *icamodule.AppModule, co
vm[moduleName] = mm.Modules[moduleName].ConsensusVersion()
}

vm[icatypes.ModuleName] = icamodule.ConsensusVersion()
vm[icatypes.ModuleName] = mm.Modules[icatypes.ModuleName].ConsensusVersion()

// create ICS27 Controller submodule params
controllerParams := icacontrollertypes.Params{
Expand Down Expand Up @@ -60,7 +68,15 @@ func CreateUpgradeHandler(mm *module.Manager, icamodule *icamodule.AppModule, co
ctx.Logger().Info("Starting to init interchainaccount module...")

// initialize ICS27 module
icamodule.InitModule(ctx, controllerParams, hostParams)
// icamodule.InitModule(ctx, controllerParams, hostParams)

// initialize ICS27 module
icamoduleInstance, correctTypecast := mm.Modules[icatypes.ModuleName].(icamodule.AppModule)
if !correctTypecast {
panic("mm.Modules[icatypes.ModuleName] is not of type ica.AppModule")
}

icamoduleInstance.InitModule(ctx, controllerParams, hostParams)

ctx.Logger().Info("Starting to run module migrations...")

Expand Down
29 changes: 29 additions & 0 deletions app/upgrades/v1.4/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package v1_4

import (
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/enigmampc/SecretNetwork/app/upgrades"
)

const UpgradeName = "v1.4"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}

func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// We're not upgrading cosmos-sdk, Tendermint or ibc-go, so no ConsensusVersion changes
// Therefore mm.RunMigrations() should not find any module to upgrade

ctx.Logger().Info("Running module migrations for v1.4...")

return mm.RunMigrations(ctx, configurator, vm)
}
}
10 changes: 0 additions & 10 deletions go-cosmwasm/types/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,6 @@ type ContractInfoQuery struct {
ContractAddr string `json:"contract_addr"`
}

type ContractInfoResponse struct {
CodeID uint64 `json:"code_id"`
Creator string `json:"creator"`
// Set to the admin who can migrate contract, if any
Admin string `json:"admin,omitempty"`
Pinned bool `json:"pinned"`
// Set if the contract is IBC enabled
IBCPort string `json:"ibc_port,omitempty"`
}

type DistQuery struct {
Rewards *RewardsQuery `json:"rewards,omitempty"`
}
Expand Down
3 changes: 0 additions & 3 deletions x/compute/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,4 @@ type (
QueryHandler = keeper.QueryHandler
CustomQuerier = keeper.CustomQuerier
QueryPlugins = keeper.QueryPlugins
// MsgMigrateContract = types.MsgMigrateContract
// MsgUpdateAdmin = types.MsgUpdateAdmin
// MsgClearAdmin = types.MsgClearAdmin
)
Loading

0 comments on commit 614bf70

Please sign in to comment.