Skip to content

Commit 00a5a8b

Browse files
authored
docs: fix cosmovisor readme (cosmos#9549)
## Description <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> The pull request fixes the staking amount, adds the auto-restart option, and improves the user flow for the simd example. This pull request also fixes spelling and grammar, updates content for clarity, and applies consistent formatting. --- ### 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)) - [ ] provided a link to the relevant issue or specification - [x] followed the [documentation writing guidelines](https://github.com/cosmos/cosmos-sdk/blob/master/docs/DOC_WRITING_GUIDELINES.md) - [x] reviewed "Files changed" and left comments if necessary - [x] 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 `docs:` prefix in the PR title - [ ] confirmed all author checklist items have been addressed - [ ] confirmed that this PR only changes documentation - [ ] reviewed content for consistency - [ ] reviewed content for thoroughness - [ ] reviewed content for spelling and grammar - [ ] tested instructions (if applicable)
1 parent d60cb3a commit 00a5a8b

File tree

1 file changed

+77
-94
lines changed

1 file changed

+77
-94
lines changed

cosmovisor/README.md

+77-94
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
11
# Cosmosvisor Quick Start
22

3-
`cosmovisor` is a small process manager around Cosmos SDK binaries that monitors the governance module via stdout to see if there's a chain upgrade proposal coming in. If it see a proposal that gets approved it can be run manually or automatically to download the new code, stop the node, run the migration script, replace the node binary, and start with the new genesis file.
3+
`cosmovisor` is a small process manager for Cosmos SDK binaries that monitors the governance module via stdout for incoming chain upgrade proposals. If it sees a proposal that gets approved, it can be run manually or automatically to download the new binary, stop the current binary, run the migration script, replace the old node binary with the new one, and finally restart the node with the new genesis file.
44

55
## Installation
66

7-
Run:
7+
To install `cosmovisor`, run the following command:
88

9-
`go get github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor`
9+
```
10+
go get github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor
11+
```
1012

1113
## Command Line Arguments And Environment Variables
1214

13-
All arguments passed to the `cosmovisor` program will be passed to the current daemon binary (as a subprocess).
14-
It will return `/dev/stdout` and `/dev/stderr` of the subprocess as its own. Because of that, it cannot accept
15-
any command line arguments, nor print anything to output (unless it terminates unexpectedly before executing a
16-
binary).
15+
All arguments passed to the `cosmovisor` program will be passed to the current daemon binary (as a subprocess). `cosmovisor` will return `/dev/stdout` and `/dev/stderr` of the subprocess as its own. For this reason, `cosmovisor` cannot accept any command line arguments, nor print anything to output (unless it terminates unexpectedly before executing a binary).
1716

1817
`cosmovisor` reads its configuration from environment variables:
1918

20-
* `DAEMON_HOME` is the location where upgrade binaries should be kept (e.g. `$HOME/.gaiad` or `$HOME/.xrnd`).
21-
* `DAEMON_NAME` is the name of the binary itself (eg. `xrnd`, `gaiad`, `simd`, etc).
22-
* `DAEMON_ALLOW_DOWNLOAD_BINARIES` (*optional*) if set to `true` will enable auto-downloading of new binaries
23-
(for security reasons, this is intended for full nodes rather than validators).
24-
* `DAEMON_RESTART_AFTER_UPGRADE` (*optional*) if set to `true` it will restart the sub-process with the same
25-
command line arguments and flags (but new binary) after a successful upgrade. By default, `cosmovisor` dies
26-
afterwards and allows the supervisor to restart it if needed. Note that this will not auto-restart the child
27-
if there was an error.
19+
* `DAEMON_HOME` is the location where the `cosmovisor/` directory is kept that contains the upgrade binaries (e.g. `$HOME/.gaiad`, `$HOME/.regend`, `$HOME/.simd`, etc.).
20+
* `DAEMON_NAME` is the name of the binary itself (e.g. `gaiad`, `regend`, `simd`, etc.).
21+
* `DAEMON_ALLOW_DOWNLOAD_BINARIES` (*optional*), if set to `true`, will enable auto-downloading of new binaries (for security reasons, this is intended for full nodes rather than validators). By default, `cosmovisor` will not auto-download new binaries.
22+
* `DAEMON_RESTART_AFTER_UPGRADE` (*optional*), if set to `true`, will restart the subprocess with the same command line arguments and flags (but with the new binary) after a successful upgrade. By default, `cosmovisor` stops running after an upgrade and requires the system administrator to manually restart it. Note that `cosmovisor` will not auto-restart the subprocess if there was an error.
2823

2924
## Data Folder Layout
3025

31-
`$DAEMON_HOME/cosmovisor` is expected to belong completely to `cosmovisor` and
32-
subprocesses that are controlled by it. The folder content is organised as follows:
26+
`$DAEMON_HOME/cosmovisor` is expected to belong completely to `cosmovisor` and the subprocesses that are controlled by it. The folder content is organized as follows:
3327

3428
```
3529
.
@@ -43,18 +37,11 @@ subprocesses that are controlled by it. The folder content is organised as follo
4337
└── $DAEMON_NAME
4438
```
4539

46-
Each version of the Cosmos SDK application is stored under either `genesis` or `upgrades/<name>`, which holds `bin/$DAEMON_NAME`
47-
along with any other needed files such as auxiliary client programs or libraries. `current` is a symbolic link to the currently
48-
active folder (so `current/bin/$DAEMON_NAME` is the currently active binary).
40+
Each version of the Cosmos SDK application is stored under either `genesis` or `upgrades/<name>`, which holds `bin/$DAEMON_NAME` along with any other needed files such as auxiliary client programs or libraries. `current` is a symbolic link to the currently active folder and `current/bin/$DAEMON_NAME` is the currently active binary.
4941

50-
*Note: the `name` variable in `upgrades/<name>` holds the URI-encoded name of the upgrade as specified in the upgrade module plan.*
42+
*Note: The `name` variable in `upgrades/<name>` holds the URI-encoded name of the upgrade as specified in the upgrade module plan.*
5143

52-
Please note that `$DAEMON_HOME/cosmovisor` just stores the *binaries* and associated *program code*.
53-
The `cosmovisor` binary can be stored in any typical location (eg `/usr/local/bin`). The actual blockchain
54-
program will store it's data under their default data directory (e.g. `$HOME/.gaiad`) which is independent of
55-
the `$DAEMON_HOME`. You can choose to set `$DAEMON_HOME` to the actual binary's home directory and then end up
56-
with a configuation like the following, but this is left as a choice to the system admininstrator for best
57-
directory layout:
44+
Please note that `$DAEMON_HOME/cosmovisor` just stores the *binaries* and associated *program code*. The `cosmovisor` binary can be stored in any typical location (e.g. `/usr/local/bin`). The actual blockchain program will store its data under the default data directory (e.g. `$HOME/.gaiad`) which is independent of `$DAEMON_HOME`. `$DAEMON_HOME` can be set to any location. If you set `$DAEMON_HOME` to the default data directory, you will end up with a configuation like the following:
5845

5946
```
6047
.gaiad
@@ -65,37 +52,27 @@ directory layout:
6552

6653
## Usage
6754

68-
The system administrator admin is responsible for:
55+
The system administrator is responsible for:
6956

70-
* installing the `cosmovisor` binary and configure the host's init system (e.g. `systemd`, `launchd`, etc) along with the environmental variables appropriately;
71-
* installing the `genesis` folder manually;
72-
* installing the `upgrades/<name>` folders manually.
57+
- installing the `cosmovisor` binary
58+
- configuring the host's init system (e.g. `systemd`, `launchd`, etc.)
59+
- appropriately setting the environmental variables
60+
- installing the `genesis` folder manually
61+
- installing the `upgrades/<name>` folders manually
7362

74-
`cosmovisor` will set the `current` link to point to `genesis` at first start (when no `current` link exists) and handles
75-
binaries switch overs at the correct points in time, so that the system administrator can prepare days in advance and relax at upgrade time.
63+
`cosmovisor` will set the `current` link to point to `genesis` at first start (when no `current` link exists) and will handle switching binaries at the correct points in time so that the system administrator can prepare days in advance and relax at upgrade time.
7664

77-
Note that blockchain applications that wish to support upgrades may package up a genesis `cosmovisor` tarball with this information,
78-
just as they prepare the genesis binary tarball. In fact, they may offer a tarball will all upgrades up to current point for easy download
79-
for those who wish to sync a fullnode from start.
65+
Note that blockchain applications that wish to support upgrades may package up a genesis `cosmovisor` tarball with this information, just as they prepare the genesis binary tarball. In fact, they may package up a tarball with all upgrades up to a current point so that the upgrades can be easily downloaded for others who wish to sync a fullnode from start.
8066

81-
The `DAEMON` specific code and operations (e.g. tendermint config, the application db, syncing blocks, etc) are performed as normal.
82-
Application binaries' directives such as command-line flags and environment variables work normally.
67+
The `DAEMON` specific code and operations (e.g. tendermint config, the application db, syncing blocks, etc.) all work as expected. The application binaries' directives such as command-line flags and environment variables also work as expected.
8368

8469
## Auto-Download
8570

86-
Generally, the system requires that the system administrator place all relevant binaries
87-
on the disk before the upgrade happens. However, for people who don't need such
88-
control and want an easier setup (maybe they are syncing a non-validating fullnode
89-
and want to do little maintenance), there is another option.
71+
Generally, the system requires that the system administrator place all relevant binaries on the disk before the upgrade happens. However, for people who don't need such control and want an easier setup (maybe they are syncing a non-validating fullnode and want to do little maintenance), there is another option.
9072

91-
If you set `DAEMON_ALLOW_DOWNLOAD_BINARIES=on` then when an upgrade is triggered and no local binary
92-
can be found, the `cosmovisor` will attempt to download and install the binary itself.
93-
The plan stored in the upgrade module has an info field for arbitrary json.
94-
This info is expected to be outputed on the halt log message. There are two
95-
valid format to specify a download in such a message:
73+
If you set `DAEMON_ALLOW_DOWNLOAD_BINARIES=on`, and no local binary can be found when an upgrade is triggered, `cosmovisor` will attempt to download and install the binary itself. The plan stored in the upgrade module has an info field for arbitrary JSON. This info is expected to be outputed on the halt log message. There are two valid formats to specify a download in such a message:
9674

97-
1. Store an os/architecture -> binary URI map in the upgrade plan info field
98-
as JSON under the `"binaries"` key, eg:
75+
1. Store an os/architecture -> binary URI map in the upgrade plan info field as JSON under the `"binaries"` key. For example:
9976

10077
```json
10178
{
@@ -105,74 +82,76 @@ as JSON under the `"binaries"` key, eg:
10582
}
10683
```
10784

108-
2. Store a link to a file that contains all information in the above format (eg. if you want
109-
to specify lots of binaries, changelog info, etc without filling up the blockchain).
85+
2. Store a link to a file that contains all information in the above format (e.g. if you want to specify lots of binaries, changelog info, etc. without filling up the blockchain). For example:
86+
87+
```
88+
https://example.com/testnet-1001-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e
89+
```
11090

111-
e.g. `https://example.com/testnet-1001-info.json?checksum=sha256:deaaa99fda9407c4dbe1d04bd49bab0cc3c1dd76fa392cd55a9425be074af01e`
91+
This file contained in the link will be retrieved by [go-getter](https://github.com/hashicorp/go-getter) and the `"binaries"` field will be parsed as above.
11292

113-
This file contained in the link will be retrieved by [go-getter](https://github.com/hashicorp/go-getter)
114-
and the `"binaries"` field will be parsed as above.
93+
If there is no local binary, `DAEMON_ALLOW_DOWNLOAD_BINARIES=on`, and we can access a canonical url for the new binary, then the `cosmovisor` will download it with [go-getter](https://github.com/hashicorp/go-getter) and unpack it into the `upgrades/<name>` folder to be run as if we installed it manually.
11594

116-
If there is no local binary, `DAEMON_ALLOW_DOWNLOAD_BINARIES=on`, and we can access a canonical url for the new binary,
117-
then the `cosmovisor` will download it with [go-getter](https://github.com/hashicorp/go-getter) and
118-
unpack it into the `upgrades/<name>` folder to be run as if we installed it manually.
95+
Note that for this mechanism to provide strong security guarantees, all URLs should include a SHA 256/512 checksum. This ensures that no false binary is run, even if someone hacks the server or hijacks the DNS. `go-getter` will always ensure the downloaded file matches the checksum if it is provided. `go-getter` will also handle unpacking archives into directories (in this case the download link should point to a `zip` file of all data in the `bin` directory).
96+
97+
To properly create a sha256 checksum on linux, you can use the `sha256sum` utility. For example:
98+
99+
```
100+
sha256sum ./testdata/repo/zip_directory/autod.zip
101+
```
119102

120-
Note that for this mechanism to provide strong security guarantees, all URLS should include a
121-
sha{256,512} checksum. This ensures that no false binary is run, even if someone hacks the server
122-
or hijacks the DNS. go-getter will always ensure the downloaded file matches the checksum if it
123-
is provided. go-getter will also handle unpacking archives into directories (so these download links should be
124-
a zip of all data in the `bin` directory).
103+
The result will look something like the following: `29139e1381b8177aec909fab9a75d11381cab5adf7d3af0c05ff1c9c117743a7`.
125104

126-
To properly create a checksum on linux, you can use the `sha256sum` utility. e.g.
127-
`sha256sum ./testdata/repo/zip_directory/autod.zip`
128-
which should return `29139e1381b8177aec909fab9a75d11381cab5adf7d3af0c05ff1c9c117743a7`.
129-
You can also use `sha512sum` if you like longer hashes, or `md5sum` if you like to use broken hashes.
130-
Make sure to set the hash algorithm properly in the checksum argument to the url.
105+
You can also use `sha512sum` if you would prefer to use longer hashes, or `md5sum` if you would prefer to use broken hashes. Whichever you choose, make sure to set the hash algorithm properly in the checksum argument to the URL.
131106

132107
## Example: simd
133108

134-
The following instructions provide a demonstration of `cosmovisor`'s integration with the `simd` application
135-
shipped along the Cosmos SDK's source code.
109+
The following instructions provide a demonstration of `cosmovisor`'s integration with the `simd` application shipped along the Cosmos SDK's source code. The following commands are to be run from within the `cosmos-sdk` repository.
136110

137111
First compile `simd`:
138112

139113
```
140-
cd cosmos-sdk/
141114
make build
142115
```
143116

144-
Create a new key and setup the `simd` node:
117+
Create a new key and set up the `simd` node:
145118

146119
```
147120
rm -rf $HOME/.simapp
148121
./build/simd keys --keyring-backend=test add validator
149122
./build/simd init testing --chain-id test
150-
./build/simd add-genesis-account --keyring-backend=test $(./build/simd keys --keyring-backend=test show validator -a) 1000000000stake,1000000000validatortoken
151-
./build/simd gentx --keyring-backend test --chain-id test validator 100000stake
123+
./build/simd add-genesis-account --keyring-backend=test validator 1000000000stake
124+
./build/simd gentx --keyring-backend test --chain-id test validator 1000000stake
152125
./build/simd collect-gentxs
153126
```
154127

155128
Set the required environment variables:
156129

157130
```
158-
export DAEMON_NAME=simd # binary name
159-
export DAEMON_HOME=$HOME/.simapp # daemon's home directory
131+
export DAEMON_NAME=simd
132+
export DAEMON_HOME=$HOME/.simapp
160133
```
161134

162-
Create the `cosmovisor`’s genesis folders and deploy the binary:
135+
Set the optional environment variable to trigger an automatic restart:
136+
137+
```
138+
export DAEMON_RESTART_AFTER_UPGRADE=true
139+
```
140+
141+
Create the `cosmovisor`’s genesis folders and copy the `simd` binary:
163142

164143
```
165144
mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin
166145
cp ./build/simd $DAEMON_HOME/cosmovisor/genesis/bin
167146
```
168147

169-
For the sake of this demonstration, we would amend `voting_params.voting_period` in `.simapp/config/genesis.json` to a reduced time ~5 minutes (300s) and eventually launch `cosmosvisor`:
148+
For the sake of this demonstration, amend `voting_params.voting_period` in `$HOME/.simapp/config/genesis.json` to a reduced time of ~5 minutes (`300s`) and then start `cosmosvisor`:
170149

171150
```
172151
cosmovisor start
173152
```
174153

175-
Submit a software upgrade proposal:
154+
Open a new terminal window and submit a software upgrade proposal:
176155

177156
```
178157
./build/simd tx gov submit-proposal software-upgrade test1 --title "upgrade-demo" --description "upgrade" --from validator --upgrade-height 100 --deposit 10000000stake --chain-id test --keyring-backend test -y
@@ -184,35 +163,39 @@ Query the proposal to ensure it was correctly broadcast and added to a block:
184163
./build/simd query gov proposal 1
185164
```
186165

187-
Submit a `Yes` vote for the upgrade proposal:
166+
Submit a `yes` vote for the upgrade proposal:
188167

189168
```
190169
./build/simd tx gov vote 1 yes --from validator --keyring-backend test --chain-id test -y
191170
```
192171

193-
For the sake of this demonstration, we will hardcode a modification in `simapp` to simulate a code change.
194-
In `simapp/app.go`, find the line containing the upgrade Keeper initialisation, it should look like
195-
`app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath)`.
172+
For the sake of this demonstration, we will hardcode a modification in `simapp` to simulate a code change. In `simapp/app.go`, find the line containing the `UpgradeKeeper` initialization. It should look like the following:
173+
174+
```
175+
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath)
176+
```
177+
196178
After that line, add the following snippet:
197179

198180
```
199-
app.UpgradeKeeper.SetUpgradeHandler("test1", func(ctx sdk.Context, plan upgradetypes.Plan) {
200-
// Add some coins to a random account
201-
addr, err := sdk.AccAddressFromBech32("cosmos18cgkqduwuh253twzmhedesw3l7v3fm37sppt58")
202-
if err != nil {
203-
panic(err)
204-
}
205-
err = app.BankKeeper.AddCoins(ctx, addr, sdk.Coins{sdk.Coin{Denom: "stake", Amount: sdk.NewInt(345600000)}})
206-
if err != nil {
207-
panic(err)
208-
}
209-
})
181+
app.UpgradeKeeper.SetUpgradeHandler("test1", func(ctx sdk.Context, plan upgradetypes.Plan) {
182+
// Add some coins to a random account
183+
addr, err := sdk.AccAddressFromBech32("cosmos18cgkqduwuh253twzmhedesw3l7v3fm37sppt58")
184+
if err != nil {
185+
panic(err)
186+
}
187+
err = app.BankKeeper.AddCoins(ctx, addr, sdk.Coins{sdk.Coin{Denom: "stake", Amount: sdk.NewInt(345600000)}})
188+
if err != nil {
189+
panic(err)
190+
}
191+
})
210192
```
211193

212-
Now recompile a new binary and place it in `$DAEMON_HOME/cosmosvisor/upgrades/test1/bin`:
194+
Now recompile a new binary and make a copy of it in `$DAEMON_HOME/cosmosvisor/upgrades/test1/bin` (you may need to run `export DAEMON_HOME=$HOME/.simapp` again if you are using a new window):
213195

214196
```
215197
make build
198+
mkdir -p $DAEMON_HOME/cosmovisor/upgrades/test1/bin
216199
cp ./build/simd $DAEMON_HOME/cosmovisor/upgrades/test1/bin
217200
```
218201

0 commit comments

Comments
 (0)