#!/bin/bash # VALIDATOR CHECKS WILL BE UPDATED AFTER MIGRATION # # HOST="http://localhost:3333" # # VALIDATOR_ADDRESS=$(curl -s -X POST "$HOST/key/list" -H "Content-Type: application/json" \ # -d '{"network_identifier": {"network": "mainnet"}}' \ # | jq -r ".public_keys[0].identifiers.validator_entity_identifier.address") # IS_VALIDATING=$(curl -s -X POST "$HOST/entity" -H "Content-Type: application/json" \ # -d "{\"network_identifier\": {\"network\": \"mainnet\"}, \"entity_identifier\": # {\"address\": \"$VALIDATOR_ADDRESS\", \"sub_entity\": {\"address\": \"system\"}}}" \ # | jq ".data_objects | any(.type == \"ValidatorBFTData\")") # # get_completed_proposals () { # curl -s -X POST "$HOST/entity" -H "Content-Type: application/json" \ # -d "{\"network_identifier\": {\"network\": \"mainnet\"}, \"entity_identifier\": # {\"address\": \"$VALIDATOR_ADDRESS\", \"sub_entity\": {\"address\": \"system\"}}}" \ # | jq ".data_objects[] | select(.type == \"ValidatorBFTData\") | .proposals_completed" # } IS_VALIDATING=false check_return_code () { if [[ $? -eq 0 ]] then echo "Successfully switched radix mode and restarted." else echo "Error: Failed to switch radix mode and restart." fi } switch_grafana () { if [[ ! -f /etc/grafana-agent.yaml ]] then return fi if sudo sed -i "s/$1/$2/g" /etc/grafana-agent.yaml && \ sudo systemctl restart grafana-agent then echo "Successfully switched grafana agent to $2 mode." else echo "Error: Failed to switch grafana agent to $2 mode." fi } if [[ "$1" == "validator" ]] then echo "Restarting Radix Node in validator mode ..." sudo systemctl stop radix-babylon && \ rm -f /etc/radix-babylon/node/secrets && \ ln -s /etc/radix-babylon/node/secrets-validator /etc/radix-babylon/node/secrets && \ sudo systemctl start radix-babylon check_return_code switch_grafana "fullnode" $1 elif [[ "$1" == "fullnode" ]] then if [[ $IS_VALIDATING == true && "$2" != "force" ]] then PROPOSALS_COMPLETED=$(get_completed_proposals) echo "Wait until node completed proposal to minimise risk of a missed proposal ..." while (( $(get_completed_proposals) == PROPOSALS_COMPLETED)) || (( $(get_completed_proposals) == 0)) do echo "Waiting ..." sleep 1 done echo "Validator completed proposal - updating now." fi echo "Restarting Radix Node in fullnode mode ..." sudo systemctl stop radix-babylon && \ rm -f /etc/radix-babylon/node/secrets && \ ln -s /etc/radix-babylon/node/secrets-fullnode /etc/radix-babylon/node/secrets && \ sudo systemctl start radix-babylon check_return_code switch_grafana "validator" $1 else echo "Radix Node Switch Mode" echo "" echo "Usage:" echo " switch-mode fullnode Switch radix node to fullnode mode." echo " switch-mode validator Switch radix node to validator mode." fi