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

Upgrade tests #1052

Merged
merged 10 commits into from
Nov 9, 2023
2 changes: 1 addition & 1 deletion .github/workflows/chain_genesis-export.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
version: 0.6.30

- run: earthly --ci +prep-genesis
- run: earthly --ci --no-cache --output +prep-genesis
working-directory: ./chain

- name: Archive genesis file
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/chain_upgrade-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "Test EmpowerChain Upgrade"

on:
workflow_dispatch:
# TODO: Maybe do on a cron schedule, every week or something?

jobs:
test-testnet-upgrade:
name: Test EmpowerChain Testnet Upgrade
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- uses: earthly/actions-setup@v1
with:
version: 0.6.30

- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: exported-testnet-genesis
path: chain

- run: earthly --ci --no-cache +upgrade-test --UPGRADE_NAME=v2 # Rely on defaults for other args/env vars
working-directory: ./chain
134 changes: 121 additions & 13 deletions chain/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,25 @@ ibc-conformance-test:
END
SAVE ARTIFACT /root/.interchaintest/reports/* AS LOCAL build/interchaintest-reports/

# TODO: Make all the URLs and network version (mainnet/testnet) into ARGS
prep-genesis:
ARG CURRENT_VERSION=v1.0.0 # TODO: Any way to get the correct version for mainnet, testnet?
ARG CHAIN_ID=circulus-1 #empowerchain-1
ARG STATE_SYNC_RPC=https://empower-testnet-rpc.polkachu.com:443 #https://empower-rpc.polkachu.com:443 # TODO: Switch to Empower's own STATE SYNC RPC
ARG STATE_SYNC_PEER=95ea7999e3ecd3fb7fd73fae70b3b29a6af24c8d@46.4.5.45:17456 #[email protected]:17456 # TODO: Switch to Empower's own state sync peer
node-base:
ARG CURRENT_VERSION=v1.0.1-rc1 # TODO: Any way to get the correct version for mainnet, testnet?
RUN apt-get update -yq \
&& apt-get install --no-install-recommends -yq \
curl tar wget clang pkg-config libssl-dev jq \
build-essential bsdmainutils git make ncdu gcc \
git jq chrony liblz4-tool unzip
RUN wget https://github.com/EmpowerPlastic/empowerchain/releases/download/${CURRENT_VERSION}/empowerd-${CURRENT_VERSION}-linux-amd64.zip
RUN unzip empowerd-${CURRENT_VERSION}-linux-amd64.zip
RUN ./empowerd init genesis-prepper --chain-id ${CHAIN_ID}
RUN unzip empowerd-${CURRENT_VERSION}-linux-amd64.zip -d /root/binaries
ENV PATH $PATH:/root/binaries

# earthly +prep-genesis --CHAIN_ID=empowerchain-1 --STATE_SYNC_RPC=https://empower-rpc.polkachu.com:443 --STATE_SYNC_PEER=074640d8f2bc981fd201badd19c5b6dba38e00be@65.108.238.219:17456
prep-genesis:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions here:

  1. Do we have state sync set up ourselves (for both testnet and mainnet)?
  2. Should we make the args into a single arg (mainnet, testnet) and use a script or something to export args somehow? Got any good ideas how to make this a bit nicer to use?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Just enabled state sync on both.
  2. It'd go old fashioned way and create bash script(s) with the args and leave earthly invocation as it is

ARG CURRENT_VERSION=v1.0.1-rc1 # TODO: Any way to get the correct version for mainnet, testnet?
ARG CHAIN_ID=circulus-1 #empowerchain-1
ARG STATE_SYNC_RPC=https://empower-testnet-rpc.polkachu.com:443 #https://empower-rpc.polkachu.com:443 # TODO: Switch to Empower's own STATE SYNC RPC
gjermundgaraba marked this conversation as resolved.
Show resolved Hide resolved
ARG STATE_SYNC_PEER=95ea7999e3ecd3fb7fd73fae70b3b29a6af24c8d@46.4.5.45:17456 #[email protected]:17456 # TODO: Switch to Empower's own state sync peer
FROM +node-base --CURRENT_VERSION=${CURRENT_VERSION}
RUN empowerd init genesis-prepper --chain-id ${CHAIN_ID}
RUN echo '#!/bin/bash\n\
\n\
SNAP_RPC="${STATE_SYNC_RPC}"\n\
Expand All @@ -227,10 +232,113 @@ prep-genesis:
s|^(persistent_peers[[:space:]]+=[[:space:]]+).*$|\\1\"$PEER\"|" $HOME/.empowerchain/config/config.toml' > state_sync.sh
RUN chmod 700 state_sync.sh
RUN ./state_sync.sh
RUN ./empowerd start > /dev/null 2>&1 & sleep 5; \
while [ "`./empowerd status | jq -r ".SyncInfo.catching_up"`" != "false" ]; do \
echo "Waiting to catch up, current block: $(./empowerd status | jq -r ".SyncInfo.latest_block_height")"; \
RUN empowerd start > /dev/null 2>&1 & sleep 5; \
while [ "`empowerd status | jq -r ".SyncInfo.catching_up"`" != "false" ]; do \
echo "Waiting to catch up, current block: $(empowerd status | jq -r ".SyncInfo.latest_block_height")"; \
sleep 5; \
done
RUN ./empowerd export > exported-genesis.json
SAVE ARTIFACT exported-genesis.json AS LOCAL exported-genesis.json
RUN empowerd export > exported-genesis.json
SAVE ARTIFACT exported-genesis.json AS LOCAL exported-genesis.json

upgrade-test:
ARG CURRENT_VERSION=v1.0.1-rc1 # TODO: Any way to get the correct version for mainnet, testnet?
ARG VALPASS=passw0rd
ARG VALNAME=validator
ARG --required UPGRADE_NAME # TODO: Could this be parsed from CURRENT_VERSION if we keep a sane naming scheme?
FROM +node-base --CURRENT_VERSION=${CURRENT_VERSION}
COPY exported-genesis.json exported-genesis.json
COPY +build-with-wasmvm/empowerd ./new_empowerd
COPY +build-with-wasmvm/libwasmvm.x86_64.so /usr/local/lib/libwasmvm.x86_64.so
COPY +build-with-wasmvm/libwasmvm.aarch64.so /usr/local/lib/libwasmvm.aarch64.so
ENV LD_LIBRARY_PATH=/usr/local/lib

RUN empowerd init ${VALNAME}
# Set up validator key
RUN { echo ${VALPASS}; echo ${VALPASS}; } | empowerd keys add ${VALNAME}

# Set up devnet genesis for new key
RUN echo ${VALPASS} | empowerd genesis single-validator ./exported-genesis.json ${VALNAME} $(jq -r .pub_key.value ~/.empowerchain/config/priv_validator_key.json)
RUN mv exported-genesis.json.generated ~/.empowerchain/config/genesis.json
RUN sed -i -e 's/"voting_period": "172800s"/"voting_period": "30s"/g' ~/.empowerchain/config/genesis.json

RUN empowerd start > /tmp/before_upgrade_log 2>&1 & sleep 10; \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could of course be put into a script file, but not sure if there is much need for that? I am agnostic

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably put it into a script file, because of all these escape characters :)

max_catch_up_attempts=10; \
catch_up_count=0; \
while [ "`empowerd status | jq -r ".SyncInfo.catching_up"`" != "false" ] && [ $catch_up_count -lt $max_catch_up_attempts ]; do \
echo "Waiting to catch up (attempt ${catch_up_count}/${max_catch_up_attempts}, current block: $(empowerd status | jq -r ".SyncInfo.latest_block_height")"; \
sleep 5; \
catch_up_count=$((catch_up_count+1)); \
done; \
if [ $catch_up_count -eq $max_catch_up_attempts ]; then \
echo "Failed to catch up after ${max_catch_up_attempts} attempts."; \
cat /tmp/before_upgrade_log; \
exit 1; \
fi; \
sleep 10; \ # Just for good measure
UPGRADE_HEIGHT=$(($(empowerd status | jq -r ".SyncInfo.latest_block_height")+20)); \
echo "Upgrade prop for height $UPGRADE_HEIGHT"; \
echo "{\n\
\"messages\": [\n\
{\n\
\"@type\": \"/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade\",\n\
\"authority\": \"empower10d07y265gmmuvt4z0w9aw880jnsr700jxwhwvd\",\n\
\"plan\": {\n\
\"name\": \"${UPGRADE_NAME}\",\n\
\"time\": \"0001-01-01T00:00:00Z\",\n\
\"height\": \"${UPGRADE_HEIGHT}\",\n\
\"info\": \"${UPGRADE_NAME}\",\n\
\"upgraded_client_state\": null\n\
}\n\
}\n\
],\n\
\"metadata\": \"ipfs://CID\",\n\
\"deposit\": \"2000000000umpwr\",\n\
\"title\": \"Test upgrade proposal\",\n\
\"summary\": \"Test upgrade proposal summary\"\n\
}" > upgrade_proposal.json; \
echo ${VALPASS} | empowerd tx gov submit-proposal upgrade_proposal.json --from validator --yes --chain-id emp-devnet-1; \
sleep 5; \
PROP_ID=$(empowerd q gov proposals --reverse --limit 1 --output json | jq -r ".proposals[0].id"); \
echo "Voting on proposal $PROP_ID"; \
echo ${VALPASS} | empowerd tx gov vote ${PROP_ID} yes --from validator --yes --chain-id emp-devnet-1; \
sleep 30; \
GOV_RESULT=$(empowerd q gov proposal ${PROP_ID} --output json | jq -r ".status"); \
if [ "$GOV_RESULT" != "PROPOSAL_STATUS_PASSED" ]; then \
echo "Error: Proposal not passed: $GOV_RESULT"; \
exit 1; \
fi; \
max_upgrade_wait_attempts=30; \
upgrade_wait_count=0; \
while [ "`empowerd status | jq -r ".SyncInfo.latest_block_height"`" != ${UPGRADE_HEIGHT} ] && [ $upgrade_wait_count -lt $max_upgrade_wait_attempts ]; do \
echo "Waiting for upgrade height (${UPGRADE_HEIGHT}, attempt ${upgrade_wait_count}/${max_upgrade_wait_attempts}), current block: $(empowerd status | jq -r ".SyncInfo.latest_block_height")"; \
sleep 5; \
upgrade_wait_count=$((upgrade_wait_count+1)); \
done; \
if [ $upgrade_wait_count -eq $max_upgrade_wait_attempts ]; then \
echo "Failed to wait for upgrade height ${max_upgrade_wait_attempts} attempts."; \
cat /tmp/before_upgrade_log; \
exit 1; \
fi; \
sleep 5; \ # Just for good measure
pkill empowerd; \
sleep 5; \ # Just for good measure
./new_empowerd start > /tmp/after_upgrade_log 2>&1 & sleep 60; \
after_upgrade_max_catch_up_attempts=10; \
after_upgrade_catch_up_count=0; \
while [ "`./new_empowerd status | jq -r ".SyncInfo.catching_up"`" != "false" ] && [ $after_upgrade_catch_up_count -lt $after_upgrade_max_catch_up_attempts ]; do \
echo "Waiting to catch up after upgrade (attempt ${after_upgrade_catch_up_count}/${after_upgrade_max_catch_up_attempts}, current block: $(./new_empowerd status | jq -r ".SyncInfo.latest_block_height")"; \
sleep 5; \
after_upgrade_catch_up_count=$((after_upgrade_catch_up_count+1)); \
done; \
if [ $after_upgrade_catch_up_count -eq $after_upgrade_max_catch_up_attempts ]; then \
echo "Failed to catch up after the upgrade after ${after_upgrade_max_catch_up_attempts} attempts."; \
cat /tmp/after_upgrade_log; \
exit 1; \
fi; \
CURRENT_HEIGHT=$(./new_empowerd status | jq -r ".SyncInfo.latest_block_height"); \
if [ $CURRENT_HEIGHT -le $UPGRADE_HEIGHT ]; then \
echo "Error: Current height ($CURRENT_HEIGHT) is less than or equal to upgrade height ($UPGRADE_HEIGHT)"; \
cat /tmp/after_upgrade_log; \
exit 1; \
fi; \
echo "Upgrade test passed! Halted and upgraded on $UPGRADE_HEIGHT, current height: $CURRENT_HEIGHT";