#!/usr/bin/env bash # # Start a validator # here=$(dirname "$0") # shellcheck source=multinode-demo/common.sh source "$here"/common.sh usage() { if [[ -n $1 ]]; then echo "$*" echo fi cat </dev/null 2>&1 } set -e PS4="$(basename "$0"): " pid= kill_node() { # Note: do not echo anything from this function to ensure $pid is actually # killed when stdout/stderr are redirected set +ex if [[ -n $pid ]]; then declare _pid=$pid pid= kill "$_pid" || true wait "$_pid" || true fi exit } kill_node_and_exit() { kill_node exit } trap 'kill_node_and_exit' INT TERM ERR wallet() { ( set -x $solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" "$@" ) } setup_validator_accounts() { declare node_lamports=$1 if ((airdrops_enabled)); then echo "Adding $node_lamports to validator identity account:" ( declare fees=100 # TODO: No hardcoded transaction fees, fetch the current cluster fees wallet airdrop $((node_lamports+fees)) ) || return $? else echo "Validator identity account balance:" wallet balance || return $? fi if ! wallet show-vote-account "$voting_keypair_path"; then echo "Creating validator vote account" wallet create-vote-account "$voting_keypair_path" "$identity_keypair_path" 1 --commission 127 || return $? fi echo "Validator vote account configured" if ! wallet show-storage-account "$storage_keypair_path"; then echo "Creating validator storage account" wallet create-validator-storage-account "$identity_keypair_path" "$storage_keypair_path" || return $? fi echo "Validator storage account configured" return 0 } while true; do rpc_url=$($solana_gossip get-rpc-url --entrypoint "$gossip_entrypoint") if new_genesis_block; then # If the genesis block has changed remove the now stale ledger and start all # over again ( set -x rm -rf "$ledger_dir" ) fi [[ -r "$identity_keypair_path" ]] || $solana_keygen new -o "$identity_keypair_path" [[ -r "$voting_keypair_path" ]] || $solana_keygen new -o "$voting_keypair_path" [[ -r "$storage_keypair_path" ]] || $solana_keygen new -o "$storage_keypair_path" setup_validator_accounts "$node_lamports" vote_pubkey=$($solana_keygen pubkey "$voting_keypair_path") storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") identity_pubkey=$($solana_keygen pubkey "$identity_keypair_path") export SOLANA_METRICS_HOST_ID="$identity_pubkey" cat <