Skip to content

Commit 2a08efd

Browse files
committed
Generate / renew particiation key based on current key status.
We allow generation 417104 blocks out, which with blocktime of 2.9 seconds should equate about 14 days.
1 parent f7e0653 commit 2a08efd

File tree

1 file changed

+106
-32
lines changed

1 file changed

+106
-32
lines changed

install.sh

+106-32
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ get_account_info() {
252252

253253
check_if_account_exists() {
254254
allow_one_account_override="$1"
255+
255256
get_account_info "$allow_one_account_override" > /dev/null
256257
}
257258

@@ -266,12 +267,83 @@ get_account_address() {
266267
account_addr=$account_address
267268
}
268269

269-
generate_participation_key() {
270-
start_block=$(execute_interactive_docker_command "goal node status" | grep "Last committed block" | cut -d\ -f4 | tr -d '\r')
270+
get_participation_expiration_eta() {
271+
local active_key_last_valid_round=$1
272+
local last_committed_block=$2
273+
local current_key_blocks_remaining=$((active_key_last_valid_round - last_committed_block))
274+
local remaining_seconds
275+
local current_timestamp
276+
local expiration_timestamp
277+
local expiration_date
278+
279+
remaining_seconds=$(echo "${current_key_blocks_remaining}*2.9" | bc)
280+
current_timestamp=$(date +%s)
281+
expiration_timestamp=$(echo "${current_timestamp}+${remaining_seconds}" | bc)
282+
283+
# Convert the new timestamp to a date and time
284+
expiration_date=$(date -d "@${expiration_timestamp}" '+%Y-%m-%d %H:%M')
285+
286+
echo "${expiration_date}"
287+
}
288+
289+
get_current_keys_info() {
290+
execute_docker_command "goal account listpartkeys" | tail -n +2
291+
}
292+
293+
get_last_committed_block() {
294+
execute_docker_command "goal node status" | grep 'Last committed block' | cut -d\ -f4 | tr -d '\r'
295+
}
296+
297+
generate_new_key() {
298+
local start_block
299+
local end_block
300+
301+
start_block=$(get_last_committed_block)
271302
end_block=$((start_block + 2000000))
303+
echo "Generating participation key for account ${account_addr} with start block ${start_block} and end block ${end_block}"
272304
execute_interactive_docker_command "goal account addpartkey -a ${account_addr} --roundFirstValid ${start_block} --roundLastValid ${end_block}"
273305
}
274306

307+
generate_participation_key() {
308+
local current_keys_info
309+
local active_key_last_valid_round
310+
local last_committed_block
311+
312+
display_banner "Generating/Updating participation key"
313+
314+
current_keys_info=$(get_current_keys_info)
315+
active_key_last_valid_round=$(echo "$current_keys_info" | awk '/yes/ {print $NF}')
316+
last_committed_block=$(get_last_committed_block)
317+
318+
if [[ -z ${active_key_last_valid_round} ]]; then
319+
generate_new_key
320+
elif [[ $((active_key_last_valid_round-last_committed_block)) -le 417104 ]]; then
321+
local expiration_date
322+
local current_key_prefix
323+
local current_key_id
324+
local end_block
325+
326+
expiration_date=$(get_participation_expiration_eta "${active_key_last_valid_round}" "${last_committed_block}")
327+
echo "Current participation key is expected to expire at: ${expiration_date}"
328+
329+
current_key_prefix=$(echo "$current_keys_info" | awk '/yes/ {print $3}' | tr -d .)
330+
current_key_id=$(execute_docker_command "goal account partkeyinfo" | grep "${current_key_prefix}" | awk '{print $3}')
331+
332+
end_block=$((last_committed_block + 2000000))
333+
echo "Current participation key is close to expiring (less than 417,104 blocks / ~14 days). Generating a new key."
334+
echo "Generating participation key for account ${account_addr} with end block ${end_block}"
335+
336+
execute_interactive_docker_command "goal account renewpartkey -a ${account_addr} --roundLastValid ${end_block}"
337+
execute_interactive_docker_command "goal account deletepartkey --partkeyid ${current_key_id}"
338+
else
339+
local expiration_date
340+
expiration_date=$(get_participation_expiration_eta "${active_key_last_valid_round}" "${last_committed_block}")
341+
342+
echo "Current participation key is expected to expire at: ${expiration_date}"
343+
echo "This is above the required threshold of 417,104 blocks / ~14 days."
344+
fi
345+
}
346+
275347
display_banner() {
276348
echo
277349
echo "********************************************************************************"
@@ -326,6 +398,35 @@ joined_network_instructions() {
326398
echo ""
327399
}
328400

401+
join_as_new_user() {
402+
display_banner "Joining network"
403+
404+
generate_participation_key
405+
406+
busy_wait_until_balance_is_1_voi
407+
408+
echo "Enter your password to join the network."
409+
execute_interactive_docker_command "goal account changeonlinestatus -a ${account_addr}"
410+
411+
account_status=$(execute_docker_command "goal account dump -a ${account_addr}" | jq -r .onl)
412+
413+
if [[ ${account_status} -eq 1 ]]; then
414+
display_banner "Welcome to Voi! You are now online!"
415+
else
416+
display_banner "Your account ${account_addr} is currently offline."
417+
echo "There seems to be an issue with going online. Please seek assistance in the #node-help channel on the Voi Network Discord."
418+
echo "Join us at: https://discord.com/invite/vnFbrJrHeW"
419+
abort "Exiting the program."
420+
fi
421+
422+
echo "PLEASE SAVE THIS INFORMATION SAFELY"
423+
echo "***********************************"
424+
echo "Your Voi address: ${account_addr}"
425+
echo "Enter password to get your Voi account recovery mnemonic. Store your mnemonic safely:"
426+
427+
execute_interactive_docker_command "goal account export -a ${account_addr}"
428+
}
429+
329430
add_docker_groups() {
330431
if [[ is_root -eq 0 ]]; then
331432
if [[ ! $(getent group docker) ]]; then
@@ -418,7 +519,7 @@ if ! docker --version | grep -q 'Docker version'; then
418519
fi
419520

420521
## Install script dependencies
421-
execute_sudo "apt-get install -y jq"
522+
execute_sudo "apt-get install -y jq bc"
422523

423524
display_banner "Starting stack"
424525

@@ -502,37 +603,10 @@ fi
502603
catchup_node
503604

504605
if [[ ${skip_account_setup} -eq 0 ]]; then
505-
display_banner "Joining network"
506-
606+
join_as_new_user
607+
else
507608
generate_participation_key
508609

509-
busy_wait_until_balance_is_1_voi
510-
511-
echo "Enter your password to join the network."
512-
execute_interactive_docker_command "goal account changeonlinestatus -a ${account_addr}"
513-
514-
account_status=$(execute_docker_command "goal account dump -a ${account_addr}" | jq -r .onl)
515-
fi
516-
517-
if [[ ${skip_account_setup} -eq 0 ]]; then
518-
if [[ ${account_status} -eq 1 ]]; then
519-
display_banner "Welcome to Voi! You are now online!"
520-
521-
joined_network_instructions
522-
else
523-
display_banner "Your account ${account_addr} is currently offline."
524-
echo "There seems to be an issue with going online. Please seek assistance in the #node-help channel on the Voi Network Discord."
525-
echo "Join us at: https://discord.com/invite/vnFbrJrHeW"
526-
abort "Exiting the program."
527-
fi
528-
529-
echo "PLEASE SAVE THIS INFORMATION SAFELY"
530-
echo "***********************************"
531-
echo "Your Voi address: ${account_addr}"
532-
echo "Enter password to get your Voi account recovery mnemonic. Store your mnemonic safely:"
533-
534-
execute_interactive_docker_command "goal account export -a ${account_addr}"
535-
else
536610
display_banner "Welcome to Voi!"
537611

538612
joined_network_instructions

0 commit comments

Comments
 (0)