]>
Commit | Line | Data |
---|---|---|
6962bb3d | 1 | #!/bin/bash |
0cfc9d65 NW |
2 | set -u |
3 | ||
6962bb3d | 4 | |
51c8c56b | 5 | DATADIR=./benchmark-datadir |
c66c731a JG |
6 | SHA256CMD="$(command -v sha256sum || echo shasum)" |
7 | SHA256ARGS="$(command -v sha256sum >/dev/null || echo '-a 256')" | |
51c8c56b | 8 | |
6962bb3d | 9 | function zcash_rpc { |
5a027a4a | 10 | ./src/zcash-cli -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 "$@" |
6962bb3d TH |
11 | } |
12 | ||
338ff457 JG |
13 | function zcash_rpc_slow { |
14 | # Timeout of 1 hour | |
4e476986 | 15 | zcash_rpc -rpcclienttimeout=3600 "$@" |
338ff457 JG |
16 | } |
17 | ||
18 | function zcash_rpc_veryslow { | |
19 | # Timeout of 2.5 hours | |
4e476986 | 20 | zcash_rpc -rpcclienttimeout=9000 "$@" |
338ff457 JG |
21 | } |
22 | ||
5a027a4a NW |
23 | function zcash_rpc_wait_for_start { |
24 | zcash_rpc -rpcwait getinfo > /dev/null | |
25 | } | |
26 | ||
f5edc37f JG |
27 | function zcashd_generate { |
28 | zcash_rpc generate 101 > /dev/null | |
29 | } | |
30 | ||
a76174b7 JG |
31 | function extract_benchmark_datadir { |
32 | if [ -f "$1.tar.xz" ]; then | |
33 | # Check the hash of the archive: | |
34 | "$SHA256CMD" $SHA256ARGS -c <<EOF | |
35 | $2 $1.tar.xz | |
36 | EOF | |
37 | ARCHIVE_RESULT=$? | |
38 | else | |
39 | echo "$1.tar.xz not found." | |
40 | ARCHIVE_RESULT=1 | |
41 | fi | |
42 | if [ $ARCHIVE_RESULT -ne 0 ]; then | |
43 | zcashd_stop | |
44 | echo | |
45 | echo "Please download it and place it in the base directory of the repository." | |
46 | exit 1 | |
47 | fi | |
48 | xzcat "$1.tar.xz" | tar x | |
49 | } | |
50 | ||
51 | function use_200k_benchmark { | |
52 | rm -rf benchmark-200k-UTXOs | |
53 | extract_benchmark_datadir benchmark-200k-UTXOs dc8ab89eaa13730da57d9ac373c1f4e818a37181c1443f61fd11327e49fbcc5e | |
54 | DATADIR="./benchmark-200k-UTXOs/node$1" | |
55 | } | |
56 | ||
6962bb3d | 57 | function zcashd_start { |
a76174b7 | 58 | case "$1" in |
99dd50c3 | 59 | sendtoaddress|loadwallet|listunspent) |
a76174b7 JG |
60 | case "$2" in |
61 | 200k-recv) | |
62 | use_200k_benchmark 0 | |
63 | ;; | |
64 | 200k-send) | |
65 | use_200k_benchmark 1 | |
66 | ;; | |
67 | *) | |
72b4f0b3 | 68 | echo "Bad arguments to zcashd_start." |
a76174b7 JG |
69 | exit 1 |
70 | esac | |
71 | ;; | |
72 | *) | |
73 | rm -rf "$DATADIR" | |
74 | mkdir -p "$DATADIR/regtest" | |
75 | touch "$DATADIR/zcash.conf" | |
76 | esac | |
dfe29d59 | 77 | ./src/zcashd -regtest -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 -showmetrics=0 & |
6962bb3d | 78 | ZCASHD_PID=$! |
5a027a4a | 79 | zcash_rpc_wait_for_start |
6962bb3d TH |
80 | } |
81 | ||
82 | function zcashd_stop { | |
83 | zcash_rpc stop > /dev/null | |
453c7474 | 84 | wait $ZCASHD_PID |
6962bb3d TH |
85 | } |
86 | ||
87 | function zcashd_massif_start { | |
a76174b7 | 88 | case "$1" in |
99dd50c3 | 89 | sendtoaddress|loadwallet|listunspent) |
a76174b7 JG |
90 | case "$2" in |
91 | 200k-recv) | |
92 | use_200k_benchmark 0 | |
93 | ;; | |
94 | 200k-send) | |
95 | use_200k_benchmark 1 | |
96 | ;; | |
97 | *) | |
72b4f0b3 | 98 | echo "Bad arguments to zcashd_massif_start." |
a76174b7 JG |
99 | exit 1 |
100 | esac | |
101 | ;; | |
102 | *) | |
103 | rm -rf "$DATADIR" | |
104 | mkdir -p "$DATADIR/regtest" | |
105 | touch "$DATADIR/zcash.conf" | |
106 | esac | |
6962bb3d | 107 | rm -f massif.out |
dfe29d59 | 108 | valgrind --tool=massif --time-unit=ms --massif-out-file=massif.out ./src/zcashd -regtest -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 -showmetrics=0 & |
6962bb3d | 109 | ZCASHD_PID=$! |
5a027a4a | 110 | zcash_rpc_wait_for_start |
6962bb3d TH |
111 | } |
112 | ||
113 | function zcashd_massif_stop { | |
114 | zcash_rpc stop > /dev/null | |
115 | wait $ZCASHD_PID | |
116 | ms_print massif.out | |
117 | } | |
118 | ||
d578de8e TH |
119 | function zcashd_valgrind_start { |
120 | rm -rf "$DATADIR" | |
c66c731a | 121 | mkdir -p "$DATADIR/regtest" |
336fa630 | 122 | touch "$DATADIR/zcash.conf" |
d578de8e | 123 | rm -f valgrind.out |
dfe29d59 | 124 | 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 & |
d578de8e | 125 | ZCASHD_PID=$! |
5a027a4a | 126 | zcash_rpc_wait_for_start |
d578de8e TH |
127 | } |
128 | ||
129 | function zcashd_valgrind_stop { | |
130 | zcash_rpc stop > /dev/null | |
131 | wait $ZCASHD_PID | |
132 | cat valgrind.out | |
133 | } | |
134 | ||
c66c731a | 135 | function extract_benchmark_data { |
08dc7889 | 136 | if [ -f "block-107134.tar.xz" ]; then |
c66c731a JG |
137 | # Check the hash of the archive: |
138 | "$SHA256CMD" $SHA256ARGS -c <<EOF | |
08dc7889 | 139 | 4bd5ad1149714394e8895fa536725ed5d6c32c99812b962bfa73f03b5ffad4bb block-107134.tar.xz |
c66c731a JG |
140 | EOF |
141 | ARCHIVE_RESULT=$? | |
142 | else | |
08dc7889 | 143 | echo "block-107134.tar.xz not found." |
c66c731a JG |
144 | ARCHIVE_RESULT=1 |
145 | fi | |
146 | if [ $ARCHIVE_RESULT -ne 0 ]; then | |
147 | zcashd_stop | |
148 | echo | |
149 | echo "Please generate it using qa/zcash/create_benchmark_archive.py" | |
150 | echo "and place it in the base directory of the repository." | |
151 | echo "Usage details are inside the Python script." | |
152 | exit 1 | |
153 | fi | |
08dc7889 | 154 | xzcat block-107134.tar.xz | tar x -C "$DATADIR/regtest" |
c66c731a JG |
155 | } |
156 | ||
147fffb7 JDL |
157 | |
158 | if [ $# -lt 2 ] | |
159 | then | |
a20b975a | 160 | echo "$0 : At least two arguments are required!" |
147fffb7 JDL |
161 | exit 1 |
162 | fi | |
163 | ||
1737627c SB |
164 | # Precomputation |
165 | case "$1" in | |
166 | *) | |
167 | case "$2" in | |
88b7f3c2 | 168 | verifyjoinsplit) |
a76174b7 | 169 | zcashd_start "${@:2}" |
1737627c SB |
170 | RAWJOINSPLIT=$(zcash_rpc zcsamplejoinsplit) |
171 | zcashd_stop | |
172 | esac | |
173 | esac | |
174 | ||
36b1269b TH |
175 | case "$1" in |
176 | time) | |
a76174b7 | 177 | zcashd_start "${@:2}" |
36b1269b TH |
178 | case "$2" in |
179 | sleep) | |
180 | zcash_rpc zcbenchmark sleep 10 | |
181 | ;; | |
182 | parameterloading) | |
183 | zcash_rpc zcbenchmark parameterloading 10 | |
184 | ;; | |
ecde950b JG |
185 | createsaplingspend) |
186 | zcash_rpc zcbenchmark createsaplingspend 10 | |
187 | ;; | |
188 | verifysaplingspend) | |
189 | zcash_rpc zcbenchmark verifysaplingspend 1000 | |
190 | ;; | |
191 | createsaplingoutput) | |
192 | zcash_rpc zcbenchmark createsaplingoutput 50 | |
193 | ;; | |
194 | verifysaplingoutput) | |
195 | zcash_rpc zcbenchmark verifysaplingoutput 1000 | |
196 | ;; | |
36b1269b | 197 | createjoinsplit) |
4082dcb1 | 198 | zcash_rpc zcbenchmark createjoinsplit 10 "${@:3}" |
36b1269b TH |
199 | ;; |
200 | verifyjoinsplit) | |
f7478de6 | 201 | zcash_rpc zcbenchmark verifyjoinsplit 1000 "\"$RAWJOINSPLIT\"" |
36b1269b TH |
202 | ;; |
203 | solveequihash) | |
338ff457 | 204 | zcash_rpc_slow zcbenchmark solveequihash 50 "${@:3}" |
36b1269b TH |
205 | ;; |
206 | verifyequihash) | |
207 | zcash_rpc zcbenchmark verifyequihash 1000 | |
208 | ;; | |
f5edc37f | 209 | validatelargetx) |
818b94f9 | 210 | zcash_rpc zcbenchmark validatelargetx 10 "${@:3}" |
f5edc37f | 211 | ;; |
0fbab55b | 212 | trydecryptnotes) |
88b7f3c2 | 213 | zcash_rpc zcbenchmark trydecryptnotes 1000 "${@:3}" |
0fbab55b | 214 | ;; |
0bb3d40f JG |
215 | incnotewitnesses) |
216 | zcash_rpc zcbenchmark incnotewitnesses 100 "${@:3}" | |
217 | ;; | |
c66c731a JG |
218 | connectblockslow) |
219 | extract_benchmark_data | |
220 | zcash_rpc zcbenchmark connectblockslow 10 | |
221 | ;; | |
a76174b7 JG |
222 | sendtoaddress) |
223 | zcash_rpc zcbenchmark sendtoaddress 10 "${@:4}" | |
224 | ;; | |
2e8aefdc AG |
225 | loadwallet) |
226 | zcash_rpc zcbenchmark loadwallet 10 | |
227 | ;; | |
99dd50c3 JG |
228 | listunspent) |
229 | zcash_rpc zcbenchmark listunspent 10 | |
230 | ;; | |
36b1269b TH |
231 | *) |
232 | zcashd_stop | |
72b4f0b3 | 233 | echo "Bad arguments to time." |
36b1269b TH |
234 | exit 1 |
235 | esac | |
236 | zcashd_stop | |
237 | ;; | |
238 | memory) | |
a76174b7 | 239 | zcashd_massif_start "${@:2}" |
36b1269b TH |
240 | case "$2" in |
241 | sleep) | |
242 | zcash_rpc zcbenchmark sleep 1 | |
243 | ;; | |
244 | parameterloading) | |
245 | zcash_rpc zcbenchmark parameterloading 1 | |
246 | ;; | |
ecde950b JG |
247 | createsaplingspend) |
248 | zcash_rpc zcbenchmark createsaplingspend 1 | |
249 | ;; | |
250 | verifysaplingspend) | |
251 | zcash_rpc zcbenchmark verifysaplingspend 1 | |
252 | ;; | |
253 | createsaplingoutput) | |
254 | zcash_rpc zcbenchmark createsaplingoutput 1 | |
255 | ;; | |
256 | verifysaplingoutput) | |
257 | zcash_rpc zcbenchmark verifysaplingoutput 1 | |
258 | ;; | |
36b1269b | 259 | createjoinsplit) |
338ff457 | 260 | zcash_rpc_slow zcbenchmark createjoinsplit 1 "${@:3}" |
36b1269b TH |
261 | ;; |
262 | verifyjoinsplit) | |
f7478de6 | 263 | zcash_rpc zcbenchmark verifyjoinsplit 1 "\"$RAWJOINSPLIT\"" |
36b1269b TH |
264 | ;; |
265 | solveequihash) | |
338ff457 | 266 | zcash_rpc_slow zcbenchmark solveequihash 1 "${@:3}" |
36b1269b TH |
267 | ;; |
268 | verifyequihash) | |
269 | zcash_rpc zcbenchmark verifyequihash 1 | |
270 | ;; | |
94790c5d JG |
271 | validatelargetx) |
272 | zcash_rpc zcbenchmark validatelargetx 1 | |
273 | ;; | |
0fbab55b | 274 | trydecryptnotes) |
88b7f3c2 | 275 | zcash_rpc zcbenchmark trydecryptnotes 1 "${@:3}" |
0fbab55b | 276 | ;; |
0bb3d40f JG |
277 | incnotewitnesses) |
278 | zcash_rpc zcbenchmark incnotewitnesses 1 "${@:3}" | |
279 | ;; | |
c66c731a JG |
280 | connectblockslow) |
281 | extract_benchmark_data | |
282 | zcash_rpc zcbenchmark connectblockslow 1 | |
283 | ;; | |
a76174b7 JG |
284 | sendtoaddress) |
285 | zcash_rpc zcbenchmark sendtoaddress 1 "${@:4}" | |
286 | ;; | |
091c089d JG |
287 | loadwallet) |
288 | # The initial load is sufficient for measurement | |
289 | ;; | |
99dd50c3 JG |
290 | listunspent) |
291 | zcash_rpc zcbenchmark listunspent 1 | |
292 | ;; | |
36b1269b TH |
293 | *) |
294 | zcashd_massif_stop | |
72b4f0b3 | 295 | echo "Bad arguments to memory." |
36b1269b TH |
296 | exit 1 |
297 | esac | |
298 | zcashd_massif_stop | |
299 | rm -f massif.out | |
300 | ;; | |
d578de8e | 301 | valgrind) |
9c45b501 | 302 | zcashd_valgrind_start |
d578de8e TH |
303 | case "$2" in |
304 | sleep) | |
305 | zcash_rpc zcbenchmark sleep 1 | |
306 | ;; | |
307 | parameterloading) | |
308 | zcash_rpc zcbenchmark parameterloading 1 | |
309 | ;; | |
ecde950b JG |
310 | createsaplingspend) |
311 | zcash_rpc zcbenchmark createsaplingspend 1 | |
312 | ;; | |
313 | verifysaplingspend) | |
314 | zcash_rpc zcbenchmark verifysaplingspend 1 | |
315 | ;; | |
316 | createsaplingoutput) | |
317 | zcash_rpc zcbenchmark createsaplingoutput 1 | |
318 | ;; | |
319 | verifysaplingoutput) | |
320 | zcash_rpc zcbenchmark verifysaplingoutput 1 | |
321 | ;; | |
d578de8e | 322 | createjoinsplit) |
338ff457 | 323 | zcash_rpc_veryslow zcbenchmark createjoinsplit 1 "${@:3}" |
d578de8e TH |
324 | ;; |
325 | verifyjoinsplit) | |
f7478de6 | 326 | zcash_rpc zcbenchmark verifyjoinsplit 1 "\"$RAWJOINSPLIT\"" |
d578de8e TH |
327 | ;; |
328 | solveequihash) | |
338ff457 | 329 | zcash_rpc_veryslow zcbenchmark solveequihash 1 "${@:3}" |
d578de8e TH |
330 | ;; |
331 | verifyequihash) | |
332 | zcash_rpc zcbenchmark verifyequihash 1 | |
333 | ;; | |
0fbab55b | 334 | trydecryptnotes) |
88b7f3c2 | 335 | zcash_rpc zcbenchmark trydecryptnotes 1 "${@:3}" |
0fbab55b | 336 | ;; |
0bb3d40f JG |
337 | incnotewitnesses) |
338 | zcash_rpc zcbenchmark incnotewitnesses 1 "${@:3}" | |
339 | ;; | |
c66c731a JG |
340 | connectblockslow) |
341 | extract_benchmark_data | |
342 | zcash_rpc zcbenchmark connectblockslow 1 | |
343 | ;; | |
d578de8e TH |
344 | *) |
345 | zcashd_valgrind_stop | |
72b4f0b3 | 346 | echo "Bad arguments to valgrind." |
d578de8e TH |
347 | exit 1 |
348 | esac | |
349 | zcashd_valgrind_stop | |
350 | rm -f valgrind.out | |
351 | ;; | |
88325d8a TH |
352 | valgrind-tests) |
353 | case "$2" in | |
354 | gtest) | |
355 | rm -f valgrind.out | |
356 | valgrind --leak-check=yes -v --error-limit=no --log-file="valgrind.out" ./src/zcash-gtest | |
357 | cat valgrind.out | |
358 | rm -f valgrind.out | |
359 | ;; | |
360 | test_bitcoin) | |
361 | rm -f valgrind.out | |
362 | valgrind --leak-check=yes -v --error-limit=no --log-file="valgrind.out" ./src/test/test_bitcoin | |
363 | cat valgrind.out | |
364 | rm -f valgrind.out | |
365 | ;; | |
366 | *) | |
72b4f0b3 | 367 | echo "Bad arguments to valgrind-tests." |
88325d8a TH |
368 | exit 1 |
369 | esac | |
370 | ;; | |
36b1269b | 371 | *) |
72b4f0b3 | 372 | echo "Invalid benchmark type." |
36b1269b TH |
373 | exit 1 |
374 | esac | |
a0be8e26 | 375 | |
51c8c56b | 376 | # Cleanup |
51c8c56b | 377 | rm -rf "$DATADIR" |