-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Upgrade Scripts to Dockernet (#307)
- Loading branch information
Showing
11 changed files
with
183 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters