You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

  1. #! /bin/bash
  2. set -eu
  3. NUM_OF_PEERS=$1
  4. # how many attempts for each peer to catch up by height
  5. MAX_ATTEMPTS_TO_CATCH_UP=120
  6. echo "Waiting for nodes to come online"
  7. set +e
  8. for i in $(seq 1 "$NUM_OF_PEERS"); do
  9. addr=$(test/p2p/ip.sh "$i"):46657
  10. curl -s "$addr/status" > /dev/null
  11. ERR=$?
  12. while [ "$ERR" != 0 ]; do
  13. sleep 1
  14. curl -s "$addr/status" > /dev/null
  15. ERR=$?
  16. done
  17. echo "... node $i is up"
  18. done
  19. set -e
  20. # get the first peer's height
  21. addr=$(test/p2p/ip.sh 1):46657
  22. h1=$(curl -s "$addr/status" | jq .result.sync_info.latest_block_height)
  23. echo "1st peer is on height $h1"
  24. echo "Waiting until other peers reporting a height higher than the 1st one"
  25. for i in $(seq 2 "$NUM_OF_PEERS"); do
  26. attempt=1
  27. hi=0
  28. while [[ $hi -le $h1 ]] ; do
  29. addr=$(test/p2p/ip.sh "$i"):46657
  30. hi=$(curl -s "$addr/status" | jq .result.sync_info.latest_block_height)
  31. echo "... peer $i is on height $hi"
  32. ((attempt++))
  33. if [ "$attempt" -ge $MAX_ATTEMPTS_TO_CATCH_UP ] ; then
  34. echo "$attempt unsuccessful attempts were made to catch up"
  35. curl -s "$addr/dump_consensus_state" | jq .result
  36. exit 1
  37. fi
  38. sleep 1
  39. done
  40. done