|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
| 3 | +execute_sudo() { |
| 4 | + if sudo -v &> /dev/null; then |
| 5 | + if [[ $(id -u) -eq 0 ]]; then |
| 6 | + bash -c "$*" |
| 7 | + else |
| 8 | + sudo bash -c "$*" |
| 9 | + fi |
| 10 | + else |
| 11 | + echo "The user does not have sudo privileges. Exiting the program." |
| 12 | + exit 1 |
| 13 | + fi |
| 14 | +} |
| 15 | + |
| 16 | +get_last_committed_block() { |
| 17 | + docker exec -it "${container_id}" bash -c "goal node status | grep 'Last committed block' | cut -d' ' -f4 | tr -cd '[:digit:]'" |
| 18 | +} |
| 19 | + |
| 20 | +get_account_info() { |
| 21 | + if execute_sudo 'test ! -f "/var/lib/voi/algod/data/voitest-v1/accountList.json"'; then |
| 22 | + abort "Account list not found. Exiting the program." |
| 23 | + fi |
| 24 | + |
| 25 | + accounts_json=$(execute_sudo 'cat /var/lib/voi/algod/data/voitest-v1/accountList.json') |
| 26 | + number_of_accounts=$(echo "${accounts_json}" | jq '.Accounts | length') |
| 27 | + |
| 28 | + if [[ ! $number_of_accounts -eq 1 ]]; then |
| 29 | + echo "More than one account, or zero, found in wallet." |
| 30 | + return 1 |
| 31 | + fi |
| 32 | + |
| 33 | + account_address=$(echo "$accounts_json" | jq -r '.Accounts | keys[0]') |
| 34 | + echo "${account_address}" |
| 35 | +} |
| 36 | + |
| 37 | +get_participation_expiration_eta() { |
| 38 | + local active_key_last_valid_round=$1 |
| 39 | + local last_committed_block=$2 |
| 40 | + local current_key_blocks_remaining=$((active_key_last_valid_round - last_committed_block)) |
| 41 | + local remaining_seconds |
| 42 | + local current_timestamp |
| 43 | + local expiration_timestamp |
| 44 | + local expiration_date |
| 45 | + |
| 46 | + remaining_seconds=$(echo "${current_key_blocks_remaining}*2.9" | bc) |
| 47 | + current_timestamp=$(date +%s) |
| 48 | + expiration_timestamp=$(echo "${current_timestamp}+${remaining_seconds}" | bc) |
| 49 | + |
| 50 | + # Convert the new timestamp to a date and time |
| 51 | + expiration_date=$(date -d "@${expiration_timestamp}" '+%Y-%m-%d %H:%M') |
| 52 | + |
| 53 | + echo "${expiration_date}" |
| 54 | +} |
| 55 | + |
| 56 | +display_participation_key_information() { |
| 57 | + local existing_expiration_date |
| 58 | + local active_key_last_valid_round |
| 59 | + local last_committed_block |
| 60 | + last_committed_block=$(get_last_committed_block) |
| 61 | + |
| 62 | + active_key_last_valid_round=$(docker exec -it "${container_id}" bash -c 'goal account listpartkeys' | awk '$1=="yes" {print $6}' | tr -cd '[:digit:]') |
| 63 | + existing_expiration_date=$(get_participation_expiration_eta "${active_key_last_valid_round}" "${last_committed_block}") |
| 64 | + |
| 65 | + echo "Participation status: $(docker exec -it "${container_id}" bash -c 'goal account dump -a '"${account_address}"' | jq -r '\''if (.onl == 1) then "online" else "offline" end'\''')" |
| 66 | + echo "Participation key expires at block: ${active_key_last_valid_round} (last committed: ${last_committed_block})" |
| 67 | + echo "Participation key expected to expire at: ${existing_expiration_date}" |
| 68 | +} |
| 69 | + |
3 | 70 | container_id=$(docker ps -q -f name=voinetwork_algod)
|
4 | 71 | if [ -z "${container_id}" ]; then
|
5 | 72 | echo "AVM container is not running. Please start it first."
|
|
26 | 93 | health_checks["Daemon ready (and caught up)"]="false"
|
27 | 94 | fi
|
28 | 95 |
|
29 |
| -# Print all health checks |
30 |
| -echo "Health checks:" |
| 96 | +echo "Voi Swarm Docker status:" |
| 97 | +echo "**************" |
| 98 | +swarm_running_image=$(docker inspect --format='{{.Image}}' "${container_id}" | cut -d':' -f2) |
| 99 | +echo "Running container image (sha256): ${swarm_running_image}" |
| 100 | +echo "" |
| 101 | + |
| 102 | +echo "AVM version:" |
| 103 | +echo "**************" |
| 104 | +algod_version=$(docker exec -it "${container_id}" bash -c 'goal version -v') |
| 105 | +account_address=$(get_account_info) |
| 106 | +echo "${algod_version}" |
| 107 | +echo "" |
| 108 | + |
| 109 | +echo "Node health checks:" |
31 | 110 | echo "**************"
|
32 | 111 | for check in "${!health_checks[@]}"; do
|
33 | 112 | echo "$check: ${health_checks[$check]}"
|
34 | 113 | done
|
| 114 | +echo "" |
| 115 | + |
| 116 | +echo "Account status:" |
| 117 | +echo "**************" |
| 118 | +echo "Address: ${account_address}" |
| 119 | +echo "Balance: $(docker exec -it "${container_id}" bash -c 'goal account balance -a '"${account_address}"'')" |
| 120 | +display_participation_key_information |
| 121 | + |
| 122 | +echo "" |
| 123 | +echo "Telemetry status:" |
| 124 | +echo "**************" |
| 125 | +echo "Enabled: $(execute_sudo "cat /var/lib/voi/algod/data/logging.config | jq -r .Enable")" |
| 126 | +echo "Name: $(execute_sudo "cat /var/lib/voi/algod/data/logging.config | jq -r .Name")" |
| 127 | +echo "Short GUID: $(execute_sudo "cat /var/lib/voi/algod/data/logging.config | jq -r .GUID | cut -c 1-13")" |
0 commit comments