#!/usr/bin/env bash # # Start a fullnode # here=$(dirname "$0") # shellcheck source=multinode-demo/common.sh source "$here"/common.sh # shellcheck source=scripts/oom-score-adj.sh source "$here"/../scripts/oom-score-adj.sh fullnode_usage() { if [[ -n $1 ]]; then echo "$*" echo fi cat </dev/null 2>&1 } set -e PS4="$(basename "$0"): " pid= trap '[[ -n $pid ]] && kill "$pid" >/dev/null 2>&1 && wait "$pid"' INT TERM ERR while true; do if new_gensis_block; then # If the genesis block has changed remove the now stale ledger and vote # keypair for the node and start all over again ( set -x rm -rf "$ledger_config_dir" "$state_dir" "$configured_flag" ) fi if [[ ! -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger ]]; then if [[ $node_type = bootstrap_leader ]]; then ledger_not_setup "$SOLANA_RSYNC_CONFIG_DIR/ledger does not exist" elif [[ $node_type = validator ]]; then ( SECONDS=0 set -x cd "$SOLANA_RSYNC_CONFIG_DIR" $rsync -qPr "${rsync_entrypoint_url:?}"/config/{ledger,state.tgz} . echo "Fetched snapshot in $SECONDS seconds" ) || true fi fi ( set -x if [[ $node_type = validator ]]; then if [[ -f "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz ]]; then mkdir -p "$state_dir" SECONDS= tar -C "$state_dir" -zxf "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz echo "Extracted snapshot in $SECONDS seconds" fi fi if [[ ! -d "$ledger_config_dir" ]]; then cp -a "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ "$ledger_config_dir" fi ) if ((stake_lamports)); then if [[ $node_type = validator ]]; then setup_validator_accounts "${entrypoint_address%:*}" \ "$identity_keypair_path" \ "$vote_keypair_path" \ "$stake_keypair_path" \ "$storage_keypair_path" \ "$node_lamports" \ "$stake_lamports" elif [[ $node_type = replicator ]]; then setup_replicator_account "${entrypoint_address%:*}" \ "$identity_keypair_path" \ "$storage_keypair_path" \ "$node_lamports" fi fi echo "$PS4$program ${args[*]}" $program "${args[@]}" & pid=$! oom_score_adj "$pid" 1000 if ((no_restart)); then wait "$pid" exit $? fi secs_to_next_genesis_poll=5 secs_to_next_snapshot=30 while true; do if ! kill -0 "$pid"; then wait "$pid" || true echo "############## $node_type exited, restarting ##############" break fi sleep 1 if ((generate_snapshots && --secs_to_next_snapshot == 0)); then ( SECONDS= new_state_dir="$SOLANA_RSYNC_CONFIG_DIR"/new_state new_state_archive="$SOLANA_RSYNC_CONFIG_DIR"/new_state.tgz ( rm -rf "$new_state_dir" "$new_state_archive" cp -a "$state_dir" "$new_state_dir" cd "$new_state_dir" tar zcf "$new_state_archive" ./* ) ln -f "$new_state_archive" "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz rm -rf "$new_state_dir" "$new_state_archive" ls -hl "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz echo "Snapshot generated in $SECONDS seconds" ) || ( echo "Error: failed to generate snapshot" ) secs_to_next_snapshot=60 fi if ((poll_for_new_genesis_block && --secs_to_next_genesis_poll == 0)); then echo "Polling for new genesis block..." ( set -x $rsync -r "${rsync_entrypoint_url:?}"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR" ) || ( echo "Error: failed to rsync ledger" ) new_gensis_block && break secs_to_next_genesis_poll=60 fi done echo "############## New genesis detected, restarting $node_type ##############" kill "$pid" || true wait "$pid" || true # give the cluster time to come back up ( set -x sleep 60 ) done