Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Upgrade Scripts to Dockernet #307

Merged
merged 8 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
sampocs marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
2 changes: 1 addition & 1 deletion scripts/init_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions scripts/start_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,37 @@ 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
# Create cosmovisor directories
mkdir -p $SCRIPT_DIR/upgrades/cosmovisor/genesis/bin/
mkdir -p $SCRIPT_DIR/upgrades/cosmovisor/upgrades/$UPGRADE_NAME/bin/
mkdir -p $SCRIPT_DIR/state/stride/cosmovisor

# Update binary2 with the binary that was just compiled
rm -f $SCRIPT_DIR/upgrades/binaries/strided2
cp $SCRIPT_DIR/../build/strided $SCRIPT_DIR/upgrades/binaries/strided2

# Place the two binaries in the appropriate cosmosvisor directory
cp $SCRIPT_DIR/upgrades/binaries/strided1 $SCRIPT_DIR/upgrades/cosmovisor/genesis/bin/strided
cp $SCRIPT_DIR/upgrades/binaries/strided2 $SCRIPT_DIR/upgrades/cosmovisor/upgrades/$UPGRADE_NAME/bin/strided

# 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
docker build -t stridezone:cosmovisor --build-arg old_commit_hash=$UPGRADE_OLD_COMMIT_HASH -f ${SCRIPT_DIR}/upgrades/Dockerfile.cosmovisor .
docker build -t stridezone:stride -f ${SCRIPT_DIR}/upgrades/Dockerfile.stride .
fi

# Initialize the state for each chain
for chain_id in STRIDE ${HOST_CHAINS[@]}; do
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-util/4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 26 additions & 0 deletions scripts/upgrades/Dockerfile.cosmovisor
Original file line number Diff line number Diff line change
@@ -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 \
&& make cosmovisor

# Build the old binary
RUN git clone https://github.com/Stride-Labs/stride.git \
&& cd stride \
&& git checkout $old_commit_hash \
&& 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 make build


24 changes: 24 additions & 0 deletions scripts/upgrades/Dockerfile.stride
Original file line number Diff line number Diff line change
@@ -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" ]
36 changes: 36 additions & 0 deletions scripts/upgrades/README.md
Original file line number Diff line number Diff line change
@@ -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`
34 changes: 34 additions & 0 deletions scripts/upgrades/submit_upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

PROPOSAL_NAME="v2"
UPGRADE_HEIGHT=150

STRIDED="$SCRIPT_DIR/binaries/strided1 --home $SCRIPT_DIR/../state/stride"

printf "\nPROPOSAL\n"
$STRIDED tx gov submit-proposal software-upgrade $PROPOSAL_NAME \
--title $PROPOSAL_NAME --description "version 2 description" \
--upgrade-height $UPGRADE_HEIGHT --from val1 -y

sleep 5
printf "\nPROPOSAL CONFIRMATION\n"
$STRIDED query gov proposals

sleep 5
printf "\nDEPOSIT\n"
$STRIDED tx gov deposit 1 10000001ustrd --from val1 -y

sleep 5
printf "\nDEPOSIT CONFIRMATION\n"
$STRIDED query gov deposits 1

sleep 5
printf "\nVOTE\n"
$STRIDED tx gov vote 1 yes --from val1 -y

sleep 5
printf "\nVOTE CONFIRMATION\n"
$STRIDED query gov tally 1
8 changes: 8 additions & 0 deletions scripts/upgrades/view_proposal_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
STRIDED=scripts-local/upgrades/binaries/strided1
sampocs marked this conversation as resolved.
Show resolved Hide resolved

$STRIDED query gov proposal 1 | grep "voting_end_time"

while true; do
$STRIDED query gov proposal 1 | grep "status"
sleep 5
done
4 changes: 4 additions & 0 deletions scripts/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down