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
  1. theStack commented at 9:57 PM on February 17, 2022: member

    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.

  2. 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.
    3f863cfff1
  3. 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.
    254a63e097
  4. DrahtBot added the label Scripts and tools on Feb 17, 2022
  5. laanwj commented at 6:04 PM on February 22, 2022: member

    Concept ACK NIce cleanup!

  6. 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.

  7. 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-L72

    I agree though that having more detailled tests would probably be nice.

  8. 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.

  9. laanwj commented at 11:43 AM on March 30, 2022: member

    Code review ACK 254a63e097def1bf7e157c72ea9e4fff1eeb7a28

  10. laanwj merged this on Mar 30, 2022
  11. laanwj closed this on Mar 30, 2022

  12. theStack deleted the branch on Mar 30, 2022
  13. sidhujag referenced this in commit 1f7739e4f7 on Apr 3, 2022
  14. DrahtBot locked this on Mar 30, 2023
Contributors

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 21:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me