-
Notifications
You must be signed in to change notification settings - Fork 28
/
deploy_blockchain_sandbox_gcp.sh
448 lines (416 loc) · 17.6 KB
/
deploy_blockchain_sandbox_gcp.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#!/bin/bash
if [[ $# -lt 2 ]] || [[ $# -gt 7 ]]; then
printf "Usage: bash deploy_blockchain_sandbox_gcp.sh <# start node> <# end node> [--setup] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--chown-data|--no-chown-data] [--kill-job|--kill-only]\n"
printf "Example: bash deploy_blockchain_sandbox_gcp.sh 10 99 --setup --no-chown-data\n"
printf "\n"
exit
fi
printf "\n[[[[[ deploy_blockchain_sandbox_gcp.sh ]]]]]\n\n"
SEASON=sandbox
PROJECT_ID=testnet-$SEASON-ground
printf "SEASON=$SEASON\n"
printf "PROJECT_ID=$PROJECT_ID\n"
GCP_USER="runner"
START_NODE_IDX="$1"
END_NODE_IDX="$2"
ACCOUNT_INJECTION_OPTION="--private-key" # always use the private keys
printf "GCP_USER=$GCP_USER\n"
printf "START_NODE_IDX=$START_NODE_IDX\n"
printf "END_NODE_IDX=$END_NODE_IDX\n"
printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n"
if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then
printf "Must provide an ACCOUNT_INJECTION_OPTION\n"
exit
fi
function parse_options() {
local option="$1"
if [[ $option = '--setup' ]]; then
SETUP_OPTION="$option"
elif [[ $option = '--keep-code' ]]; then
KEEP_CODE_OPTION="$option"
elif [[ $option = '--no-keep-code' ]]; then
KEEP_CODE_OPTION="$option"
elif [[ $option = '--keep-data' ]]; then
KEEP_DATA_OPTION="$option"
elif [[ $option = '--no-keep-data' ]]; then
KEEP_DATA_OPTION="$option"
elif [[ $option = '--chown-data' ]]; then
CHOWN_DATA_OPTION="$option"
elif [[ $option = '--no-chown-data' ]]; then
CHOWN_DATA_OPTION="$option"
elif [[ $option = '--kill-job' ]]; then
KILL_OPTION="$option"
elif [[ $option = '--kill-only' ]]; then
KILL_OPTION="$option"
else
printf "Invalid options: $option\n"
exit
fi
}
# Parse options.
SETUP_OPTION=""
KEEP_CODE_OPTION="--no-keep-code"
KEEP_DATA_OPTION="--no-keep-data"
CHOWN_DATA_OPTION="--no-chown-data"
KILL_OPTION="--kill-job"
ARG_INDEX=3
while [ $ARG_INDEX -le $# ]; do
parse_options "${!ARG_INDEX}"
((ARG_INDEX++))
done
if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
printf "You cannot use --setup without --no-keep-code\n"
exit
fi
printf "SETUP_OPTION=$SETUP_OPTION\n"
printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n"
printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n"
printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n"
printf "KILL_OPTION=$KILL_OPTION\n"
# Get confirmation.
printf "\n"
read -p "Do you want to proceed for $SEASON? [y/N]: " -n 1 -r
printf "\n\n"
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
# Read node urls
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt
function inject_account() {
local node_index="$1"
local node_url=${NODE_URL_LIST[${node_index}]}
local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json"
printf "\n* >> Injecting an account for node $node_index ********************\n\n"
printf "node_url='$node_url'\n"
PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key')
echo $PRIVATE_KEY | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION
}
# GCP node address
# NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-node-0-taiwan"
# NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-node-1-oregon"
# NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-node-2-singapore"
# NODE_3_TARGET_ADDR="${GCP_USER}@${SEASON}-node-3-iowa"
# NODE_4_TARGET_ADDR="${GCP_USER}@${SEASON}-node-4-netherlands"
# NODE_5_TARGET_ADDR="${GCP_USER}@${SEASON}-node-5-taiwan"
# NODE_6_TARGET_ADDR="${GCP_USER}@${SEASON}-node-6-oregon"
# NODE_7_TARGET_ADDR="${GCP_USER}@${SEASON}-node-7-singapore"
# NODE_8_TARGET_ADDR="${GCP_USER}@${SEASON}-node-8-iowa"
# NODE_9_TARGET_ADDR="${GCP_USER}@${SEASON}-node-9-netherlands"
NODE_10_TARGET_ADDR="${GCP_USER}@${SEASON}-node-10-taiwan"
NODE_11_TARGET_ADDR="${GCP_USER}@${SEASON}-node-11-oregon"
NODE_12_TARGET_ADDR="${GCP_USER}@${SEASON}-node-12-singapore"
NODE_13_TARGET_ADDR="${GCP_USER}@${SEASON}-node-13-iowa"
NODE_14_TARGET_ADDR="${GCP_USER}@${SEASON}-node-14-netherlands"
NODE_15_TARGET_ADDR="${GCP_USER}@${SEASON}-node-15-taiwan"
NODE_16_TARGET_ADDR="${GCP_USER}@${SEASON}-node-16-oregon"
NODE_17_TARGET_ADDR="${GCP_USER}@${SEASON}-node-17-singapore"
NODE_18_TARGET_ADDR="${GCP_USER}@${SEASON}-node-18-iowa"
NODE_19_TARGET_ADDR="${GCP_USER}@${SEASON}-node-19-netherlands"
NODE_20_TARGET_ADDR="${GCP_USER}@${SEASON}-node-20-taiwan"
NODE_21_TARGET_ADDR="${GCP_USER}@${SEASON}-node-21-oregon"
NODE_22_TARGET_ADDR="${GCP_USER}@${SEASON}-node-22-singapore"
NODE_23_TARGET_ADDR="${GCP_USER}@${SEASON}-node-23-iowa"
NODE_24_TARGET_ADDR="${GCP_USER}@${SEASON}-node-24-netherlands"
NODE_25_TARGET_ADDR="${GCP_USER}@${SEASON}-node-25-taiwan"
NODE_26_TARGET_ADDR="${GCP_USER}@${SEASON}-node-26-oregon"
NODE_27_TARGET_ADDR="${GCP_USER}@${SEASON}-node-27-singapore"
NODE_28_TARGET_ADDR="${GCP_USER}@${SEASON}-node-28-iowa"
NODE_29_TARGET_ADDR="${GCP_USER}@${SEASON}-node-29-netherlands"
NODE_30_TARGET_ADDR="${GCP_USER}@${SEASON}-node-30-taiwan"
NODE_31_TARGET_ADDR="${GCP_USER}@${SEASON}-node-31-oregon"
NODE_32_TARGET_ADDR="${GCP_USER}@${SEASON}-node-32-singapore"
NODE_33_TARGET_ADDR="${GCP_USER}@${SEASON}-node-33-iowa"
NODE_34_TARGET_ADDR="${GCP_USER}@${SEASON}-node-34-netherlands"
NODE_35_TARGET_ADDR="${GCP_USER}@${SEASON}-node-35-taiwan"
NODE_36_TARGET_ADDR="${GCP_USER}@${SEASON}-node-36-oregon"
NODE_37_TARGET_ADDR="${GCP_USER}@${SEASON}-node-37-singapore"
NODE_38_TARGET_ADDR="${GCP_USER}@${SEASON}-node-38-iowa"
NODE_39_TARGET_ADDR="${GCP_USER}@${SEASON}-node-39-netherlands"
NODE_40_TARGET_ADDR="${GCP_USER}@${SEASON}-node-40-taiwan"
NODE_41_TARGET_ADDR="${GCP_USER}@${SEASON}-node-41-oregon"
NODE_42_TARGET_ADDR="${GCP_USER}@${SEASON}-node-42-singapore"
NODE_43_TARGET_ADDR="${GCP_USER}@${SEASON}-node-43-iowa"
NODE_44_TARGET_ADDR="${GCP_USER}@${SEASON}-node-44-netherlands"
NODE_45_TARGET_ADDR="${GCP_USER}@${SEASON}-node-45-taiwan"
NODE_46_TARGET_ADDR="${GCP_USER}@${SEASON}-node-46-oregon"
NODE_47_TARGET_ADDR="${GCP_USER}@${SEASON}-node-47-singapore"
NODE_48_TARGET_ADDR="${GCP_USER}@${SEASON}-node-48-iowa"
NODE_49_TARGET_ADDR="${GCP_USER}@${SEASON}-node-49-netherlands"
NODE_50_TARGET_ADDR="${GCP_USER}@${SEASON}-node-50-taiwan"
NODE_51_TARGET_ADDR="${GCP_USER}@${SEASON}-node-51-oregon"
NODE_52_TARGET_ADDR="${GCP_USER}@${SEASON}-node-52-singapore"
NODE_53_TARGET_ADDR="${GCP_USER}@${SEASON}-node-53-iowa"
NODE_54_TARGET_ADDR="${GCP_USER}@${SEASON}-node-54-netherlands"
NODE_55_TARGET_ADDR="${GCP_USER}@${SEASON}-node-55-taiwan"
NODE_56_TARGET_ADDR="${GCP_USER}@${SEASON}-node-56-oregon"
NODE_57_TARGET_ADDR="${GCP_USER}@${SEASON}-node-57-singapore"
NODE_58_TARGET_ADDR="${GCP_USER}@${SEASON}-node-58-iowa"
NODE_59_TARGET_ADDR="${GCP_USER}@${SEASON}-node-59-netherlands"
NODE_60_TARGET_ADDR="${GCP_USER}@${SEASON}-node-60-taiwan"
NODE_61_TARGET_ADDR="${GCP_USER}@${SEASON}-node-61-oregon"
NODE_62_TARGET_ADDR="${GCP_USER}@${SEASON}-node-62-singapore"
NODE_63_TARGET_ADDR="${GCP_USER}@${SEASON}-node-63-iowa"
NODE_64_TARGET_ADDR="${GCP_USER}@${SEASON}-node-64-netherlands"
NODE_65_TARGET_ADDR="${GCP_USER}@${SEASON}-node-65-taiwan"
NODE_66_TARGET_ADDR="${GCP_USER}@${SEASON}-node-66-oregon"
NODE_67_TARGET_ADDR="${GCP_USER}@${SEASON}-node-67-singapore"
NODE_68_TARGET_ADDR="${GCP_USER}@${SEASON}-node-68-iowa"
NODE_69_TARGET_ADDR="${GCP_USER}@${SEASON}-node-69-netherlands"
NODE_70_TARGET_ADDR="${GCP_USER}@${SEASON}-node-70-taiwan"
NODE_71_TARGET_ADDR="${GCP_USER}@${SEASON}-node-71-oregon"
NODE_72_TARGET_ADDR="${GCP_USER}@${SEASON}-node-72-singapore"
NODE_73_TARGET_ADDR="${GCP_USER}@${SEASON}-node-73-iowa"
NODE_74_TARGET_ADDR="${GCP_USER}@${SEASON}-node-74-netherlands"
NODE_75_TARGET_ADDR="${GCP_USER}@${SEASON}-node-75-taiwan"
NODE_76_TARGET_ADDR="${GCP_USER}@${SEASON}-node-76-oregon"
NODE_77_TARGET_ADDR="${GCP_USER}@${SEASON}-node-77-singapore"
NODE_78_TARGET_ADDR="${GCP_USER}@${SEASON}-node-78-iowa"
NODE_79_TARGET_ADDR="${GCP_USER}@${SEASON}-node-79-netherlands"
NODE_80_TARGET_ADDR="${GCP_USER}@${SEASON}-node-80-taiwan"
NODE_81_TARGET_ADDR="${GCP_USER}@${SEASON}-node-81-oregon"
NODE_82_TARGET_ADDR="${GCP_USER}@${SEASON}-node-82-singapore"
NODE_83_TARGET_ADDR="${GCP_USER}@${SEASON}-node-83-iowa"
NODE_84_TARGET_ADDR="${GCP_USER}@${SEASON}-node-84-netherlands"
NODE_85_TARGET_ADDR="${GCP_USER}@${SEASON}-node-85-taiwan"
NODE_86_TARGET_ADDR="${GCP_USER}@${SEASON}-node-86-oregon"
NODE_87_TARGET_ADDR="${GCP_USER}@${SEASON}-node-87-singapore"
NODE_88_TARGET_ADDR="${GCP_USER}@${SEASON}-node-88-iowa"
NODE_89_TARGET_ADDR="${GCP_USER}@${SEASON}-node-89-netherlands"
NODE_90_TARGET_ADDR="${GCP_USER}@${SEASON}-node-90-taiwan"
NODE_91_TARGET_ADDR="${GCP_USER}@${SEASON}-node-91-oregon"
NODE_92_TARGET_ADDR="${GCP_USER}@${SEASON}-node-92-singapore"
NODE_93_TARGET_ADDR="${GCP_USER}@${SEASON}-node-93-iowa"
NODE_94_TARGET_ADDR="${GCP_USER}@${SEASON}-node-94-netherlands"
NODE_95_TARGET_ADDR="${GCP_USER}@${SEASON}-node-95-taiwan"
NODE_96_TARGET_ADDR="${GCP_USER}@${SEASON}-node-96-oregon"
NODE_97_TARGET_ADDR="${GCP_USER}@${SEASON}-node-97-singapore"
NODE_98_TARGET_ADDR="${GCP_USER}@${SEASON}-node-98-iowa"
NODE_99_TARGET_ADDR="${GCP_USER}@${SEASON}-node-99-netherlands"
# Node time zone
# NODE_0_ZONE="asia-east1-b"
# NODE_1_ZONE="us-west1-b"
# NODE_2_ZONE="asia-southeast1-b"
# NODE_3_ZONE="us-central1-a"
# NODE_4_ZONE="europe-west4-a"
# NODE_5_ZONE="asia-east1-b"
# NODE_6_ZONE="us-west1-b"
# NODE_7_ZONE="asia-southeast1-b"
# NODE_8_ZONE="us-central1-a"
# NODE_9_ZONE="europe-west4-a"
NODE_10_ZONE="asia-east1-b"
NODE_11_ZONE="us-west1-b"
NODE_12_ZONE="asia-southeast1-b"
NODE_13_ZONE="us-central1-a"
NODE_14_ZONE="europe-west4-a"
NODE_15_ZONE="asia-east1-b"
NODE_16_ZONE="us-west1-b"
NODE_17_ZONE="asia-southeast1-b"
NODE_18_ZONE="us-central1-a"
NODE_19_ZONE="europe-west4-a"
NODE_20_ZONE="asia-east1-b"
NODE_21_ZONE="us-west1-b"
NODE_22_ZONE="asia-southeast1-b"
NODE_23_ZONE="us-central1-a"
NODE_24_ZONE="europe-west4-a"
NODE_25_ZONE="asia-east1-b"
NODE_26_ZONE="us-west1-b"
NODE_27_ZONE="asia-southeast1-b"
NODE_28_ZONE="us-central1-a"
NODE_29_ZONE="europe-west4-a"
NODE_30_ZONE="asia-east1-b"
NODE_31_ZONE="us-west1-b"
NODE_32_ZONE="asia-southeast1-b"
NODE_33_ZONE="us-central1-a"
NODE_34_ZONE="europe-west4-a"
NODE_35_ZONE="asia-east1-b"
NODE_36_ZONE="us-west1-b"
NODE_37_ZONE="asia-southeast1-b"
NODE_38_ZONE="us-central1-a"
NODE_39_ZONE="europe-west4-a"
NODE_40_ZONE="asia-east1-b"
NODE_41_ZONE="us-west1-b"
NODE_42_ZONE="asia-southeast1-b"
NODE_43_ZONE="us-central1-a"
NODE_44_ZONE="europe-west4-a"
NODE_45_ZONE="asia-east1-b"
NODE_46_ZONE="us-west1-b"
NODE_47_ZONE="asia-southeast1-b"
NODE_48_ZONE="us-central1-a"
NODE_49_ZONE="europe-west4-a"
NODE_50_ZONE="asia-east1-b"
NODE_51_ZONE="us-west1-b"
NODE_52_ZONE="asia-southeast1-b"
NODE_53_ZONE="us-central1-a"
NODE_54_ZONE="europe-west4-a"
NODE_55_ZONE="asia-east1-b"
NODE_56_ZONE="us-west1-b"
NODE_57_ZONE="asia-southeast1-b"
NODE_58_ZONE="us-central1-a"
NODE_59_ZONE="europe-west4-a"
NODE_60_ZONE="asia-east1-b"
NODE_61_ZONE="us-west1-b"
NODE_62_ZONE="asia-southeast1-b"
NODE_63_ZONE="us-central1-a"
NODE_64_ZONE="europe-west4-a"
NODE_65_ZONE="asia-east1-b"
NODE_66_ZONE="us-west1-b"
NODE_67_ZONE="asia-southeast1-b"
NODE_68_ZONE="us-central1-a"
NODE_69_ZONE="europe-west4-a"
NODE_70_ZONE="asia-east1-b"
NODE_71_ZONE="us-west1-b"
NODE_72_ZONE="asia-southeast1-b"
NODE_73_ZONE="us-central1-a"
NODE_74_ZONE="europe-west4-a"
NODE_75_ZONE="asia-east1-b"
NODE_76_ZONE="us-west1-b"
NODE_77_ZONE="asia-southeast1-b"
NODE_78_ZONE="us-central1-a"
NODE_79_ZONE="europe-west4-a"
NODE_80_ZONE="asia-east1-b"
NODE_81_ZONE="us-west1-b"
NODE_82_ZONE="asia-southeast1-b"
NODE_83_ZONE="us-central1-a"
NODE_84_ZONE="europe-west4-a"
NODE_85_ZONE="asia-east1-b"
NODE_86_ZONE="us-west1-b"
NODE_87_ZONE="asia-southeast1-b"
NODE_88_ZONE="us-central1-a"
NODE_89_ZONE="europe-west4-a"
NODE_90_ZONE="asia-east1-b"
NODE_91_ZONE="us-west1-b"
NODE_92_ZONE="asia-southeast1-b"
NODE_93_ZONE="us-central1-a"
NODE_94_ZONE="europe-west4-a"
NODE_95_ZONE="asia-east1-b"
NODE_96_ZONE="us-west1-b"
NODE_97_ZONE="asia-southeast1-b"
NODE_98_ZONE="us-central1-a"
NODE_99_ZONE="europe-west4-a"
# deploy files
FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync.sh"
# Work in progress spinner
spin="-\|/"
i=0
spinner() {
i=$(( (i+1) %4 ))
printf "\r${spin:$i:1}"
sleep .1
}
# kill any processes still alive
printf "\nKilling all blockchain nodes...\n"
index=$START_NODE_IDX
while [ $index -le $END_NODE_IDX ]; do
NODE_TARGET_ADDR=NODE_${index}_TARGET_ADDR
NODE_ZONE=NODE_${index}_ZONE
KILL_NODE_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command 'sudo killall node' --project $PROJECT_ID --zone ${!NODE_ZONE}"
# NOTE(minsulee2): Keep printf for extensibility experiment debugging purpose
# printf "KILL_NODE_CMD=$KILL_NODE_CMD\n"
if [[ $index < "$(($NUM_NODES - 1))" ]]; then
eval $KILL_NODE_CMD &> /dev/null &
else
eval $KILL_NODE_CMD &> /dev/null
fi
((index++))
spinner
done
printf "Kill all processes done.\n\n";
# If --kill-only, do not proceed any further
if [[ $KILL_OPTION = "--kill-only" ]]; then
exit
fi
# deploy files to GCP instances
if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
printf "\nDeploying parent blockchain...\n"
index=$START_NODE_IDX
while [ $index -le $END_NODE_IDX ]; do
NODE_TARGET_ADDR=NODE_${index}_TARGET_ADDR
NODE_ZONE=NODE_${index}_ZONE
gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE}
DEPLOY_BLOCKCHAIN_CMD="gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain --project $PROJECT_ID --zone ${!NODE_ZONE}"
# NOTE(minsulee2): Keep printf for extensibility experiment debugging purpose
# printf "DEPLOY_BLOCKCHAIN_CMD=$DEPLOY_BLOCKCHAIN_CMD\n"
if [[ $index < "$(($NUM_NODES - 1))" ]]; then
eval $DEPLOY_BLOCKCHAIN_CMD &> /dev/null &
else
eval $DEPLOY_BLOCKCHAIN_CMD &> /dev/null
fi
((index++))
spinner
done
printf "Deploy files done.\n\n";
fi
# ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME)
if [[ $SETUP_OPTION = "--setup" ]]; then
printf "\n\n##########################\n# Setting up blockchain nodes #\n##########################\n"
index=$START_NODE_IDX
while [ $index -le $END_NODE_IDX ]; do
NODE_TARGET_ADDR=NODE_${index}_TARGET_ADDR
NODE_ZONE=NODE_${index}_ZONE
SETUP_BLOCKCHAIN_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '. setup_blockchain_ubuntu_gcp.sh' --project $PROJECT_ID --zone ${!NODE_ZONE}"
# NOTE(minsulee2): Keep printf for extensibility experiment debugging purpose
# printf "SETUP_BLOCKCHAIN_CMD=$SETUP_BLOCKCHAIN_CMD\n"
if [[ $index < "$(($NUM_NODES - 1))" ]]; then
eval $SETUP_BLOCKCHAIN_CMD &> /dev/null &
else
eval $SETUP_BLOCKCHAIN_CMD &> /dev/null
fi
((index++))
spinner
done
printf "Setting up blockchain nodes done.\n\n";
fi
printf "\nStarting blockchain servers...\n\n"
if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain"
else
GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)"
fi
if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then
# restart after removing chains, snapshots, and log files (but keep the keys)
CHAINS_DIR=/home/ain_blockchain_data/chains
SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots
LOGS_DIR=/home/ain_blockchain_data/logs
START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh"
else
# restart with existing chains, snapshots, and log files
START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh"
fi
printf "\n"
printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n"
printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n"
printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n"
printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n"
node_index=$START_NODE_IDX
while [ $node_index -le $END_NODE_IDX ]; do
NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR
NODE_ZONE=NODE_${node_index}_ZONE
printf "\n\n##########################\n# Starting parent node $node_index #\n##########################\n\n"
if [[ $node_index -ge 5 ]]; then
JSON_RPC_OPTION="--json-rpc"
else
JSON_RPC_OPTION=""
fi
UPDATE_FRONT_DB_OPTION="--update-front-db"
if [[ $node_index -ge 5 ]] && [[ $node_index -lt 8 ]]; then
REST_FUNC_OPTION="--rest-func"
else
REST_FUNC_OPTION=""
fi
printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n"
printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n"
printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n"
printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n"
printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n"
printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n"
printf "\n"
START_NODE_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '$START_NODE_CMD_BASE $SEASON $GCP_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $ACCOUNT_INJECTION_OPTION' --project $PROJECT_ID --zone ${!NODE_ZONE}"
# NOTE(minsulee2): Keep printf for extensibility experiment debugging purpose
# printf "START_NODE_CMD=$START_NODE_CMD\n"
eval $START_NODE_CMD
sleep 5
inject_account "$node_index"
((node_index++))
sleep 1
done