Skip to content

Conversation

theStack
Copy link
Contributor

Making the GeneratingRandomKey helper (recently introduced in PR #28433, commit b6934fd) 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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 12, 2023

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.

@kevkevinpal
Copy link
Contributor

Code Review ACK 81187d0

@kevkevinpal
Copy link
Contributor

kevkevinpal commented Sep 12, 2023

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?

Copy link
Contributor

@stratospher stratospher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Sjors
Copy link
Member

Sjors commented Dec 22, 2023

ACK 81187d0

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.

@DrahtBot DrahtBot requested a review from stratospher December 22, 2023 10:50
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(...)`.
@theStack theStack force-pushed the 202309-refactor-use_GenerateRandomKey_helper branch from 81187d0 to fa1d495 Compare December 23, 2023 12:27
@theStack
Copy link
Contributor Author

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.

@Sjors
Copy link
Member

Sjors commented Dec 27, 2023

re-ACK fa1d495

Copy link
Member

@sipa sipa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK fa1d495

Copy link
Contributor

@kristapsk kristapsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cr utACK fa1d495

Copy link
Contributor

@stratospher stratospher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fa1d495.

@achow101
Copy link
Member

achow101 commented Jan 2, 2024

ACK fa1d495

@achow101 achow101 merged commit 2652506 into bitcoin:master Jan 2, 2024
@theStack theStack deleted the 202309-refactor-use_GenerateRandomKey_helper branch January 2, 2024 15:58
@bitcoin bitcoin locked and limited conversation to collaborators Jan 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants