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.

148 lines
3.8 KiB

  1. #!/usr/bin/env bash
  2. # Requires: killall command and jq JSON processor.
  3. # Get the parent directory of where this script is.
  4. SOURCE="${BASH_SOURCE[0]}"
  5. while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
  6. DIR="$( cd -P "$( dirname "$SOURCE" )/../.." && pwd )"
  7. # Change into that dir because we expect that.
  8. cd "$DIR" || exit 1
  9. # Make sure we have a tendermint command.
  10. if ! hash tendermint 2>/dev/null; then
  11. make install
  12. fi
  13. # Make sure we have a cutWALUntil binary.
  14. cutWALUntil=./scripts/cutWALUntil/cutWALUntil
  15. cutWALUntilDir=$(dirname $cutWALUntil)
  16. if ! hash $cutWALUntil 2>/dev/null; then
  17. cd "$cutWALUntilDir" && go build && cd - || exit 1
  18. fi
  19. TMHOME=$(mktemp -d)
  20. export TMHOME="$TMHOME"
  21. if [[ ! -d "$TMHOME" ]]; then
  22. echo "Could not create temp directory"
  23. exit 1
  24. else
  25. echo "TMHOME: ${TMHOME}"
  26. fi
  27. # TODO: eventually we should replace with `tendermint init --test`
  28. DIR_TO_COPY=$HOME/.tendermint_test/consensus_state_test
  29. if [ ! -d "$DIR_TO_COPY" ]; then
  30. echo "$DIR_TO_COPY does not exist. Please run: go test ./consensus"
  31. exit 1
  32. fi
  33. echo "==> Copying ${DIR_TO_COPY} to ${TMHOME} directory..."
  34. cp -r "$DIR_TO_COPY"/* "$TMHOME"
  35. # preserve original genesis file because later it will be modified (see small_block2)
  36. cp "$TMHOME/genesis.json" "$TMHOME/genesis.json.bak"
  37. function reset(){
  38. echo "==> Resetting tendermint..."
  39. tendermint unsafe_reset_all
  40. cp "$TMHOME/genesis.json.bak" "$TMHOME/genesis.json"
  41. }
  42. reset
  43. # function empty_block(){
  44. # echo "==> Starting tendermint..."
  45. # tendermint node --proxy_app=persistent_dummy &> /dev/null &
  46. # sleep 5
  47. # echo "==> Killing tendermint..."
  48. # killall tendermint
  49. # echo "==> Copying WAL log..."
  50. # $cutWALUntil "$TMHOME/data/cs.wal/wal" 1 consensus/test_data/new_empty_block.cswal
  51. # mv consensus/test_data/new_empty_block.cswal consensus/test_data/empty_block.cswal
  52. # reset
  53. # }
  54. function many_blocks(){
  55. bash scripts/txs/random.sh 1000 36657 &> /dev/null &
  56. PID=$!
  57. echo "==> Starting tendermint..."
  58. tendermint node --proxy_app=persistent_dummy &> /dev/null &
  59. sleep 10
  60. echo "==> Killing tendermint..."
  61. kill -9 $PID
  62. killall tendermint
  63. echo "==> Copying WAL log..."
  64. $cutWALUntil "$TMHOME/data/cs.wal/wal" 6 consensus/test_data/new_many_blocks.cswal
  65. mv consensus/test_data/new_many_blocks.cswal consensus/test_data/many_blocks.cswal
  66. reset
  67. }
  68. # function small_block1(){
  69. # bash scripts/txs/random.sh 1000 36657 &> /dev/null &
  70. # PID=$!
  71. # echo "==> Starting tendermint..."
  72. # tendermint node --proxy_app=persistent_dummy &> /dev/null &
  73. # sleep 10
  74. # echo "==> Killing tendermint..."
  75. # kill -9 $PID
  76. # killall tendermint
  77. # echo "==> Copying WAL log..."
  78. # $cutWALUntil "$TMHOME/data/cs.wal/wal" 1 consensus/test_data/new_small_block1.cswal
  79. # mv consensus/test_data/new_small_block1.cswal consensus/test_data/small_block1.cswal
  80. # reset
  81. # }
  82. # # block part size = 512
  83. # function small_block2(){
  84. # cat "$TMHOME/genesis.json" | jq '. + {consensus_params: {block_size_params: {max_bytes: 22020096}, block_gossip_params: {block_part_size_bytes: 512}}}' > "$TMHOME/new_genesis.json"
  85. # mv "$TMHOME/new_genesis.json" "$TMHOME/genesis.json"
  86. # bash scripts/txs/random.sh 1000 36657 &> /dev/null &
  87. # PID=$!
  88. # echo "==> Starting tendermint..."
  89. # tendermint node --proxy_app=persistent_dummy &> /dev/null &
  90. # sleep 5
  91. # echo "==> Killing tendermint..."
  92. # kill -9 $PID
  93. # killall tendermint
  94. # echo "==> Copying WAL log..."
  95. # $cutWALUntil "$TMHOME/data/cs.wal/wal" 1 consensus/test_data/new_small_block2.cswal
  96. # mv consensus/test_data/new_small_block2.cswal consensus/test_data/small_block2.cswal
  97. # reset
  98. # }
  99. case "$1" in
  100. # "small_block1")
  101. # small_block1
  102. # ;;
  103. # "small_block2")
  104. # small_block2
  105. # ;;
  106. # "empty_block")
  107. # empty_block
  108. # ;;
  109. "many_blocks")
  110. many_blocks
  111. ;;
  112. *)
  113. # small_block1
  114. # small_block2
  115. # empty_block
  116. many_blocks
  117. esac
  118. echo "==> Cleaning up..."
  119. rm -rf "$TMHOME"