Skip to content

Commit b35f893

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 b35f893

File tree

1 file changed

+104
-32
lines changed

1 file changed

+104
-32
lines changed

install.sh

+104-32
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,82 @@ get_account_address() {
266266
account_addr=$account_address
267267
}
268268

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

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

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

420519
## Install script dependencies
421-
execute_sudo "apt-get install -y jq"
520+
execute_sudo "apt-get install -y jq bc"
422521

423522
display_banner "Starting stack"
424523

@@ -502,37 +601,10 @@ fi
502601
catchup_node
503602

504603
if [[ ${skip_account_setup} -eq 0 ]]; then
505-
display_banner "Joining network"
506-
604+
join_as_new_user
605+
else
507606
generate_participation_key
508607

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
536608
display_banner "Welcome to Voi!"
537609

538610
joined_network_instructions

0 commit comments

Comments
 (0)