| 1 | #!/bin/bash |
| 2 | set -u |
| 3 | |
| 4 | |
| 5 | DATADIR=./benchmark-datadir |
| 6 | SHA256CMD="$(command -v sha256sum || echo shasum)" |
| 7 | SHA256ARGS="$(command -v sha256sum >/dev/null || echo '-a 256')" |
| 8 | |
| 9 | function zcash_rpc { |
| 10 | ./src/zcash-cli -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 "$@" |
| 11 | } |
| 12 | |
| 13 | function zcash_rpc_slow { |
| 14 | # Timeout of 1 hour |
| 15 | zcash_rpc -rpcclienttimeout=3600 "$@" |
| 16 | } |
| 17 | |
| 18 | function zcash_rpc_veryslow { |
| 19 | # Timeout of 2.5 hours |
| 20 | zcash_rpc -rpcclienttimeout=9000 "$@" |
| 21 | } |
| 22 | |
| 23 | function zcash_rpc_wait_for_start { |
| 24 | zcash_rpc -rpcwait getinfo > /dev/null |
| 25 | } |
| 26 | |
| 27 | function zcashd_generate { |
| 28 | zcash_rpc generate 101 > /dev/null |
| 29 | } |
| 30 | |
| 31 | function zcashd_start { |
| 32 | rm -rf "$DATADIR" |
| 33 | mkdir -p "$DATADIR/regtest" |
| 34 | touch "$DATADIR/zcash.conf" |
| 35 | ./src/zcashd -regtest -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 -showmetrics=0 & |
| 36 | ZCASHD_PID=$! |
| 37 | zcash_rpc_wait_for_start |
| 38 | } |
| 39 | |
| 40 | function zcashd_stop { |
| 41 | zcash_rpc stop > /dev/null |
| 42 | wait $ZCASHD_PID |
| 43 | } |
| 44 | |
| 45 | function zcashd_massif_start { |
| 46 | rm -rf "$DATADIR" |
| 47 | mkdir -p "$DATADIR/regtest" |
| 48 | touch "$DATADIR/zcash.conf" |
| 49 | rm -f massif.out |
| 50 | valgrind --tool=massif --time-unit=ms --massif-out-file=massif.out ./src/zcashd -regtest -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 -showmetrics=0 & |
| 51 | ZCASHD_PID=$! |
| 52 | zcash_rpc_wait_for_start |
| 53 | } |
| 54 | |
| 55 | function zcashd_massif_stop { |
| 56 | zcash_rpc stop > /dev/null |
| 57 | wait $ZCASHD_PID |
| 58 | ms_print massif.out |
| 59 | } |
| 60 | |
| 61 | function zcashd_valgrind_start { |
| 62 | rm -rf "$DATADIR" |
| 63 | mkdir -p "$DATADIR/regtest" |
| 64 | touch "$DATADIR/zcash.conf" |
| 65 | rm -f valgrind.out |
| 66 | valgrind --leak-check=yes -v --error-limit=no --log-file="valgrind.out" ./src/zcashd -regtest -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 -showmetrics=0 & |
| 67 | ZCASHD_PID=$! |
| 68 | zcash_rpc_wait_for_start |
| 69 | } |
| 70 | |
| 71 | function zcashd_valgrind_stop { |
| 72 | zcash_rpc stop > /dev/null |
| 73 | wait $ZCASHD_PID |
| 74 | cat valgrind.out |
| 75 | } |
| 76 | |
| 77 | function extract_benchmark_data { |
| 78 | if [ -f "block-107134.tar.xz" ]; then |
| 79 | # Check the hash of the archive: |
| 80 | "$SHA256CMD" $SHA256ARGS -c <<EOF |
| 81 | 4bd5ad1149714394e8895fa536725ed5d6c32c99812b962bfa73f03b5ffad4bb block-107134.tar.xz |
| 82 | EOF |
| 83 | ARCHIVE_RESULT=$? |
| 84 | else |
| 85 | echo "block-107134.tar.xz not found." |
| 86 | ARCHIVE_RESULT=1 |
| 87 | fi |
| 88 | if [ $ARCHIVE_RESULT -ne 0 ]; then |
| 89 | zcashd_stop |
| 90 | echo |
| 91 | echo "Please generate it using qa/zcash/create_benchmark_archive.py" |
| 92 | echo "and place it in the base directory of the repository." |
| 93 | echo "Usage details are inside the Python script." |
| 94 | exit 1 |
| 95 | fi |
| 96 | xzcat block-107134.tar.xz | tar x -C "$DATADIR/regtest" |
| 97 | } |
| 98 | |
| 99 | # Precomputation |
| 100 | case "$1" in |
| 101 | *) |
| 102 | case "$2" in |
| 103 | verifyjoinsplit) |
| 104 | zcashd_start |
| 105 | RAWJOINSPLIT=$(zcash_rpc zcsamplejoinsplit) |
| 106 | zcashd_stop |
| 107 | esac |
| 108 | esac |
| 109 | |
| 110 | case "$1" in |
| 111 | time) |
| 112 | zcashd_start |
| 113 | case "$2" in |
| 114 | sleep) |
| 115 | zcash_rpc zcbenchmark sleep 10 |
| 116 | ;; |
| 117 | parameterloading) |
| 118 | zcash_rpc zcbenchmark parameterloading 10 |
| 119 | ;; |
| 120 | createjoinsplit) |
| 121 | zcash_rpc zcbenchmark createjoinsplit 10 "${@:3}" |
| 122 | ;; |
| 123 | verifyjoinsplit) |
| 124 | zcash_rpc zcbenchmark verifyjoinsplit 1000 "\"$RAWJOINSPLIT\"" |
| 125 | ;; |
| 126 | solveequihash) |
| 127 | zcash_rpc_slow zcbenchmark solveequihash 50 "${@:3}" |
| 128 | ;; |
| 129 | verifyequihash) |
| 130 | zcash_rpc zcbenchmark verifyequihash 1000 |
| 131 | ;; |
| 132 | validatelargetx) |
| 133 | zcash_rpc zcbenchmark validatelargetx 5 |
| 134 | ;; |
| 135 | trydecryptnotes) |
| 136 | zcash_rpc zcbenchmark trydecryptnotes 1000 "${@:3}" |
| 137 | ;; |
| 138 | incnotewitnesses) |
| 139 | zcash_rpc zcbenchmark incnotewitnesses 100 "${@:3}" |
| 140 | ;; |
| 141 | connectblockslow) |
| 142 | extract_benchmark_data |
| 143 | zcash_rpc zcbenchmark connectblockslow 10 |
| 144 | ;; |
| 145 | *) |
| 146 | zcashd_stop |
| 147 | echo "Bad arguments." |
| 148 | exit 1 |
| 149 | esac |
| 150 | zcashd_stop |
| 151 | ;; |
| 152 | memory) |
| 153 | zcashd_massif_start |
| 154 | case "$2" in |
| 155 | sleep) |
| 156 | zcash_rpc zcbenchmark sleep 1 |
| 157 | ;; |
| 158 | parameterloading) |
| 159 | zcash_rpc zcbenchmark parameterloading 1 |
| 160 | ;; |
| 161 | createjoinsplit) |
| 162 | zcash_rpc_slow zcbenchmark createjoinsplit 1 "${@:3}" |
| 163 | ;; |
| 164 | verifyjoinsplit) |
| 165 | zcash_rpc zcbenchmark verifyjoinsplit 1 "\"$RAWJOINSPLIT\"" |
| 166 | ;; |
| 167 | solveequihash) |
| 168 | zcash_rpc_slow zcbenchmark solveequihash 1 "${@:3}" |
| 169 | ;; |
| 170 | verifyequihash) |
| 171 | zcash_rpc zcbenchmark verifyequihash 1 |
| 172 | ;; |
| 173 | trydecryptnotes) |
| 174 | zcash_rpc zcbenchmark trydecryptnotes 1 "${@:3}" |
| 175 | ;; |
| 176 | incnotewitnesses) |
| 177 | zcash_rpc zcbenchmark incnotewitnesses 1 "${@:3}" |
| 178 | ;; |
| 179 | connectblockslow) |
| 180 | extract_benchmark_data |
| 181 | zcash_rpc zcbenchmark connectblockslow 1 |
| 182 | ;; |
| 183 | *) |
| 184 | zcashd_massif_stop |
| 185 | echo "Bad arguments." |
| 186 | exit 1 |
| 187 | esac |
| 188 | zcashd_massif_stop |
| 189 | rm -f massif.out |
| 190 | ;; |
| 191 | valgrind) |
| 192 | zcashd_valgrind_start |
| 193 | case "$2" in |
| 194 | sleep) |
| 195 | zcash_rpc zcbenchmark sleep 1 |
| 196 | ;; |
| 197 | parameterloading) |
| 198 | zcash_rpc zcbenchmark parameterloading 1 |
| 199 | ;; |
| 200 | createjoinsplit) |
| 201 | zcash_rpc_veryslow zcbenchmark createjoinsplit 1 "${@:3}" |
| 202 | ;; |
| 203 | verifyjoinsplit) |
| 204 | zcash_rpc zcbenchmark verifyjoinsplit 1 "\"$RAWJOINSPLIT\"" |
| 205 | ;; |
| 206 | solveequihash) |
| 207 | zcash_rpc_veryslow zcbenchmark solveequihash 1 "${@:3}" |
| 208 | ;; |
| 209 | verifyequihash) |
| 210 | zcash_rpc zcbenchmark verifyequihash 1 |
| 211 | ;; |
| 212 | trydecryptnotes) |
| 213 | zcash_rpc zcbenchmark trydecryptnotes 1 "${@:3}" |
| 214 | ;; |
| 215 | incnotewitnesses) |
| 216 | zcash_rpc zcbenchmark incnotewitnesses 1 "${@:3}" |
| 217 | ;; |
| 218 | connectblockslow) |
| 219 | extract_benchmark_data |
| 220 | zcash_rpc zcbenchmark connectblockslow 1 |
| 221 | ;; |
| 222 | *) |
| 223 | zcashd_valgrind_stop |
| 224 | echo "Bad arguments." |
| 225 | exit 1 |
| 226 | esac |
| 227 | zcashd_valgrind_stop |
| 228 | rm -f valgrind.out |
| 229 | ;; |
| 230 | valgrind-tests) |
| 231 | case "$2" in |
| 232 | gtest) |
| 233 | rm -f valgrind.out |
| 234 | valgrind --leak-check=yes -v --error-limit=no --log-file="valgrind.out" ./src/zcash-gtest |
| 235 | cat valgrind.out |
| 236 | rm -f valgrind.out |
| 237 | ;; |
| 238 | test_bitcoin) |
| 239 | rm -f valgrind.out |
| 240 | valgrind --leak-check=yes -v --error-limit=no --log-file="valgrind.out" ./src/test/test_bitcoin |
| 241 | cat valgrind.out |
| 242 | rm -f valgrind.out |
| 243 | ;; |
| 244 | *) |
| 245 | echo "Bad arguments." |
| 246 | exit 1 |
| 247 | esac |
| 248 | ;; |
| 249 | *) |
| 250 | echo "Bad arguments." |
| 251 | exit 1 |
| 252 | esac |
| 253 | |
| 254 | # Cleanup |
| 255 | rm -rf "$DATADIR" |