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.

64 lines
1.6 KiB

  1. #! /bin/bash
  2. set -eu
  3. set -o pipefail
  4. IPV=$1
  5. ID=$2
  6. ASSERT_CASE=$3
  7. ASSERT_NODE_UP=1
  8. ASSERT_NODE_DOWN=0
  9. MAX_TRY=10
  10. ###########################################
  11. #
  12. # Wait for peer to catchup to other peers
  13. #
  14. ###########################################
  15. addr=$(test/p2p/address.sh $IPV $ID 26657)
  16. peerID=$(( $(($ID % 4)) + 1 )) # 1->2 ... 3->4 ... 4->1
  17. peer_addr=$(test/p2p/address.sh $IPV $peerID 26657)
  18. # get another peer's height
  19. h1=`curl -s $peer_addr/status | jq .result.sync_info.latest_block_height | jq fromjson`
  20. # get another peer's state
  21. root1=`curl -s $peer_addr/status | jq .result.sync_info.latest_app_hash`
  22. echo "Other peer is on height $h1 with state $root1"
  23. echo "Waiting for peer $ID to catch up"
  24. # wait for it to sync to past its previous height
  25. set +e
  26. set +o pipefail
  27. h2="0"
  28. COUNT=0
  29. while [[ "$h2" -lt "$(($h1+1))" ]]; do
  30. sleep 1
  31. h2=`curl -s $addr/status --connect-timeout 1 | jq .result.sync_info.latest_block_height | jq fromjson`
  32. COUNT=$((COUNT+1))
  33. echo "... $h2, try $COUNT"
  34. if [ "$COUNT" -ge "$MAX_TRY" ]; then
  35. if [ $ASSERT_CASE -eq $ASSERT_NODE_DOWN ]; then
  36. echo "double sign risk reduction operates normally as expected"
  37. fi
  38. if [ $ASSERT_CASE -eq $ASSERT_NODE_UP ]; then
  39. echo "double sign risk reduction fail"
  40. exit 1
  41. fi
  42. break
  43. fi
  44. done
  45. if [ $ASSERT_CASE -eq $ASSERT_NODE_UP ]; then
  46. # check the app hash
  47. root2=`curl -s $addr/status | jq .result.sync_info.latest_app_hash`
  48. if [[ "$root1" != "$root2" ]]; then
  49. echo "App hash after restart does not match. Got $root2; expected $root1"
  50. exit 1
  51. fi
  52. echo "... double sign risk reduction test passed"
  53. fi