@@ -252,6 +252,7 @@ get_account_info() {
252
252
253
253
check_if_account_exists () {
254
254
allow_one_account_override=" $1 "
255
+
255
256
get_account_info " $allow_one_account_override " > /dev/null
256
257
}
257
258
@@ -266,12 +267,83 @@ get_account_address() {
266
267
account_addr=$account_address
267
268
}
268
269
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)
271
302
end_block=$(( start_block + 2000000 ))
303
+ echo " Generating participation key for account ${account_addr} with start block ${start_block} and end block ${end_block} "
272
304
execute_interactive_docker_command " goal account addpartkey -a ${account_addr} --roundFirstValid ${start_block} --roundLastValid ${end_block} "
273
305
}
274
306
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
+
275
347
display_banner () {
276
348
echo
277
349
echo " ********************************************************************************"
@@ -326,6 +398,35 @@ joined_network_instructions() {
326
398
echo " "
327
399
}
328
400
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
+
329
430
add_docker_groups () {
330
431
if [[ is_root -eq 0 ]]; then
331
432
if [[ ! $( getent group docker) ]]; then
@@ -418,7 +519,7 @@ if ! docker --version | grep -q 'Docker version'; then
418
519
fi
419
520
420
521
# # Install script dependencies
421
- execute_sudo " apt-get install -y jq"
522
+ execute_sudo " apt-get install -y jq bc "
422
523
423
524
display_banner " Starting stack"
424
525
502
603
catchup_node
503
604
504
605
if [[ ${skip_account_setup} -eq 0 ]]; then
505
- display_banner " Joining network "
506
-
606
+ join_as_new_user
607
+ else
507
608
generate_participation_key
508
609
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
536
610
display_banner " Welcome to Voi!"
537
611
538
612
joined_network_instructions
0 commit comments