Skip to content

Commit

Permalink
Add a script to make testing upgrades easier. (#1097)
Browse files Browse the repository at this point in the history
* Add script for submiting a test upgraade proposal, voting for it and querying the votes.

* Update documentation on how to do a test software upgrade.
  • Loading branch information
SpicyLemon authored Oct 4, 2022
1 parent 2c758fa commit 98ee791
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 56 deletions.
69 changes: 13 additions & 56 deletions docs/testing_software_upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,22 @@ This document outlines how to do a local software upgrade for testing purposes o
An upgrade in Provenance is done by a node submitting a proposal with a deposit in hash. This proposal contains the blockchain height as well as the upgrade name. Once a sufficient deposit has been made the proposal enters a voting period where any user with hash may vote. After the voting period, defined in the genesis.json, the proposal will either pass or fail. If the proposal passes, the chain will stop at the height of the proposal. Then the chain must be restarted with the upgrade handler with the upgrade name. This upgrade handler will execute and the chain will continue running with the software upgrade.

## Steps
1. [ ] Check out previous version of Provenance
1. [ ] Check out previous version of Provenance.
- For example: `git checkout v1.7.5`
2. [ ] Build and configure Provenance

2. [ ] Build and configure Provenance:
- `go mod vendor && make clean build run-config`
3. [ ] Update the genesis.json file to shorten the voting period to 20s

3. [ ] Update the genesis.json file to shorten the voting period to 20s:
- `./scripts/upgrade-config.sh`
4. [ ] Run the chain

4. [ ] Run the chain:
- `make run`

5. [ ] In a separate terminal window save the validator address:
- `provenanced -t keys list --home ./build/run/provenanced`
- `export valAddr="<addr listed above>"`

6. [ ] Submit a software upgrade proposal with the desired name and upgrade height. The upgrade height should be at least 100 blocks above the current height to allow for the 20s voting period to finish before the height is reached or the upgrade will become invalid.
```bash
provenanced -t tx gov submit-proposal software-upgrade "<name>" \
--title "<title>" \
--description "<description>" \
--upgrade-info="<name>" \
--from "$valAddr" \
--upgrade-height 200 \
--deposit 10000000nhash \
--chain-id=testing \
--keyring-backend test \
--gas-prices="1905nhash" \
--gas=auto \
--gas-adjustment=1.5 \
--home=./build/run/provenanced \
--yes
```

7. [ ] Query the proposal with the following command:
```bash
provenanced query gov proposals
```

8. [ ] Before the 20s voting period has elapsed vote with the following cmd:
```bash
provenanced -t tx gov vote "1" yes\
--gas-prices="1905nhash" \
--gas=auto \
--gas-adjustment=1.5 \
--from "$valAddr" \
--keyring-backend=test \
--chain-id=testing \
--home=./build/run/provenanced \
--yes
```
If there are more than one proposals you will need to replace "1" with the number of the proposal you wish to vote on.

9. [ ] Query the vote tally before the voting period has ended
```bash
provenanced query gov tally 1
```
5. [ ] In a separate terminal window, submit a new proposal, vote on it, and get the tally:
- `./scripts/upgrade-test.sh <upgrade color>`

10. [ ] Wait for the chain to halt with an error when it reaches the upgrade height specified
11. [ ] Check out the branch with the upgrade handler
12. [ ] Run `go mod vendor && make build run` to restart the chain triggering the software upgrade
13. [ ] Verify and enjoy any new functionality from the upgraded version :)
6. [ ] Wait for the chain to halt with an error when it reaches the upgrade height specified.
7. [ ] Check out the branch with the upgrade handler.
8. [ ] Run `go mod vendor && make build run` to restart the chain triggering the software upgrade.
9. [ ] Verify and enjoy any new functionality from the upgraded version. :)
72 changes: 72 additions & 0 deletions scripts/upgrade-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash
# This script will submit a test upgrade proposal, and vote for it.
# It's assumed that you're running it from the root of this repo.
# This script looks to the following env vars for configuration:
# PIO_HOME: Default: build/run/provenanced
# PIO_CHAIN_ID: Default: testing
# PIO_KEYRING_BACKEND: Default: test
# PROV: The provenanced executable. Default: build/provenanced
# DEPOSIT: The --deposit amount for the upgrade gov proposal. Default: 10000000nhash
# GAS_PRICES: The --gas-prices amount for the tx commands. Default: 1905nhash
# GAS: The --gas amount for the tx commands. Default: auto
# GAS_ADJUSTMENT: The --gas-adjustment amount for tx commands. Only used for --gas=auto. Default: 1.5
# HEIGHT_PLUS: The number of blocks in the future to do the upgrade (must happen after voting ends). Default: 40

if [[ -z "$1" ]]; then
printf 'Usage: %s <color>\n' "$0"
exit 1
fi

color="$1"
shift


set -ex
export PIO_TESTNET=true
export PIO_OUTPUT=json
export PIO_HOME="${PIO_HOME:-build/run/provenanced}"
export PIO_CHAIN_ID="${PIO_CHAIN_ID:-testing}"
export PIO_KEYRING_BACKEND="${PIO_KEYRING_BACKEND:-test}"
prov="${PROV:-build/provenanced}"
deposit="${DEPOSIT:-10000000nhash}"
gasPrices="${GAS_PRICES:-1905nhash}"
gas="${GAS:-auto}"
gasAdj="${GAS_ADJUSTMENT:-1.5}"
gasArgs="--gas-prices=$gasPrices --gas=$gas"
if [ "$gas" == 'auto' ]; then
gasArgs="$gasArgs --gas-adjustment=$gasAdj"
fi
heightPlus="${HEIGHT_PLUS:-40}"

prop_cmd='submit-proposal'
no_val=''
if "$prov" tx gov "$prop_cmd" software-upgrade --help 2>&1 | grep -qF 'proposal.json' > /dev/null 2>&1; then
prop_cmd='submit-legacy-proposal'
no_val='--no-validate'
fi


valAddr="$( "$prov" keys list --output json | jq -r '.[] | select( .name == "validator" ) | .address' )"
curHeight="$( "$prov" status | jq -r '.SyncInfo.latest_block_height' )"
targetHeight="$(( curHeight + heightPlus ))"

propRes="$( "$prov" tx gov "$prop_cmd" software-upgrade "$color" \
--title "Upgrade for $color" \
--description "Upgrading provenance to $color" \
--upgrade-info="$color" \
--upgrade-height "$targetHeight" \
--deposit "$deposit" \
--from "$valAddr" \
$gasArgs $no_val \
--yes )"

propId="$( tail -n 1 <<< "$propRes" | jq -r '.logs[0].events[] | select( .type == "submit_proposal" ) | .attributes[] | select( .key == "proposal_id" ) | .value' )"

"$prov" tx gov vote "$propId" yes \
--from "$valAddr" \
$gasArgs \
--yes

"$prov" query gov tally "$propId"

printf 'Success: Upgrade will happen at height=%d\n' "$targetHeight"

0 comments on commit 98ee791

Please sign in to comment.