From 0e64fa77d1173b485421e0dd4d4e95af462cef96 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Thu, 17 Jun 2021 20:34:33 +0530 Subject: [PATCH] docs: Add docs for setting store loader (#9526) ## Description Closes: #9503 Add documentation for setting StoreLoader as part of in-place store migration. --- ### 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... - [x] included the correct `docs:` prefix in the PR title - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the [documentation writing guidelines](https://github.com/cosmos/cosmos-sdk/blob/master/docs/DOC_WRITING_GUIDELINES.md) - [ ] 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... - [x] confirmed the correct `docs:` prefix in the PR title - [ ] confirmed all author checklist items have been addressed - [x] confirmed that this PR only changes documentation - [x] reviewed content for consistency - [x] reviewed content for thoroughness - [x] reviewed content for spelling and grammar - [ ] tested instructions (if applicable) --- docs/building-modules/upgrade.md | 2 +- docs/core/upgrade.md | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/building-modules/upgrade.md b/docs/building-modules/upgrade.md index 53864fa58..2f9eaa98f 100644 --- a/docs/building-modules/upgrade.md +++ b/docs/building-modules/upgrade.md @@ -8,7 +8,7 @@ In-place store migrations allow your modules to upgrade to new versions that inc ## Prerequisite Readings -- [In-Place Store Migration](../core-concepts/upgrade.md) {prereq} +- [In-Place Store Migration](../core/upgrade.md) {prereq} ## Consensus Version diff --git a/docs/core/upgrade.md b/docs/core/upgrade.md index 4e48e10b9..c37d81387 100644 --- a/docs/core/upgrade.md +++ b/docs/core/upgrade.md @@ -82,6 +82,29 @@ To learn more about configuring migration scripts for your modules, see the [Mig You can introduce entirely new modules to the application during an upgrade. New modules are recognized because they have not yet been registered in `x/upgrade`'s `VersionMap` store. In this case, `RunMigrations` calls the `InitGenesis` function from the corresponding module to set up its initial state. +### Add StoreUpgrades for New Modules + +All chains preparing to run in-place store migrations will need to manually add store upgrades for new modules and then configure the store loader to apply those upgrades. This ensures that the new module's stores are added to the multistore before the migrations begin. + +```golang +upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() +if err != nil { + panic(err) +} + +if upgradeInfo.Name == "my-plan" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + storeUpgrades := storetypes.StoreUpgrades{ + // add store upgrades for new modules + // Example: + // Added: []string{"foo", "bar"}, + // ... + } + + // configure store loader that checks if version == upgradeHeight and applies store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) +} +``` + ## Overwriting Genesis Functions The Cosmos SDK offers modules that the application developer can import in their app. These modules often have an `InitGenesis` function already defined.