2019-05-23 15:06:01 -07:00
|
|
|
#!/usr/bin/env bash
|
2019-07-30 22:43:47 -07:00
|
|
|
#
|
|
|
|
# Start a validator
|
|
|
|
#
|
2019-05-23 15:06:01 -07:00
|
|
|
here=$(dirname "$0")
|
2019-07-30 22:43:47 -07:00
|
|
|
# shellcheck source=multinode-demo/common.sh
|
|
|
|
source "$here"/common.sh
|
|
|
|
|
2020-04-29 18:53:34 -07:00
|
|
|
args=(
|
|
|
|
--max-genesis-archive-unpacked-size 1073741824
|
2021-02-28 13:03:56 -08:00
|
|
|
--no-poh-speed-test
|
2021-10-25 18:25:55 -07:00
|
|
|
--no-os-network-limits-test
|
2020-04-29 18:53:34 -07:00
|
|
|
)
|
2019-12-10 14:52:35 -08:00
|
|
|
airdrops_enabled=1
|
2020-02-15 11:53:52 -08:00
|
|
|
node_sol=500 # 500 SOL: number of SOL to airdrop the node for transaction fees and vote account rent exemption (ignored if airdrops_enabled=0)
|
2019-12-10 14:52:35 -08:00
|
|
|
label=
|
2020-03-13 11:41:18 -07:00
|
|
|
identity=
|
|
|
|
vote_account=
|
2019-12-10 14:52:35 -08:00
|
|
|
no_restart=0
|
|
|
|
gossip_entrypoint=
|
|
|
|
ledger_dir=
|
|
|
|
|
2019-08-01 13:48:00 -07:00
|
|
|
usage() {
|
2019-07-30 22:43:47 -07:00
|
|
|
if [[ -n $1 ]]; then
|
|
|
|
echo "$*"
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
cat <<EOF
|
|
|
|
|
2019-08-01 13:48:00 -07:00
|
|
|
usage: $0 [OPTIONS] [cluster entry point hostname]
|
2019-07-30 22:43:47 -07:00
|
|
|
|
2019-08-01 13:48:00 -07:00
|
|
|
Start a validator with no stake
|
2019-07-30 22:43:47 -07:00
|
|
|
|
2019-08-01 13:48:00 -07:00
|
|
|
OPTIONS:
|
2019-08-05 12:42:52 -07:00
|
|
|
--ledger PATH - store ledger under this PATH
|
2019-07-30 22:43:47 -07:00
|
|
|
--init-complete-file FILE - create this file, if it doesn't already exist, once node initialization is complete
|
|
|
|
--label LABEL - Append the given label to the configuration files, useful when running
|
2019-08-01 13:48:00 -07:00
|
|
|
multiple validators in the same workspace
|
2020-02-15 11:53:52 -08:00
|
|
|
--node-sol SOL - Number of SOL this node has been funded from the genesis config (default: $node_sol)
|
2019-07-30 22:43:47 -07:00
|
|
|
--no-voting - start node without vote signer
|
|
|
|
--rpc-port port - custom RPC port for this node
|
|
|
|
--no-restart - do not restart the node if it exits
|
2019-11-08 20:56:57 -08:00
|
|
|
--no-airdrop - The genesis config has an account for the node. Airdrops are not required.
|
2019-07-30 22:43:47 -07:00
|
|
|
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-08-18 22:02:28 -07:00
|
|
|
maybeRequireTower=true
|
|
|
|
|
2019-07-30 22:43:47 -07:00
|
|
|
positional_args=()
|
|
|
|
while [[ -n $1 ]]; do
|
|
|
|
if [[ ${1:0:1} = - ]]; then
|
2019-09-05 14:57:35 -07:00
|
|
|
# validator.sh-only options
|
2019-07-30 22:43:47 -07:00
|
|
|
if [[ $1 = --label ]]; then
|
|
|
|
label="-$2"
|
|
|
|
shift 2
|
|
|
|
elif [[ $1 = --no-restart ]]; then
|
|
|
|
no_restart=1
|
|
|
|
shift
|
2020-02-15 11:53:52 -08:00
|
|
|
elif [[ $1 = --node-sol ]]; then
|
|
|
|
node_sol="$2"
|
2019-07-30 22:43:47 -07:00
|
|
|
shift 2
|
2019-09-05 14:57:35 -07:00
|
|
|
elif [[ $1 = --no-airdrop ]]; then
|
|
|
|
airdrops_enabled=0
|
|
|
|
shift
|
|
|
|
# solana-validator options
|
2019-11-08 20:56:57 -08:00
|
|
|
elif [[ $1 = --expected-genesis-hash ]]; then
|
2019-09-29 19:09:24 -07:00
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2020-03-06 14:49:04 -08:00
|
|
|
elif [[ $1 = --expected-shred-version ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2020-03-13 11:41:18 -07:00
|
|
|
elif [[ $1 = --identity ]]; then
|
|
|
|
identity=$2
|
2019-07-30 22:43:47 -07:00
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2020-03-13 11:41:18 -07:00
|
|
|
elif [[ $1 = --authorized-voter ]]; then
|
2019-07-30 22:43:47 -07:00
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2021-09-02 17:22:33 -07:00
|
|
|
elif [[ $1 = --authorized-withdrawer ]]; then
|
2021-09-03 12:56:57 -07:00
|
|
|
authorized_withdrawer=$2
|
2021-09-02 17:22:33 -07:00
|
|
|
shift 2
|
2019-09-05 14:57:35 -07:00
|
|
|
elif [[ $1 = --vote-account ]]; then
|
2020-03-13 11:41:18 -07:00
|
|
|
vote_account=$2
|
2019-09-05 14:57:35 -07:00
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2019-07-30 22:43:47 -07:00
|
|
|
elif [[ $1 = --init-complete-file ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2019-09-05 14:57:35 -07:00
|
|
|
elif [[ $1 = --ledger ]]; then
|
|
|
|
ledger_dir=$2
|
|
|
|
shift 2
|
|
|
|
elif [[ $1 = --entrypoint ]]; then
|
|
|
|
gossip_entrypoint=$2
|
|
|
|
args+=("$1" "$2")
|
2019-07-30 22:43:47 -07:00
|
|
|
shift 2
|
2019-08-14 19:25:22 -07:00
|
|
|
elif [[ $1 = --no-snapshot-fetch ]]; then
|
|
|
|
args+=("$1")
|
|
|
|
shift
|
2019-07-30 22:43:47 -07:00
|
|
|
elif [[ $1 = --no-voting ]]; then
|
|
|
|
args+=("$1")
|
|
|
|
shift
|
2019-08-08 09:14:30 -07:00
|
|
|
elif [[ $1 = --dev-no-sigverify ]]; then
|
2019-07-30 22:43:47 -07:00
|
|
|
args+=("$1")
|
|
|
|
shift
|
2019-09-05 14:57:35 -07:00
|
|
|
elif [[ $1 = --dev-halt-at-slot ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
|
|
|
elif [[ $1 = --rpc-port ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2019-12-16 13:05:17 -08:00
|
|
|
elif [[ $1 = --rpc-faucet-address ]]; then
|
2019-07-30 22:43:47 -07:00
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2019-09-05 14:57:35 -07:00
|
|
|
elif [[ $1 = --accounts ]]; then
|
2019-07-30 22:43:47 -07:00
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
|
|
|
elif [[ $1 = --gossip-port ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2019-09-05 14:57:35 -07:00
|
|
|
elif [[ $1 = --dynamic-port-range ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
|
|
|
elif [[ $1 = --snapshot-interval-slots ]]; then
|
|
|
|
args+=("$1" "$2")
|
2019-07-30 22:43:47 -07:00
|
|
|
shift 2
|
2021-05-12 10:32:27 -07:00
|
|
|
elif [[ $1 = --maximum-snapshots-to-retain ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2019-09-05 14:57:35 -07:00
|
|
|
elif [[ $1 = --limit-ledger-size ]]; then
|
2020-03-23 08:42:32 -07:00
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
|
|
|
elif [[ $1 = --no-rocksdb-compaction ]]; then
|
2019-09-05 14:57:35 -07:00
|
|
|
args+=("$1")
|
|
|
|
shift
|
2020-03-23 10:25:39 -07:00
|
|
|
elif [[ $1 = --enable-rpc-transaction-history ]]; then
|
2020-02-12 16:08:27 -08:00
|
|
|
args+=("$1")
|
|
|
|
shift
|
2021-02-01 13:00:51 -08:00
|
|
|
elif [[ $1 = --enable-cpi-and-log-storage ]]; then
|
|
|
|
args+=("$1")
|
|
|
|
shift
|
2022-03-22 15:17:05 -07:00
|
|
|
elif [[ $1 = --enable-extended-tx-metadata-storage ]]; then
|
|
|
|
args+=("$1")
|
|
|
|
shift
|
2019-11-04 21:14:55 -08:00
|
|
|
elif [[ $1 = --skip-poh-verify ]]; then
|
2019-09-05 14:57:35 -07:00
|
|
|
args+=("$1")
|
|
|
|
shift
|
2022-08-24 08:21:01 -07:00
|
|
|
elif [[ $1 = --tpu-disable-quic ]]; then
|
2022-04-21 12:43:08 -07:00
|
|
|
args+=("$1")
|
|
|
|
shift
|
2022-09-07 13:19:14 -07:00
|
|
|
elif [[ $1 = --tpu-enable-udp ]]; then
|
|
|
|
args+=("$1")
|
|
|
|
shift
|
2022-04-21 12:43:08 -07:00
|
|
|
elif [[ $1 = --rpc-send-batch-ms ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
|
|
|
elif [[ $1 = --rpc-send-batch-size ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2019-11-06 11:47:34 -08:00
|
|
|
elif [[ $1 = --log ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2021-08-17 21:17:46 -07:00
|
|
|
elif [[ $1 = --known-validator ]]; then
|
2020-02-21 18:42:24 -08:00
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2021-08-17 21:17:46 -07:00
|
|
|
elif [[ $1 = --halt-on-known-validators-accounts-hash-mismatch ]]; then
|
2020-03-16 08:37:31 -07:00
|
|
|
args+=("$1")
|
|
|
|
shift
|
2020-04-29 18:53:34 -07:00
|
|
|
elif [[ $1 = --max-genesis-archive-unpacked-size ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2020-06-15 18:52:44 -07:00
|
|
|
elif [[ $1 == --wait-for-supermajority ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2020-06-03 17:50:57 -07:00
|
|
|
elif [[ $1 == --expected-bank-hash ]]; then
|
|
|
|
args+=("$1" "$2")
|
|
|
|
shift 2
|
2021-08-18 15:28:06 -07:00
|
|
|
elif [[ $1 == --accounts-db-skip-shrink ]]; then
|
|
|
|
args+=("$1")
|
|
|
|
shift
|
2021-08-18 22:02:28 -07:00
|
|
|
elif [[ $1 == --skip-require-tower ]]; then
|
|
|
|
maybeRequireTower=false
|
|
|
|
shift
|
2019-07-30 22:43:47 -07:00
|
|
|
elif [[ $1 = -h ]]; then
|
2019-08-01 13:48:00 -07:00
|
|
|
usage "$@"
|
2019-07-30 22:43:47 -07:00
|
|
|
else
|
|
|
|
echo "Unknown argument: $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
positional_args+=("$1")
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2019-10-14 09:33:32 -07:00
|
|
|
if [[ "$SOLANA_GPU_MISSING" -eq 1 ]]; then
|
|
|
|
echo "Testnet requires GPUs, but none were found! Aborting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-07-30 22:43:47 -07:00
|
|
|
if [[ ${#positional_args[@]} -gt 1 ]]; then
|
2019-08-01 13:48:00 -07:00
|
|
|
usage "$@"
|
2019-07-30 22:43:47 -07:00
|
|
|
fi
|
|
|
|
|
2019-08-05 12:42:52 -07:00
|
|
|
if [[ -n $REQUIRE_LEDGER_DIR ]]; then
|
|
|
|
if [[ -z $ledger_dir ]]; then
|
|
|
|
usage "Error: --ledger not specified"
|
2019-07-30 22:43:47 -07:00
|
|
|
fi
|
2019-08-05 12:42:52 -07:00
|
|
|
SOLANA_CONFIG_DIR="$ledger_dir"
|
2019-07-30 22:43:47 -07:00
|
|
|
fi
|
|
|
|
|
2019-08-05 10:39:16 -07:00
|
|
|
if [[ -n $REQUIRE_KEYPAIRS ]]; then
|
2020-03-13 11:41:18 -07:00
|
|
|
if [[ -z $identity ]]; then
|
|
|
|
usage "Error: --identity not specified"
|
2019-08-05 10:39:16 -07:00
|
|
|
fi
|
2020-03-13 11:41:18 -07:00
|
|
|
if [[ -z $vote_account ]]; then
|
|
|
|
usage "Error: --vote-account not specified"
|
2019-08-05 10:39:16 -07:00
|
|
|
fi
|
2021-09-03 12:44:55 -07:00
|
|
|
if [[ -z $authorized_withdrawer ]]; then
|
2021-09-02 17:22:33 -07:00
|
|
|
usage "Error: --authorized_withdrawer not specified"
|
|
|
|
fi
|
2019-08-05 10:39:16 -07:00
|
|
|
fi
|
|
|
|
|
2019-08-05 12:42:52 -07:00
|
|
|
if [[ -z "$ledger_dir" ]]; then
|
|
|
|
ledger_dir="$SOLANA_CONFIG_DIR/validator$label"
|
2019-07-30 22:43:47 -07:00
|
|
|
fi
|
2019-08-05 12:42:52 -07:00
|
|
|
mkdir -p "$ledger_dir"
|
2019-07-30 22:43:47 -07:00
|
|
|
|
2019-07-31 09:54:39 -07:00
|
|
|
if [[ -n $gossip_entrypoint ]]; then
|
|
|
|
# Prefer the --entrypoint argument if supplied...
|
|
|
|
if [[ ${#positional_args[@]} -gt 0 ]]; then
|
2019-08-01 13:48:00 -07:00
|
|
|
usage "$@"
|
2019-07-31 09:54:39 -07:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
# ...but also support providing the entrypoint's hostname as the first
|
|
|
|
# positional argument
|
|
|
|
entrypoint_hostname=${positional_args[0]}
|
|
|
|
if [[ -z $entrypoint_hostname ]]; then
|
|
|
|
gossip_entrypoint=127.0.0.1:8001
|
|
|
|
else
|
|
|
|
gossip_entrypoint="$entrypoint_hostname":8001
|
|
|
|
fi
|
2019-07-30 22:43:47 -07:00
|
|
|
fi
|
2019-08-13 10:49:48 -07:00
|
|
|
|
2019-12-16 13:05:17 -08:00
|
|
|
faucet_address="${gossip_entrypoint%:*}":9900
|
2019-07-30 22:43:47 -07:00
|
|
|
|
2020-03-13 11:41:18 -07:00
|
|
|
: "${identity:=$ledger_dir/identity.json}"
|
|
|
|
: "${vote_account:=$ledger_dir/vote-account.json}"
|
2021-09-03 12:44:55 -07:00
|
|
|
: "${authorized_withdrawer:=$ledger_dir/authorized-withdrawer.json}"
|
2019-07-30 22:43:47 -07:00
|
|
|
|
|
|
|
default_arg --entrypoint "$gossip_entrypoint"
|
|
|
|
if ((airdrops_enabled)); then
|
2019-12-16 13:05:17 -08:00
|
|
|
default_arg --rpc-faucet-address "$faucet_address"
|
2019-07-30 22:43:47 -07:00
|
|
|
fi
|
|
|
|
|
2020-03-13 11:41:18 -07:00
|
|
|
default_arg --identity "$identity"
|
|
|
|
default_arg --vote-account "$vote_account"
|
2019-08-05 12:42:52 -07:00
|
|
|
default_arg --ledger "$ledger_dir"
|
2019-11-06 11:47:34 -08:00
|
|
|
default_arg --log -
|
2022-01-28 18:00:18 -08:00
|
|
|
default_arg --full-rpc-api
|
2022-02-09 11:26:35 -08:00
|
|
|
default_arg --no-incremental-snapshots
|
2023-02-22 09:54:15 -08:00
|
|
|
default_arg --allow-private-addr
|
2021-08-18 22:02:28 -07:00
|
|
|
|
|
|
|
if [[ $maybeRequireTower = true ]]; then
|
|
|
|
default_arg --require-tower
|
|
|
|
fi
|
2019-07-30 22:43:47 -07:00
|
|
|
|
|
|
|
if [[ -n $SOLANA_CUDA ]]; then
|
|
|
|
program=$solana_validator_cuda
|
|
|
|
else
|
|
|
|
program=$solana_validator
|
|
|
|
fi
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2019-09-06 14:08:30 -07:00
|
|
|
|
2019-07-30 22:43:47 -07:00
|
|
|
kill_node_and_exit() {
|
|
|
|
kill_node
|
|
|
|
exit
|
|
|
|
}
|
2019-09-06 14:08:30 -07:00
|
|
|
|
2019-07-30 22:43:47 -07:00
|
|
|
trap 'kill_node_and_exit' INT TERM ERR
|
|
|
|
|
2019-08-05 12:42:52 -07:00
|
|
|
wallet() {
|
|
|
|
(
|
|
|
|
set -x
|
2020-03-13 11:41:18 -07:00
|
|
|
$solana_cli --keypair "$identity" --url "$rpc_url" "$@"
|
2019-08-05 12:42:52 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_validator_accounts() {
|
2020-02-15 11:53:52 -08:00
|
|
|
declare node_sol=$1
|
2019-08-05 12:42:52 -07:00
|
|
|
|
2020-09-10 11:30:34 -07:00
|
|
|
if [[ -n "$SKIP_ACCOUNTS_CREATION" ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2020-03-13 11:41:18 -07:00
|
|
|
if ! wallet vote-account "$vote_account"; then
|
2019-09-19 22:33:35 -07:00
|
|
|
if ((airdrops_enabled)); then
|
2020-02-15 11:53:52 -08:00
|
|
|
echo "Adding $node_sol to validator identity account:"
|
2020-05-19 20:07:30 -07:00
|
|
|
(
|
|
|
|
set -x
|
2021-03-22 11:10:44 -07:00
|
|
|
$solana_cli \
|
|
|
|
--keypair "$SOLANA_CONFIG_DIR/faucet.json" --url "$rpc_url" \
|
|
|
|
transfer --allow-unfunded-recipient "$identity" "$node_sol"
|
2020-05-19 20:07:30 -07:00
|
|
|
) || return $?
|
2019-09-19 22:33:35 -07:00
|
|
|
fi
|
|
|
|
|
2019-08-05 12:42:52 -07:00
|
|
|
echo "Creating validator vote account"
|
2021-09-02 17:22:33 -07:00
|
|
|
wallet create-vote-account "$vote_account" "$identity" "$authorized_withdrawer" || return $?
|
2019-08-05 12:42:52 -07:00
|
|
|
fi
|
|
|
|
echo "Validator vote account configured"
|
|
|
|
|
2019-09-19 22:33:35 -07:00
|
|
|
echo "Validator identity account balance:"
|
2020-02-15 11:53:52 -08:00
|
|
|
wallet balance || return $?
|
2019-09-19 22:33:35 -07:00
|
|
|
|
2019-08-05 12:42:52 -07:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-02-22 09:54:15 -08:00
|
|
|
# shellcheck disable=SC2086
|
|
|
|
rpc_url=$($solana_gossip --allow-private-addr rpc-url --timeout 180 --entrypoint "$gossip_entrypoint")
|
2019-11-22 08:44:16 -08:00
|
|
|
|
2020-03-13 11:41:18 -07:00
|
|
|
[[ -r "$identity" ]] || $solana_keygen new --no-passphrase -so "$identity"
|
|
|
|
[[ -r "$vote_account" ]] || $solana_keygen new --no-passphrase -so "$vote_account"
|
2021-09-03 12:44:55 -07:00
|
|
|
[[ -r "$authorized_withdrawer" ]] || $solana_keygen new --no-passphrase -so "$authorized_withdrawer"
|
2019-07-30 22:43:47 -07:00
|
|
|
|
2020-02-15 11:53:52 -08:00
|
|
|
setup_validator_accounts "$node_sol"
|
2019-08-05 12:42:52 -07:00
|
|
|
|
2019-11-22 08:44:16 -08:00
|
|
|
while true; do
|
2019-07-30 22:43:47 -07:00
|
|
|
echo "$PS4$program ${args[*]}"
|
|
|
|
|
|
|
|
$program "${args[@]}" &
|
|
|
|
pid=$!
|
|
|
|
echo "pid: $pid"
|
|
|
|
|
|
|
|
if ((no_restart)); then
|
|
|
|
wait "$pid"
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
if [[ -z $pid ]] || ! kill -0 "$pid"; then
|
|
|
|
echo "############## validator exited, restarting ##############"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
kill_node
|
|
|
|
done
|