uint256: Remove unnecessary crypto/common.h dependency #13258

pull kallewoof wants to merge 1 commits into bitcoin:master from kallewoof:uint256-no-crypto-alt changing 5 files +21 −18
  1. kallewoof commented at 5:53 am on May 17, 2018: member

    This is an alternative to #13242 which keeps the ReadLE64 part, but moves the crypto/common.h dependency into crypto/common.h as a function outside of uint256.

    Reason: this change will remove dependencies for uint256 to crypto/common.h, compat/endian.h, and compat/byteswap.h.

    This PR removes the need to update tests to be endian-aware/-independent, but keeps the (arguably dubious) ReadLE64 part (which was only introduced to fix the tests, not for any functionality).

  2. kallewoof renamed this:
    uint256: Remove unnecessary crypto/common.h use (alternative)
    uint256: Remove unnecessary crypto/common.h dependency (alternative)
    on May 17, 2018
  3. kallewoof renamed this:
    uint256: Remove unnecessary crypto/common.h dependency (alternative)
    uint256: Remove unnecessary crypto/common.h dependency
    on May 17, 2018
  4. Empact commented at 6:06 am on May 17, 2018: member

    All the GetCheapHash calls are relative to CHashWriter and BlockHasher, how about putting it higher up?

    I’m not crazy about the template approach because it’s overly general and doesn’t guarantee that there are 64 bits there to read.

  5. fanquake added the label Refactoring on May 17, 2018
  6. kallewoof commented at 6:20 am on May 17, 2018: member

    I’m not crazy about the template approach because it’s overly general and doesn’t guarantee that there are 64 bits there to read.

    Yeah, but a uint256 does not guarantee it is random, either, so you still have to use this cautiously, even before this patch.

    Putting it in CHashWriter may be a better idea, for sure. I’ll try that and see what it looks like.

  7. kallewoof force-pushed on May 17, 2018
  8. kallewoof commented at 6:37 am on May 17, 2018: member
    @Empact Changed to your suggested approach. No more template, and code looks cleaner. Only gotcha here is people may be tempted to GetHash().GetCheapHash() which will do double-double-SHA256, instead of double-SHA256. Considering the limited use, I think that gotcha is acceptable.
  9. Empact commented at 6:41 am on May 17, 2018: member
    Nice, looks much better IMO.
  10. in src/addrman.cpp:11 in a02e3e6bf8 outdated
     7@@ -8,25 +8,26 @@
     8 #include <hash.h>
     9 #include <serialize.h>
    10 #include <streams.h>
    11+#include <crypto/common.h>
    


    Empact commented at 6:41 am on May 17, 2018:
    Unnecessary include.

    kallewoof commented at 6:47 am on May 17, 2018:
    Thanks!
  11. kallewoof force-pushed on May 17, 2018
  12. Empact commented at 6:53 am on May 17, 2018: member
    utACK 015e0f7
  13. Empact commented at 6:58 am on May 17, 2018: member
    I’d close #13242 in favor of this - as this offers endianness consistency, test stability, and better code organization.
  14. kallewoof commented at 7:03 am on May 17, 2018: member
    Yeah, it got too big for the desired effect. I do want to get rid of the unnecessary endianness consistency, though, but I think rewriting those tests to be a bit more useful is a necessary middle-step.
  15. DrahtBot commented at 11:49 pm on July 22, 2018: member
  16. DrahtBot closed this on Jul 22, 2018

  17. DrahtBot reopened this on Jul 22, 2018

  18. DrahtBot commented at 6:54 pm on September 7, 2018: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #14624 (Some simple improvements to the RNG code by sipa)
    • #13462 (Simplify common case of CHashWriter and drop SerializeHash by Empact)

    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.

  19. kallewoof force-pushed on Sep 10, 2018
  20. sipa commented at 1:27 am on September 10, 2018: member
    utACK 361ecbf3e9ffe83800e845426b6cc835267c1932
  21. MarcoFalke commented at 1:54 am on September 10, 2018: member
    utACK 361ecbf3e9ffe83800e845426b6cc835267c1932
  22. in src/validation.h:145 in 361ecbf3e9 outdated
    138@@ -138,7 +139,7 @@ static const int DEFAULT_STOPATHEIGHT = 0;
    139 
    140 struct BlockHasher
    141 {
    142-    size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); }
    143+    size_t operator()(const uint256& hash) const { return ReadLE64(hash.begin()); }
    


    Empact commented at 5:42 pm on September 10, 2018:
    nit: Could benefit from a comment referencing GetCheapHash to explain the implementation.

    kallewoof commented at 6:11 am on September 11, 2018:
    Okay. Got 3 utACKs so will fix this if another rebase becomes necessary or other changes are suggested.

    MarcoFalke commented at 1:39 pm on September 11, 2018:
    Could add a commit with “doc: bla…” on top of the branch (not touching the existing commits)?

    kallewoof commented at 1:58 am on September 12, 2018:
    Good idea. Done!
  23. Empact commented at 5:42 pm on September 10, 2018: member
    re-utACK 361ecbf
  24. ken2812221 approved
  25. ken2812221 commented at 9:12 pm on September 11, 2018: contributor
    utACK 361ecbf
  26. in src/hash.h:142 in bf2718701c outdated
    138@@ -138,6 +139,18 @@ class CHashWriter
    139         return result;
    140     }
    141 
    142+    /** A cheap hash function that just returns 64 bits from the result, it can be
    


    laanwj commented at 11:51 am on September 13, 2018:
    I don’t think this comment is still appropriate. As it samples the output, which went through a hash function, this requirement about the distribution of the input of the hash writer no longer holds.

    kallewoof commented at 2:44 am on September 14, 2018:
    Good point. I also wonder about the ‘cheap’ part here, as it’s actually just taking the prefix of the real hash, but keeping for now.
  27. kallewoof force-pushed on Sep 14, 2018
  28. ken2812221 commented at 0:03 am on September 17, 2018: contributor
    re-utACK 93baaf9
  29. MarcoFalke commented at 7:34 pm on September 17, 2018: member
    re-utACK 93baaf9c3e
  30. in src/validation.h:21 in 93baaf9c3e outdated
    17@@ -18,6 +18,7 @@
    18 #include <script/script_error.h>
    19 #include <sync.h>
    20 #include <versionbits.h>
    21+#include <crypto/common.h> // for ReadLE64
    


    promag commented at 10:16 pm on September 17, 2018:
    nit, sort.

    kallewoof commented at 5:27 am on September 18, 2018:
    Damn. Fixed.
  31. promag commented at 10:23 pm on September 17, 2018: member
    utACK 93baaf9, sorry the nit :running:
  32. uint256: Remove unnecessary crypto/common.h use bf2e010973
  33. kallewoof force-pushed on Sep 18, 2018
  34. promag commented at 10:27 am on September 18, 2018: member
    utACK bf2e010.
  35. MarcoFalke commented at 6:28 pm on November 7, 2018: member
    utACK bf2e010973
  36. Empact commented at 8:33 pm on November 7, 2018: member
    re-utACK bf2e010
  37. laanwj merged this on Nov 30, 2018
  38. laanwj closed this on Nov 30, 2018

  39. laanwj referenced this in commit 011c42c5bd on Nov 30, 2018
  40. kallewoof deleted the branch on Oct 17, 2019
  41. ptschip referenced this in commit 104e5e6127 on Oct 22, 2019
  42. jonspock referenced this in commit 7114f0fa21 on Dec 27, 2019
  43. jonspock referenced this in commit 2a89c2eee7 on Dec 29, 2019
  44. Munkybooty referenced this in commit 34cb575526 on Aug 2, 2021
  45. Munkybooty referenced this in commit 26d4c048af on Aug 3, 2021
  46. Munkybooty referenced this in commit 65ee5e6c96 on Aug 5, 2021
  47. vijaydasmp referenced this in commit 0d05ddcf0e on Oct 10, 2021
  48. vijaydasmp referenced this in commit e1bd4045f8 on Oct 10, 2021
  49. vijaydasmp referenced this in commit 9f157bb4fa on Oct 12, 2021
  50. vijaydasmp referenced this in commit 291fced17d on Oct 14, 2021
  51. vijaydasmp referenced this in commit 45981b043c on Oct 14, 2021
  52. vijaydasmp referenced this in commit 07687ad475 on Oct 20, 2021
  53. vijaydasmp referenced this in commit d0724b5ee1 on Oct 21, 2021
  54. PastaPastaPasta referenced this in commit dc93063857 on Oct 21, 2021
  55. pravblockc referenced this in commit f708ff12ec on Nov 18, 2021
  56. DrahtBot locked this on Feb 15, 2022

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: 2024-11-17 12:12 UTC

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