This PR simplifies the linearization scripts linearize-data.py and linearize-hashes.py by replacing overly complicated cruft (block header hash string calculation, hex string reverse) with means of the Python3 standard library.
contrib: refactor: simplify linearize scripts #24374
pull theStack wants to merge 2 commits into bitcoin:master from theStack:202202-contrib-simplify_linearize_script changing 2 files +4 −49-
theStack commented at 9:57 PM on February 17, 2022: member
-
3f863cfff1
contrib: refactor: simplify block header string routine in linearize-data.py
The string representation of a block header hash is simply the hexlified byte-reversed double SHA256 hash of its serialization.
-
254a63e097
contrib: refactor: replace `hex_switchEndian` in linearize scripts
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.
- DrahtBot added the label Scripts and tools on Feb 17, 2022
-
laanwj commented at 6:04 PM on February 22, 2022: member
Concept ACK NIce cleanup!
-
laanwj commented at 1:48 PM on February 23, 2022: member
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.
-
theStack commented at 2:26 PM on February 23, 2022: member
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
-loadblock: https://github.com/bitcoin/bitcoin/blob/5a8d56680b615a3eaa4496ae636db8f65e719284/test/functional/feature_loadblock.py#L63-L72I agree though that having more detailled tests would probably be nice.
-
laanwj commented at 2:32 PM on February 23, 2022: member
Currently, the functional test feature_loadblock.py uses it to generate a serialized blockchain (bootstrap.dat), which is then loaded via -loadblock:
Oh that's good to know. I had no idea.
-
laanwj commented at 11:43 AM on March 30, 2022: member
Code review ACK 254a63e097def1bf7e157c72ea9e4fff1eeb7a28
- laanwj merged this on Mar 30, 2022
- laanwj closed this on Mar 30, 2022
- theStack deleted the branch on Mar 30, 2022
- sidhujag referenced this in commit 1f7739e4f7 on Apr 3, 2022
- DrahtBot locked this on Mar 30, 2023