github.com/Finschia/finschia-sdk@v0.48.1/contrib/localnet_liveness.sh (about) 1 #!/bin/bash 2 3 CNT=0 4 ITER=$1 5 SLEEP=$2 6 NUMBLOCKS=$3 7 NODEADDR=$4 8 9 if [ -z "$1" ]; then 10 echo "Need to input number of iterations to run..." 11 exit 1 12 fi 13 14 if [ -z "$2" ]; then 15 echo "Need to input number of seconds to sleep between iterations" 16 exit 1 17 fi 18 19 if [ -z "$3" ]; then 20 echo "Need to input block height to declare completion..." 21 exit 1 22 fi 23 24 if [ -z "$4" ]; then 25 echo "Need to input node address to poll..." 26 exit 1 27 fi 28 29 docker_containers=( $(docker ps -q -f name=simd --format='{{.Names}}') ) 30 31 while [ ${CNT} -lt $ITER ]; do 32 curr_block=$(curl -s $NODEADDR:26657/status | jq -r '.result.sync_info.latest_block_height') 33 34 if [ ! -z ${curr_block} ] ; then 35 echo "Number of Blocks: ${curr_block}" 36 fi 37 38 if [ ! -z ${curr_block} ] && [ ${curr_block} -gt ${NUMBLOCKS} ]; then 39 echo "Number of blocks reached. Success!" 40 exit 0 41 fi 42 43 # Emulate network chaos: 44 # 45 # Every 10 blocks, pick a random container and restart it. 46 if ! ((${CNT} % 10)); then 47 rand_container=${docker_containers["$[RANDOM % ${#docker_containers[@]}]"]}; 48 echo "Restarting random docker container ${rand_container}" 49 docker restart ${rand_container} &>/dev/null & 50 fi 51 let CNT=CNT+1 52 sleep $SLEEP 53 done 54 echo "Timeout reached. Failure!" 55 exit 1