From 19ea5fe0c094ffaa56334d8eb82ae3a59d3ae230 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 1 Jul 2019 11:54:00 -0700 Subject: [PATCH] Rework fullnode.sh to recover better from genesis block resets (#4884) --- multinode-demo/common.sh | 15 +++ multinode-demo/fullnode.sh | 248 ++++++++++++++++++------------------- 2 files changed, 135 insertions(+), 128 deletions(-) diff --git a/multinode-demo/common.sh b/multinode-demo/common.sh index a70b2e4e4..1f2c7e07c 100644 --- a/multinode-demo/common.sh +++ b/multinode-demo/common.sh @@ -88,3 +88,18 @@ default_arg() { args+=("$name") fi } + +replace_arg() { + declare name=$1 + declare value=$2 + + default_arg "$name" "$value" + + declare index=0 + for arg in "${args[@]}"; do + index=$((index + 1)) + if [[ $arg = "$name" ]]; then + args[$index]="$value" + fi + done +} diff --git a/multinode-demo/fullnode.sh b/multinode-demo/fullnode.sh index 6e5dd9abc..c4afc32fb 100755 --- a/multinode-demo/fullnode.sh +++ b/multinode-demo/fullnode.sh @@ -9,6 +9,7 @@ source "$here"/common.sh # shellcheck source=scripts/oom-score-adj.sh source "$here"/../scripts/oom-score-adj.sh + fullnode_usage() { if [[ -n $1 ]]; then echo "$*" @@ -76,24 +77,8 @@ rsync_url() { # adds the 'rsync://` prefix to URLs that need it setup_validator_accounts() { declare entrypoint_ip=$1 - declare node_keypair_path=$2 - declare vote_keypair_path=$3 - declare stake_keypair_path=$4 - declare storage_keypair_path=$5 - declare node_lamports=$6 - declare stake_lamports=$7 - - declare node_pubkey - node_pubkey=$($solana_keygen pubkey "$node_keypair_path") - - declare vote_pubkey - vote_pubkey=$($solana_keygen pubkey "$vote_keypair_path") - - declare stake_pubkey - stake_pubkey=$($solana_keygen pubkey "$stake_keypair_path") - - declare storage_pubkey - storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") + declare node_lamports=$2 + declare stake_lamports=$3 if [[ -f $configured_flag ]]; then echo "Vote and stake accounts have already been configured" @@ -101,75 +86,66 @@ setup_validator_accounts() { if ((airdrops_enabled)); then # Fund the node with enough tokens to fund its Vote, Staking, and Storage accounts declare fees=100 # TODO: No hardcoded transaction fees, fetch the current cluster fees - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" airdrop $((node_lamports+stake_lamports+fees)) || return $? + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" airdrop $((node_lamports+stake_lamports+fees)) || return $? else echo "current account balance is " - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" balance || return $? + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" balance || return $? fi - # Fund the vote account from the node, with the node as the node_pubkey - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ - create-vote-account "$vote_pubkey" "$node_pubkey" 1 --commission 65535 || return $? + # Fund the vote account from the node, with the node as the identity_pubkey + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \ + create-vote-account "$vote_pubkey" "$identity_pubkey" 1 --commission 65535 || return $? - # Fund the stake account from the node, with the node as the node_pubkey - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ + # Fund the stake account from the node, with the node as the identity_pubkey + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \ create-stake-account "$stake_pubkey" "$stake_lamports" || return $? # Delegate the stake. The transaction fee is paid by the node but the # transaction must be signed by the stake_keypair - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \ delegate-stake "$stake_keypair_path" "$vote_pubkey" "$stake_lamports" || return $? # Setup validator storage account - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ - create-validator-storage-account "$node_pubkey" "$storage_pubkey" || return $? + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \ + create-validator-storage-account "$identity_pubkey" "$storage_pubkey" || return $? touch "$configured_flag" fi - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \ show-vote-account "$vote_pubkey" - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \ show-stake-account "$stake_pubkey" - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \ show-storage-account "$storage_pubkey" echo "Identity account balance:" $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" balance - echo "========================================================================" return 0 } setup_replicator_account() { declare entrypoint_ip=$1 - declare node_keypair_path=$2 - declare storage_keypair_path=$3 - declare node_lamports=$4 - - declare node_pubkey - node_pubkey=$($solana_keygen pubkey "$node_keypair_path") - - declare storage_pubkey - storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") + declare node_lamports=$2 if [[ -f $configured_flag ]]; then echo "Replicator account has already been configured" else if ((airdrops_enabled)); then - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" airdrop "$node_lamports" || return $? + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" airdrop "$node_lamports" || return $? else echo "current account balance is " - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" balance || return $? + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" balance || return $? fi # Setup replicator storage account - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ - create-replicator-storage-account "$node_pubkey" "$storage_pubkey" || return $? + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \ + create-replicator-storage-account "$identity_pubkey" "$storage_pubkey" || return $? touch "$configured_flag" fi - $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ + $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \ show-storage-account "$storage_pubkey" return 0 @@ -275,24 +251,13 @@ if [[ $node_type = replicator ]]; then shift "$shift" : "${identity_keypair_path:=$SOLANA_CONFIG_DIR/replicator-keypair$label.json}" + mkdir -p "$SOLANA_CONFIG_DIR" + [[ -r "$identity_keypair_path" ]] || $solana_keygen new -o "$identity_keypair_path" + storage_keypair_path="$SOLANA_CONFIG_DIR"/replicator-storage-keypair$label.json ledger_config_dir=$SOLANA_CONFIG_DIR/replicator-ledger$label configured_flag=$SOLANA_CONFIG_DIR/replicator$label.configured - mkdir -p "$SOLANA_CONFIG_DIR" - [[ -r "$identity_keypair_path" ]] || $solana_keygen new -o "$identity_keypair_path" - [[ -r "$storage_keypair_path" ]] || $solana_keygen new -o "$storage_keypair_path" - - identity_pubkey=$($solana_keygen pubkey "$identity_keypair_path") - storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") - - cat </dev/null 2>&1 } @@ -417,63 +374,104 @@ kill_fullnode() { trap 'kill_fullnode' INT TERM ERR while true; do - if new_gensis_block; then - # If the genesis block has changed remove the now stale ledger and vote - # keypair for the node and start all over again + if [[ $node_type != bootstrap_leader ]] && new_gensis_block; then + # If the genesis block has changed remove the now stale ledger and + # vote/stake/storage keypairs for the node and start all over again ( set -x rm -rf "$ledger_config_dir" "$state_dir" "$configured_flag" ) + if [[ $node_type = validator ]]; then + $solana_keygen new -f -o "$vote_keypair_path" + $solana_keygen new -f -o "$stake_keypair_path" + $solana_keygen new -f -o "$storage_keypair_path" + fi + if [[ $node_type = replicator ]]; then + $solana_keygen new -f -o "$storage_keypair_path" + fi fi - if [[ ! -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger ]]; then - if [[ $node_type = bootstrap_leader ]]; then + if [[ $node_type = replicator ]]; then + storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") + setup_replicator_account "${entrypoint_address%:*}" \ + "$node_lamports" + + cat <