forked from CosmWasm/wasmd
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
835 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,90 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" | ||
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" | ||
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck | ||
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" | ||
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/module" | ||
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" | ||
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
|
||
"github.com/CosmWasm/wasmd/app/upgrades" | ||
"github.com/CosmWasm/wasmd/app/upgrades/noop" | ||
v050 "github.com/CosmWasm/wasmd/app/upgrades/v050" | ||
) | ||
|
||
// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade | ||
// from v047 to v050. | ||
// | ||
// NOTE: This upgrade defines a reference implementation of what an upgrade | ||
// could look like when an application is migrating from Cosmos SDK version | ||
// v0.47.x to v0.50.x. | ||
const UpgradeName = "v047-to-v050" | ||
// Upgrades list of chain upgrades | ||
var Upgrades = []upgrades.Upgrade{v050.Upgrade} | ||
|
||
// RegisterUpgradeHandlers registers the chain upgrade handlers | ||
func (app WasmApp) RegisterUpgradeHandlers() { | ||
app.UpgradeKeeper.SetUpgradeHandler( | ||
UpgradeName, | ||
func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM) | ||
}, | ||
) | ||
setupLegacyKeyTables(app.ParamsKeeper) | ||
if len(Upgrades) == 0 { | ||
// always have a unique upgrade registered for the current version to test in system tests | ||
Upgrades = append(Upgrades, noop.NewUpgrade(app.Version())) | ||
} | ||
|
||
keepers := upgrades.AppKeepers{AccountKeeper: app.AccountKeeper} | ||
// register all upgrade handlers | ||
for _, upgrade := range Upgrades { | ||
app.UpgradeKeeper.SetUpgradeHandler( | ||
upgrade.UpgradeName, | ||
upgrade.CreateUpgradeHandler( | ||
app.ModuleManager, | ||
app.configurator, | ||
&keepers, | ||
), | ||
) | ||
} | ||
|
||
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() | ||
if err != nil { | ||
panic(err) | ||
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err)) | ||
} | ||
|
||
if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { | ||
storeUpgrades := storetypes.StoreUpgrades{} | ||
if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { | ||
return | ||
} | ||
|
||
// register store loader for current upgrade | ||
for _, upgrade := range Upgrades { | ||
if upgradeInfo.Name == upgrade.UpgradeName { | ||
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades)) // nolint:gosec | ||
break | ||
} | ||
} | ||
} | ||
|
||
func setupLegacyKeyTables(k paramskeeper.Keeper) { | ||
// Set param key table for params module migration | ||
for _, subspace := range k.GetSubspaces() { | ||
subspace := subspace | ||
|
||
var keyTable paramstypes.KeyTable | ||
switch subspace.Name() { | ||
// ibc types | ||
case ibcexported.ModuleName: | ||
keyTable = ibcclienttypes.ParamKeyTable() | ||
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{}) | ||
case ibctransfertypes.ModuleName: | ||
keyTable = ibctransfertypes.ParamKeyTable() | ||
case icahosttypes.SubModuleName: | ||
keyTable = icahosttypes.ParamKeyTable() | ||
case icacontrollertypes.SubModuleName: | ||
keyTable = icacontrollertypes.ParamKeyTable() | ||
default: | ||
continue | ||
} | ||
|
||
// configure store loader that checks if version == upgradeHeight and applies store upgrades | ||
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) | ||
if !subspace.HasKeyTable() { | ||
subspace.WithKeyTable(keyTable) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package noop | ||
|
||
import ( | ||
"context" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
||
"github.com/CosmWasm/wasmd/app/upgrades" | ||
) | ||
|
||
// NewUpgrade constructor | ||
func NewUpgrade(semver string) upgrades.Upgrade { | ||
return upgrades.Upgrade{ | ||
UpgradeName: semver, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: storetypes.StoreUpgrades{ | ||
Added: []string{}, | ||
Deleted: []string{}, | ||
}, | ||
} | ||
} | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
ak *upgrades.AppKeepers, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
return mm.RunMigrations(ctx, configurator, fromVM) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package upgrades | ||
|
||
import ( | ||
storetypes "cosmossdk.io/store/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/module" | ||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
) | ||
|
||
type AppKeepers struct { | ||
authkeeper.AccountKeeper | ||
} | ||
|
||
// 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. `v7` | ||
UpgradeName string | ||
|
||
// CreateUpgradeHandler defines the function that creates an upgrade handler | ||
CreateUpgradeHandler func(*module.Manager, module.Configurator, *AppKeepers) upgradetypes.UpgradeHandler | ||
StoreUpgrades storetypes.StoreUpgrades | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package v050 | ||
|
||
import ( | ||
"context" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
circuittypes "cosmossdk.io/x/circuit/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
||
"github.com/CosmWasm/wasmd/app/upgrades" | ||
) | ||
|
||
// UpgradeName defines the on-chain upgrade name | ||
const UpgradeName = "v0.50" | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: storetypes.StoreUpgrades{ | ||
Added: []string{ | ||
circuittypes.ModuleName, | ||
}, | ||
Deleted: []string{}, | ||
}, | ||
} | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
ak *upgrades.AppKeepers, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
return mm.RunMigrations(ctx, configurator, fromVM) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.