#!/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= kill_fullnode() { # 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 } trap 'kill_fullnode' INT TERM ERR if ((reset_ledger)); then echo "Resetting ledger..." ( set -x rm -rf "$state_dir" rm -rf "$ledger_config_dir" ) if [[ -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ ]]; then cp -a "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ "$ledger_config_dir" fi fi while true; do if [[ $node_type != bootstrap_leader ]] && 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_config_dir" "$state_dir" "$configured_flag" ) fi if [[ $node_type = bootstrap_leader && ! -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger ]]; then ledger_not_setup "$SOLANA_RSYNC_CONFIG_DIR/ledger does not exist" fi if [[ ! -d "$ledger_config_dir" ]]; then if [[ $node_type = validator ]]; then ( cd "$SOLANA_RSYNC_CONFIG_DIR" echo "Rsyncing genesis ledger from ${rsync_entrypoint_url:?}..." SECONDS= while ! $rsync -Pr "${rsync_entrypoint_url:?}"/config/ledger .; do echo "Genesis ledger rsync failed" sleep 5 done echo "Fetched genesis ledger in $SECONDS seconds" if ((boot_from_snapshot)); then SECONDS= echo "Rsyncing state snapshot ${rsync_entrypoint_url:?}..." if ! $rsync -P "${rsync_entrypoint_url:?}"/config/state.tgz .; then echo "State snapshot rsync failed" rm -f "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz exit fi echo "Fetched snapshot in $SECONDS seconds" SECONDS= mkdir -p "$state_dir" ( set -x tar -C "$state_dir" -zxf "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz ) echo "Extracted snapshot in $SECONDS seconds" fi ) fi ( set -x cp -a "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ "$ledger_config_dir" ) fi vote_pubkey=$($solana_keygen pubkey "$voting_keypair_path") stake_pubkey=$($solana_keygen pubkey "$stake_keypair_path") storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") if [[ $node_type = validator ]] && ((stake_lamports)); then setup_validator_accounts "${entrypoint_address%:*}" \ "$node_lamports" \ "$stake_lamports" fi cat <