#!/bin/bash ROOT=$(dirname $0)/.. USER=$(whoami) . "${ROOT}/scripts/setup_bls_build_flags.sh" set -x set -eo pipefail function check_result() { find $log_folder -name leader-*.log > $log_folder/all-leaders.txt find $log_folder -name validator-*.log > $log_folder/all-validators.txt echo ====== RESULTS ====== results=$($ROOT/test/cal_tps.sh $log_folder/all-leaders.txt $log_folder/all-validators.txt) echo $results | tee -a $LOG_FILE echo $results > $log_folder/tps.log } function cleanup() { for pid in `/bin/ps -fu $USER| grep "harmony\|txgen\|soldier\|commander\|profiler\|bootnode" | grep -v "grep" | grep -v "vi" | awk '{print $2}'`; do echo 'Killed process: '$pid $DRYRUN kill -9 $pid 2> /dev/null done rm -rf ./db/harmony_* } function killnode() { local port=$1 if [ -n "port" ]; then pid=$(/bin/ps -fu $USER | grep "harmony" | grep "$port" | awk '{print $2}') echo "killing node with port: $port" $DRYRUN kill -9 $pid 2> /dev/null echo "node with port: $port is killed" fi } trap cleanup SIGINT SIGTERM function usage { local ME=$(basename $0) cat< $log_folder/bootnode.log 2>&1 | tee -a $LOG_FILE & sleep 1 BN_MA=$(grep "BN_MA" $log_folder/bootnode.log | awk -F\= ' { print $2 } ') HMY_OPT2=" -bootnodes $BN_MA" echo "bootnode launched." + " $BN_MA" HMY_OPT3=" -is_beacon" NUM_NN=0 sleep 2 # Start nodes i=0 while IFS='' read -r line || [[ -n "$line" ]]; do IFS=' ' read ip port mode shardID <<< $line if [ "$mode" == "leader" ]; then echo "launching leader ..." $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 $HMY_OPT3 -key /tmp/$ip-$port.key -is_leader 2>&1 | tee -a $LOG_FILE & fi if [ "$mode" == "validator" ]; then echo "launching validator ..." $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 $HMY_OPT3 -key /tmp/$ip-$port.key 2>&1 | tee -a $LOG_FILE & fi if [ "$mode" == "archival" ]; then echo "launching archival node ... wait" $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -account_index $i $HMY_OPT2 -key /tmp/$ip-$port.key -is_archival 2>&1 | tee -a $LOG_FILE & fi sleep 0.5 if [[ "$mode" == "newnode" && "$SYNC" == "true" ]]; then (( NUM_NN += 10 )) echo "launching new node ..." (sleep $NUM_NN; $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 $HMY_OPT3 -key /tmp/$ip-$port.key 2>&1 | tee -a $LOG_FILE ) & fi (( i++ )) done < $config # Emulate node offline if [ "$SYNC" == "false" ]; then (sleep 45; killnode $KILLPORT) & fi if [ "$TXGEN" == "true" ]; then echo "launching txgen ... wait" # sleep 2 line=$(grep client $config) IFS=' ' read ip port mode shardID <<< $line if [ "$mode" == "client" ]; then $DRYRUN $ROOT/bin/txgen -log_folder $log_folder -duration $DURATION -ip $ip -port $port $HMY_OPT2 2>&1 | tee -a $LOG_FILE fi else sleep $DURATION fi cleanup check_result