Commit bcb316b
committed
Merge bitcoin/bitcoin#32050: test: avoid treating hash results as integers
a82829f test: simplify (w)txid checks by avoiding .calc_sha256 calls (Sebastian Falbesoner)
346a099 test: avoid unneeded hash -> uint256 -> hash roundtrips (Sebastian Falbesoner)
Pull request description:
In the functional test framework we currently have a strong tendency to treat and store identifiers that result from hash functions (e.g. (w)txids, block hashes) as integers, which seems an unnatural and confusing choice. Hashes are just pseudo-random sequences of bytes, and there is usually no need to apply integer operations on them; the only exceptions I could think of is PoW-verification of block hashes with the less-than (`<`) operator, or interpreting the byte-string as scalar in the EC-context for e.g. key derivation.
I'd hence argue that most uses of `ser_uint256`/`uint256_from_str` and txid conversions via `int(txid/blockhash, 16)` are potential code smells and should be reduced to a minimum long-term if possible. This PR is a first step into this direction, intentionally kept small with (what I think) uncontroversial changes for demonstration purposes, to check out if other contributors are interested in this. A next step could be to change the classes of primitives (CTransaction, CBlock etc.) and network messages (msg_) to store hash results as actual bytes (maybe in a class wrapping the bytes that offers conversion from/to human-readable strings [1], for easier interaction with RPC calls and debug outputs) rather than ints. But that would of course need larger, potentially more controversial changes, and its questionable if its really worth the effort.
[1] unfortunately, txids and block hashes are shown to user in reverse byte order, so e.g. a txid_bytes->txid_str conversion is not just a simple `txid_bytes.hex()`, but a `txid_bytes[::-1].hex()`
ACKs for top commit:
maflcko:
review ACK a82829f 🐘
rkrux:
Concept and utACK a82829f
ryanofsky:
Code review ACK a82829f. Nice changes, and sorry about the false bug report
Tree-SHA512: bb0465802d743a495207800f922b65f49ed0d20552f95bb0bee764944664092aad74812e29df6e01ef40bcb8f9bc6c84c7e9cbbe6f008ee1a14d94ed88e698b4File tree
5 files changed
+22
-28
lines changed- test/functional
- test_framework
5 files changed
+22
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
| 270 | + | |
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | | - | |
| 286 | + | |
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
| 309 | + | |
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
350 | | - | |
351 | 350 | | |
352 | | - | |
| 351 | + | |
353 | 352 | | |
354 | 353 | | |
355 | | - | |
356 | | - | |
| 354 | + | |
357 | 355 | | |
358 | 356 | | |
359 | 357 | | |
| |||
590 | 588 | | |
591 | 589 | | |
592 | 590 | | |
593 | | - | |
594 | | - | |
| 591 | + | |
595 | 592 | | |
596 | | - | |
| 593 | + | |
597 | 594 | | |
598 | 595 | | |
599 | 596 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | | - | |
340 | | - | |
| 339 | + | |
341 | 340 | | |
342 | 341 | | |
343 | 342 | | |
| |||
1293 | 1292 | | |
1294 | 1293 | | |
1295 | 1294 | | |
1296 | | - | |
| 1295 | + | |
1297 | 1296 | | |
1298 | 1297 | | |
1299 | 1298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
111 | 110 | | |
112 | 111 | | |
113 | 112 | | |
114 | | - | |
115 | | - | |
| 113 | + | |
| 114 | + | |
116 | 115 | | |
117 | 116 | | |
118 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
22 | | - | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
| |||
711 | 709 | | |
712 | 710 | | |
713 | 711 | | |
| 712 | + | |
714 | 713 | | |
715 | | - | |
716 | | - | |
717 | | - | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
718 | 717 | | |
719 | 718 | | |
720 | 719 | | |
721 | 720 | | |
722 | 721 | | |
723 | | - | |
| 722 | + | |
724 | 723 | | |
725 | 724 | | |
726 | 725 | | |
727 | 726 | | |
728 | 727 | | |
729 | | - | |
| 728 | + | |
730 | 729 | | |
731 | 730 | | |
732 | 731 | | |
733 | 732 | | |
734 | 733 | | |
735 | | - | |
| 734 | + | |
736 | 735 | | |
737 | 736 | | |
738 | | - | |
| 737 | + | |
739 | 738 | | |
740 | 739 | | |
741 | 740 | | |
742 | | - | |
743 | | - | |
| 741 | + | |
| 742 | + | |
744 | 743 | | |
745 | 744 | | |
746 | 745 | | |
747 | 746 | | |
748 | | - | |
| 747 | + | |
749 | 748 | | |
750 | 749 | | |
751 | 750 | | |
| |||
0 commit comments