github.com/Finschia/finschia-sdk@v0.48.1/docs/migrations/chain-upgrade-guide-044.md (about) 1 <!-- 2 order: 1 3 --> 4 5 # Chain Upgrade Guide to v0.44 6 7 This document provides guidelines for a chain upgrade from v0.42 to v0.44 and an example of the upgrade process using `simapp`. {synopsis} 8 9 ::: tip 10 You must upgrade to Stargate v0.42 before upgrading to v0.44. If you have not done so, please see [Chain Upgrade Guide to v0.42](/v0.42/migrations/chain-upgrade-guide-040.html). Please note, v0.43 was discontinued shortly after being released and all chains should upgrade directly to v0.44 from v0.42. 11 ::: 12 13 ## Prerequisite Readings 14 15 - [Upgrading Modules](../building-modules/upgrade.html) {prereq} 16 - [In-Place Store Migrations](../core/upgrade.html) {prereq} 17 - [Cosmovisor](../run-node/cosmovisor.html) {prereq} 18 19 Cosmos SDK v0.44 introduces a new way of handling chain upgrades that no longer requires exporting state to JSON, making the necessary changes, and then creating a new chain with the modified JSON as the new genesis file. 20 21 The IBC module for the Cosmos SDK has moved to its [own repository](https://github.com/cosmos/ibc-go) for v0.42 and later versions. If you are using IBC, make sure to also go through the [IBC migration docs](https://github.com/cosmos/ibc-go/blob/main/docs/migrations/ibc-migration-043.md). 22 23 Instead of starting a new chain, the upgrade binary will read the existing database and perform in-place store migrations. This new way of handling chain upgrades can be used alongside [Cosmovisor](../run-node/cosmovisor.html) to make the upgrade process seamless. 24 25 ## In-Place Store Migrations 26 27 We recommend using [In-Place Store Migrations](../core/upgrade.html) to upgrade your chain from v0.42 to v0.44. The first step is to make sure all your modules follow the [Module Upgrade Guide](../building-modules/upgrade.html). The second step is to add an [upgrade handler](../core/upgrade.html#running-migrations) to `app.go`. 28 29 In this document, we'll provide an example of what the upgrade handler looks like for a chain upgrading module versions for the first time. It's critical to note that the initial version of each module must be set to `1` rather than `0` or else the upgrade handler will re-initialize each module. 30 31 In addition to migrating existing modules, the upgrade handler also performs store upgrades for new modules. In the example below, we'll be adding store migrations for two new modules made available in v0.44: `x/authz` and `x/feegrant`. 32 33 ## Using Cosmovisor 34 35 We recommend validators use [Cosmovisor](../run-node/cosmovisor.html), which is a process manager for running application binaries. For security reasons, we recommend validators build their own upgrade binaries rather than enabling the auto-download option. Validators may still choose to use the auto-download option if the necessary security guarantees are in place (i.e. the URL provided in the upgrade proposal for the downloadable upgrade binary includes a proper checksum). 36 37 Validators can use the auto-restart option to prevent unecessary downtime during the upgrade process. The auto-restart option will automatically restart the chain with the upgrade binary once the chain has halted at the proposed upgrade height. With the auto-restart option, validators can prepare the upgrade binary in advance and then relax at the time of the upgrade. 38 39 ## Migrating app.toml 40 41 With the update to `v0.44`, new server configuration options have been added to `app.toml`. The updates include new configuration sections for Rosetta and gRPC Web as well as a new configuration option for State Sync. Check out the default [`app.toml`](https://github.com/cosmos/cosmos-sdk/blob/release/v0.44.x/server/config/toml.go) file in the latest version of `v0.44` for more information. 42 43 ## Example: Simapp Upgrade 44 45 The following example will walk through the upgrade process using `simapp` as our blockchain application. We will be upgrading `simapp` from v0.42 to v0.44. We will be building the upgrade binary ourselves and enabling the auto-restart option. 46 47 *Note: In this example, we will be starting a new chain from `v0.42`. The binary for this version will be the genesis binary. For validators using Cosmovisor for the first time, the binary for the current version of the chain should be used as the genesis binary (i.e. the starting binary). For more information, see [Cosmovisor](../run-node/cosmovisor.html).* 48 49 ### Initial Setup 50 51 From within the `cosmos-sdk` repository, check out the latest `v0.42.x` release: 52 53 ``` 54 git checkout release/v0.42.x 55 ``` 56 57 Build the `simd` binary for the latest `v0.42.x` release (the genesis binary): 58 59 ``` 60 make build 61 ``` 62 63 Reset `~/.simapp` (never do this in a production environment): 64 65 ``` 66 ./build/simd unsafe-reset-all 67 ``` 68 69 Configure the `simd` binary for testing: 70 71 ``` 72 ./build/simd config chain-id test 73 ./build/simd config keyring-backend test 74 ./build/simd config broadcast-mode block 75 ``` 76 77 Initialize the node and overwrite any previous genesis file (never do this in a production environment): 78 79 <!-- TODO: init does not read chain-id from config --> 80 81 ``` 82 ./build/simd init test --chain-id test --overwrite 83 ``` 84 85 Set the minimum gas price to `0stake` in `~/.simapp/config/app.toml`: 86 87 ``` 88 minimum-gas-prices = "0stake" 89 ``` 90 91 For the purpose of this demonstration, change `voting_period` in `genesis.json` to a reduced time of 20 seconds (`20s`): 92 93 ``` 94 cat <<< $(jq '.app_state.gov.voting_params.voting_period = "20s"' $HOME/.simapp/config/genesis.json) > $HOME/.simapp/config/genesis.json 95 ``` 96 97 Create a new key for the validator, then add a genesis account and transaction: 98 99 <!-- TODO: add-genesis-account does not read keyring-backend from config --> 100 <!-- TODO: gentx does not read chain-id from config --> 101 102 ``` 103 ./build/simd keys add validator 104 ./build/simd add-genesis-account validator 5000000000stake --keyring-backend test 105 ./build/simd gentx validator 1000000stake --chain-id test 106 ./build/simd collect-gentxs 107 ``` 108 109 Now that our node is initialized and we are ready to start a new `simapp` chain, let's set up `cosmovisor` and the genesis binary. 110 111 ### Cosmovisor Setup 112 113 First, install or update `cosmovisor`: 114 115 ``` 116 go get github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor 117 ``` 118 119 Set the required environment variables: 120 121 ``` 122 export DAEMON_NAME=simd 123 export DAEMON_HOME=$HOME/.simapp 124 ``` 125 126 Set the optional environment variable to trigger an automatic restart: 127 128 ``` 129 export DAEMON_RESTART_AFTER_UPGRADE=true 130 ``` 131 132 Create the folder for the genesis binary and copy the `v0.42.x` binary: 133 134 ``` 135 mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin 136 cp ./build/simd $DAEMON_HOME/cosmovisor/genesis/bin 137 ``` 138 139 Now that `cosmovisor` is installed and the genesis binary has been added, let's add the upgrade handler to `simapp/app.go` and prepare the upgrade binary. 140 141 ### Chain Upgrade 142 143 <!-- TODO: update example to use v0.44.x --> 144 145 Check out `release/v0.44.x`: 146 147 ``` 148 git checkout release/v0.44.x 149 ``` 150 151 Add the following to `simapp/app.go` inside `NewSimApp` and after `app.UpgradeKeeper`: 152 153 ```go 154 app.registerUpgradeHandlers() 155 ``` 156 157 Add the following to `simapp/app.go` after `NewSimApp` (to learn more about the upgrade handler, see the [In-Place Store Migrations](../core/upgrade.html)): 158 159 ```go 160 func (app *SimApp) registerUpgradeHandlers() { 161 app.UpgradeKeeper.SetUpgradeHandler("v0.44", func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { 162 // 1st-time running in-store migrations, using 1 as fromVersion to 163 // avoid running InitGenesis. 164 fromVM := map[string]uint64{ 165 "auth": 1, 166 "bank": 1, 167 "capability": 1, 168 "crisis": 1, 169 "distribution": 1, 170 "evidence": 1, 171 "gov": 1, 172 "mint": 1, 173 "params": 1, 174 "slashing": 1, 175 "staking": 1, 176 "upgrade": 1, 177 "vesting": 1, 178 "ibc": 1, 179 "genutil": 1, 180 "transfer": 1, 181 } 182 183 return app.mm.RunMigrations(ctx, app.configurator, fromVM) 184 }) 185 186 upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() 187 if err != nil { 188 panic(err) 189 } 190 191 if upgradeInfo.Name == "v0.44" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { 192 storeUpgrades := storetypes.StoreUpgrades{ 193 Added: []string{"authz", "feegrant"}, 194 } 195 196 // configure store loader that checks if version == upgradeHeight and applies store upgrades 197 app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) 198 } 199 } 200 ``` 201 202 Add `storetypes` to imports: 203 204 ```go 205 storetypes "github.com/Finschia/finschia-sdk/store/types" 206 ``` 207 208 Build the `simd` binary for `v0.44.x` (the upgrade binary): 209 210 ``` 211 make build 212 ``` 213 214 Create the folder for the upgrade binary and copy the `v0.44.x` binary: 215 216 ``` 217 mkdir -p $DAEMON_HOME/cosmovisor/upgrades/v0.44/bin 218 cp ./build/simd $DAEMON_HOME/cosmovisor/upgrades/v0.44/bin 219 ``` 220 221 Now that we have added the upgrade handler and prepared the upgrade binary, we are ready to start `cosmovisor` and simulate the upgrade proposal process. 222 223 ### Upgrade Proposal 224 225 Start the node using `cosmovisor`: 226 227 ``` 228 cosmovisor start 229 ``` 230 231 Open a new terminal window and submit an upgrade proposal along with a deposit and a vote (these commands must be run within 20 seconds of each other): 232 233 ``` 234 ./build/simd tx gov submit-proposal software-upgrade v0.44 --title upgrade --description upgrade --upgrade-height 20 --from validator --yes 235 ./build/simd tx gov deposit 1 10000000stake --from validator --yes 236 ./build/simd tx gov vote 1 yes --from validator --yes 237 ``` 238 239 Confirm the chain automatically upgrades at height 20.