feat: Add example upgrade handler for upgrading simapp from 045 to 046 (#11893)
This commit is contained in:
parent
137c758d57
commit
67d2406585
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
|
||||
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
|
||||
"github.com/cosmos/cosmos-sdk/snapshots"
|
||||
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
)
|
||||
|
||||
|
|
|
@ -324,6 +324,10 @@ func NewSimApp(
|
|||
)
|
||||
// set the governance module account as the authority for conducting upgrades
|
||||
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())
|
||||
|
||||
// RegisterUpgradeHandlers is used for registering any on-chain upgrades
|
||||
app.RegisterUpgradeHandlers()
|
||||
|
||||
app.NFTKeeper = nftkeeper.NewKeeper(keys[nftkeeper.StoreKey], appCodec, app.AccountKeeper, app.BankKeeper)
|
||||
|
||||
// create evidence keeper with router
|
||||
|
@ -605,7 +609,7 @@ func (app *SimApp) RegisterTendermintService(clientCtx client.Context) {
|
|||
}
|
||||
|
||||
// RegisterSwaggerAPI registers swagger route with API Server
|
||||
func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) {
|
||||
func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) {
|
||||
statikFS, err := fs.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package simapp
|
||||
|
||||
import (
|
||||
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/x/group"
|
||||
"github.com/cosmos/cosmos-sdk/x/nft"
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
)
|
||||
|
||||
// UpgradeName defines the on-chain upgrade name for the sample simap upgrade from v045 to v046.
|
||||
//
|
||||
// NOTE: This upgrade defines a reference implementation of what an upgrade could look like
|
||||
// when an application is migrating from Cosmos SDK version v0.45.x to v0.46.x.
|
||||
const UpgradeName = "v045-to-v046"
|
||||
|
||||
func (app SimApp) RegisterUpgradeHandlers() {
|
||||
app.UpgradeKeeper.SetUpgradeHandler(UpgradeName,
|
||||
func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
|
||||
// We set fromVersion to 1 to avoid running InitGenesis for modules for
|
||||
// in-store migrations.
|
||||
//
|
||||
// If you wish to skip any module migrations, i.e. they were already migrated
|
||||
// in an older version, you can use `modulename.AppModule{}.ConsensusVersion()`
|
||||
// instead of `1` below.
|
||||
//
|
||||
// For example:
|
||||
// "auth": auth.AppModule{}.ConsensusVersion()
|
||||
fromVM := map[string]uint64{
|
||||
"auth": 1,
|
||||
"authz": 1,
|
||||
"bank": 1,
|
||||
"capability": 1,
|
||||
"crisis": 1,
|
||||
"distribution": 1,
|
||||
"evidence": 1,
|
||||
"feegrant": 1,
|
||||
"gov": 1,
|
||||
"mint": 1,
|
||||
"params": 1,
|
||||
"slashing": 1,
|
||||
"staking": 1,
|
||||
"upgrade": 1,
|
||||
"vesting": 1,
|
||||
"genutil": 1,
|
||||
}
|
||||
|
||||
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
|
||||
})
|
||||
|
||||
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
|
||||
storeUpgrades := storetypes.StoreUpgrades{
|
||||
Added: []string{
|
||||
group.ModuleName,
|
||||
nft.ModuleName,
|
||||
},
|
||||
}
|
||||
|
||||
// configure store loader that checks if version == upgradeHeight and applies store upgrades
|
||||
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
|
||||
}
|
||||
}
|
|
@ -8,9 +8,9 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/address"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
)
|
||||
|
||||
type msgServer struct {
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
)
|
||||
|
||||
// ConvertToLegacyProposal takes a new proposal and attempts to convert it to the
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
)
|
||||
|
||||
func TestProposalStatus_Format(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue