From f9c093022cd3fd362b1616d30529a570d8b2edb5 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 3 May 2019 12:33:48 -0700 Subject: [PATCH] multinode-demo/: Merge bootstrap-leader.sh into fullnode.sh (#4139) --- multinode-demo/bootstrap-leader.sh | 57 +-------- multinode-demo/extra-fullnode-args.sh | 4 + multinode-demo/fullnode.sh | 159 +++++++++++++++----------- 3 files changed, 99 insertions(+), 121 deletions(-) diff --git a/multinode-demo/bootstrap-leader.sh b/multinode-demo/bootstrap-leader.sh index 541bec49d1..e2a931ccf4 100755 --- a/multinode-demo/bootstrap-leader.sh +++ b/multinode-demo/bootstrap-leader.sh @@ -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$$ "$@" diff --git a/multinode-demo/extra-fullnode-args.sh b/multinode-demo/extra-fullnode-args.sh index 549da4712a..45e1195bac 100644 --- a/multinode-demo/extra-fullnode-args.sh +++ b/multinode-demo/extra-fullnode-args.sh @@ -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 diff --git a/multinode-demo/fullnode.sh b/multinode-demo/fullnode.sh index d42aab9326..07b930cdf5 100755 --- a/multinode-demo/fullnode.sh +++ b/multinode-demo/fullnode.sh @@ -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 </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