diff --git a/.gitignore b/.gitignore index fa635c451..79305aad9 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,8 @@ scripts/tests/validator_selection scripts/tests/local_tests.bats scripts-local/upgrades/binaries scripts-local/upgrades/cosmovisor +scripts/upgrades/binaries +scripts/upgrades/cosmovisor vue/* # Test binary, built with `go test -c` *.test diff --git a/README.md b/README.md index 3df789dd7..eacb669d6 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ You can optionally pass build arguments to specify which binary to rebuild 2. `g` This will re-build the Gaia binary 3. `j` This will re-build the Juno binary 4. `j` This will re-build the Osmo binary -5. `j` This will re-build the Stargaze binary +5. `t` This will re-build the Stargaze binary 6. `r` This will re-build the Go Relayer binary 7. `h` This will re-build the Hermes binary 8. `i` This will re-build the ICQ binary diff --git a/scripts/init_chain.sh b/scripts/init_chain.sh index 06e49aa40..c70242ebe 100644 --- a/scripts/init_chain.sh +++ b/scripts/init_chain.sh @@ -165,7 +165,7 @@ $MAIN_NODE_CMD collect-gentxs &> /dev/null # wipe out the persistent peers for the main node (these are incorrectly autogenerated for each validator during collect-gentxs) sed -i -E "s|persistent_peers = .*|persistent_peers = \"\"|g" $MAIN_CONFIG -# update chian-specific genesis settings +# update chain-specific genesis settings if [ "$CHAIN_ID" == "$STRIDE_CHAIN_ID" ]; then set_stride_genesis $MAIN_GENESIS else diff --git a/scripts/register_host.sh b/scripts/register_host.sh index ddf75ba1b..52aee00dd 100644 --- a/scripts/register_host.sh +++ b/scripts/register_host.sh @@ -10,7 +10,6 @@ HOST_ZONE_NUM="$2" CONNECTION="connection-$HOST_ZONE_NUM" CHANNEL="channel-$HOST_ZONE_NUM" -MAIN_CMD=$(GET_VAR_VALUE ${CHAIN_ID}_MAIN_CMD) VAL_PREFIX=$(GET_VAR_VALUE ${CHAIN_ID}_VAL_PREFIX) IBC_DENOM=$(GET_VAR_VALUE IBC_${CHAIN_ID}_CHANNEL_${HOST_ZONE_NUM}_DENOM) HOST_DENOM=$(GET_VAR_VALUE ${CHAIN_ID}_DENOM) @@ -20,7 +19,7 @@ NUM_VALS=$(GET_VAR_VALUE ${CHAIN_ID}_NUM_NODES) echo "$CHAIN_ID - Registering host zone..." $STRIDE_MAIN_CMD tx stakeibc register-host-zone \ $CONNECTION $HOST_DENOM $ADDRESS_PREFIX $IBC_DENOM $CHANNEL 1 \ - --gas 1000000 --from $STRIDE_ADMIN_ACCT --home $SCRIPT_DIR/state/stride1 -y | grep -E "code:|txhash:" | sed 's/^/ /' + --gas 1000000 --from $STRIDE_ADMIN_ACCT --home $SCRIPT_DIR/state/stride1 -y | TRIM_TX sleep 4 echo "$CHAIN_ID - Registering validators..." @@ -30,7 +29,7 @@ for (( i=1; i <= $NUM_VALS; i++ )); do weight=${weights[$i]} $STRIDE_MAIN_CMD tx stakeibc add-validator $CHAIN_ID ${VAL_PREFIX}${i} $delegate_val 10 $weight \ - --from $STRIDE_ADMIN_ACCT -y | grep -E "code:|txhash:" | sed 's/^/ /' + --from $STRIDE_ADMIN_ACCT -y | TRIM_TX sleep 4 done diff --git a/scripts/start_network.sh b/scripts/start_network.sh index b9769377c..69d97d988 100755 --- a/scripts/start_network.sh +++ b/scripts/start_network.sh @@ -4,15 +4,36 @@ set -eu SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source ${SCRIPT_DIR}/vars.sh +HOST_CHAINS=(GAIA JUNO OSMO STARS) + # cleanup any stale state -docker-compose down +make stop-docker rm -rf $SCRIPT_DIR/state $SCRIPT_DIR/logs/*.log $SCRIPT_DIR/logs/temp mkdir -p $SCRIPT_DIR/logs HERMES_LOGS=$SCRIPT_DIR/logs/hermes.log ICQ_LOGS=$SCRIPT_DIR/logs/icq.log -HOST_CHAINS=(GAIA JUNO OSMO STARS) +# If we're testing an upgrade, setup cosmovisor +if [[ "$UPGRADE_NAME" != "" ]]; then + printf "\n>>> UPGRADE ENABLED! ($UPGRADE_NAME)\n\n" + + # Update binary #2 with the binary that was just compiled + mkdir -p $SCRIPT_DIR/upgrades/binaries + rm -f $SCRIPT_DIR/upgrades/binaries/strided2 + cp $SCRIPT_DIR/../build/strided $SCRIPT_DIR/upgrades/binaries/strided2 + + # Build a cosmovisor image with the old binary and replace the stride docker image with a new one + # that has both binaries and is running cosmovisor + # The reason for having a separate cosmovisor image is so we can cache the building of cosmovisor and the old binary + echo "Building Cosmovisor..." + docker build -t stridezone:cosmovisor --build-arg old_commit_hash=$UPGRADE_OLD_COMMIT_HASH -f ${SCRIPT_DIR}/upgrades/Dockerfile.cosmovisor . + + echo "Re-Building Stride with Upgrade Support..." + docker build -t stridezone:stride -f ${SCRIPT_DIR}/upgrades/Dockerfile.stride . + + echo "Done" +fi # Initialize the state for each chain for chain_id in STRIDE ${HOST_CHAINS[@]}; do diff --git a/scripts/test-util/4.sh b/scripts/test-util/4.sh index cbcb1d0a6..fec083536 100644 --- a/scripts/test-util/4.sh +++ b/scripts/test-util/4.sh @@ -7,7 +7,7 @@ source ${SCRIPT_DIR}/../vars.sh $GAIA_MAIN_CMD q bank balances $GAIA_RECEIVER_ACCT #claim stake -EPOCH=5 +EPOCH=$($STRIDE_MAIN_CMD q records list-user-redemption-record | grep -Fiw 'epochNumber' | head -n 1 | grep -o -E '[0-9]+') SENDER=stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7 $STRIDE_MAIN_CMD tx stakeibc claim-undelegated-tokens GAIA $EPOCH $(STRIDE_ADDRESS) --from ${STRIDE_VAL_PREFIX}1 -y diff --git a/scripts/upgrades/Dockerfile.cosmovisor b/scripts/upgrades/Dockerfile.cosmovisor new file mode 100644 index 000000000..184c265e9 --- /dev/null +++ b/scripts/upgrades/Dockerfile.cosmovisor @@ -0,0 +1,26 @@ +# syntax = docker/dockerfile:1 +FROM golang:1.18-alpine3.15 AS builder + +ARG old_commit_hash +RUN test -n "$old_commit_hash" + +WORKDIR /opt/ + +RUN apk add --no-cache make git gcc musl-dev openssl-dev linux-headers + +# Install cosmovisor +RUN git clone https://github.com/cosmos/cosmos-sdk \ + && cd cosmos-sdk \ + && git checkout cosmovisor/v1.1.0 +RUN --mount=type=cache,target=/root/.cache/go-build cd /opt/cosmos-sdk && make cosmovisor + +# Build the old binary +RUN git clone https://github.com/Stride-Labs/stride.git \ + && cd stride \ + && git checkout $old_commit_hash \ + && sed -i -E "s|stride1k8c2m5cn322akk5wy8lpt87dd2f4yh9azg7jlh|stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8|g" utils/utils.go \ + && env GOOS=linux GOARCH=amd64 go build -mod=readonly -trimpath -o /opt/build/ ./... \ + && mv /opt/build/strided /opt/build/strided1 +RUN --mount=type=cache,target=/root/.cache/go-build cd /opt/stride && make build + + diff --git a/scripts/upgrades/Dockerfile.stride b/scripts/upgrades/Dockerfile.stride new file mode 100644 index 000000000..c3dd02751 --- /dev/null +++ b/scripts/upgrades/Dockerfile.stride @@ -0,0 +1,24 @@ +# syntax = docker/dockerfile:1 +FROM alpine:3.15 + +ENV DAEMON_NAME=strided +ENV DAEMON_HOME=/home/stride/.stride +ENV DAEMON_RESTART_AFTER_UPGRADE=true +ENV COSMOVISOR_HOME=/home/stride/cosmovisor + +RUN apk add --update vim bash \ + && addgroup -g 1000 stride \ + && adduser -S -h /home/stride -D stride -u 1000 -G stride + +COPY --from=stridezone:cosmovisor /opt/cosmos-sdk/cosmovisor/cosmovisor /usr/local/bin/cosmovisor +COPY --from=stridezone:cosmovisor --chown=stride:stride /opt/build/strided1 ${COSMOVISOR_HOME}/genesis/bin/strided +COPY --from=stridezone:stride --chown=stride:stride /usr/local/bin/strided ${COSMOVISOR_HOME}/upgrades/${UPGRADE_NAME}/bin/strided + +USER stride +WORKDIR /home/stride + +EXPOSE 26657 26656 1317 9090 + +RUN echo "mv ${COSMOVISOR_HOME} ${DAEMON_HOME}/cosmovisor && cosmovisor run start" > start.sh + +CMD ["bash", "start.sh" ] diff --git a/scripts/upgrades/README.md b/scripts/upgrades/README.md new file mode 100644 index 000000000..f16d7eb55 --- /dev/null +++ b/scripts/upgrades/README.md @@ -0,0 +1,36 @@ +# Testing Upgrades in Local Mode +## Run Instructions +* Before working on the upgrade logic, compile the original binary and place it in `scripts/upgrades/binaries/` named `strided1` +* **This binary should represent the code before the upgrade changes. You'll likely want to checkout to the main branch to compile this.** +``` +git checkout {OLD_COMMIT_HASH} +make build-docker build=s +mkdir -p scripts/upgrades/binaries +cp build/strided scripts/upgrades/binaries/strided1 +git checkout {UPDATED_BRANCH} +``` +* Then switch the code back to the most recent version +* Enter the commit hash of the old binary (built above) as `UPGRADE_OLD_COMMIT_HASH` in `scripts/vars.sh` +* Enter upgrade name as `UPGRADE_NAME` in `scripts/vars.sh` and `PROPOSAL_NAME` in `scripts/submit_upgrade.sh` +* Optionally update timing parameters the upgrade height (`UPGRADE_HEIGHT` in `scripts/submit_upgrade.sh`) +* Then startup the chain as normal and rebuild stride +``` +make start-docker build=s +``` +* The startup script will: + * Compile the new binary + * Create the cosmosvisor file structure required for upgrades + * Rebuild and replace the stride docker image with an image that has both binaries and is running cosmosvisor + * This image pulls the new binary from the normal docker build that happens at the start of running this make command +* Once the chain is up and running, run the upgrade script to propose and vote on an upgrade +``` +bash scripts/upgrades/submit_upgrade.sh +``` +* To view the status of the proposal (and confirm it has passed), open up a new terminal window and run +``` +bash scripts/upgrades/view_proposal_status.sh +``` + * It will first print the time at which voting ends, and then continuously probe the status. You must see "PROPOSAL_STATUS_PASSED" before the upgrade height in order for the upgrade to go through. +* While the chain is running, now is a good time to test your pre-upgrade condition (i.e. some validation that indicates you are on the old binary). When doing so, use `scripts/upgrades/binaries/strided1` +* View the stride logs - you should notice an update occuring at the specified upgrade height. +* After the upgrade has occured, check a post-upgrade condition using `scripts/upgrades/binaries/strided2` diff --git a/scripts/upgrades/submit_upgrade.sh b/scripts/upgrades/submit_upgrade.sh new file mode 100644 index 000000000..b8654ce5c --- /dev/null +++ b/scripts/upgrades/submit_upgrade.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +set -eu +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source ${SCRIPT_DIR}/../vars.sh + +UPGRADE_HEIGHT=250 + +printf "PROPOSAL\n" +$STRIDE_MAIN_CMD tx gov submit-proposal software-upgrade $UPGRADE_NAME \ + --title $UPGRADE_NAME --description "version 2 description" \ + --upgrade-height $UPGRADE_HEIGHT --from val1 -y | TRIM_TX + +sleep 5 +printf "\nPROPOSAL CONFIRMATION\n" +$STRIDE_MAIN_CMD query gov proposals + +sleep 5 +printf "\nDEPOSIT\n" +$STRIDE_MAIN_CMD tx gov deposit 1 10000001ustrd --from val1 -y | TRIM_TX + +sleep 5 +printf "\nDEPOSIT CONFIRMATION\n" +$STRIDE_MAIN_CMD query gov deposits 1 + +sleep 5 +printf "\nVOTING\n" +$STRIDE_MAIN_CMD tx gov vote 1 yes --from val1 -y | TRIM_TX +$STRIDE_MAIN_CMD tx gov vote 1 yes --from val2 -y | TRIM_TX +$STRIDE_MAIN_CMD tx gov vote 1 yes --from val3 -y | TRIM_TX + +sleep 5 +printf "\nVOTE CONFIRMATION\n" +$STRIDE_MAIN_CMD query gov tally 1 + +printf "\nPROPOSAL STATUS\n" +while true; do + status=$($STRIDE_MAIN_CMD query gov proposal 1 | grep "status" | awk '{printf $2}') + if [[ "$status" == "PROPOSAL_STATUS_VOTING_PERIOD" ]]; then + echo "Proposal still in progress..." + sleep 5 + elif [[ "$status" == "PROPOSAL_STATUS_PASSED" ]]; then + echo "Proposal passed!" + exit 0 + elif [[ "$status" == "PROPOSAL_STATUS_REJECTED" ]]; then + echo "Proposal Failed!" + exit 1 + else + echo "Unknown proposal status: $status" + exit 1 + fi +done diff --git a/scripts/vars.sh b/scripts/vars.sh index 9cdcea4d1..7b4bbe562 100644 --- a/scripts/vars.sh +++ b/scripts/vars.sh @@ -12,6 +12,10 @@ STRIDE_LOGS=$LOGS/stride.log TX_LOGS=$SCRIPT_DIR/logs/tx.log KEYS_LOGS=$SCRIPT_DIR/logs/keys.log +# Sets up upgrade if {UPGRADE_NAME} is non-empty +UPGRADE_NAME="" +UPGRADE_OLD_COMMIT_HASH="" + # DENOMS ATOM_DENOM='uatom' JUNO_DENOM='ujuno' @@ -71,12 +75,18 @@ ADMIN_TOKENS=1000000000 STRIDE_CHAIN_ID=STRIDE STRIDE_NODE_PREFIX=stride STRIDE_NUM_NODES=3 -STRIDE_CMD="$SCRIPT_DIR/../build/strided" STRIDE_VAL_PREFIX=val STRIDE_DENOM=$STRD_DENOM STRIDE_RPC_PORT=26657 STRIDE_ADMIN_ACCT=admin STRIDE_ADMIN_ADDRESS=stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8 + +# Binaries are contigent on whether we're doing an upgrade or not +if [[ "$UPGRADE_NAME" == "" ]]; then + STRIDE_CMD="$SCRIPT_DIR/../build/strided" +else + STRIDE_CMD="$SCRIPT_DIR/upgrades/binaries/strided1" +fi STRIDE_MAIN_CMD="$STRIDE_CMD --home $SCRIPT_DIR/state/${STRIDE_NODE_PREFIX}1" STRIDE_MNEMONIC_1="close soup mirror crew erode defy knock trigger gather eyebrow tent farm gym gloom base lemon sleep weekend rich forget diagram hurt prize fly" @@ -297,4 +307,8 @@ GET_ICA_ADDR() { ica_type="$2" #delegation, fee, redemption, or withdrawal $STRIDE_MAIN_CMD q stakeibc show-host-zone $chain_id | grep ${ica_type}Account -A 1 | grep address | awk '{print $2}' +} + +TRIM_TX() { + grep -E "code:|txhash:" | sed 's/^/ /' } \ No newline at end of file