Skip to content

Commit a160160

Browse files
authored
Ensure accounts are taken offline when switching networks (#38)
1 parent e2d2732 commit a160160

File tree

1 file changed

+80
-7
lines changed

1 file changed

+80
-7
lines changed

install.sh

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ wallet_password=""
1111
new_user_setup=0
1212
new_network=0
1313
network_status_url=""
14+
container_id=""
1415

1516
voi_logo="MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
1617
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
@@ -222,12 +223,31 @@ wait_for_stack_to_be_ready() {
222223
display_banner "Stack is ready!"
223224
}
224225
226+
function get_container_id() {
227+
case ${VOINETWORK_PROFILE} in
228+
"relay")
229+
container_id=$(docker ps -q -f name=voinetwork_relay)
230+
;;
231+
"developer")
232+
container_id=$(docker ps -q -f name=voinetwork_developer)
233+
;;
234+
"archiver")
235+
container_id=$(docker ps -q -f name=voinetwork_archiver)
236+
;;
237+
"participation")
238+
container_id=$(docker ps -q -f name=voinetwork_algod)
239+
;;
240+
*)
241+
abort "Invalid profile. Exiting the program."
242+
;;
243+
esac
244+
}
245+
225246
verify_node_is_running() {
226247
local retries=0
227248
local max_retries=5
228249
229250
while [[ $retries -lt $max_retries ]]; do
230-
container_id=$(execute_sudo "docker ps -q -f name=voinetwork_algod")
231251
if [[ -n "$container_id" ]]; then
232252
execute_sudo "docker exec ${container_id} bash -c \"curl -sS http://localhost:8080/health > /dev/null\""
233253
local exit_code=$?
@@ -309,6 +329,7 @@ catchup_node() {
309329
get_node_status
310330
sleep 5
311331
done
332+
echo ""
312333
display_banner "Caught up with the network!"
313334
}
314335
@@ -475,6 +496,37 @@ generate_new_key() {
475496
execute_interactive_docker_command "/node/bin/goal account addpartkey -a ${address} --roundFirstValid ${start_block} --roundLastValid ${end_block}"
476497
}
477498
499+
ensure_accounts_are_offline() {
500+
account_addresses=$(get_account_addresses)
501+
502+
if [[ -z ${account_addresses} ]]; then
503+
return
504+
fi
505+
506+
if [[ ${container_id} == "" ]]; then
507+
echo "Skipping account offline check as container not found."
508+
return
509+
fi
510+
511+
display_banner "Migrating to new network. Ensuring all accounts are offline."
512+
513+
echo "Checking if accounts are online and have a balance of 1,000 microVoi or more."
514+
echo "Accounts with a balance of 1,000 microVoi or more will be taken offline."
515+
516+
for account in ${account_addresses}; do
517+
local balance
518+
balance=$(get_account_balance "${account}")
519+
account_status=$(execute_docker_command "/node/bin/goal account dump -a ${account}" | jq -r .onl)
520+
521+
if [[ ${balance} -ge 1000 && ${account_status} -eq 1 ]]; then
522+
echo ""
523+
echo "Balance is ${balance} which is above 1,000 microVoi. Taking account ${account} offline."
524+
execute_interactive_docker_command "/node/bin/goal account changeonlinestatus -a ${account} -o=false"
525+
echo "Account ${account} is now offline!"
526+
fi
527+
done
528+
}
529+
478530
generate_participation_key() {
479531
display_banner "Generating/Updating participation key"
480532
@@ -504,12 +556,12 @@ generate_participation_key() {
504556
return 1
505557
fi
506558
507-
local balance
508-
balance=$(get_account_balance "${account}")
509-
510559
if [[ ${account_addresses_length} -eq 1 ]]; then
511560
generate_new_key "${account}"
512561
else
562+
local balance
563+
balance=$(get_account_balance "${account}")
564+
513565
if [[ ${balance} -ge 1000 ]]; then
514566
echo "Balance is equal/above 1,000 microVoi. Generating participation key for account ${account}"
515567
generate_new_key "${account}"
@@ -524,6 +576,7 @@ generate_participation_key() {
524576
else
525577
echo "Balance is below 1,000 microVoi. Skipping participation key generation for account ${account}"
526578
fi
579+
echo ""
527580
fi
528581
elif [[ $((active_key_last_valid_round-last_committed_block)) -le 417104 ]]; then
529582
local existing_expiration_date
@@ -625,10 +678,10 @@ joined_network_instructions() {
625678
echo "Account setup skipped. Multiple accounts detected in your wallet."
626679
else
627680
echo "Account setup skipped. Detected existing account with address: ${account_addr}"
628-
fi
629681

630-
echo "To see network participation status use ${HOME}/voi/bin/get-participation-status ${account_addr}"
631-
echo "To go online use ${HOME}/voi/bin/go-online ${account_addr}"
682+
echo "To see network participation status use ${HOME}/voi/bin/get-participation-status ${account_addr}"
683+
echo "To go online use ${HOME}/voi/bin/go-online ${account_addr}"
684+
fi
632685
fi
633686

634687
# Display information informing the user that the network will catch up in the background if used in non-interactive mode
@@ -676,10 +729,23 @@ change_account_online_status() {
676729

677730
join_as_new_user() {
678731
new_user_setup=1
732+
local account_addresses
733+
account_addresses=$(get_account_addresses)
734+
679735
display_banner "Joining network"
680736

681737
generate_participation_key
682738

739+
# If there are multiple accounts, we don't want to go online automatically, unless previously done
740+
# as part of participation key generation.
741+
if [[ $(echo "$account_addresses" | wc -l) -gt 1 ]]; then
742+
display_banner "Welcome to Voi!"
743+
744+
joined_network_instructions
745+
746+
exit
747+
fi
748+
683749
busy_wait_until_balance_is_sufficient
684750

685751
change_account_online_status "${account}"
@@ -1084,6 +1150,11 @@ fi
10841150

10851151
check_minimum_requirements
10861152

1153+
if [[ ${new_network} -eq 1 ]]; then
1154+
get_container_id
1155+
ensure_accounts_are_offline
1156+
fi
1157+
10871158
get_telemetry_name
10881159
set_telemetry_name
10891160

@@ -1149,6 +1220,7 @@ start_stack
11491220
wait_for_stack_to_be_ready
11501221

11511222
if [[ ${VOINETWORK_PROFILE} == "participation" ]]; then
1223+
get_container_id
11521224
verify_node_is_running
11531225
fi
11541226

@@ -1219,6 +1291,7 @@ if [[ ${skip_account_setup} -eq 0 || ${new_network} -eq 1 ]]; then
12191291
else
12201292
generate_participation_key
12211293
participation_key_generation_status=$?
1294+
12221295
## Catch cases where an install was aborted / user didn't succeed in going online
12231296
## This can happen where there are no part keys present on the machine, or where there's multiple part keys but
12241297
## no key is active.

0 commit comments

Comments
 (0)