refactor: share and use GenerateRandomKey helper #28455

pull theStack wants to merge 1 commits into bitcoin:master from theStack:202309-refactor-use_GenerateRandomKey_helper changing 16 files +63 −100
  1. theStack commented at 1:51 am on September 12, 2023: contributor

    Making the GeneratingRandomKey helper (recently introduced in PR #28433, commit b6934fd03f080d437acb1fd2b665503c3d6de785) available to other modules via key.{h.cpp} allows us to create random private keys directly at CKey instantiation, in contrast to the currently needed two-step process of creating an (invalid) CKey instance first and then having to call MakeNewKey(...).

    This is mostly used in unit tests and a few instances in the wallet.

  2. DrahtBot commented at 1:51 am on September 12, 2023: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK Sjors, sipa, kristapsk, stratospher, achow101
    Stale ACK kevkevinpal

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #28710 (Remove the legacy wallet and BDB dependency by achow101)
    • #28574 (wallet: optimize migration process, batch db transactions by furszy)

    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.

  3. DrahtBot added the label Refactoring on Sep 12, 2023
  4. kevkevinpal commented at 3:01 am on September 12, 2023: contributor
    Code Review ACK 81187d0
  5. kevkevinpal commented at 3:12 am on September 12, 2023: contributor

    I see MakeNewKey being used in

    ./src/test/multisig_tests.cpp ./src/test/descriptor_tests.cpp ./src/test/script_p2sh_tests.cpp ./src/test/script_standard_tests.cpp ./src/wallet/test/scriptpubkeyman_tests.cpp ./src/wallet/test/ismine_tests.cpp ./src/wallet/test/wallet_tests.cpp ./src/wallet/scriptpubkeyman.cpp

    I found these by doing grep -nri "MakeNewKey" ./src --binary-files=without-match do we plan on making this modification to these files aswell?

  6. fanquake requested review from sipa on Sep 12, 2023
  7. in src/net.cpp:941 in 81187d04c2 outdated
    978@@ -979,13 +979,6 @@ class V2MessageMap
    979 
    980 const V2MessageMap V2_MESSAGE_MAP;
    981 
    982-CKey GenerateRandomKey() noexcept
    


    stratospher commented at 2:52 pm on December 21, 2023:
    81187d0: we’d need to #include <key.h> since we’re still using GenerateRandomKey() in src/net.cpp

    Sjors commented at 10:50 am on December 22, 2023:
    Indeed directly including key.h makes sense.

    theStack commented at 12:28 pm on December 23, 2023:
    Good catch, done.
  8. stratospher commented at 3:18 pm on December 21, 2023: contributor

    Concept ACK. I think this is a useful refactor to have since it’s more modular to have GenerateRandomKey in key.cpp rather than net code.

    I found these by doing grep -nri “MakeNewKey” ./src –binary-files=without-match do we plan on making this modification to these files aswell? @kevkevinpal, it makes sense to do this refactor when we’re instantiating a CKey object and also filling the value together in the same line. we can’t do this in arrays for example, where the instantiation is done prior to filling values. we can do this refactor in:

    1. script_standard_Solver_failure test
    2. script_standard_ExtractDestination test
  9. Sjors commented at 10:50 am on December 22, 2023: member

    ACK 81187d04c2925bbd1281fe3cbdc2a30c2a02cca5

    The Stratum v2 Template Provider in #28983 also uses the CKey static_key; static_key.MakeNewKey(true); pattern, so would (slightly) benefit from this change.

    do we plan on making this modification to these files aswell?

    I can re-review if more tests are modified to use this new helper, but I’m also fine with leaving as is. New code can use it.

  10. DrahtBot requested review from stratospher on Dec 22, 2023
  11. refactor: share and use `GenerateRandomKey` helper
    Making the `GenerateRandomKey` helper available to other modules via
    key.{h.cpp} allows us to create random private keys directly at
    instantiation of CKey, in contrast to the two-step process of creating
    the instance and then having to call `MakeNewKey(...)`.
    fa1d49542e
  12. theStack force-pushed on Dec 23, 2023
  13. theStack commented at 12:33 pm on December 23, 2023: contributor
    Thanks for the reviews! I’ve tackled the missing header include and the two more instances where the refactoring can be done (script_standard_Solver_failure and script_standard_ExtractDestination). Can be easily re-reviewed via $ git range-diff 81187d0...fa1d495.
  14. Sjors commented at 8:41 am on December 27, 2023: member
    re-ACK fa1d49542e4b69a5d8b1177ffe4207f051a468bb
  15. sipa commented at 4:43 pm on December 27, 2023: member
    utACK fa1d49542e4b69a5d8b1177ffe4207f051a468bb
  16. kristapsk approved
  17. kristapsk commented at 4:53 pm on December 27, 2023: contributor
    cr utACK fa1d49542e4b69a5d8b1177ffe4207f051a468bb
  18. stratospher commented at 5:00 pm on December 27, 2023: contributor
    ACK fa1d495.
  19. achow101 commented at 3:47 pm on January 2, 2024: member
    ACK fa1d49542e4b69a5d8b1177ffe4207f051a468bb
  20. achow101 merged this on Jan 2, 2024
  21. achow101 closed this on Jan 2, 2024

  22. theStack deleted the branch on Jan 2, 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: 2024-09-28 22:12 UTC

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