| 
									
										
										
										
											2018-11-11 08:19:04 -08:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							|  |  |  | set -e | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | here=$(dirname "$0") | 
					
						
							|  |  |  | SOLANA_ROOT="$(cd "$here"/..; pwd)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # shellcheck source=net/common.sh | 
					
						
							|  |  |  | source "$here"/common.sh | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | usage() { | 
					
						
							|  |  |  |   exitcode=0 | 
					
						
							|  |  |  |   if [[ -n "$1" ]]; then | 
					
						
							|  |  |  |     exitcode=1 | 
					
						
							|  |  |  |     echo "Error: $*" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  |   cat <<EOF | 
					
						
							| 
									
										
										
										
											2018-09-04 15:16:25 -07:00
										 |  |  | usage: $0 [start|stop|restart|sanity] [command-specific options] | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  | Operate a configured testnet | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  |  start    - Start the network | 
					
						
							|  |  |  |  sanity   - Sanity check the network | 
					
						
							|  |  |  |  stop     - Stop the network | 
					
						
							|  |  |  |  restart  - Shortcut for stop then start | 
					
						
							| 
									
										
										
										
											2018-12-10 21:05:39 -08:00
										 |  |  |  update   - Live update all network nodes | 
					
						
							| 
									
										
										
										
											2018-12-23 08:54:24 -08:00
										 |  |  |  logs     - Fetch remote logs from each network node | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 21:05:39 -08:00
										 |  |  |  start/update-specific options: | 
					
						
							| 
									
										
										
										
											2018-11-07 13:32:48 -08:00
										 |  |  |    -T [tarFilename]            - Deploy the specified release tarball | 
					
						
							| 
									
										
										
										
											2018-11-06 15:02:55 -08:00
										 |  |  |    -t edge|beta|stable|vX.Y.Z  - Deploy the latest tarball release for the | 
					
						
							|  |  |  |                                  specified release channel (edge|beta|stable) or release tag | 
					
						
							|  |  |  |                                  (vX.Y.Z) | 
					
						
							|  |  |  |    -f [cargoFeatures]          - List of |cargo --feaures=| to activate | 
					
						
							|  |  |  |                                  (ignored if -s or -S is specified) | 
					
						
							| 
									
										
										
										
											2018-12-09 17:28:18 -08:00
										 |  |  |    -r                          - Reuse existing node/ledger configuration from a | 
					
						
							| 
									
										
										
										
											2019-02-16 10:01:27 -08:00
										 |  |  |                                  previous |start| (ie, don't run ./multinode-demo/setup.sh). | 
					
						
							| 
									
										
										
										
											2019-02-18 11:43:36 -07:00
										 |  |  |    -D /path/to/programs        - Deploy custom programs from this location | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 21:05:39 -08:00
										 |  |  |  sanity/start/update-specific options: | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  |    -o noLedgerVerify    - Skip ledger verification | 
					
						
							| 
									
										
										
										
											2018-12-05 16:40:08 -08:00
										 |  |  |    -o noValidatorSanity - Skip fullnode sanity | 
					
						
							| 
									
										
										
										
											2018-09-11 20:00:49 -07:00
										 |  |  |    -o rejectExtraNodes  - Require the exact number of nodes | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  |  stop-specific options: | 
					
						
							|  |  |  |    none | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-23 08:54:24 -08:00
										 |  |  |  logs-specific options: | 
					
						
							|  |  |  |    none | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-09 12:57:00 -07:00
										 |  |  | Note: if RUST_LOG is set in the environment it will be propogated into the | 
					
						
							|  |  |  |       network nodes. | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | EOF | 
					
						
							|  |  |  |   exit $exitcode | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-30 18:05:38 -07:00
										 |  |  | releaseChannel= | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  | deployMethod=local | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  | sanityExtraArgs= | 
					
						
							| 
									
										
										
										
											2018-09-04 23:01:07 -07:00
										 |  |  | cargoFeatures= | 
					
						
							| 
									
										
										
										
											2018-12-09 17:28:18 -08:00
										 |  |  | skipSetup=false | 
					
						
							| 
									
										
										
										
											2018-12-10 21:05:39 -08:00
										 |  |  | updateNodes=false | 
					
						
							| 
									
										
										
										
											2019-02-18 11:43:36 -07:00
										 |  |  | customPrograms= | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | command=$1 | 
					
						
							|  |  |  | [[ -n $command ]] || usage | 
					
						
							|  |  |  | shift | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-02 17:08:46 -08:00
										 |  |  | while getopts "h?T:t:o:f:r:D:" opt; do | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   case $opt in | 
					
						
							|  |  |  |   h | \?) | 
					
						
							|  |  |  |     usage | 
					
						
							|  |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2018-11-07 13:32:48 -08:00
										 |  |  |   T) | 
					
						
							|  |  |  |     tarballFilename=$OPTARG | 
					
						
							| 
									
										
										
										
											2019-03-02 17:08:46 -08:00
										 |  |  |     [[ -r $tarballFilename ]] || usage "File not readable: $tarballFilename" | 
					
						
							| 
									
										
										
										
											2018-11-07 13:32:48 -08:00
										 |  |  |     deployMethod=tar | 
					
						
							|  |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2018-10-30 18:05:38 -07:00
										 |  |  |   t) | 
					
						
							|  |  |  |     case $OPTARG in | 
					
						
							| 
									
										
										
										
											2018-11-06 15:02:55 -08:00
										 |  |  |     edge|beta|stable|v*) | 
					
						
							| 
									
										
										
										
											2018-10-30 18:05:38 -07:00
										 |  |  |       releaseChannel=$OPTARG | 
					
						
							|  |  |  |       deployMethod=tar | 
					
						
							|  |  |  |       ;; | 
					
						
							|  |  |  |     *) | 
					
						
							|  |  |  |       usage "Invalid release channel: $OPTARG" | 
					
						
							|  |  |  |       ;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2018-09-04 23:01:07 -07:00
										 |  |  |   f) | 
					
						
							|  |  |  |     cargoFeatures=$OPTARG | 
					
						
							|  |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2018-12-09 17:28:18 -08:00
										 |  |  |   r) | 
					
						
							|  |  |  |     skipSetup=true | 
					
						
							|  |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2019-02-18 11:43:36 -07:00
										 |  |  |   D) | 
					
						
							|  |  |  |     customPrograms=$OPTARG | 
					
						
							|  |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  |   o) | 
					
						
							|  |  |  |     case $OPTARG in | 
					
						
							| 
									
										
										
										
											2018-09-11 20:00:49 -07:00
										 |  |  |     noLedgerVerify|noValidatorSanity|rejectExtraNodes) | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  |       sanityExtraArgs="$sanityExtraArgs -o $OPTARG" | 
					
						
							|  |  |  |       ;; | 
					
						
							|  |  |  |     *) | 
					
						
							|  |  |  |       echo "Error: unknown option: $OPTARG" | 
					
						
							|  |  |  |       exit 1 | 
					
						
							|  |  |  |       ;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   *) | 
					
						
							|  |  |  |     usage "Error: unhandled option: $opt" | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   esac | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | loadConfigFile | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | build() { | 
					
						
							| 
									
										
										
										
											2018-08-28 20:55:13 -07:00
										 |  |  |   declare MAYBE_DOCKER= | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   if [[ $(uname) != Linux ]]; then | 
					
						
							| 
									
										
										
										
											2018-08-28 20:55:13 -07:00
										 |  |  |     MAYBE_DOCKER="ci/docker-run.sh solanalabs/rust" | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   fi | 
					
						
							|  |  |  |   SECONDS=0 | 
					
						
							|  |  |  |   ( | 
					
						
							|  |  |  |     cd "$SOLANA_ROOT" | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  |     echo "--- Build started at $(date)" | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 20:55:13 -07:00
										 |  |  |     set -x | 
					
						
							|  |  |  |     rm -rf farf | 
					
						
							| 
									
										
										
										
											2018-11-14 19:19:27 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if [[ -r target/perf-libs/env.sh ]]; then | 
					
						
							|  |  |  |       # shellcheck source=/dev/null | 
					
						
							|  |  |  |       source target/perf-libs/env.sh | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2018-11-16 08:04:46 -08:00
										 |  |  |     $MAYBE_DOCKER bash -c "
 | 
					
						
							|  |  |  |       set -ex | 
					
						
							| 
									
										
										
										
											2018-12-19 10:30:24 -08:00
										 |  |  |       scripts/cargo-install-all.sh farf \"$cargoFeatures\" | 
					
						
							| 
									
										
										
										
											2019-02-19 11:19:35 -08:00
										 |  |  |       if [[ -n \"$customPrograms\" ]]; then | 
					
						
							| 
									
										
										
										
											2019-02-18 11:43:36 -07:00
										 |  |  |         scripts/cargo-install-custom-programs.sh farf $customPrograms | 
					
						
							|  |  |  |       fi | 
					
						
							| 
									
										
										
										
											2018-11-16 08:04:46 -08:00
										 |  |  |     "
 | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   ) | 
					
						
							|  |  |  |   echo "Build took $SECONDS seconds" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 08:49:22 -07:00
										 |  |  | startCommon() { | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   declare ipAddress=$1 | 
					
						
							| 
									
										
										
										
											2018-09-04 15:16:25 -07:00
										 |  |  |   test -d "$SOLANA_ROOT" | 
					
						
							| 
									
										
										
										
											2019-01-08 23:11:31 -07:00
										 |  |  |   if $skipSetup; then | 
					
						
							|  |  |  |     ssh "${sshOptions[@]}" "$ipAddress" "
 | 
					
						
							|  |  |  |       set -x; | 
					
						
							|  |  |  |       mkdir -p ~/solana/config{,-local} | 
					
						
							|  |  |  |       rm -rf ~/config{,-local}; | 
					
						
							|  |  |  |       mv ~/solana/config{,-local} ~; | 
					
						
							|  |  |  |       rm -rf ~/solana; | 
					
						
							|  |  |  |       mkdir -p ~/solana ~/.cargo/bin; | 
					
						
							|  |  |  |       mv ~/config{,-local} ~/solana/ | 
					
						
							|  |  |  |     "
 | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     ssh "${sshOptions[@]}" "$ipAddress" "
 | 
					
						
							|  |  |  |       set -x; | 
					
						
							|  |  |  |       rm -rf ~/solana; | 
					
						
							|  |  |  |       mkdir -p ~/.cargo/bin | 
					
						
							|  |  |  |     "
 | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2018-09-04 15:16:25 -07:00
										 |  |  |   rsync -vPrc -e "ssh ${sshOptions[*]}" \
 | 
					
						
							|  |  |  |     "$SOLANA_ROOT"/{fetch-perf-libs.sh,scripts,net,multinode-demo} \
 | 
					
						
							|  |  |  |     "$ipAddress":~/solana/ | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  | startBootstrapLeader() { | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   declare ipAddress=$1 | 
					
						
							|  |  |  |   declare logFile="$2" | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  |   echo "--- Starting bootstrap leader: $ipAddress" | 
					
						
							| 
									
										
										
										
											2018-09-08 13:48:17 -07:00
										 |  |  |   echo "start log: $logFile" | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  |   # Deploy local binaries to bootstrap fullnode.  Other fullnodes and clients later fetch the | 
					
						
							| 
									
										
										
										
											2018-12-05 16:40:08 -08:00
										 |  |  |   # binaries from it | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   ( | 
					
						
							|  |  |  |     set -x | 
					
						
							| 
									
										
										
										
											2018-09-07 08:49:22 -07:00
										 |  |  |     startCommon "$ipAddress" || exit 1 | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  |     case $deployMethod in | 
					
						
							| 
									
										
										
										
											2018-10-30 18:05:38 -07:00
										 |  |  |     tar) | 
					
						
							|  |  |  |       rsync -vPrc -e "ssh ${sshOptions[*]}" "$SOLANA_ROOT"/solana-release/bin/* "$ipAddress:~/.cargo/bin/" | 
					
						
							|  |  |  |       ;; | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  |     local) | 
					
						
							| 
									
										
										
										
											2018-09-04 15:16:25 -07:00
										 |  |  |       rsync -vPrc -e "ssh ${sshOptions[*]}" "$SOLANA_ROOT"/farf/bin/* "$ipAddress:~/.cargo/bin/" | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  |       ;; | 
					
						
							|  |  |  |     *) | 
					
						
							|  |  |  |       usage "Internal error: invalid deployMethod: $deployMethod" | 
					
						
							|  |  |  |       ;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  |     ssh "${sshOptions[@]}" -n "$ipAddress" \
 | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  |       "./solana/net/remote/remote-node.sh \
 | 
					
						
							|  |  |  |          $deployMethod \
 | 
					
						
							|  |  |  |          bootstrap-leader \
 | 
					
						
							|  |  |  |          $publicNetwork \
 | 
					
						
							|  |  |  |          $entrypointIp \
 | 
					
						
							|  |  |  |          ${#fullnodeIpList[@]} \
 | 
					
						
							|  |  |  |          \"$RUST_LOG\" \
 | 
					
						
							| 
									
										
										
										
											2018-12-09 17:28:18 -08:00
										 |  |  |          $skipSetup \
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:33:32 -08:00
										 |  |  |          $leaderRotation \
 | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  |       "
 | 
					
						
							| 
									
										
										
										
											2018-09-04 15:16:25 -07:00
										 |  |  |   ) >> "$logFile" 2>&1 || { | 
					
						
							|  |  |  |     cat "$logFile" | 
					
						
							|  |  |  |     echo "^^^ +++" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 16:40:08 -08:00
										 |  |  | startNode() { | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   declare ipAddress=$1 | 
					
						
							| 
									
										
										
										
											2019-02-17 09:48:27 -08:00
										 |  |  |   declare nodeType=$2 | 
					
						
							| 
									
										
										
										
											2018-12-05 16:40:08 -08:00
										 |  |  |   declare logFile="$netLogDir/fullnode-$ipAddress.log" | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-17 09:48:27 -08:00
										 |  |  |   echo "--- Starting $nodeType: $ipAddress" | 
					
						
							| 
									
										
										
										
											2018-09-08 13:48:17 -07:00
										 |  |  |   echo "start log: $logFile" | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   ( | 
					
						
							|  |  |  |     set -x | 
					
						
							| 
									
										
										
										
											2018-09-07 08:49:22 -07:00
										 |  |  |     startCommon "$ipAddress" | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  |     ssh "${sshOptions[@]}" -n "$ipAddress" \
 | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  |       "./solana/net/remote/remote-node.sh \
 | 
					
						
							|  |  |  |          $deployMethod \
 | 
					
						
							| 
									
										
										
										
											2019-02-17 09:48:27 -08:00
										 |  |  |          $nodeType \
 | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  |          $publicNetwork \
 | 
					
						
							|  |  |  |          $entrypointIp \
 | 
					
						
							|  |  |  |          ${#fullnodeIpList[@]} \
 | 
					
						
							|  |  |  |          \"$RUST_LOG\" \
 | 
					
						
							| 
									
										
										
										
											2018-12-09 17:28:18 -08:00
										 |  |  |          $skipSetup \
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:33:32 -08:00
										 |  |  |          $leaderRotation \
 | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  |       "
 | 
					
						
							| 
									
										
										
										
											2018-09-08 13:48:17 -07:00
										 |  |  |   ) >> "$logFile" 2>&1 & | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  |   declare pid=$! | 
					
						
							| 
									
										
										
										
											2018-12-05 16:40:08 -08:00
										 |  |  |   ln -sfT "fullnode-$ipAddress.log" "$netLogDir/fullnode-$pid.log" | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  |   pids+=("$pid") | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | startClient() { | 
					
						
							|  |  |  |   declare ipAddress=$1 | 
					
						
							|  |  |  |   declare logFile="$2" | 
					
						
							| 
									
										
										
										
											2018-09-04 15:16:25 -07:00
										 |  |  |   echo "--- Starting client: $ipAddress" | 
					
						
							| 
									
										
										
										
											2018-09-08 13:48:17 -07:00
										 |  |  |   echo "start log: $logFile" | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  |   ( | 
					
						
							|  |  |  |     set -x | 
					
						
							| 
									
										
										
										
											2018-09-07 08:49:22 -07:00
										 |  |  |     startCommon "$ipAddress" | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  |     ssh "${sshOptions[@]}" -f "$ipAddress" \
 | 
					
						
							| 
									
										
										
										
											2018-11-06 13:55:01 -08:00
										 |  |  |       "./solana/net/remote/remote-client.sh $deployMethod $entrypointIp \"$RUST_LOG\"" | 
					
						
							| 
									
										
										
										
											2018-09-04 15:16:25 -07:00
										 |  |  |   ) >> "$logFile" 2>&1 || { | 
					
						
							|  |  |  |     cat "$logFile" | 
					
						
							|  |  |  |     echo "^^^ +++" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  | sanity() { | 
					
						
							| 
									
										
										
										
											2018-09-06 13:00:01 -07:00
										 |  |  |   declare ok=true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  |   echo "--- Sanity" | 
					
						
							| 
									
										
										
										
											2018-09-06 13:00:01 -07:00
										 |  |  |   $metricsWriteDatapoint "testnet-deploy net-sanity-begin=1" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  |   declare host=${fullnodeIpList[0]} | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  |   ( | 
					
						
							|  |  |  |     set -x | 
					
						
							| 
									
										
										
										
											2018-09-04 14:36:35 -07:00
										 |  |  |     # shellcheck disable=SC2029 # remote-client.sh args are expanded on client side intentionally | 
					
						
							| 
									
										
										
										
											2018-11-05 08:30:10 -08:00
										 |  |  |     ssh "${sshOptions[@]}" "$host" \
 | 
					
						
							| 
									
										
										
										
											2019-01-09 12:57:00 -07:00
										 |  |  |       "./solana/net/remote/remote-sanity.sh $sanityExtraArgs \"$RUST_LOG\"" | 
					
						
							| 
									
										
										
										
											2018-09-06 13:00:01 -07:00
										 |  |  |   ) || ok=false | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $metricsWriteDatapoint "testnet-deploy net-sanity-complete=1" | 
					
						
							|  |  |  |   $ok || exit 1 | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  | start() { | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  |   case $deployMethod in | 
					
						
							| 
									
										
										
										
											2018-10-30 18:05:38 -07:00
										 |  |  |   tar) | 
					
						
							|  |  |  |     if [[ -n $releaseChannel ]]; then | 
					
						
							|  |  |  |       rm -f "$SOLANA_ROOT"/solana-release.tar.bz2 | 
					
						
							| 
									
										
										
										
											2018-12-05 16:40:08 -08:00
										 |  |  |       ( | 
					
						
							|  |  |  |         set -x | 
					
						
							|  |  |  |         curl -o "$SOLANA_ROOT"/solana-release.tar.bz2 http://solana-release.s3.amazonaws.com/"$releaseChannel"/solana-release.tar.bz2 | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |       tarballFilename="$SOLANA_ROOT"/solana-release.tar.bz2 | 
					
						
							| 
									
										
										
										
											2018-10-30 18:05:38 -07:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2018-12-05 16:40:08 -08:00
										 |  |  |     ( | 
					
						
							|  |  |  |       set -x | 
					
						
							|  |  |  |       rm -rf "$SOLANA_ROOT"/solana-release | 
					
						
							|  |  |  |       (cd "$SOLANA_ROOT"; tar jxv) < "$tarballFilename" | 
					
						
							|  |  |  |       cat "$SOLANA_ROOT"/solana-release/version.txt | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-10-30 18:05:38 -07:00
										 |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  |   local) | 
					
						
							|  |  |  |     build | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   *) | 
					
						
							|  |  |  |     usage "Internal error: invalid deployMethod: $deployMethod" | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   esac | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   echo "Deployment started at $(date)" | 
					
						
							| 
									
										
										
										
											2018-12-10 21:05:39 -08:00
										 |  |  |   if $updateNodes; then | 
					
						
							|  |  |  |     $metricsWriteDatapoint "testnet-deploy net-update-begin=1" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     $metricsWriteDatapoint "testnet-deploy net-start-begin=1" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-17 09:48:27 -08:00
										 |  |  |   declare bootstrapLeader=true | 
					
						
							|  |  |  |   declare nodeType=fullnode | 
					
						
							| 
									
										
										
										
											2019-02-21 16:35:26 -07:00
										 |  |  |   for ipAddress in "${fullnodeIpList[@]}" - "${blockstreamerIpList[@]}"; do | 
					
						
							| 
									
										
										
										
											2019-02-17 09:48:27 -08:00
										 |  |  |     if [[ $ipAddress = - ]]; then | 
					
						
							| 
									
										
										
										
											2019-02-21 16:35:26 -07:00
										 |  |  |       nodeType=blockstreamer | 
					
						
							| 
									
										
										
										
											2019-02-17 09:48:27 -08:00
										 |  |  |       continue | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2018-12-10 21:05:39 -08:00
										 |  |  |     if $updateNodes; then | 
					
						
							|  |  |  |       stopNode "$ipAddress" | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  |     if $bootstrapLeader; then | 
					
						
							|  |  |  |       SECONDS=0 | 
					
						
							|  |  |  |       declare bootstrapNodeDeployTime= | 
					
						
							|  |  |  |       startBootstrapLeader "$ipAddress" "$netLogDir/bootstrap-leader-$ipAddress.log" | 
					
						
							|  |  |  |       bootstrapNodeDeployTime=$SECONDS | 
					
						
							|  |  |  |       $metricsWriteDatapoint "testnet-deploy net-bootnode-leader-started=1" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       bootstrapLeader=false | 
					
						
							|  |  |  |       SECONDS=0 | 
					
						
							|  |  |  |       pids=() | 
					
						
							|  |  |  |       loopCount=0 | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2019-02-17 09:48:27 -08:00
										 |  |  |       startNode "$ipAddress" $nodeType | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Stagger additional node start time. If too many nodes start simultaneously | 
					
						
							|  |  |  |       # the bootstrap node gets more rsync requests from the additional nodes than | 
					
						
							|  |  |  |       # it can handle. | 
					
						
							|  |  |  |       ((loopCount++ % 2 == 0)) && sleep 2 | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  |   done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for pid in "${pids[@]}"; do | 
					
						
							|  |  |  |     declare ok=true | 
					
						
							|  |  |  |     wait "$pid" || ok=false | 
					
						
							|  |  |  |     if ! $ok; then | 
					
						
							| 
									
										
										
										
											2018-12-05 16:40:08 -08:00
										 |  |  |       cat "$netLogDir/fullnode-$pid.log" | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  |       echo ^^^ +++ | 
					
						
							|  |  |  |       exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   done | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-06 08:04:01 -08:00
										 |  |  |   $metricsWriteDatapoint "testnet-deploy net-fullnodes-started=1" | 
					
						
							| 
									
										
										
										
											2018-12-05 16:40:08 -08:00
										 |  |  |   additionalNodeDeployTime=$SECONDS | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-08 14:28:07 -08:00
										 |  |  |   if $updateNodes; then | 
					
						
							|  |  |  |     for ipAddress in "${clientIpList[@]}"; do | 
					
						
							|  |  |  |       stopNode "$ipAddress" | 
					
						
							|  |  |  |     done | 
					
						
							| 
									
										
										
										
											2018-12-10 21:05:39 -08:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2019-01-08 14:28:07 -08:00
										 |  |  |   sanity | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  |   SECONDS=0 | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   for ipAddress in "${clientIpList[@]}"; do | 
					
						
							|  |  |  |     startClient "$ipAddress" "$netLogDir/client-$ipAddress.log" | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  |   clientDeployTime=$SECONDS | 
					
						
							| 
									
										
										
										
											2018-12-10 21:05:39 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if $updateNodes; then | 
					
						
							|  |  |  |     $metricsWriteDatapoint "testnet-deploy net-update-complete=1" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     $metricsWriteDatapoint "testnet-deploy net-start-complete=1" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 22:01:45 -08:00
										 |  |  |   declare networkVersion=unknown | 
					
						
							|  |  |  |   case $deployMethod in | 
					
						
							|  |  |  |   tar) | 
					
						
							|  |  |  |     networkVersion="$( | 
					
						
							|  |  |  |       tail -n1 "$SOLANA_ROOT"/solana-release/version.txt || echo "tar-unknown" | 
					
						
							|  |  |  |     )"
 | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   local) | 
					
						
							|  |  |  |     networkVersion="$(git rev-parse HEAD || echo local-unknown)" | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   *) | 
					
						
							|  |  |  |     usage "Internal error: invalid deployMethod: $deployMethod" | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   esac | 
					
						
							|  |  |  |   $metricsWriteDatapoint "testnet-deploy version=\"${networkVersion:0:9}\"" | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   echo | 
					
						
							| 
									
										
										
										
											2018-09-08 14:12:32 -07:00
										 |  |  |   echo "+++ Deployment Successful" | 
					
						
							| 
									
										
										
										
											2018-12-09 09:42:09 -08:00
										 |  |  |   echo "Bootstrap leader deployment took $bootstrapNodeDeployTime seconds" | 
					
						
							| 
									
										
										
										
											2019-02-21 16:35:26 -07:00
										 |  |  |   echo "Additional fullnode deployment (${#fullnodeIpList[@]} full nodes, ${#blockstreamerIpList[@]} blockstreamer nodes) took $additionalNodeDeployTime seconds" | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   echo "Client deployment (${#clientIpList[@]} instances) took $clientDeployTime seconds" | 
					
						
							| 
									
										
										
										
											2018-09-07 12:48:06 -07:00
										 |  |  |   echo "Network start logs in $netLogDir:" | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   ls -l "$netLogDir" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 08:49:22 -07:00
										 |  |  | stopNode() { | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   local ipAddress=$1 | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  |   echo "--- Stopping node: $ipAddress" | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   ( | 
					
						
							|  |  |  |     set -x | 
					
						
							| 
									
										
										
										
											2019-01-09 22:06:58 -07:00
										 |  |  |     # shellcheck disable=SC2029 # It's desired that PS4 be expanded on the client side | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |     ssh "${sshOptions[@]}" "$ipAddress" "
 | 
					
						
							| 
									
										
										
										
											2019-01-09 22:01:42 -07:00
										 |  |  |       PS4=\"$PS4\" | 
					
						
							| 
									
										
										
										
											2018-09-07 08:34:42 -07:00
										 |  |  |       set -x | 
					
						
							|  |  |  |       ! tmux list-sessions || tmux kill-session | 
					
						
							| 
									
										
										
										
											2019-01-09 11:17:34 -07:00
										 |  |  |       for pid in solana/{net-stats,oom-monitor}.pid; do | 
					
						
							|  |  |  |         pgid=\$(ps opgid= \$(cat \$pid) | tr -d '[:space:]') | 
					
						
							|  |  |  |         sudo kill -- -\$pgid | 
					
						
							|  |  |  |       done | 
					
						
							|  |  |  |       for pattern in solana- remote-; do | 
					
						
							| 
									
										
										
										
											2018-09-07 08:34:42 -07:00
										 |  |  |         pkill -9 \$pattern | 
					
						
							|  |  |  |       done | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |     "
 | 
					
						
							|  |  |  |   ) || true | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | stop() { | 
					
						
							|  |  |  |   SECONDS=0 | 
					
						
							| 
									
										
										
										
											2018-09-06 13:00:01 -07:00
										 |  |  |   $metricsWriteDatapoint "testnet-deploy net-stop-begin=1" | 
					
						
							| 
									
										
										
										
											2018-09-03 18:15:55 -10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-21 16:35:26 -07:00
										 |  |  |   for ipAddress in "${fullnodeIpList[@]}" "${blockstreamerIpList[@]}" "${clientIpList[@]}"; do | 
					
						
							| 
									
										
										
										
											2018-09-07 08:49:22 -07:00
										 |  |  |     stopNode "$ipAddress" | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 13:00:01 -07:00
										 |  |  |   $metricsWriteDatapoint "testnet-deploy net-stop-complete=1" | 
					
						
							| 
									
										
										
										
											2018-08-28 10:19:33 -07:00
										 |  |  |   echo "Stopping nodes took $SECONDS seconds" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  | case $command in | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  | restart) | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  |   stop | 
					
						
							|  |  |  |   start | 
					
						
							|  |  |  |   ;; | 
					
						
							| 
									
										
										
										
											2018-09-04 09:21:03 -07:00
										 |  |  | start) | 
					
						
							|  |  |  |   start | 
					
						
							|  |  |  |   ;; | 
					
						
							| 
									
										
										
										
											2018-12-10 21:05:39 -08:00
										 |  |  | update) | 
					
						
							|  |  |  |   $leaderRotation || { | 
					
						
							|  |  |  |     echo Warning: unable to update because leader rotation is disabled | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   skipSetup=true | 
					
						
							|  |  |  |   updateNodes=true | 
					
						
							|  |  |  |   start | 
					
						
							|  |  |  |   ;; | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  | sanity) | 
					
						
							|  |  |  |   sanity | 
					
						
							|  |  |  |   ;; | 
					
						
							|  |  |  | stop) | 
					
						
							|  |  |  |   stop | 
					
						
							|  |  |  |   ;; | 
					
						
							| 
									
										
										
										
											2018-12-23 08:54:24 -08:00
										 |  |  | logs) | 
					
						
							|  |  |  |   fetchRemoteLog() { | 
					
						
							|  |  |  |     declare ipAddress=$1 | 
					
						
							|  |  |  |     declare log=$2 | 
					
						
							|  |  |  |     echo "--- fetching $log from $ipAddress" | 
					
						
							|  |  |  |     ( | 
					
						
							|  |  |  |       set -x | 
					
						
							|  |  |  |       timeout 30s scp "${sshOptions[@]}" \
 | 
					
						
							| 
									
										
										
										
											2018-12-23 10:33:40 -08:00
										 |  |  |         "$ipAddress":solana/"$log".log "$netLogDir"/remote-"$log"-"$ipAddress".log | 
					
						
							| 
									
										
										
										
											2018-12-23 08:54:24 -08:00
										 |  |  |     ) || echo "failed to fetch log" | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   fetchRemoteLog "${fullnodeIpList[0]}" drone | 
					
						
							|  |  |  |   for ipAddress in "${fullnodeIpList[@]}"; do | 
					
						
							|  |  |  |     fetchRemoteLog "$ipAddress" fullnode | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  |   for ipAddress in "${clientIpList[@]}"; do | 
					
						
							|  |  |  |     fetchRemoteLog "$ipAddress" client | 
					
						
							|  |  |  |   done | 
					
						
							| 
									
										
										
										
											2019-02-21 16:35:26 -07:00
										 |  |  |   for ipAddress in "${blockstreamerIpList[@]}"; do | 
					
						
							| 
									
										
										
										
											2019-02-17 09:48:27 -08:00
										 |  |  |     fetchRemoteLog "$ipAddress" fullnode | 
					
						
							|  |  |  |   done | 
					
						
							| 
									
										
										
										
											2018-12-23 08:54:24 -08:00
										 |  |  |   ;; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 19:33:40 -10:00
										 |  |  | *) | 
					
						
							|  |  |  |   echo "Internal error: Unknown command: $command" | 
					
						
							|  |  |  |   exit 1 | 
					
						
							|  |  |  | esac |