-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathupgrade-test.sh
executable file
·171 lines (141 loc) · 5.04 KB
/
upgrade-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
# the upgrade is a fork, "true" otherwise
FORK=${FORK:-"false"}
# $(curl --silent "https://api.github.com/repos/classic-terra/core/releases/latest" | jq -r '.tag_name')
OLD_VERSION=v2.2.1
UPGRADE_WAIT=${UPGRADE_WAIT:-20}
HOME=mytestnet
ROOT=$(pwd)
DENOM=uluna
CHAIN_ID=localterra
SOFTWARE_UPGRADE_NAME="v6"
ADDITIONAL_PRE_SCRIPTS=${ADDITIONAL_PRE_SCRIPTS:-""}
ADDITIONAL_AFTER_SCRIPTS=${ADDITIONAL_AFTER_SCRIPTS:-""}
if [[ "$FORK" == "true" ]]; then
export TERRAD_HALT_HEIGHT=20
fi
# underscore so that go tool will not take gocache into account
mkdir -p _build/gocache
export GOMODCACHE=$ROOT/_build/gocache
# install old binary if not exist
if [ ! -f "_build/$OLD_VERSION.zip" ] &> /dev/null
then
mkdir -p _build/old
wget -c "https://github.com/classic-terra/core/archive/refs/tags/${OLD_VERSION}.zip" -O _build/${OLD_VERSION}.zip
unzip _build/${OLD_VERSION}.zip -d _build
fi
# reinstall old binary
if [ $# -eq 1 ] && [ $1 == "--reinstall-old" ] || ! command -v _build/old/terrad &> /dev/null; then
cd ./_build/core-${OLD_VERSION:1}
GOBIN="$ROOT/_build/old" go install -mod=readonly ./...
cd ../..
fi
# install new binary
if ! command -v _build/new/terrad &> /dev/null
then
cd ./_build/core-${NEW_VERSION:1}
GOBIN="$ROOT/_build/new" go install -mod=readonly ./...
cd ../..
fi
# run old node
if [[ "$OSTYPE" == "darwin"* ]]; then
screen -L -dmS node1 bash scripts/run-node.sh _build/old/terrad $DENOM
else
screen -L -Logfile $HOME/log-screen.txt -dmS node1 bash scripts/run-node.sh _build/old/terrad $DENOM
fi
sleep 20
# execute additional pre scripts
if [ ! -z "$ADDITIONAL_PRE_SCRIPTS" ]; then
# slice ADDITIONAL_SCRIPTS by ,
SCRIPTS=($(echo "$ADDITIONAL_PRE_SCRIPTS" | tr ',' ' '))
for SCRIPT in "${SCRIPTS[@]}"; do
# check if SCRIPT is a file
if [ -f "$SCRIPT" ]; then
echo "executing additional pre scripts from $SCRIPT"
source $SCRIPT
sleep 5
else
echo "$SCRIPT is not a file"
fi
done
fi
run_fork () {
echo "forking"
while true; do
BLOCK_HEIGHT=$(./_build/old/terrad status | jq '.SyncInfo.latest_block_height' -r)
# if BLOCK_HEIGHT is not empty
if [ ! -z "$BLOCK_HEIGHT" ]; then
echo "BLOCK_HEIGHT = $BLOCK_HEIGHT"
sleep 10
else
echo "BLOCK_HEIGHT is empty, forking"
break
fi
done
}
run_upgrade () {
echo "upgrading"
STATUS_INFO=($(./_build/old/terrad status --home $HOME | jq -r '.NodeInfo.network,.SyncInfo.latest_block_height'))
UPGRADE_HEIGHT=$((STATUS_INFO[1] + 20))
tar -cf ./_build/new/terrad.tar -C ./_build/new terrad
SUM=$(shasum -a 256 ./_build/new/terrad.tar | cut -d ' ' -f1)
UPGRADE_INFO=$(jq -n '
{
"binaries": {
"linux/amd64": "file://'$(pwd)'/_build/new/terrad.tar?checksum=sha256:'"$SUM"'",
}
}')
./_build/old/terrad keys list --home $HOME --keyring-backend test
./_build/old/terrad tx gov submit-legacy-proposal software-upgrade "$SOFTWARE_UPGRADE_NAME" --upgrade-height $UPGRADE_HEIGHT --upgrade-info "$UPGRADE_INFO" --title "upgrade" --description "upgrade" --from test1 --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y
sleep 5
./_build/old/terrad tx gov deposit 1 "20000000${DENOM}" --from test1 --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y
sleep 5
./_build/old/terrad tx gov vote 1 yes --from test0 --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y
sleep 5
./_build/old/terrad tx gov vote 1 yes --from test1 --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y
sleep 5
# determine block_height to halt
while true; do
BLOCK_HEIGHT=$(./_build/old/terrad status | jq '.SyncInfo.latest_block_height' -r)
if [ $BLOCK_HEIGHT = "$UPGRADE_HEIGHT" ]; then
# assuming running only 1 terrad
echo "BLOCK HEIGHT = $UPGRADE_HEIGHT REACHED, KILLING OLD ONE"
pkill terrad
break
else
./_build/old/terrad q gov proposal 1 --output=json | jq ".status"
echo "BLOCK_HEIGHT = $BLOCK_HEIGHT"
sleep 10
fi
done
}
# if FORK = true
if [[ "$FORK" == "true" ]]; then
run_fork
unset TERRAD_HALT_HEIGHT
else
run_upgrade
fi
sleep 5
# run new node
if [[ "$OSTYPE" == "darwin"* ]]; then
CONTINUE="true" screen -L -dmS node1 bash scripts/run-node.sh _build/new/terrad $DENOM
else
CONTINUE="true" screen -L -Logfile $HOME/log-screen.txt -dmS node1 bash scripts/run-node.sh _build/new/terrad $DENOM
fi
sleep 20
# execute additional after scripts
if [ ! -z "$ADDITIONAL_AFTER_SCRIPTS" ]; then
# slice ADDITIONAL_SCRIPTS by ,
SCRIPTS=($(echo "$ADDITIONAL_AFTER_SCRIPTS" | tr ',' ' '))
for SCRIPT in "${SCRIPTS[@]}"; do
# check if SCRIPT is a file
if [ -f "$SCRIPT" ]; then
echo "executing additional after scripts from $SCRIPT"
source $SCRIPT
sleep 5
else
echo "$SCRIPT is not a file"
fi
done
fi