diff --git a/CHANGELOG.md b/CHANGELOG.md index cd82a461657b..76e37a3b8246 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,9 +37,16 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +* (cli) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Add the `tendermint key-migrate` to perform Tendermint v0.35 DB key migration. + +### Bug Fixes + +* (migrations) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Fix v0.45->v0.46 in-place store migrations. + +## [v0.46.0-rc1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc1) - 2022-05-23 + ### Features -* (types) [#11985](https://github.com/cosmos/cosmos-sdk/pull/11985) Add a `Priority` field on `sdk.Context`, which represents the CheckTx priority field. It is only used during CheckTx. * (gRPC) [#11889](https://github.com/cosmos/cosmos-sdk/pull/11889) Support custom read and write gRPC options in `app.toml`. See `max-recv-msg-size` and `max-send-msg-size` respectively. * (cli) [\#11738](https://github.com/cosmos/cosmos-sdk/pull/11738) Add `tx auth multi-sign` as alias of `tx auth multisign` for consistency with `multi-send`. * (cli) [\#11738](https://github.com/cosmos/cosmos-sdk/pull/11738) Add `tx bank multi-send` command for bulk send of coins to multiple accounts. diff --git a/server/tm_cmds.go b/server/tm_cmds.go index 0f243e5a8f32..6cc63850ff74 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -3,10 +3,14 @@ package server // DONTCOVER import ( + "context" "fmt" "github.com/spf13/cobra" + cfg "github.com/tendermint/tendermint/config" pvm "github.com/tendermint/tendermint/privval" + "github.com/tendermint/tendermint/scripts/keymigrate" + "github.com/tendermint/tendermint/scripts/scmigrate" tversion "github.com/tendermint/tendermint/version" "sigs.k8s.io/yaml" @@ -123,3 +127,67 @@ func VersionCmd() *cobra.Command { }, } } + +// makeKeyMigrateCmd is ported from tendermint's key-migrate command, but +// uses the SDK's own server.Context. +// ref: https://github.com/tendermint/tendermint/blob/master/UPGRADING.md#database-key-format-changes +func makeKeyMigrateCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "key-migrate", + Short: "Run Tendermint database key migration", + RunE: func(cmd *cobra.Command, args []string) error { + ctx, cancel := context.WithCancel(cmd.Context()) + defer cancel() + + serverCtx := GetServerContextFromCmd(cmd) + config := serverCtx.Config + + contexts := []string{ + // this is ordered to put the + // (presumably) biggest/most important + // subsets first. + "blockstore", + "state", + "peerstore", + "tx_index", + "evidence", + "light", + } + + for idx, dbctx := range contexts { + serverCtx.Logger.Info("beginning a key migration", + "dbctx", dbctx, + "num", idx+1, + "total", len(contexts), + ) + + db, err := cfg.DefaultDBProvider(&cfg.DBContext{ + ID: dbctx, + Config: config, + }) + + if err != nil { + return fmt.Errorf("constructing database handle: %w", err) + } + + if err = keymigrate.Migrate(ctx, db); err != nil { + return fmt.Errorf("running migration for context %q: %w", + dbctx, err) + } + + if dbctx == "blockstore" { + if err := scmigrate.Migrate(ctx, db); err != nil { + return fmt.Errorf("running seen commit migration: %w", err) + + } + } + } + + serverCtx.Logger.Info("completed database migration successfully") + + return nil + }, + } + + return cmd +} diff --git a/server/util.go b/server/util.go index 44823b28bb6c..8a47a520197c 100644 --- a/server/util.go +++ b/server/util.go @@ -283,6 +283,7 @@ func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator type tmcmd.ResetAllCmd, tmcmd.ResetStateCmd, tmcmd.InspectCmd, + makeKeyMigrateCmd(), ) startCmd := StartCmd(appCreator, defaultNodeHome) diff --git a/simapp/app.go b/simapp/app.go index 2af2dae79b39..4d3a4e14f20b 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -296,6 +296,8 @@ func NewSimApp( // set the BaseApp's parameter store bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())) + app.UpgradeKeeper = upgradeKeeper + app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) // Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating // their scoped modules in `NewApp` with `ScopeToModule` @@ -365,11 +367,6 @@ func NewSimApp( ), ) - upgradeKeeper.SetVersionSetter(app.BaseApp) - app.UpgradeKeeper = upgradeKeeper - // 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 @@ -454,6 +451,10 @@ func NewSimApp( app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) app.mm.RegisterServices(app.configurator) + // RegisterUpgradeHandlers is used for registering any on-chain upgrades. + // Make sure it's called after `app.mm` and `app.configurator` are set. + app.RegisterUpgradeHandlers() + // add test gRPC service for testing gRPC queries in isolation testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{}) diff --git a/simapp/upgrades.go b/simapp/upgrades.go index dd44a8d5633e..51f786482539 100644 --- a/simapp/upgrades.go +++ b/simapp/upgrades.go @@ -39,35 +39,7 @@ func GetUpgradeStoreOption(keeper upgradekeeper.Keeper) baseapp.StoreOption { 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, - } - + func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { return app.mm.RunMigrations(ctx, app.configurator, fromVM) }) } diff --git a/x/staking/migrations/v046/store.go b/x/staking/migrations/v046/store.go index 20825ec26029..e2be22cbb1ff 100644 --- a/x/staking/migrations/v046/store.go +++ b/x/staking/migrations/v046/store.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" ) -// MigrateStore performs in-place store migrations from v0.43/v0.44 to v0.45. +// MigrateStore performs in-place store migrations from v0.43/v0.44/v0.45 to v0.46. // The migration includes: // // - Setting the MinCommissionRate param in the paramstore @@ -19,6 +19,10 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar } func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) { - paramstore.WithKeyTable(types.ParamKeyTable()) - paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate) + if paramstore.HasKeyTable() { + paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate) + } else { + paramstore.WithKeyTable(types.ParamKeyTable()) + paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate) + } }