refactor: use `Hash` helpers for double-SHA256 calculations #27010

pull theStack wants to merge 1 commits into bitcoin:master from theStack:202301-refactor-use_double_sha256_helper changing 5 files +8 −23
  1. theStack commented at 6:51 PM on January 31, 2023: contributor

    We have two helper templates Hash(const T& in1) and Hash(const T& in1, const T& in2) available for calculating the double-SHA256 hash of one object or two concatenated objects, respectively:

    https://github.com/bitcoin/bitcoin/blob/b5868f4b1f884e8d6612f34ca4005fe3a992053d/src/hash.h#L74-L89

    This PR uses them in order to increase readability and simplify the code. As in #15294 (which inspired this PR, doing the same for RIPEMD160), the helper is not utilized in validation.cpp and script/interpreter.cpp to avoid touching consensus-relevant code.

  2. refactor: use `Hash` helper for double-SHA256 calculations 87f11ef47f
  3. DrahtBot commented at 6:51 PM on January 31, 2023: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK john-moffett, stickies-v, MarcoFalke

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26390 (index: Compare deserialized block hash with the block hash from the blockindex by kcalvinalvin)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. DrahtBot added the label Refactoring on Jan 31, 2023
  5. john-moffett approved
  6. john-moffett commented at 8:49 PM on January 31, 2023: contributor

    ACK 87f11ef47fea31d51bcc3f5df68f78fb28e3d8dd

    It does make it far more readable. I looked and couldn't find any other suitable places to use the helpers.

  7. stickies-v approved
  8. stickies-v commented at 9:51 PM on January 31, 2023: contributor

    ACK 87f11ef47fea31d51bcc3f5df68f78fb28e3d8dd

    Avoid duplication, easier to read, can't see behaviour change.

  9. DrahtBot cross-referenced this on Feb 1, 2023 from issue index: Compare deserialized block hash with the block hash from the blockindex by kcalvinalvin
  10. maflcko approved
  11. maflcko commented at 2:56 PM on February 1, 2023: member

    review ACK 87f11ef47fea31d51bcc3f5df68f78fb28e3d8dd 😬

    <details><summary>Show signature</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    review ACK 87f11ef47fea31d51bcc3f5df68f78fb28e3d8dd  😬
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUj9lQv9HytY6oVQ1voN8ClRAJIVVgNODDZQbZV2TzpietMli+PyOukp1S4vyXCx
    +vz3mPAwrp0mw64GxwnLyc7UoLw9CVG3b2lzbvUnAvPGYMBAY7wxbWH6HMqeyKPI
    XtKQyA8lvp5Fo++4Cn59lWtQejlMsvHHQA3jakmkPwDmDsDbptBETcfgfOqrTILC
    wCBr4R6/4ml5UZ4ziIrnxzXmzzjc58wHuCld26HcqLlkIl1P6QBkiouybXfjwlH1
    q5IWW6v0zEH01ocw6FCLyWwZyXkiGGh8DWGwUIF7WnKQ4sKifPa1o26eE3IIPY82
    +u7IjkJSdgz8tWAYeViAq5mAZGgV0+OrArkMzBhgDLsGbd+/2bhjhGjhF+EEJBto
    kZWgo7A73RTDkmRv+xaXCCD+OtmgAmc+eMH0kwQiEVtDVvlhV1Bou7PUA91VK3Va
    Nc/2iQmwrPCrDZxsSgdgXJ6sZB12fLOX1ii/r4ti5OLxNWN/L56jh6nb9V3uaWRu
    jWfVWwuU
    =mACN
    -----END PGP SIGNATURE-----
    

    </details>

  12. maflcko merged this on Feb 1, 2023
  13. maflcko closed this on Feb 1, 2023

  14. theStack deleted the branch on Feb 1, 2023
  15. sidhujag referenced this in commit 5d9550900b on Feb 1, 2023
  16. bitcoin locked this on Feb 1, 2024

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-05-20 06:53 UTC