multinode-demo/: Merge bootstrap-leader.sh into fullnode.sh (#4139)
This commit is contained in:
		@@ -4,59 +4,4 @@
 | 
				
			|||||||
#
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
here=$(dirname "$0")
 | 
					here=$(dirname "$0")
 | 
				
			||||||
# shellcheck source=multinode-demo/common.sh
 | 
					exec "$here"/fullnode.sh --bootstrap-leader x$$ "$@"
 | 
				
			||||||
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"
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,7 @@ fi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
extra_fullnode_args=()
 | 
					extra_fullnode_args=()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bootstrap_leader=false
 | 
				
			||||||
stake=43 # number of lamports to assign as stake (plus transaction fee to setup the stake)
 | 
					stake=43 # number of lamports to assign as stake (plus transaction fee to setup the stake)
 | 
				
			||||||
poll_for_new_genesis_block=0
 | 
					poll_for_new_genesis_block=0
 | 
				
			||||||
label=
 | 
					label=
 | 
				
			||||||
@@ -21,6 +22,9 @@ while [[ ${1:0:1} = - ]]; do
 | 
				
			|||||||
  if [[ $1 = --label ]]; then
 | 
					  if [[ $1 = --label ]]; then
 | 
				
			||||||
    label="-$2"
 | 
					    label="-$2"
 | 
				
			||||||
    shift 2
 | 
					    shift 2
 | 
				
			||||||
 | 
					  elif [[ $1 = --bootstrap-leader ]]; then
 | 
				
			||||||
 | 
					    bootstrap_leader=true
 | 
				
			||||||
 | 
					    shift
 | 
				
			||||||
  elif [[ $1 = --poll-for-new-genesis-block ]]; then
 | 
					  elif [[ $1 = --poll-for-new-genesis-block ]]; then
 | 
				
			||||||
    poll_for_new_genesis_block=1
 | 
					    poll_for_new_genesis_block=1
 | 
				
			||||||
    shift
 | 
					    shift
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,11 @@ source "$here"/../scripts/oom-score-adj.sh
 | 
				
			|||||||
# shellcheck source=multinode-demo/extra-fullnode-args.sh
 | 
					# shellcheck source=multinode-demo/extra-fullnode-args.sh
 | 
				
			||||||
source "$here"/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() {
 | 
					find_leader() {
 | 
				
			||||||
  declare leader leader_address
 | 
					  declare leader leader_address
 | 
				
			||||||
  declare shift=0
 | 
					  declare shift=0
 | 
				
			||||||
@@ -32,42 +37,6 @@ find_leader() {
 | 
				
			|||||||
  echo "$leader" "$leader_address" "$shift"
 | 
					  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
 | 
					rsync_url() { # adds the 'rsync://` prefix to URLs that need it
 | 
				
			||||||
  declare url="$1"
 | 
					  declare url="$1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -144,13 +113,76 @@ setup_vote_account() {
 | 
				
			|||||||
  return 0
 | 
					  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
 | 
					set -e
 | 
				
			||||||
rsync_leader_url=$(rsync_url "$leader")
 | 
					 | 
				
			||||||
secs_to_next_genesis_poll=0
 | 
					secs_to_next_genesis_poll=0
 | 
				
			||||||
PS4="$(basename "$0"): "
 | 
					PS4="$(basename "$0"): "
 | 
				
			||||||
while true; do
 | 
					while true; do
 | 
				
			||||||
  set -x
 | 
					 | 
				
			||||||
  if [[ ! -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger ]]; then
 | 
					  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"
 | 
					    $rsync -vPr "$rsync_leader_url"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR"
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -161,23 +193,19 @@ while true; do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  trap '[[ -n $pid ]] && kill "$pid" >/dev/null 2>&1 && wait "$pid"' INT TERM ERR
 | 
					  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"
 | 
					    setup_vote_account "${leader_address%:*}" "$fullnode_id_path" "$fullnode_vote_id_path" "$stake"
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
  set +x
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  default_fullnode_arg --identity "$fullnode_id_path"
 | 
					  echo "$PS4$program ${extra_fullnode_args[*]}"
 | 
				
			||||||
  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[*]}"
 | 
					 | 
				
			||||||
  $program "${extra_fullnode_args[@]}" > >($fullnode_logger) 2>&1 &
 | 
					  $program "${extra_fullnode_args[@]}" > >($fullnode_logger) 2>&1 &
 | 
				
			||||||
  pid=$!
 | 
					  pid=$!
 | 
				
			||||||
  oom_score_adj "$pid" 1000
 | 
					  oom_score_adj "$pid" 1000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if $bootstrap_leader; then
 | 
				
			||||||
 | 
					    wait "$pid"
 | 
				
			||||||
 | 
					    sleep 1
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
    while true; do
 | 
					    while true; do
 | 
				
			||||||
      if ! kill -0 "$pid"; then
 | 
					      if ! kill -0 "$pid"; then
 | 
				
			||||||
        wait "$pid"
 | 
					        wait "$pid"
 | 
				
			||||||
@@ -200,5 +228,6 @@ while true; do
 | 
				
			|||||||
    wait "$pid" || true
 | 
					    wait "$pid" || true
 | 
				
			||||||
    rm -rf "$ledger_config_dir" "$accounts_config_dir" "$fullnode_vote_id_path".configured
 | 
					    rm -rf "$ledger_config_dir" "$accounts_config_dir" "$fullnode_vote_id_path".configured
 | 
				
			||||||
    sleep 60 # give the network time to come back up
 | 
					    sleep 60 # give the network time to come back up
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user