Export Mainnet Upgrade States #107
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
--- | |
name: Export Mainnet Upgrade States | |
on: | |
workflow_dispatch: | |
schedule: | |
# At 05:30 on Monday. | |
- cron: '30 5 * * 1' | |
# push: | |
# concurrency: | |
# group: self-hosted-runners | |
jobs: | |
export-cosmoshub-mainnet: | |
runs-on: cosmos-runner-set | |
environment: export-cosmoshub-mainnet | |
env: | |
SSH_PUB_KEYS: ${{ vars.SSH_PUB_KEYS }} | |
steps: | |
# Get system info | |
- name: Install required packages | |
run: | | |
sudo apt update | |
sudo apt dist-upgrade -y | |
sudo apt -y install python-is-python3 python3-distutils screen curl jq wget python3-venv python3-pip build-essential git psmisc net-tools lz4 | |
- run: ifconfig | |
- run: lscpu | |
- run: df -h | |
- run: free -m | |
- run: uname -a | |
- run: lsb_release -a | |
- run: echo "GitHub branch is ${{ github.ref }}" | |
- run: whoami | |
- run: pwd | |
- name: mkdir ~/artifact | |
run: mkdir ~/artifact | |
- name: Update Apt | |
run: | | |
sudo apt update | |
sudo apt dist-upgrade -y | |
- name: Install openssh-server | |
run: | | |
sudo apt install -y openssh-server | |
sudo mkdir /run/sshd | |
sudo /usr/sbin/sshd | |
- name: Setup SSH auth | |
run: | | |
if [ ! -d ~/.ssh ] | |
then | |
mkdir -m 700 ~/.ssh | |
fi | |
echo "$SSH_PUB_KEYS" > ~/.ssh/authorized_keys | |
ssh-keyscan files.polypore.xyz >> ~/.ssh/known_hosts | |
- name: Set SSH key | |
run: | | |
if [ ! -d ~/.ssh ] | |
then | |
mkdir -m 700 ~/.ssh | |
fi | |
echo "${{ secrets.SSH_PRIV_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
- name: Check out repository code | |
uses: actions/checkout@v3 | |
- name: Init Python venv | |
run: python -m venv ~/env | |
- name: Install dependencies | |
run: | | |
source ~/env/bin/activate | |
python -m pip install --upgrade pip | |
python -m pip install toml-cli requests | |
- name: Get current running gaiad version | |
run: | | |
RUNNING_VERSION=$(curl -s ${{ vars.RPC_NODE }}/abci_info | jq -r '.result.response.version') | |
echo "Running gaiad version: $RUNNING_VERSION" | |
echo "RUNNING_VERSION=$RUNNING_VERSION" >> $GITHUB_ENV | |
- name: Download binary from cosmos/gaia repo | |
run: | | |
sudo wget -nv https://github.com/cosmos/gaia/releases/download/${{ env.RUNNING_VERSION }}/gaiad-${{ env.RUNNING_VERSION }}-linux-amd64 -O /usr/local/bin/gaiad | |
sudo chmod +x /usr/local/bin/gaiad | |
- name: Initializing chain to sync with mainnet | |
env: | |
NODE_HOME: /home/runner/.gaia | |
NODE_MONIKER: mainnet-export | |
SERVICE_NAME: mainnet-export | |
CHAIN_ID: cosmoshub-4 | |
CHAIN_BINARY: 'gaiad' | |
GENESIS_URL: https://github.com/cosmos/mainnet/raw/master/genesis/genesis.cosmoshub-4.json.gz | |
GAS_PRICES: "0.0025uatom" | |
run: | | |
echo "Initializing $NODE_HOME..." | |
$CHAIN_BINARY config set client chain-id $CHAIN_ID --home $NODE_HOME | |
$CHAIN_BINARY config set client keyring-backend test --home $NODE_HOME | |
$CHAIN_BINARY config set client broadcast-mode sync --home $NODE_HOME | |
$CHAIN_BINARY init $NODE_MONIKER --chain-id $CHAIN_ID --home $NODE_HOME | |
sed -i -e "/^persistent_peers =/ s^= .*^= \"${{ vars.PERSISTENT_PEERS }}\"^" $NODE_HOME/config/config.toml | |
echo "Configuring state sync..." | |
CURRENT_BLOCK=$(curl -s ${{ vars.SYNC_RPC_1 }}/block | jq -r '.result.block.header.height') | |
TRUST_HEIGHT=$[$CURRENT_BLOCK-${{ vars.TRUST_HEIGHT_DELTA }}] | |
TRUST_BLOCK=$(curl -s ${{ vars.SYNC_RPC_1 }}/block\?height\=$TRUST_HEIGHT) | |
TRUST_HASH=$(echo $TRUST_BLOCK | jq -r '.result.block_id.hash') | |
sed -i -e '/enable =/ s/= .*/= true/' $NODE_HOME/config/config.toml | |
sed -i -e '/trust_period =/ s/= .*/= "8h0m0s"/' $NODE_HOME/config/config.toml | |
sed -i -e "/trust_height =/ s/= .*/= $TRUST_HEIGHT/" $NODE_HOME/config/config.toml | |
sed -i -e "/trust_hash =/ s/= .*/= \"$TRUST_HASH\"/" $NODE_HOME/config/config.toml | |
sed -i -e "/rpc_servers =/ s^= .*^= \"${{ vars.SYNC_RPC_1 }},${{ vars.SYNC_RPC_2 }}\"^" $NODE_HOME/config/config.toml | |
sed -i -e "/minimum-gas-prices =/ s^= .*^= \"$GAS_PRICES\"^" $NODE_HOME/config/app.toml | |
echo "${{ secrets.PRIV_VALIDATOR_KEY }}" | base64 --decode > $NODE_HOME/config/priv_validator_key.json | |
echo "${{ secrets.NODE_KEY }}" | base64 --decode > $NODE_HOME/config/node_key.json | |
echo "Replaceing genesis..." | |
wget -nv $GENESIS_URL -O genesis.json.gz | |
gunzip genesis.json.gz | |
mv genesis.json $NODE_HOME/config/genesis.json | |
- name: Archive config files | |
env: | |
NODE_HOME: /home/runner/.gaia | |
run: mkdir -p /home/runner/artifact/config/cosmoshub-4 && cp -rvp $NODE_HOME/config /home/runner/artifact/config/cosmoshub-4/ | |
- name: Get archive url | |
run: | | |
# Node Stake | |
SNAP_NAME=$(curl -s https://ss.cosmos.nodestake.org/ | egrep -o ">20.*\.tar.lz4" | tr -d ">") | |
echo "ARCHIVE_URL=https://ss.cosmos.nodestake.org/${SNAP_NAME}" >> $GITHUB_ENV | |
# Polkachu | |
# SNAP_NAME=$(curl -s https://www.polkachu.com/tendermint_snapshots/cosmos | egrep -o "cosmos_20.*\.tar.lz4 https" | awk -F " " '{ print $1 }') | |
# echo "ARCHIVE_URL=https://snapshots.polkachu.com/snapshots/cosmos/${SNAP_NAME}" >> $GITHUB_ENV | |
- name: Download snapshot | |
run: | | |
cd ~/.gaia | |
curl -o - -L ${{ env.ARCHIVE_URL }} | lz4 -d | tar vx -C . | |
- name: Get addrbook | |
run: curl -Ls https://snapshots.polkachu.com/addrbook/cosmos/addrbook.json > /home/runner/.gaia/config/addrbook.json | |
- name: Start Chain | |
env: | |
NODE_HOME: /home/runner/.gaia | |
CHAIN_BINARY: 'gaiad' | |
run: screen -L -Logfile /home/runner/artifact/gaiad_sync.log -S gaiad -d -m $CHAIN_BINARY start --x-crisis-skip-assert-invariants --home $NODE_HOME | |
- name: Wait for gaiad to start and stabilize | |
run: tests/test_block_production.sh 127.0.0.1 26657 50 100000 | |
- name: Syncing Chain | |
run: | | |
catching_up="true" | |
while [ $catching_up == "true" ] | |
do | |
catching_up=$(curl -s 127.0.0.1:26657/status | jq -r .result.sync_info.catching_up) | |
echo "Still Syncing: $catching_up" | |
sleep 5 | |
done | |
echo "Done Syncing" | |
- name: Stop gaiad | |
run: | | |
killall gaiad screen | |
sleep 10s | |
- name: Install Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ vars.GO_VER }} | |
- name: Build fork tool | |
run: | | |
cd /home/runner | |
git clone https://github.com/cosmos/gaia.git | |
cd gaia | |
# git checkout ${{ env.RUNNING_VERSION }} | |
git checkout ${{ vars.FORK_TOOL_TAG }} | |
make build BUILD_TAGS="-tag unsafe_start_local_validator" | |
cp build/gaiad /home/runner/go/bin/gaiad-fork | |
- name: Fork the chain | |
env: | |
NODE_HOME: /home/runner/.gaia | |
run: | | |
curl -L https://raw.githubusercontent.com/hyphacoop/cosmos-ansible/main/examples/validator-keys/validator-40/priv_validator_key.json > /home/runner/.gaia/config/priv_validator_key.json | |
curl -L https://raw.githubusercontent.com/hyphacoop/cosmos-ansible/main/examples/validator-keys/validator-40/node_key.json > /home/runner/.gaia/config/node_key.json | |
pubkey=$(jq -r .pub_key.value /home/runner/.gaia/config/priv_validator_key.json) | |
privkey=$(jq -r .priv_key.value /home/runner/.gaia/config/priv_validator_key.json) | |
sed -i -e "/^persistent_peers =/ s^= .*^= \"\"^" $NODE_HOME/config/config.toml | |
sed -i -e '/enable =/ s/= .*/= false/' $NODE_HOME/config/config.toml | |
sed -i -e "/trust_height =/ s/= .*/= 0/" $NODE_HOME/config/config.toml | |
sed -i -e "/trust_hash =/ s/= .*/= \"\"/" $NODE_HOME/config/config.toml | |
sed -i -e "/rpc_servers =/ s^= .*^= \"\"^" $NODE_HOME/config/config.toml | |
screen -L -Logfile /home/runner/artifact/gaiad_fork.log -S gaiad -d -m /home/runner/go/bin/gaiad-fork testnet unsafe-start-local-validator --validator-operator cosmosvaloper1r5v5srda7xfth3hn2s26txvrcrntldju7lnwmv --validator-pubkey "$pubkey" --accounts-to-fund cosmos1r5v5srda7xfth3hn2s26txvrcrntldjumt8mhl --validator-privkey "$privkey" --home /home/runner/.gaia | |
screen -r gaiad -p0 -X logfile flush 0 | |
- name: Wait for gaiad to start and stabilize | |
run: tests/test_block_production.sh 127.0.0.1 26657 50 1000 | |
- name: Stop fork tool | |
run: | | |
echo "exiting gaia and screen" | |
killall gaiad-fork screen | |
sleep 10s | |
- name: Start gaiad | |
run: | | |
screen -L -Logfile /home/runner/artifact/gaiad_upgrade.log -S gaiad -d -m gaiad --home /home/runner/.gaia start | |
- name: Wait for gaiad to start and stabilize | |
run: tests/test_block_production.sh 127.0.0.1 26657 50 1000 | |
- name: Submit and vote on the upgrade proposal | |
run: | | |
echo "Restoring validator key" | |
echo "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art" | gaiad --output json keys add val --keyring-backend test --recover > ~/.gaia/validator.json | |
echo "Delegate 10ATOM to validator." | |
gaiad tx staking delegate cosmosvaloper1r5v5srda7xfth3hn2s26txvrcrntldju7lnwmv 10000000uatom --from val --keyring-backend test --fees 1000000uatom -y | |
echo "Wait for the delegation to go on chain..." | |
tests/test_block_production.sh 127.0.0.1 26657 1 10 | |
current_block=$(curl -s 127.0.0.1:26657/block | jq -r .result.block.header.height) | |
upgrade_height=$(($current_block+20)) | |
echo "upgrade_height=$upgrade_height" >> $GITHUB_ENV | |
echo "Submitting the upgrade proposal..." | |
echo "Upgrade Name set to: ${{ vars.UPGRADE_NAME }}" | |
echo "Creating json proposal" | |
jq ".messages[].plan .height=$upgrade_height | .messages[].plan .name=\"${{ vars.UPGRADE_NAME }}\"" templates/proposal-software-upgrade.json > upgrade_prop.json | |
proposal="gaiad --output json tx gov submit-proposal upgrade_prop.json --fees 1000000uatom --from val --yes" | |
$proposal | |
txhash=$($proposal | jq -r .txhash) | |
echo "Wait for the proposal to go on chain..." | |
tests/test_block_production.sh 127.0.0.1 26657 1 1 | |
echo "Get proposal ID from txhash..." | |
proposal_id=$(gaiad --output json q tx $txhash | jq -r '.events[] | select(.type=="submit_proposal") | .attributes[] | select(.key=="proposal_id") | .value') | |
echo "Submitting the \"yes\" vote to proposal $proposal_id..." | |
vote="gaiad tx gov vote $proposal_id yes --from val --keyring-backend test --fees 1000uatom --yes" | |
$vote | |
- name: Stop gaiad when reached upgrade height | |
run: | | |
current_block=0 | |
echo "Upgrade height is: ${{ env.upgrade_height }}" | |
( tail -f -n0 /home/runner/artifact/gaiad_upgrade.log & ) | grep -q "CONSENSUS FAILURE" | |
echo "exiting gaia and screen" | |
killall gaiad screen | |
tail -30 /home/runner/artifact/gaiad_upgrade.log | |
- name: ls ~/.gaia/wasm/state/wasm/ | |
run: ls -al ~/.gaia/wasm/state/wasm/ | |
- name: Compress and upload files | |
run: | | |
echo "Compressing ~/.gaia ..." | |
cd /home/runner/ | |
tar cfz ${{ env.RUNNING_VERSION }}_${{ env.upgrade_height }}-stateful-upgrade.tar.gz .gaia | |
echo "Uploading archived state to files.polypore.xyz" | |
scp ${{ env.RUNNING_VERSION }}_${{ env.upgrade_height }}-stateful-upgrade.tar.gz [email protected]:/var/www/html/archived-state/ | |
# Update latest file symlinks | |
ssh [email protected] ln -sf /var/www/html/archived-state/${{ env.RUNNING_VERSION }}_${{ env.upgrade_height }}-stateful-upgrade.tar.gz /var/www/html/archived-state/latest_v$(echo ${{ env.RUNNING_VERSION }} | awk -F "." '{ print substr($1,2) }').tar.gz | |
- name: Upload artifacts | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: export-cosmos-hub-mainnet | |
path: ~/artifact/ | |