multinode-demo/: Merge bootstrap-leader.sh into fullnode.sh (#4139)

This commit is contained in:
Michael Vines 2019-05-03 12:33:48 -07:00 committed by GitHub
parent 7fe3c75c6b
commit f9c093022c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 121 deletions

View File

@ -4,59 +4,4 @@
#
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
fullnode_usage "$@"
fi
# shellcheck source=multinode-demo/extra-fullnode-args.sh
source "$here"/extra-fullnode-args.sh
[[ -f "$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json ]] || {
echo "$SOLANA_CONFIG_DIR/bootstrap-leader-id.json not found, create it by running:"
echo
echo " ${here}/setup.sh"
exit 1
}
if [[ -n "$SOLANA_CUDA" ]]; then
program="$solana_fullnode_cuda"
else
program="$solana_fullnode"
fi
if [[ -z $CI ]]; then # Skip in CI
# shellcheck source=scripts/tune-system.sh
source "$SOLANA_ROOT"/scripts/tune-system.sh
fi
$solana_ledger_tool --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger verify
bootstrap_leader_id_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json
bootstrap_leader_vote_id_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-vote-id.json
bootstrap_leader_vote_id=$($solana_keygen pubkey "$bootstrap_leader_vote_id_path")
trap 'kill "$pid" && wait "$pid"' INT TERM ERR
default_fullnode_arg --identity "$bootstrap_leader_id_path"
default_fullnode_arg --voting-keypair "$bootstrap_leader_vote_id_path"
default_fullnode_arg --vote-account "$bootstrap_leader_vote_id"
default_fullnode_arg --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger
default_fullnode_arg --accounts "$SOLANA_CONFIG_DIR"/bootstrap-leader-accounts
default_fullnode_arg --rpc-port 8899
default_fullnode_arg --rpc-drone-address 127.0.0.1:9900
default_fullnode_arg --gossip-port 8001
echo "$PS4 $program ${extra_fullnode_args[*]}"
$program "${extra_fullnode_args[@]}" > >($bootstrap_leader_logger) 2>&1 &
pid=$!
oom_score_adj "$pid" 1000
wait "$pid"
exec "$here"/fullnode.sh --bootstrap-leader x$$ "$@"

View File

@ -13,6 +13,7 @@ fi
extra_fullnode_args=()
bootstrap_leader=false
stake=43 # number of lamports to assign as stake (plus transaction fee to setup the stake)
poll_for_new_genesis_block=0
label=
@ -21,6 +22,9 @@ while [[ ${1:0:1} = - ]]; do
if [[ $1 = --label ]]; then
label="-$2"
shift 2
elif [[ $1 = --bootstrap-leader ]]; then
bootstrap_leader=true
shift
elif [[ $1 = --poll-for-new-genesis-block ]]; then
poll_for_new_genesis_block=1
shift

View File

@ -12,6 +12,11 @@ source "$here"/../scripts/oom-score-adj.sh
# shellcheck source=multinode-demo/extra-fullnode-args.sh
source "$here"/extra-fullnode-args.sh
if [[ -z $CI ]]; then # Skip in CI
# shellcheck source=scripts/tune-system.sh
source "$SOLANA_ROOT"/scripts/tune-system.sh
fi
find_leader() {
declare leader leader_address
declare shift=0
@ -32,42 +37,6 @@ find_leader() {
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
fullnode_id_path=$SOLANA_CONFIG_DIR/fullnode-id$label.json
fullnode_vote_id_path=$SOLANA_CONFIG_DIR/fullnode-vote-id$label.json
ledger_config_dir=$SOLANA_CONFIG_DIR/fullnode-ledger$label
accounts_config_dir=$SOLANA_CONFIG_DIR/fullnode-accounts$label
mkdir -p "$SOLANA_CONFIG_DIR"
[[ -r "$fullnode_id_path" ]] || $solana_keygen -o "$fullnode_id_path"
[[ -r "$fullnode_vote_id_path" ]] || $solana_keygen -o "$fullnode_vote_id_path"
fullnode_id=$($solana_keygen pubkey "$fullnode_id_path")
fullnode_vote_id=$($solana_keygen pubkey "$fullnode_vote_id_path")
cat <<EOF
======================[ Fullnode configuration ]======================
node id: $fullnode_id
vote id: $fullnode_vote_id
ledger: $ledger_config_dir
accounts: $accounts_config_dir
======================================================================
EOF
if [[ -z $CI ]]; then # Skip in CI
# shellcheck source=scripts/tune-system.sh
source "$SOLANA_ROOT"/scripts/tune-system.sh
fi
rsync_url() { # adds the 'rsync://` prefix to URLs that need it
declare url="$1"
@ -144,13 +113,76 @@ setup_vote_account() {
return 0
}
ledger_not_setup() {
echo "Error: $*"
echo
echo "Please run: ${here}/setup.sh"
exit 1
}
if $bootstrap_leader; then
[[ -f "$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json ]] ||
ledger_not_setup "$SOLANA_CONFIG_DIR/bootstrap-leader-id.json not found"
$solana_ledger_tool --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger verify
fullnode_id_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json
fullnode_vote_id_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-vote-id.json
ledger_config_dir="$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger
accounts_config_dir="$SOLANA_CONFIG_DIR"/bootstrap-leader-accounts
default_fullnode_arg --rpc-port 8899
default_fullnode_arg --rpc-drone-address 127.0.0.1:9900
default_fullnode_arg --gossip-port 8001
else
read -r leader leader_address shift < <(find_leader "${@:1:2}")
shift "$shift"
fullnode_id_path=$SOLANA_CONFIG_DIR/fullnode-id$label.json
fullnode_vote_id_path=$SOLANA_CONFIG_DIR/fullnode-vote-id$label.json
ledger_config_dir=$SOLANA_CONFIG_DIR/fullnode-ledger$label
accounts_config_dir=$SOLANA_CONFIG_DIR/fullnode-accounts$label
mkdir -p "$SOLANA_CONFIG_DIR"
[[ -r "$fullnode_id_path" ]] || $solana_keygen -o "$fullnode_id_path"
[[ -r "$fullnode_vote_id_path" ]] || $solana_keygen -o "$fullnode_vote_id_path"
default_fullnode_arg --network "$leader_address"
default_fullnode_arg --rpc-drone-address "${leader_address%:*}:9900"
fi
fullnode_id=$($solana_keygen pubkey "$fullnode_id_path")
fullnode_vote_id=$($solana_keygen pubkey "$fullnode_vote_id_path")
cat <<EOF
======================[ Fullnode configuration ]======================
node id: $fullnode_id
vote id: $fullnode_vote_id
ledger: $ledger_config_dir
accounts: $accounts_config_dir
======================================================================
EOF
default_fullnode_arg --identity "$fullnode_id_path"
default_fullnode_arg --voting-keypair "$fullnode_vote_id_path"
default_fullnode_arg --vote-account "$fullnode_vote_id"
default_fullnode_arg --ledger "$ledger_config_dir"
default_fullnode_arg --accounts "$accounts_config_dir"
if [[ -n $SOLANA_CUDA ]]; then
program=$solana_fullnode_cuda
else
program=$solana_fullnode
fi
set -e
rsync_leader_url=$(rsync_url "$leader")
secs_to_next_genesis_poll=0
PS4="$(basename "$0"): "
while true; do
set -x
if [[ ! -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger ]]; then
if $bootstrap_leader; then
ledger_not_setup "$SOLANA_RSYNC_CONFIG_DIR/ledger does not exist"
fi
rsync_leader_url=$(rsync_url "$leader")
$rsync -vPr "$rsync_leader_url"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR"
fi
@ -161,44 +193,41 @@ while true; do
trap '[[ -n $pid ]] && kill "$pid" >/dev/null 2>&1 && wait "$pid"' INT TERM ERR
if ((stake)); then
if ! $bootstrap_leader && ((stake)); then
setup_vote_account "${leader_address%:*}" "$fullnode_id_path" "$fullnode_vote_id_path" "$stake"
fi
set +x
default_fullnode_arg --identity "$fullnode_id_path"
default_fullnode_arg --voting-keypair "$fullnode_vote_id_path"
default_fullnode_arg --vote-account "$fullnode_vote_id"
default_fullnode_arg --network "$leader_address"
default_fullnode_arg --ledger "$ledger_config_dir"
default_fullnode_arg --accounts "$accounts_config_dir"
default_fullnode_arg --rpc-drone-address "${leader_address%:*}:9900"
echo "$PS4 $program ${extra_fullnode_args[*]}"
echo "$PS4$program ${extra_fullnode_args[*]}"
$program "${extra_fullnode_args[@]}" > >($fullnode_logger) 2>&1 &
pid=$!
oom_score_adj "$pid" 1000
while true; do
if ! kill -0 "$pid"; then
wait "$pid"
exit 0
fi
if $bootstrap_leader; then
wait "$pid"
sleep 1
else
while true; do
if ! kill -0 "$pid"; then
wait "$pid"
exit 0
fi
((poll_for_new_genesis_block)) || continue
((secs_to_next_genesis_poll--)) && continue
sleep 1
$rsync -r "$rsync_leader_url"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR" || true
diff -q "$SOLANA_RSYNC_CONFIG_DIR"/ledger/genesis.json "$ledger_config_dir"/genesis.json >/dev/null 2>&1 || break
secs_to_next_genesis_poll=60
((poll_for_new_genesis_block)) || continue
((secs_to_next_genesis_poll--)) && continue
done
$rsync -r "$rsync_leader_url"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR" || true
diff -q "$SOLANA_RSYNC_CONFIG_DIR"/ledger/genesis.json "$ledger_config_dir"/genesis.json >/dev/null 2>&1 || break
secs_to_next_genesis_poll=60
echo "############## New genesis detected, restarting fullnode ##############"
kill "$pid" || true
wait "$pid" || true
rm -rf "$ledger_config_dir" "$accounts_config_dir" "$fullnode_vote_id_path".configured
sleep 60 # give the network time to come back up
done
echo "############## New genesis detected, restarting fullnode ##############"
kill "$pid" || true
wait "$pid" || true
rm -rf "$ledger_config_dir" "$accounts_config_dir" "$fullnode_vote_id_path".configured
sleep 60 # give the network time to come back up
fi
done