contrib: refactor: simplify linearize scripts#24374
Conversation
…data.py The string representation of a block header hash is simply the hexlified byte-reversed double SHA256 hash of its serialization.
Switching the endianness of a hex string `str` can simply be achieved by `bytes.fromhex(str)[::-1].hex()`, i.e. we can use that and remove those helper methods.
|
Concept ACK |
|
It reminds me that we don't have any kind of test for these scripts. It might be good to have a standardized test, even if it involves manual steps. If anyone is still using these scripts at all? At the time linearize was introduced it was used to create a blockchain file for distribution through torrent. I don't think anyone has done that for a long time. But maybe it has other users. |
Currently, the functional test feature_loadblock.py uses it to generate a serialized blockchain (bootstrap.dat), which is then loaded via bitcoin/test/functional/feature_loadblock.py Lines 63 to 72 in 5a8d566 I agree though that having more detailled tests would probably be nice. |
Oh that's good to know. I had no idea. |
|
Code review ACK 254a63e |
This PR simplifies the linearization scripts
linearize-data.pyandlinearize-hashes.pyby replacing overly complicated cruft (block header hash string calculation, hex string reverse) with means of the Python3 standard library.