Cosmovisor
cosmovisor is a small process manager for Cosmos SDK application binaries that monitors the governance module for incoming chain upgrade proposals. If it sees a proposal that gets approved, cosmovisor can automatically download the new binary, stop the current binary, switch from the old binary to the new one, and finally restart the node with the new binary.
We will explain how to use it based on version 0.1.0 of cosmovisor.

Cosmovisor Setup

Install the cosmovisor binary.
You will find a cosmovisor in path $GOPATH/bin.
1
go get github.com/cosmos/cosmos-sdk/cosmovisor/cmd/[email protected]
Copied!
Set the required environment variabes.
There are four variables. (two are requirement, and two are optional)
  • DAEMON_HOME (Requirement)
    • This includes genesis binary and upgrade binaries.
    • export DAEMON_HOME=$HOME/.panacea
  • DAEMON_NAME (Requirement)
    • It's the name of binary.
    • export DAEMON_NAME=panacead
  • DAEMON_ALLOW_DOWNLOAD_BINARIES (Optional)
    • Whether to automatically download the new binary.
    • The default value is false.
    • Unfortunately, automatic download is not available yet.(by libwasmvm.so)
  • DAEMON_RESTART_AFTER_UPGRADE (Optional)
    • Whether to restart the process after the upgrade is completed.
    • The default value is false, so the administrator must manually restart after the upgrade.
    • export DAEMON_RESTART_AFTER_UPGRADE=true
We make setting to manually download the binary and to automatically proceed with the upgrade.
1
export DAEMON_HOME=$HOME/.panacea
2
export DAEMON_NAME=panacead
3
export DAEMON_RESTART_AFTER_UPGRADE=true
4
export DAEMON_ALLOW_DOWNLOAD_BINARIES=false
Copied!
Create a directory for the genesis binary and upgrade binary.
1
mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin
2
mkdir -p $DAEMON_HOME/cosmovisor/upgrades/v2.0.2/bin
Copied!
Clone and check out the current panacead mainnet version. (v2.0.1)
1
git clone -b v2.0.1 https://github.com/medibloc/panacea-core.git
2
cd panacea-core
Copied!
Build a binary and copy it to the genesis path of the cosmovisor.
1
make clean && make build
2
cp ./build/panacead $DAEMON_HOME/cosmovisor/genesis/bin
Copied!
Build the upgraded version(v2.0.2) and copy it to the cosmovisor.
1
git checkout tags/v2.0.2
2
make clean && make build
3
cp ./build/panacead $DAEMON_HOME/cosmovisor/upgrades/v2.0.2/bin
Copied!
Verify that the cosmovisor is applied as the mainnet version normally.
1
cosmovisor version
2
2.0.1 # output
Copied!
Discontinue the currently running panacead and run it with cosmovisor.
1
stop panacead
2
cosmovisor start
Copied!
When this proposal passes and the upgrade date(2021-10-01T07:00:00Z) arrives, the upgrade will automatically proceed to v2.0.2.

Example

Show an example of upgrading the version of panacead in a local environment.
1
go get github.com/cosmos/cosmos-sdk/cosmovisor/cmd/[email protected]
2
3
export DAEMON_HOME=$HOME/.panacea
4
export DAEMON_NAME=panacead
5
export DAEMON_RESTART_AFTER_UPGRADE=true
6
export DAEMON_ALLOW_DOWNLOAD_BINARIES=false
7
8
mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin
9
mkdir -p $DAEMON_HOME/cosmovisor/upgrades/v2.0.2/bin
Copied!
Clone and check out the current panacead mainnet version. (v2.0.1)
Then, build it and copy it.
1
git clone -b v2.0.1 https://github.com/medibloc/panacea-core.git
2
cd panacea-core
3
4
make clean && make build
5
cp ./build/panacead $DAEMON_HOME/cosmovisor/genesis/bin
Copied!
Create a new key for the validator, then add a genesis account and transaction:
1
./build/panacead init test --chain-id test --overwrite
2
./build/panacead keys add validator
3
./build/panacead add-genesis-account validator 1000000000umed --keyring-backend test
4
./build/panacead gentx validator 1000000umed --chain-id test
5
./build/panacead collect-gentxs
6
7
cat <<< $(jq '.app_state.gov.voting_params.voting_period = "20s" | .app_state.gov.deposit_params.min_deposit[].amount = "10000000"' $DAEMON_HOME/config/genesis.json) > $DAEMON_HOME/config/genesis.json
Copied!
You need to run binary with cosmovisor.
1
cosmovisor version
2
2.0.1 # output
3
cosmovisor start
Copied!
Submit upgrade proposal along with a deposit and a vote.
1
./build/panacead tx gov submit-proposal software-upgrade v2.0.2 \
2
--title upgrade \
3
--description upgrade \
4
--upgrade-height 30 \
5
--from validator \
6
--chain-id test \
7
--yes
8
9
./build/panacead tx gov deposit 1 10000000umed --from validator --chain-id test --yes
10
./build/panacead tx gov vote 1 yes --from validator --chain-id test --yes
Copied!
Build the upgraded version(v2.0.2) and copy it to the cosmovisor.
1
git checkout tags/v2.0.2
2
make clean && make build
3
cp ./build/panacead $DAEMON_HOME/cosmovisor/upgrades/v2.0.2/bin
Copied!
The upgrade will be performed automatically at height 30.
1
cosmovisor version
2
2.0.2 # output
Copied!
Last modified 2mo ago
Copy link