Skip to content

Commit

Permalink
refactor: split start_agd from start_to_to
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 6, 2023
1 parent c8c186e commit ca3070f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 44 deletions.
11 changes: 11 additions & 0 deletions upgrade-test-scripts/start_agd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# Start and leave agd running

grep -qF 'env_setup.sh' /root/.bashrc || echo "source /usr/src/upgrade-test-scripts/env_setup.sh" >>/root/.bashrc
grep -qF 'printKeys' /root/.bashrc || echo "printKeys" >>/root/.bashrc

source ./env_setup.sh

export SLOGFILE=slog.slog

startAgd
83 changes: 39 additions & 44 deletions upgrade-test-scripts/start_to_to.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# Prepare or execute an upgrade

grep -qF 'env_setup.sh' /root/.bashrc || echo "source /usr/src/upgrade-test-scripts/env_setup.sh" >>/root/.bashrc
grep -qF 'printKeys' /root/.bashrc || echo "printKeys" >>/root/.bashrc
Expand All @@ -9,52 +10,46 @@ export SLOGFILE=slog.slog

startAgd

if [[ "$DEST" != "1" ]]; then
#Destined for an upgrade
if [[ -z "${UPGRADE_TO}" ]]; then
echo "no upgrade set. running for a few blocks and exiting"
waitForBlock 5
exit 0
fi
if [[ -z "${UPGRADE_TO}" ]]; then
echo "no upgrade set. running for a few blocks and exiting"
waitForBlock 5
exit 0
fi

voting_period_s=10
latest_height=$(agd status | jq -r .SyncInfo.latest_block_height)
height=$((latest_height + voting_period_s + 10))
info=${UPGRADE_INFO-"{}"}
if echo "$info" | jq .; then
echo "upgrade-info: $info"
else
status=$?
echo "Upgrade info is not valid JSON: $info"
exit $status
fi
agd tx gov submit-proposal software-upgrade "$UPGRADE_TO" \
--upgrade-height="$height" --upgrade-info="$info" \
--title="Upgrade to ${UPGRADE_TO}" --description="upgrades" \
--from=validator --chain-id="$CHAINID" \
--yes --keyring-backend=test
waitForBlock

voting_period_s=10
voteLatestProposalAndWait

echo "Chain in to-be-upgraded state for $UPGRADE_TO"

while true; do
latest_height=$(agd status | jq -r .SyncInfo.latest_block_height)
height=$((latest_height + voting_period_s + 10))
info=${UPGRADE_INFO-"{}"}
if echo "$info" | jq .; then
echo "upgrade-info: $info"
if [ "$latest_height" != "$height" ]; then
echo "Waiting for upgrade height for $UPGRADE_TO to be reached (need $height, have $latest_height)"
sleep 1
else
status=$?
echo "Upgrade info is not valid JSON: $info"
exit $status
echo "Upgrade height for $UPGRADE_TO reached. Killing agd"
echo "(CONSENSUS FAILURE above for height $height is expected)"
break
fi
agd tx gov submit-proposal software-upgrade "$UPGRADE_TO" \
--upgrade-height="$height" --upgrade-info="$info" \
--title="Upgrade to ${UPGRADE_TO}" --description="upgrades" \
--from=validator --chain-id="$CHAINID" \
--yes --keyring-backend=test
waitForBlock

voteLatestProposalAndWait

echo "Chain in to-be-upgraded state for $UPGRADE_TO"

while true; do
latest_height=$(agd status | jq -r .SyncInfo.latest_block_height)
if [ "$latest_height" != "$height" ]; then
echo "Waiting for upgrade height for $UPGRADE_TO to be reached (need $height, have $latest_height)"
sleep 1
else
echo "Upgrade height for $UPGRADE_TO reached. Killing agd"
echo "(CONSENSUS FAILURE above for height $height is expected)"
break
fi
done

sleep 2
killAgd
echo "state directory $HOME/.agoric ready for upgrade to $UPGRADE_TO"
else
done

waitAgd
fi
sleep 2
killAgd
echo "state directory $HOME/.agoric ready for upgrade to $UPGRADE_TO"

0 comments on commit ca3070f

Please sign in to comment.