2018-12-07 10:00:35 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Start a full node
|
|
|
|
#
|
|
|
|
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
|
|
|
|
|
|
|
|
if [[ $1 = -h ]]; then
|
2019-03-12 16:35:13 -07:00
|
|
|
fullnode_usage "$@"
|
2018-12-07 10:00:35 -08:00
|
|
|
fi
|
|
|
|
|
2019-03-04 14:27:06 -08:00
|
|
|
gossip_port=9000
|
2019-03-04 15:59:02 -08:00
|
|
|
extra_fullnode_args=()
|
2019-01-28 12:40:24 -07:00
|
|
|
self_setup=0
|
2019-03-12 16:35:13 -07:00
|
|
|
setup_stakes=true
|
2019-01-22 11:34:12 -08:00
|
|
|
|
|
|
|
while [[ ${1:0:1} = - ]]; do
|
|
|
|
if [[ $1 = -X ]]; then
|
|
|
|
self_setup=1
|
|
|
|
self_setup_label=$2
|
|
|
|
shift 2
|
|
|
|
elif [[ $1 = -x ]]; then
|
|
|
|
self_setup=1
|
|
|
|
self_setup_label=$$
|
|
|
|
shift
|
2019-02-21 16:16:09 -07:00
|
|
|
elif [[ $1 = --blockstream ]]; then
|
2019-03-04 15:59:02 -08:00
|
|
|
extra_fullnode_args+=("$1" "$2")
|
2019-01-29 00:21:27 -08:00
|
|
|
shift 2
|
2019-03-04 15:53:18 -08:00
|
|
|
elif [[ $1 = --enable-rpc-exit ]]; then
|
|
|
|
extra_fullnode_args+=("$1")
|
|
|
|
shift
|
2019-01-22 11:34:12 -08:00
|
|
|
elif [[ $1 = --init-complete-file ]]; then
|
2019-03-04 15:59:02 -08:00
|
|
|
extra_fullnode_args+=("$1" "$2")
|
2019-01-22 11:34:12 -08:00
|
|
|
shift 2
|
2019-03-12 16:35:13 -07:00
|
|
|
elif [[ $1 = --only-bootstrap-stake ]]; then
|
|
|
|
setup_stakes=false
|
2019-03-04 14:27:06 -08:00
|
|
|
shift
|
|
|
|
elif [[ $1 = --public-address ]]; then
|
2019-03-04 15:59:02 -08:00
|
|
|
extra_fullnode_args+=("$1")
|
2019-01-22 11:34:12 -08:00
|
|
|
shift
|
2019-03-13 13:50:30 -07:00
|
|
|
elif [[ $1 = --no-voting ]]; then
|
2019-03-04 15:59:02 -08:00
|
|
|
extra_fullnode_args+=("$1")
|
2019-01-23 18:05:06 -08:00
|
|
|
shift
|
2019-01-28 12:40:24 -07:00
|
|
|
elif [[ $1 = --rpc-port ]]; then
|
2019-03-04 15:59:02 -08:00
|
|
|
extra_fullnode_args+=("$1" "$2")
|
2019-01-28 12:40:24 -07:00
|
|
|
shift 2
|
2019-01-22 11:34:12 -08:00
|
|
|
else
|
|
|
|
echo "Unknown argument: $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2019-01-16 16:01:05 -08:00
|
|
|
|
2018-12-07 10:00:35 -08:00
|
|
|
if [[ -n $3 ]]; then
|
2019-03-12 16:35:13 -07:00
|
|
|
fullnode_usage "$@"
|
2018-12-07 10:00:35 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
find_leader() {
|
|
|
|
declare leader leader_address
|
|
|
|
declare shift=0
|
|
|
|
|
2019-03-02 17:08:46 -08:00
|
|
|
if [[ -z $1 ]]; then
|
|
|
|
leader=${here}/.. # Default to local tree for rsync
|
|
|
|
leader_address=127.0.0.1:8001 # Default to local leader
|
|
|
|
elif [[ -z $2 ]]; then
|
|
|
|
leader=$1
|
|
|
|
|
|
|
|
declare leader_ip
|
|
|
|
if [[ $leader =~ ^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ ]]; then
|
|
|
|
leader_ip=$leader
|
|
|
|
else
|
2018-12-07 10:00:35 -08:00
|
|
|
leader_ip=$(dig +short "${leader%:*}" | head -n1)
|
2019-03-02 17:08:46 -08:00
|
|
|
|
2018-12-07 10:00:35 -08:00
|
|
|
if [[ -z $leader_ip ]]; then
|
|
|
|
usage "Error: unable to resolve IP address for $leader"
|
|
|
|
fi
|
|
|
|
fi
|
2019-03-02 17:08:46 -08:00
|
|
|
|
2018-12-07 10:00:35 -08:00
|
|
|
leader_address=$leader_ip:8001
|
2019-03-02 17:08:46 -08:00
|
|
|
shift=1
|
2018-12-07 10:00:35 -08:00
|
|
|
else
|
2019-03-02 17:08:46 -08:00
|
|
|
leader=$1
|
|
|
|
leader_address=$2
|
|
|
|
shift=2
|
2018-12-07 10:00:35 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$leader" "$leader_address" "$shift"
|
|
|
|
}
|
|
|
|
|
|
|
|
read -r leader leader_address shift < <(find_leader "${@:1:2}")
|
|
|
|
shift "$shift"
|
|
|
|
|
|
|
|
if [[ -n $SOLANA_CUDA ]]; then
|
|
|
|
program=$solana_fullnode_cuda
|
|
|
|
else
|
|
|
|
program=$solana_fullnode
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ((!self_setup)); then
|
2019-03-04 14:27:06 -08:00
|
|
|
[[ -f $SOLANA_CONFIG_DIR/fullnode-id.json ]] || {
|
|
|
|
echo "$SOLANA_CONFIG_DIR/fullnode-id.json not found, create it by running:"
|
2018-12-07 10:00:35 -08:00
|
|
|
echo
|
|
|
|
echo " ${here}/setup.sh"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
fullnode_id_path=$SOLANA_CONFIG_DIR/fullnode-id.json
|
2019-03-08 18:29:08 -08:00
|
|
|
fullnode_staker_id_path=$SOLANA_CONFIG_DIR/fullnode-staker-id.json
|
2018-12-07 10:00:35 -08:00
|
|
|
ledger_config_dir=$SOLANA_CONFIG_DIR/fullnode-ledger
|
2019-02-23 14:23:55 -08:00
|
|
|
accounts_config_dir=$SOLANA_CONFIG_DIR/fullnode-accounts
|
2018-12-07 10:00:35 -08:00
|
|
|
else
|
|
|
|
mkdir -p "$SOLANA_CONFIG_DIR"
|
2019-01-21 18:40:16 -08:00
|
|
|
fullnode_id_path=$SOLANA_CONFIG_DIR/fullnode-id-x$self_setup_label.json
|
2019-03-08 18:29:08 -08:00
|
|
|
fullnode_staker_id_path=$SOLANA_CONFIG_DIR/fullnode-staker-id-x$self_setup_label.json
|
|
|
|
|
2019-01-21 18:40:16 -08:00
|
|
|
[[ -f "$fullnode_id_path" ]] || $solana_keygen -o "$fullnode_id_path"
|
2019-03-08 18:29:08 -08:00
|
|
|
[[ -f "$fullnode_staker_id_path" ]] || $solana_keygen -o "$fullnode_staker_id_path"
|
2018-12-07 10:00:35 -08:00
|
|
|
|
2019-03-04 14:27:06 -08:00
|
|
|
echo "Finding a port.."
|
|
|
|
# Find an available port in the range 9100-9899
|
|
|
|
(( gossip_port = 9100 + ($$ % 800) ))
|
|
|
|
while true; do
|
|
|
|
(( gossip_port = gossip_port >= 9900 ? 9100 : ++gossip_port ))
|
|
|
|
echo "Testing $gossip_port"
|
|
|
|
if ! nc -w 10 -z 127.0.0.1 $gossip_port; then
|
|
|
|
echo "Selected gossip_port $gossip_port"
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
echo "Port $gossip_port is in use"
|
|
|
|
done
|
2019-01-21 18:40:16 -08:00
|
|
|
ledger_config_dir=$SOLANA_CONFIG_DIR/fullnode-ledger-x$self_setup_label
|
2019-02-23 14:23:55 -08:00
|
|
|
accounts_config_dir=$SOLANA_CONFIG_DIR/fullnode-accounts-x$self_setup_label
|
2018-12-07 10:00:35 -08:00
|
|
|
fi
|
|
|
|
|
2019-03-08 18:29:08 -08:00
|
|
|
fullnode_id=$($solana_wallet --keypair "$fullnode_id_path" address)
|
|
|
|
fullnode_staker_id=$($solana_wallet --keypair "$fullnode_staker_id_path" address)
|
|
|
|
|
|
|
|
|
2018-12-07 10:00:35 -08:00
|
|
|
[[ -r $fullnode_id_path ]] || {
|
|
|
|
echo "$fullnode_id_path does not exist"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2019-01-18 13:06:16 -08:00
|
|
|
tune_system
|
|
|
|
|
2018-12-07 10:00:35 -08:00
|
|
|
rsync_url() { # adds the 'rsync://` prefix to URLs that need it
|
|
|
|
declare url="$1"
|
|
|
|
|
|
|
|
if [[ $url =~ ^.*:.*$ ]]; then
|
|
|
|
# assume remote-shell transport when colon is present, use $url unmodified
|
|
|
|
echo "$url"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -d $url ]]; then
|
|
|
|
# assume local directory if $url is a valid directory, use $url unmodified
|
|
|
|
echo "$url"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Default to rsync:// URL
|
|
|
|
echo "rsync://$url"
|
|
|
|
}
|
|
|
|
|
2019-03-08 18:29:08 -08:00
|
|
|
|
2018-12-07 10:00:35 -08:00
|
|
|
rsync_leader_url=$(rsync_url "$leader")
|
2019-01-18 13:06:16 -08:00
|
|
|
set -ex
|
2019-03-21 15:27:09 -07:00
|
|
|
if [[ ! -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger ]]; then
|
2019-03-21 17:06:05 -07:00
|
|
|
$rsync -vPr "$rsync_leader_url"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR"
|
2019-03-21 15:27:09 -07:00
|
|
|
fi
|
|
|
|
|
2019-01-18 13:06:16 -08:00
|
|
|
if [[ ! -d "$ledger_config_dir" ]]; then
|
2019-03-21 15:27:09 -07:00
|
|
|
cp -a "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ "$ledger_config_dir"
|
2019-01-18 13:06:16 -08:00
|
|
|
$solana_ledger_tool --ledger "$ledger_config_dir" verify
|
|
|
|
fi
|
2018-12-07 10:00:35 -08:00
|
|
|
|
2019-03-08 18:29:08 -08:00
|
|
|
trap 'kill "$pid" && wait "$pid"' INT TERM ERR
|
2018-12-07 10:00:35 -08:00
|
|
|
$program \
|
2019-03-04 14:27:06 -08:00
|
|
|
--gossip-port "$gossip_port" \
|
|
|
|
--identity "$fullnode_id_path" \
|
2019-03-08 18:29:08 -08:00
|
|
|
--voting-keypair "$fullnode_staker_id_path" \
|
|
|
|
--staking-account "$fullnode_staker_id" \
|
2018-12-07 10:00:35 -08:00
|
|
|
--network "$leader_address" \
|
2019-01-18 11:39:17 -08:00
|
|
|
--ledger "$ledger_config_dir" \
|
2019-02-23 14:23:55 -08:00
|
|
|
--accounts "$accounts_config_dir" \
|
2019-03-06 09:26:12 -08:00
|
|
|
--rpc-drone-address "${leader_address%:*}:9900" \
|
2019-03-04 15:59:02 -08:00
|
|
|
"${extra_fullnode_args[@]}" \
|
2018-12-07 10:00:35 -08:00
|
|
|
> >($fullnode_logger) 2>&1 &
|
|
|
|
pid=$!
|
|
|
|
oom_score_adj "$pid" 1000
|
2019-03-08 18:29:08 -08:00
|
|
|
|
2019-03-12 16:35:13 -07:00
|
|
|
if [[ $setup_stakes = true ]]; then
|
|
|
|
setup_fullnode_staking "${leader_address%:*}" "$fullnode_id_path" "$fullnode_staker_id_path"
|
|
|
|
fi
|
2019-03-08 18:29:08 -08:00
|
|
|
|
2018-12-07 10:00:35 -08:00
|
|
|
wait "$pid"
|