From 994219a4d2f467a0bd628d60d8670c1102edbe88 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 22 Oct 2021 12:56:08 +0200 Subject: [PATCH] chore(upgrade): cleaning (#10413) ## Description cosmetic changes spotted when reading docs and code. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- docs/core/upgrade.md | 10 +++++----- types/module/module.go | 23 ++++++++--------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/docs/core/upgrade.md b/docs/core/upgrade.md index c4abb1eadbe1..2a3844161b81 100644 --- a/docs/core/upgrade.md +++ b/docs/core/upgrade.md @@ -15,7 +15,7 @@ The Cosmos SDK uses two methods to perform upgrades. - Exporting the entire application state to a JSON file using the `export` CLI command, making changes, and then starting a new binary with the changed JSON file as the genesis file. See [Chain Upgrade Guide to v0.42](https://docs.cosmos.network/v0.42/migrations/chain-upgrade-guide-040.html). - Version v0.44 and later can perform upgrades in place to significantly decrease the upgrade time for chains with a larger state. Use the [Module Upgrade Guide](../building-modules/upgrade.md) to set up your application modules to take advantage of in-place upgrades. - + This document provides steps to use the In-Place Store Migrations upgrade method. ## Tracking Module Versions @@ -95,7 +95,7 @@ if err != nil { if upgradeInfo.Name == "my-plan" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { storeUpgrades := storetypes.StoreUpgrades{ // add store upgrades for new modules - // Example: + // Example: // Added: []string{"foo", "bar"}, // ... } @@ -119,7 +119,7 @@ You MUST manually set the consensus version in the version map passed to the `Up import foo "github.com/my/module/foo" app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - + // Register the consensus version in the version map // to avoid the SDK from triggering the default // InitGenesis function. @@ -138,7 +138,7 @@ If you do not have a custom genesis function and want to skip the module's defau import foo "github.com/my/module/foo" app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - + // Set foo's version to the latest ConsensusVersion in the VersionMap. // This will skip running InitGenesis on Foo vm["foo"] = foo.AppModule{}.ConsensusVersion() @@ -151,6 +151,6 @@ app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgrad You can sync a full node to an existing blockchain which has been upgraded using Cosmovisor -In order to successfully sync, you must start with the initial binary that the blockchain started with at genesis. Cosmovisor will handle downloading and switching to the binaries associated with each sequential upgrade. +In order to successfully sync, you must start with the initial binary that the blockchain started with at genesis. If all Software Upgrade Plans contain binary instruction then you can run Cosmovisor with auto download option to automatically handle downloading and switching to the binaries associated with each sequential upgrade. Otherwise you need to manually provide all binaries to Cosmovisor. To learn more about Cosmovisor, see the [Cosmovisor Quick Start](../run-node/cosmovisor.md). diff --git a/types/module/module.go b/types/module/module.go index 685a6dcd601b..6e1012c0ac8a 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -415,32 +415,25 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version fromVersion, exists := fromVM[moduleName] toVersion := module.ConsensusVersion() - // Only run migrations when the module exists in the fromVM. - // Run InitGenesis otherwise. + // We run migration if the module is specified in `fromVM`. + // Otherwise we run InitGenesis. // - // the module won't exist in the fromVM in two cases: + // The module won't exist in the fromVM in two cases: // 1. A new module is added. In this case we run InitGenesis with an // empty genesis state. - // 2. An existing chain is upgrading to v043 for the first time. In this case, - // all modules have yet to be added to x/upgrade's VersionMap store. + // 2. An existing chain is upgrading from version < 0.43 to v0.43+ for the first time. + // In this case, all modules have yet to be added to x/upgrade's VersionMap store. if exists { err := c.runModuleMigrations(ctx, moduleName, fromVersion, toVersion) if err != nil { return nil, err } } else { - cfgtor, ok := cfg.(configurator) - if !ok { - // Currently, the only implementator of Configurator (the interface) - // is configurator (the struct). - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", configurator{}, cfg) - } - - moduleValUpdates := module.InitGenesis(ctx, cfgtor.cdc, module.DefaultGenesis(cfgtor.cdc)) + moduleValUpdates := module.InitGenesis(ctx, c.cdc, module.DefaultGenesis(c.cdc)) // The module manager assumes only one module will update the - // validator set, and that it will not be by a new module. + // validator set, and it can't be a new module. if len(moduleValUpdates) > 0 { - return nil, sdkerrors.Wrapf(sdkerrors.ErrLogic, "validator InitGenesis updates already set by a previous module") + return nil, sdkerrors.Wrapf(sdkerrors.ErrLogic, "validator InitGenesis update is already set by another module") } }