| 
									
										
										
										
											2018-12-07 10:00:35 -08:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  | # Start a fullnode | 
					
						
							| 
									
										
										
										
											2018-12-07 10:00:35 -08:00
										 |  |  | # | 
					
						
							|  |  |  | 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  | fullnode_usage() { | 
					
						
							|  |  |  |   if [[ -n $1 ]]; then | 
					
						
							|  |  |  |     echo "$*" | 
					
						
							|  |  |  |     echo | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  |   cat <<EOF | 
					
						
							| 
									
										
										
										
											2019-05-09 13:43:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | Fullnode Usage: | 
					
						
							| 
									
										
										
										
											2019-07-22 22:59:02 -07:00
										 |  |  | usage: $0 [--config-dir PATH] [--blockstream PATH] [--init-complete-file FILE] [--label LABEL] [--stake LAMPORTS] [--no-voting] [--rpc-port port] [rsync network path to bootstrap leader configuration] [cluster entry point] | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  | Start a validator | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-22 22:59:02 -07:00
										 |  |  |   --config-dir PATH         - store configuration and data files under this PATH | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  |   --blockstream PATH        - open blockstream at this unix domain socket location | 
					
						
							|  |  |  |   --init-complete-file FILE - create this file, if it doesn't already exist, once node initialization is complete | 
					
						
							| 
									
										
										
										
											2019-05-24 04:31:39 -07:00
										 |  |  |   --label LABEL             - Append the given label to the configuration files, useful when running | 
					
						
							|  |  |  |                               multiple fullnodes in the same workspace | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  |   --stake LAMPORTS          - Number of lamports to stake | 
					
						
							| 
									
										
										
										
											2019-07-19 12:51:38 -06:00
										 |  |  |   --node-lamports LAMPORTS  - Number of lamports this node has been funded from the genesis block | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  |   --no-voting               - start node without vote signer | 
					
						
							|  |  |  |   --rpc-port port           - custom RPC port for this node | 
					
						
							| 
									
										
										
										
											2019-05-12 21:07:31 -07:00
										 |  |  |   --no-restart              - do not restart the node if it exits | 
					
						
							| 
									
										
										
										
											2019-06-10 19:42:49 -07:00
										 |  |  |   --no-airdrop              - The genesis block has an account for the node. Airdrops are not required. | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | EOF | 
					
						
							|  |  |  |   exit 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:59:22 -07:00
										 |  |  | find_entrypoint() { | 
					
						
							|  |  |  |   declare entrypoint entrypoint_address | 
					
						
							| 
									
										
										
										
											2018-12-07 10:00:35 -08:00
										 |  |  |   declare shift=0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-02 17:08:46 -08:00
										 |  |  |   if [[ -z $1 ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-09 17:09:36 -07:00
										 |  |  |     entrypoint="$SOLANA_ROOT"         # Default to local tree for rsync | 
					
						
							| 
									
										
										
										
											2019-05-08 19:59:22 -07:00
										 |  |  |     entrypoint_address=127.0.0.1:8001 # Default to local entrypoint | 
					
						
							| 
									
										
										
										
											2019-03-02 17:08:46 -08:00
										 |  |  |   elif [[ -z $2 ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-08 19:59:22 -07:00
										 |  |  |     entrypoint=$1 | 
					
						
							|  |  |  |     entrypoint_address=$entrypoint:8001 | 
					
						
							| 
									
										
										
										
											2019-03-02 17:08:46 -08:00
										 |  |  |     shift=1 | 
					
						
							| 
									
										
										
										
											2018-12-07 10:00:35 -08:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2019-05-08 19:59:22 -07:00
										 |  |  |     entrypoint=$1 | 
					
						
							|  |  |  |     entrypoint_address=$2 | 
					
						
							| 
									
										
										
										
											2019-03-02 17:08:46 -08:00
										 |  |  |     shift=2 | 
					
						
							| 
									
										
										
										
											2018-12-07 10:00:35 -08:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:59:22 -07:00
										 |  |  |   echo "$entrypoint" "$entrypoint_address" "$shift" | 
					
						
							| 
									
										
										
										
											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-05-23 14:50:23 -07:00
										 |  |  | setup_validator_accounts() { | 
					
						
							| 
									
										
										
										
											2019-05-06 07:38:26 -07:00
										 |  |  |   declare entrypoint_ip=$1 | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  |   declare node_lamports=$2 | 
					
						
							|  |  |  |   declare stake_lamports=$3 | 
					
						
							| 
									
										
										
										
											2019-05-23 14:50:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 14:51:48 -07:00
										 |  |  |   if [[ -f $configured_flag ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-09 19:31:42 -07:00
										 |  |  |     echo "Vote and stake accounts have already been configured" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:03:58 -07:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2019-06-10 19:42:49 -07:00
										 |  |  |     if ((airdrops_enabled)); then | 
					
						
							| 
									
										
										
										
											2019-07-19 20:15:55 -07:00
										 |  |  |       echo "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 | 
					
						
							|  |  |  |         set -x | 
					
						
							|  |  |  |         $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \
 | 
					
						
							|  |  |  |           airdrop $((node_lamports+stake_lamports+fees)) | 
					
						
							|  |  |  |       ) || return $? | 
					
						
							| 
									
										
										
										
											2019-06-10 19:42:49 -07:00
										 |  |  |     else | 
					
						
							|  |  |  |       echo "current account balance is " | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  |       $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" balance || return $? | 
					
						
							| 
									
										
										
										
											2019-06-10 19:42:49 -07:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2019-05-09 19:31:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-19 20:15:55 -07:00
										 |  |  |     echo "Fund the vote account from the node's identity pubkey" | 
					
						
							|  |  |  |     ( | 
					
						
							|  |  |  |       set -x | 
					
						
							|  |  |  |       $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \
 | 
					
						
							|  |  |  |       create-vote-account "$vote_pubkey" "$identity_pubkey" 1 --commission 127 | 
					
						
							|  |  |  |     ) || return $? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     echo "Delegate the stake account to the node's vote account" | 
					
						
							|  |  |  |     ( | 
					
						
							|  |  |  |       set -x | 
					
						
							|  |  |  |       $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \
 | 
					
						
							|  |  |  |         delegate-stake "$stake_keypair_path" "$vote_pubkey" "$stake_lamports" | 
					
						
							|  |  |  |     ) || return $? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     echo "Create validator storage account" | 
					
						
							|  |  |  |     ( | 
					
						
							|  |  |  |       set -x | 
					
						
							|  |  |  |       $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \
 | 
					
						
							|  |  |  |         create-validator-storage-account "$identity_pubkey" "$storage_pubkey" | 
					
						
							|  |  |  |     ) || return $? | 
					
						
							| 
									
										
										
										
											2019-04-17 18:03:58 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 14:51:48 -07:00
										 |  |  |     touch "$configured_flag" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:03:58 -07:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-04 14:51:52 -07:00
										 |  |  |   echo "Identity account balance:" | 
					
						
							| 
									
										
										
										
											2019-07-16 20:10:15 -07:00
										 |  |  |   ( | 
					
						
							|  |  |  |     set -x | 
					
						
							|  |  |  |     $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" balance | 
					
						
							|  |  |  |     $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \
 | 
					
						
							|  |  |  |       show-vote-account "$vote_pubkey" | 
					
						
							|  |  |  |     $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \
 | 
					
						
							|  |  |  |       show-stake-account "$stake_pubkey" | 
					
						
							|  |  |  |     $solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \
 | 
					
						
							|  |  |  |       show-storage-account "$storage_pubkey" | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2019-04-17 18:03:58 -07:00
										 |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-24 04:31:39 -07:00
										 |  |  | ledger_not_setup() { | 
					
						
							|  |  |  |   echo "Error: $*" | 
					
						
							|  |  |  |   echo | 
					
						
							|  |  |  |   echo "Please run: ${here}/setup.sh" | 
					
						
							|  |  |  |   exit 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  | args=() | 
					
						
							| 
									
										
										
										
											2019-05-09 13:43:39 -07:00
										 |  |  | node_type=validator | 
					
						
							| 
									
										
										
										
											2019-06-04 14:51:52 -07:00
										 |  |  | node_lamports=424242  # number of lamports to assign the node for transaction fees | 
					
						
							|  |  |  | stake_lamports=42     # number of lamports to assign as stake | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  | poll_for_new_genesis_block=0 | 
					
						
							|  |  |  | label= | 
					
						
							| 
									
										
										
										
											2019-05-24 04:31:39 -07:00
										 |  |  | identity_keypair_path= | 
					
						
							| 
									
										
										
										
											2019-05-12 21:07:31 -07:00
										 |  |  | no_restart=0 | 
					
						
							| 
									
										
										
										
											2019-06-10 19:42:49 -07:00
										 |  |  | airdrops_enabled=1 | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  | generate_snapshots=0 | 
					
						
							| 
									
										
										
										
											2019-07-11 21:03:17 -07:00
										 |  |  | boot_from_snapshot=1 | 
					
						
							| 
									
										
										
										
											2019-07-22 22:20:54 -07:00
										 |  |  | reset_ledger=0 | 
					
						
							| 
									
										
										
										
											2019-07-22 22:59:02 -07:00
										 |  |  | config_dir= | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  | positional_args=() | 
					
						
							|  |  |  | while [[ -n $1 ]]; do | 
					
						
							|  |  |  |   if [[ ${1:0:1} = - ]]; then | 
					
						
							|  |  |  |     if [[ $1 = --label ]]; then | 
					
						
							|  |  |  |       label="-$2" | 
					
						
							|  |  |  |       shift 2 | 
					
						
							| 
									
										
										
										
											2019-05-12 21:07:31 -07:00
										 |  |  |     elif [[ $1 = --no-restart ]]; then | 
					
						
							|  |  |  |       no_restart=1 | 
					
						
							|  |  |  |       shift | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |     elif [[ $1 = --bootstrap-leader ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-09 13:43:39 -07:00
										 |  |  |       node_type=bootstrap_leader | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |       generate_snapshots=1 | 
					
						
							|  |  |  |       shift | 
					
						
							|  |  |  |     elif [[ $1 = --generate-snapshots ]]; then | 
					
						
							|  |  |  |       generate_snapshots=1 | 
					
						
							| 
									
										
										
										
											2019-05-09 13:43:39 -07:00
										 |  |  |       shift | 
					
						
							| 
									
										
										
										
											2019-07-11 21:03:17 -07:00
										 |  |  |     elif [[ $1 = --no-snapshot ]]; then | 
					
						
							|  |  |  |       boot_from_snapshot=0 | 
					
						
							|  |  |  |       shift | 
					
						
							| 
									
										
										
										
											2019-05-23 15:06:01 -07:00
										 |  |  |     elif [[ $1 = --validator ]]; then | 
					
						
							|  |  |  |       node_type=validator | 
					
						
							|  |  |  |       shift | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |     elif [[ $1 = --poll-for-new-genesis-block ]]; then | 
					
						
							|  |  |  |       poll_for_new_genesis_block=1 | 
					
						
							|  |  |  |       shift | 
					
						
							|  |  |  |     elif [[ $1 = --blockstream ]]; then | 
					
						
							| 
									
										
										
										
											2019-06-04 14:51:52 -07:00
										 |  |  |       stake_lamports=0 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |       args+=("$1" "$2") | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |       shift 2 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:59:22 -07:00
										 |  |  |     elif [[ $1 = --identity ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-24 04:31:39 -07:00
										 |  |  |       identity_keypair_path=$2 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:59:22 -07:00
										 |  |  |       args+=("$1" "$2") | 
					
						
							|  |  |  |       shift 2 | 
					
						
							| 
									
										
										
										
											2019-07-26 11:05:02 -07:00
										 |  |  |     elif [[ $1 = --voting-keypair ]]; then | 
					
						
							|  |  |  |       voting_keypair_path=$2 | 
					
						
							|  |  |  |       args+=("$1" "$2") | 
					
						
							|  |  |  |       shift 2 | 
					
						
							|  |  |  |     elif [[ $1 = --storage-keypair ]]; then | 
					
						
							|  |  |  |       storage_keypair_path=$2 | 
					
						
							|  |  |  |       args+=("$1" "$2") | 
					
						
							|  |  |  |       shift 2 | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |     elif [[ $1 = --enable-rpc-exit ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |       args+=("$1") | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |       shift | 
					
						
							|  |  |  |     elif [[ $1 = --init-complete-file ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |       args+=("$1" "$2") | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |       shift 2 | 
					
						
							|  |  |  |     elif [[ $1 = --stake ]]; then | 
					
						
							| 
									
										
										
										
											2019-06-04 14:51:52 -07:00
										 |  |  |       stake_lamports="$2" | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |       shift 2 | 
					
						
							| 
									
										
										
										
											2019-07-19 12:51:38 -06:00
										 |  |  |     elif [[ $1 = --node-lamports ]]; then | 
					
						
							|  |  |  |       node_lamports="$2" | 
					
						
							|  |  |  |       shift 2 | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |     elif [[ $1 = --no-voting ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |       args+=("$1") | 
					
						
							| 
									
										
										
										
											2019-07-17 19:26:23 -07:00
										 |  |  |       shift | 
					
						
							|  |  |  |     elif [[ $1 = --skip-ledger-verify ]]; then | 
					
						
							|  |  |  |       args+=("$1") | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |       shift | 
					
						
							|  |  |  |     elif [[ $1 = --no-sigverify ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |       args+=("$1") | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |       shift | 
					
						
							| 
									
										
										
										
											2019-07-24 17:28:08 -07:00
										 |  |  |     elif [[ $1 = --limit-ledger-size ]]; then | 
					
						
							|  |  |  |       args+=("$1") | 
					
						
							|  |  |  |       shift | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |     elif [[ $1 = --rpc-port ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |       args+=("$1" "$2") | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |       shift 2 | 
					
						
							|  |  |  |     elif [[ $1 = --dynamic-port-range ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |       args+=("$1" "$2") | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |       shift 2 | 
					
						
							|  |  |  |     elif [[ $1 = --gossip-port ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |       args+=("$1" "$2") | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |       shift 2 | 
					
						
							| 
									
										
										
										
											2019-06-10 19:42:49 -07:00
										 |  |  |     elif [[ $1 = --no-airdrop ]]; then | 
					
						
							|  |  |  |       airdrops_enabled=0 | 
					
						
							|  |  |  |       shift | 
					
						
							| 
									
										
										
										
											2019-07-22 22:20:54 -07:00
										 |  |  |     elif [[ $1 = --reset-ledger ]]; then | 
					
						
							|  |  |  |       reset_ledger=1 | 
					
						
							|  |  |  |       shift | 
					
						
							| 
									
										
										
										
											2019-07-22 22:59:02 -07:00
										 |  |  |     elif [[ $1 = --config-dir ]]; then | 
					
						
							|  |  |  |       config_dir=$2 | 
					
						
							|  |  |  |       shift 2 | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |     elif [[ $1 = -h ]]; then | 
					
						
							|  |  |  |       fullnode_usage "$@" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       echo "Unknown argument: $1" | 
					
						
							|  |  |  |       exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |     positional_args+=("$1") | 
					
						
							|  |  |  |     shift | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  |   fi | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-22 22:59:02 -07:00
										 |  |  | if [[ -n $REQUIRE_CONFIG_DIR ]]; then | 
					
						
							|  |  |  |   if [[ -z $config_dir ]]; then | 
					
						
							|  |  |  |     fullnode_usage "Error: --config-dir not specified" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SOLANA_RSYNC_CONFIG_DIR="$config_dir"/config | 
					
						
							|  |  |  |   SOLANA_CONFIG_DIR="$config_dir"/config-local | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | setup_secondary_mount | 
					
						
							| 
									
										
										
										
											2019-05-24 04:31:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  | if [[ $node_type = bootstrap_leader ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |   if [[ ${#positional_args[@]} -ne 0 ]]; then | 
					
						
							|  |  |  |     fullnode_usage "Unknown argument: ${positional_args[0]}" | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:59:22 -07:00
										 |  |  |   [[ -f "$SOLANA_CONFIG_DIR"/bootstrap-leader-keypair.json ]] || | 
					
						
							|  |  |  |     ledger_not_setup "$SOLANA_CONFIG_DIR/bootstrap-leader-keypair.json not found" | 
					
						
							| 
									
										
										
										
											2019-05-03 12:33:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   $solana_ledger_tool --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger verify | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 11:05:02 -07:00
										 |  |  |   # These four keypairs are created by ./setup.sh and encoded into the genesis | 
					
						
							|  |  |  |   # block | 
					
						
							|  |  |  |   identity_keypair_path=$SOLANA_CONFIG_DIR/bootstrap-leader-keypair.json | 
					
						
							|  |  |  |   voting_keypair_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-vote-keypair.json | 
					
						
							|  |  |  |   stake_keypair_path=$SOLANA_CONFIG_DIR/bootstrap-leader-stake-keypair.json | 
					
						
							|  |  |  |   storage_keypair_path=$SOLANA_CONFIG_DIR/bootstrap-leader-storage-keypair.json | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-03 12:33:48 -07:00
										 |  |  |   ledger_config_dir="$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |   state_dir="$SOLANA_CONFIG_DIR"/bootstrap-leader-state | 
					
						
							| 
									
										
										
										
											2019-06-06 14:51:48 -07:00
										 |  |  |   configured_flag=$SOLANA_CONFIG_DIR/bootstrap-leader.configured | 
					
						
							| 
									
										
										
										
											2019-05-15 15:19:29 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |   default_arg --rpc-port 8899 | 
					
						
							| 
									
										
										
										
											2019-06-17 18:15:22 -07:00
										 |  |  |   if ((airdrops_enabled)); then | 
					
						
							|  |  |  |     default_arg --rpc-drone-address 127.0.0.1:9900 | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |   default_arg --gossip-port 8001 | 
					
						
							| 
									
										
										
										
											2019-05-09 13:43:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-24 04:31:39 -07:00
										 |  |  | elif [[ $node_type = validator ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  |   if [[ ${#positional_args[@]} -gt 2 ]]; then | 
					
						
							| 
									
										
										
										
											2019-05-03 13:32:59 -07:00
										 |  |  |     fullnode_usage "$@" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:59:22 -07:00
										 |  |  |   read -r entrypoint entrypoint_address shift < <(find_entrypoint "${positional_args[@]}") | 
					
						
							| 
									
										
										
										
											2019-05-03 12:33:48 -07:00
										 |  |  |   shift "$shift" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  |   mkdir -p "$SOLANA_CONFIG_DIR" | 
					
						
							| 
									
										
										
										
											2019-07-26 11:05:02 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   : "${identity_keypair_path:=$SOLANA_CONFIG_DIR/validator-keypair$label.json}" | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  |   [[ -r "$identity_keypair_path" ]] || $solana_keygen new -o "$identity_keypair_path" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 11:05:02 -07:00
										 |  |  |   : "${voting_keypair_path:=$SOLANA_CONFIG_DIR/validator-vote-keypair$label.json}" | 
					
						
							|  |  |  |   [[ -r "$voting_keypair_path" ]] || $solana_keygen new -o "$voting_keypair_path" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   : "${storage_keypair_path:=$SOLANA_CONFIG_DIR/validator-storage-keypair$label.json}" | 
					
						
							|  |  |  |   [[ -r "$storage_keypair_path" ]] || $solana_keygen new -o "$storage_keypair_path" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   stake_keypair_path=$SOLANA_CONFIG_DIR/validator-stake-keypair$label.json | 
					
						
							|  |  |  |   [[ -r "$stake_keypair_path" ]] || $solana_keygen new -o "$stake_keypair_path" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-24 04:31:39 -07:00
										 |  |  |   ledger_config_dir=$SOLANA_CONFIG_DIR/validator-ledger$label | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |   state_dir="$SOLANA_CONFIG_DIR"/validator-state$label | 
					
						
							| 
									
										
										
										
											2019-06-05 21:51:44 -07:00
										 |  |  |   configured_flag=$SOLANA_CONFIG_DIR/validator$label.configured | 
					
						
							| 
									
										
										
										
											2019-05-03 12:33:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:59:22 -07:00
										 |  |  |   default_arg --entrypoint "$entrypoint_address" | 
					
						
							| 
									
										
										
										
											2019-06-17 18:15:22 -07:00
										 |  |  |   if ((airdrops_enabled)); then | 
					
						
							|  |  |  |     default_arg --rpc-drone-address "${entrypoint_address%:*}:9900" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2019-05-09 17:09:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   rsync_entrypoint_url=$(rsync_url "$entrypoint") | 
					
						
							| 
									
										
										
										
											2019-05-24 04:31:39 -07:00
										 |  |  | else | 
					
						
							|  |  |  |   echo "Error: Unknown node_type: $node_type" | 
					
						
							|  |  |  |   exit 1 | 
					
						
							| 
									
										
										
										
											2019-05-03 12:33:48 -07:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | identity_pubkey=$($solana_keygen pubkey "$identity_keypair_path") | 
					
						
							| 
									
										
										
										
											2019-07-22 16:08:21 -07:00
										 |  |  | export SOLANA_METRICS_HOST_ID="$identity_pubkey" | 
					
						
							| 
									
										
										
										
											2019-05-03 12:33:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  | accounts_config_dir="$state_dir"/accounts | 
					
						
							|  |  |  | snapshot_config_dir="$state_dir"/snapshots | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  | default_arg --identity "$identity_keypair_path" | 
					
						
							|  |  |  | default_arg --voting-keypair "$voting_keypair_path" | 
					
						
							|  |  |  | default_arg --storage-keypair "$storage_keypair_path" | 
					
						
							|  |  |  | default_arg --ledger "$ledger_config_dir" | 
					
						
							|  |  |  | default_arg --accounts "$accounts_config_dir" | 
					
						
							|  |  |  | default_arg --snapshot-path "$snapshot_config_dir" | 
					
						
							| 
									
										
										
										
											2019-05-09 13:43:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  | if [[ -n $SOLANA_CUDA ]]; then | 
					
						
							|  |  |  |   program=$solana_validator_cuda | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |   program=$solana_validator | 
					
						
							| 
									
										
										
										
											2019-05-09 13:43:39 -07:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-03 20:49:24 -07:00
										 |  |  | if [[ -z $CI ]]; then # Skip in CI | 
					
						
							|  |  |  |   # shellcheck source=scripts/tune-system.sh | 
					
						
							|  |  |  |   source "$here"/../scripts/tune-system.sh | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-09 09:35:52 -06:00
										 |  |  | new_genesis_block() { | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  |   ( | 
					
						
							|  |  |  |     set -x | 
					
						
							|  |  |  |     $rsync -r "${rsync_entrypoint_url:?}"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR" | 
					
						
							|  |  |  |   ) || ( | 
					
						
							|  |  |  |     echo "Error: failed to rsync genesis ledger" | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-14 14:22:52 -07:00
										 |  |  |   ! diff -q "$SOLANA_RSYNC_CONFIG_DIR"/ledger/genesis.bin "$ledger_config_dir"/genesis.bin >/dev/null 2>&1 | 
					
						
							| 
									
										
										
										
											2019-05-09 17:09:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 18:03:58 -07:00
										 |  |  | set -e | 
					
						
							| 
									
										
										
										
											2019-03-21 23:18:19 -07:00
										 |  |  | PS4="$(basename "$0"): " | 
					
						
							| 
									
										
										
										
											2019-06-28 14:24:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  | pid= | 
					
						
							| 
									
										
										
										
											2019-06-28 14:24:44 -07:00
										 |  |  | kill_fullnode() { | 
					
						
							| 
									
										
										
										
											2019-07-18 21:18:48 -07:00
										 |  |  |   # Note: do not echo anything from this function to ensure $pid is actually | 
					
						
							|  |  |  |   # killed when stdout/stderr are redirected | 
					
						
							|  |  |  |   set +ex | 
					
						
							| 
									
										
										
										
											2019-06-28 14:24:44 -07:00
										 |  |  |   if [[ -n $pid ]]; then | 
					
						
							|  |  |  |     declare _pid=$pid | 
					
						
							|  |  |  |     pid= | 
					
						
							|  |  |  |     kill "$_pid" || true | 
					
						
							|  |  |  |     wait "$_pid" || true | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2019-07-19 08:32:03 -07:00
										 |  |  |   exit | 
					
						
							| 
									
										
										
										
											2019-06-28 14:24:44 -07:00
										 |  |  | } | 
					
						
							|  |  |  | trap 'kill_fullnode' INT TERM ERR | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-22 22:20:54 -07:00
										 |  |  | if ((reset_ledger)); then | 
					
						
							|  |  |  |   echo "Resetting ledger..." | 
					
						
							|  |  |  |   ( | 
					
						
							|  |  |  |     set -x | 
					
						
							|  |  |  |     rm -rf "$state_dir" | 
					
						
							|  |  |  |     rm -rf "$ledger_config_dir" | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  |   if [[ -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ ]]; then | 
					
						
							|  |  |  |     cp -a "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ "$ledger_config_dir" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-21 23:18:19 -07:00
										 |  |  | while true; do | 
					
						
							| 
									
										
										
										
											2019-07-09 09:35:52 -06:00
										 |  |  |   if [[ $node_type != bootstrap_leader ]] && new_genesis_block; then | 
					
						
							| 
									
										
										
										
											2019-07-26 11:05:02 -07:00
										 |  |  |     # If the genesis block has changed remove the now stale ledger and start all | 
					
						
							|  |  |  |     # over again | 
					
						
							| 
									
										
										
										
											2019-05-09 17:09:36 -07:00
										 |  |  |     ( | 
					
						
							|  |  |  |       set -x | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |       rm -rf "$ledger_config_dir" "$state_dir" "$configured_flag" | 
					
						
							| 
									
										
										
										
											2019-05-09 17:09:36 -07:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-03-21 23:18:19 -07:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2019-03-21 15:27:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |   if [[ $node_type = bootstrap_leader && ! -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger ]]; then | 
					
						
							|  |  |  |     ledger_not_setup "$SOLANA_RSYNC_CONFIG_DIR/ledger does not exist" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |   if [[ ! -d "$ledger_config_dir" ]]; then | 
					
						
							|  |  |  |     if [[ $node_type = validator ]]; then | 
					
						
							|  |  |  |       ( | 
					
						
							|  |  |  |         cd "$SOLANA_RSYNC_CONFIG_DIR" | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |         echo "Rsyncing genesis ledger from ${rsync_entrypoint_url:?}..." | 
					
						
							|  |  |  |         SECONDS= | 
					
						
							|  |  |  |         while ! $rsync -Pr "${rsync_entrypoint_url:?}"/config/ledger .; do | 
					
						
							|  |  |  |           echo "Genesis ledger rsync failed" | 
					
						
							|  |  |  |           sleep 5 | 
					
						
							|  |  |  |         done | 
					
						
							|  |  |  |         echo "Fetched genesis ledger in $SECONDS seconds" | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |         if ((boot_from_snapshot)); then | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |           SECONDS= | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |           echo "Rsyncing state snapshot ${rsync_entrypoint_url:?}..." | 
					
						
							|  |  |  |           if ! $rsync -P "${rsync_entrypoint_url:?}"/config/state.tgz .; then | 
					
						
							|  |  |  |             echo "State snapshot rsync failed" | 
					
						
							|  |  |  |             rm -f "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz | 
					
						
							|  |  |  |             exit | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  |           fi | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |           echo "Fetched snapshot in $SECONDS seconds" | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |           SECONDS= | 
					
						
							|  |  |  |           mkdir -p "$state_dir" | 
					
						
							|  |  |  |           ( | 
					
						
							|  |  |  |             set -x | 
					
						
							|  |  |  |             tar -C "$state_dir" -zxf "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |           echo "Extracted snapshot in $SECONDS seconds" | 
					
						
							|  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  |       ) | 
					
						
							| 
									
										
										
										
											2019-06-02 14:05:32 -07:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2018-12-07 10:00:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |     ( | 
					
						
							|  |  |  |       set -x | 
					
						
							|  |  |  |       cp -a "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ "$ledger_config_dir" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |   vote_pubkey=$($solana_keygen pubkey "$voting_keypair_path") | 
					
						
							|  |  |  |   stake_pubkey=$($solana_keygen pubkey "$stake_keypair_path") | 
					
						
							|  |  |  |   storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |   if [[ $node_type = validator ]] && ((stake_lamports)); then | 
					
						
							|  |  |  |     setup_validator_accounts "${entrypoint_address%:*}" \
 | 
					
						
							|  |  |  |       "$node_lamports" \
 | 
					
						
							|  |  |  |       "$stake_lamports" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cat <<EOF | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | ======================[ $node_type configuration ]====================== | 
					
						
							|  |  |  | identity pubkey: $identity_pubkey | 
					
						
							|  |  |  | vote pubkey: $vote_pubkey | 
					
						
							| 
									
										
										
										
											2019-07-16 20:10:15 -07:00
										 |  |  | stake pubkey: $stake_pubkey | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | storage pubkey: $storage_pubkey | 
					
						
							|  |  |  | ledger: $ledger_config_dir | 
					
						
							|  |  |  | accounts: $accounts_config_dir | 
					
						
							|  |  |  | snapshots: $snapshot_config_dir | 
					
						
							|  |  |  | ======================================================================== | 
					
						
							|  |  |  | EOF | 
					
						
							| 
									
										
										
										
											2019-04-16 13:03:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:12:43 -07:00
										 |  |  |   echo "$PS4$program ${args[*]}" | 
					
						
							| 
									
										
										
										
											2019-07-01 11:54:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 10:51:18 -07:00
										 |  |  |   $program "${args[@]}" & | 
					
						
							| 
									
										
										
										
											2019-03-21 23:18:19 -07:00
										 |  |  |   pid=$! | 
					
						
							| 
									
										
										
										
											2019-06-28 14:24:44 -07:00
										 |  |  |   echo "pid: $pid" | 
					
						
							| 
									
										
										
										
											2019-03-21 23:18:19 -07:00
										 |  |  |   oom_score_adj "$pid" 1000 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-12 21:07:31 -07:00
										 |  |  |   if ((no_restart)); then | 
					
						
							|  |  |  |     wait "$pid" | 
					
						
							|  |  |  |     exit $? | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |   secs_to_next_genesis_poll=5 | 
					
						
							|  |  |  |   secs_to_next_snapshot=30 | 
					
						
							|  |  |  |   while true; do | 
					
						
							| 
									
										
										
										
											2019-07-19 08:32:03 -07:00
										 |  |  |     if [[ -z $pid ]] || ! kill -0 "$pid"; then | 
					
						
							|  |  |  |       [[ -z $pid ]] || wait "$pid" | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |       echo "############## $node_type exited, restarting ##############" | 
					
						
							|  |  |  |       break | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2019-06-02 14:05:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |     sleep 1 | 
					
						
							| 
									
										
										
										
											2019-06-02 14:05:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |     if ((generate_snapshots && --secs_to_next_snapshot == 0)); then | 
					
						
							| 
									
										
										
										
											2019-06-02 14:05:32 -07:00
										 |  |  |       ( | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |         SECONDS= | 
					
						
							|  |  |  |         new_state_dir="$SOLANA_RSYNC_CONFIG_DIR"/new_state | 
					
						
							|  |  |  |         new_state_archive="$SOLANA_RSYNC_CONFIG_DIR"/new_state.tgz | 
					
						
							|  |  |  |         ( | 
					
						
							|  |  |  |           rm -rf "$new_state_dir" "$new_state_archive" | 
					
						
							| 
									
										
										
										
											2019-06-26 23:19:55 -07:00
										 |  |  |           mkdir -p "$new_state_dir" | 
					
						
							|  |  |  |           # When saving the state, its necessary to have the snapshots be saved first | 
					
						
							|  |  |  |           # followed by the accounts folder. This would avoid conditions where incomplete | 
					
						
							|  |  |  |           # accounts gets picked while its still in the process of being updated and are | 
					
						
							|  |  |  |           # not frozen yet. | 
					
						
							|  |  |  |           cp -a "$state_dir"/snapshots "$new_state_dir" | 
					
						
							|  |  |  |           cp -a "$state_dir"/accounts "$new_state_dir" | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |           cd "$new_state_dir" | 
					
						
							| 
									
										
										
										
											2019-06-25 12:10:17 -07:00
										 |  |  |           tar zcfS "$new_state_archive" ./* | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         ln -f "$new_state_archive" "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz | 
					
						
							|  |  |  |         rm -rf "$new_state_dir" "$new_state_archive" | 
					
						
							|  |  |  |         ls -hl "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz | 
					
						
							|  |  |  |         echo "Snapshot generated in $SECONDS seconds" | 
					
						
							|  |  |  |       ) || ( | 
					
						
							|  |  |  |         echo "Error: failed to generate snapshot" | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |       secs_to_next_snapshot=60 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((poll_for_new_genesis_block && --secs_to_next_genesis_poll == 0)); then | 
					
						
							|  |  |  |       echo "Polling for new genesis block..." | 
					
						
							| 
									
										
										
										
											2019-07-09 09:35:52 -06:00
										 |  |  |       if new_genesis_block; then | 
					
						
							| 
									
										
										
										
											2019-06-28 14:24:44 -07:00
										 |  |  |         echo "############## New genesis detected, restarting $node_type ##############" | 
					
						
							|  |  |  |         break | 
					
						
							|  |  |  |       fi | 
					
						
							| 
									
										
										
										
											2019-05-03 12:33:48 -07:00
										 |  |  |       secs_to_next_genesis_poll=60 | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2019-05-03 12:33:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |   done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-28 14:24:44 -07:00
										 |  |  |   kill_fullnode | 
					
						
							| 
									
										
										
										
											2019-06-18 13:07:59 -07:00
										 |  |  |   # give the cluster time to come back up | 
					
						
							|  |  |  |   ( | 
					
						
							|  |  |  |     set -x | 
					
						
							|  |  |  |     sleep 60 | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2019-03-21 23:18:19 -07:00
										 |  |  | done |