-
Notifications
You must be signed in to change notification settings - Fork 36.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split some CWallet functions into new LegacyScriptPubKeyMan #17260
Conversation
e30f0a2
to
194227b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
71588b2
to
3583a11
Compare
Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior.
This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior.
3583a11
to
1c49a20
Compare
1c49a20
to
f201ba5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK f201ba5.
You could add a seperate commit that moves isminetype IsMine(const CWallet& keystore, const CTxDestination& dest)
from IsMine.cpp
to wallet.cpp
, because that exception to the move from IsMine
to scriptpubkeyman
is a bit hard to spot now.
} | ||
return ret; | ||
} | ||
std::vector<CKeyID> GetAffectedKeys(const CScript& spk, const SigningProvider& provider); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird to have a definition in a cpp file. On a local branch I was able to move this to scriptpubkeyman.h
in the second commit, courtesy of circular includes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "MOVEONLY: Move key handling code out of wallet to keyman file" (6702048):
re: #17260 (comment)
It's a bit weird to have a definition in a cpp file. On a local branch I was able to move this to
scriptpubkeyman.h
in the second commit, courtesy of circular includes.
There's a later commit that moves this declaration at the same time as moving the call: 8e743b9, so no need to necessarily move it here, even though it is a reasonable suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing!
} | ||
return ret; | ||
} | ||
std::vector<CKeyID> GetAffectedKeys(const CScript& spk, const SigningProvider& provider); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "MOVEONLY: Move key handling code out of wallet to keyman file" (6702048):
re: #17260 (comment)
It's a bit weird to have a definition in a cpp file. On a local branch I was able to move this to
scriptpubkeyman.h
in the second commit, courtesy of circular includes.
There's a later commit that moves this declaration at the same time as moving the call: 8e743b9, so no need to necessarily move it here, even though it is a reasonable suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK f201ba5.
@@ -138,6 +138,11 @@ UniValue importprivkey(const JSONRPCRequest& request) | |||
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled"); | |||
} | |||
|
|||
LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan(); | |||
if (!spk_man) { | |||
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, could add some helper to do this repeated check (currently 9 times), like GetLegacyScriptPubKeyMan(pwallet)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #17260 (comment)
nit, could add some helper to do this repeated check (currently 9 times), like
GetLegacyScriptPubKeyMan(pwallet)
?
Would be a nice followup. My preference would be to do it in a later PR though to avoid delay on this one, since this PR is pretty big and already has some acks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed for follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK f201ba5
@@ -138,6 +138,11 @@ UniValue importprivkey(const JSONRPCRequest& request) | |||
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled"); | |||
} | |||
|
|||
LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan(); | |||
if (!spk_man) { | |||
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #17260 (comment)
nit, could add some helper to do this repeated check (currently 9 times), like
GetLegacyScriptPubKeyMan(pwallet)
?
Would be a nice followup. My preference would be to do it in a later PR though to avoid delay on this one, since this PR is pretty big and already has some acks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just some questions about segmentation faults, which shouldn't be an issue because the pointers are never null in the current code.
ACK f201ba5
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
ACK f201ba59ffd2e071a36a688b80d2cff9a9c44bb2
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUiAFQv/e/bCI5hF3Iym4me/xYc/3wwA7zmN883yoQkIBieu5fM4Z5M0g4izzGGJ
5saGqdCaiJZ05YeTNKXqC14byvKn1XhGqnrcBadNMiRgoa+LC8zbZU7ZezsI/gJ/
1g722me3tqkoihSLo5znpSLEtlnbhdO/Hx3pC7P5vtPHqupnmL3DPe47NscWm+Gl
+UqjZXX2R1MhT3cLQdOGLaK6G1CcZ/n0DYiJrsk1aCvstiAzmixdTNTaG6Kxp7oQ
JlcMD+4FSWnwF4d3bjr+KjUl5n8lqPykUgjnp8bD1UaBXsMG+kQITujiEopRWWHN
lJfitkIrEuKdAMQlB9ESFG2zaAX2Ucfi2uDkAhfJDREjEB0VIfJrOTwRQMQB33hL
3mYqN9e7FQ+m7nJrX4J3K7NXHOKZqwH5NF9jG38X2/E5MHhMtH+GMR2ENqyVYJHa
P3R7sRGbiV3FtkL8UhvMQMM6OuZ9cQCqw16w5lEWI5djpzlSt3TYqedd3Lhfymuk
CFjCzOsY
=wJ5M
-----END PGP SIGNATURE-----
Timestamp of file with hash dc73b9d8ac5a486833fc09ba84ab60c9eb65828df3f5ec1320ebd5ff54f522da -
src/wallet/scriptpubkeyman.cpp
Outdated
{ | ||
AssertLockHeld(cs_wallet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this removed?
// It provides access to things that are part of the entire wallet and not specific to a ScriptPubKeyMan such as | ||
// wallet flags, wallet version, encryption keys, encryption status, and the database itself. This allows a | ||
// ScriptPubKeyMan to have callbacks into CWallet without causing a circular dependency. | ||
// WalletStorage should be the same for all ScriptPubKeyMans. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in commit f201ba5:
Could clarify that this is "for all ScriptPubKeyMans of a wallet" and not ("for all ScriptPubKeyMans of all wallets")
void CWallet::UpgradeKeyMetadata() | ||
{ | ||
AssertLockHeld(m_spk_man->cs_wallet); | ||
if (m_spk_man) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this supposed to work? The pointer was already dereferenced in the line above
@@ -554,11 +562,11 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) | |||
Unlock(strWalletPassphrase); | |||
|
|||
// if we are using HD, replace the HD seed with a new one | |||
if (IsHDEnabled()) { | |||
SetHDSeed(GenerateNewSeed()); | |||
if (m_spk_man->IsHDEnabled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is a nullptr check required above but not here?
if (!ProduceSignature(*this, MutableTransactionSignatureCreator(&txNew, nIn, coin.txout.nValue, SIGHASH_ALL), scriptPubKey, sigdata)) | ||
const SigningProvider* provider = GetSigningProvider(); | ||
if (!provider) { | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not setting the error string?
…yMan f201ba5 Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes (Andrew Chow) 6702048 MOVEONLY: Move key handling code out of wallet to keyman file (Andrew Chow) ab053ec Move wallet enums to walletutil.h (Andrew Chow) Pull request description: Moves key management functions into a new class LegacyScriptPubKeyMan. First two commits are move-only commits which move stuff out of wallet.{h/cpp} and into newly created scriptpubkeyman.{h/cpp}. Third commit changes several things in CWallet to use LegacyScriptPubKeyMan. First step in the wallet boxes refactor. Note that LegacyScriptPubKeyMan and ScriptPubKeyMan cannot be used standalone yet and are still very much tied into CWallet with both accessing functions within each other. This PR is to help reduce review burden. ACKs for top commit: Sjors: Code review ACK f201ba5. promag: Code review ACK f201ba5. ryanofsky: Code review ACK f201ba5 MarcoFalke: ACK f201ba5 Tree-SHA512: bdc0d8595a06233fe003afcf968a38e0e8cc584a6a89c5bcd05309ac29dca852391802d46763ef81a108d146d0f40c79ea5438e87234ed12b4b8360c9aec94c0
Suggested by João Barbosa <joao.paulo.barbosa@gmail.com> bitcoin#17260 (comment)
Suggestion from MarcoFalke <falke.marco@gmail.com> bitcoin#17260 (comment)
Suggested by MarcoFalke <falke.marco@gmail.com> bitcoin#17260 (comment)
Suggestion from MarcoFalke <falke.marco@gmail.com> bitcoin#17260 (comment)
Suggested by MarcoFalke <falke.marco@gmail.com> bitcoin#17260 (comment)
Suggested by MarcoFalke <falke.marco@gmail.com> bitcoin#17260 (comment) The same check was also added in the followup commit "Refactor: Move SetupGeneration code out of CWallet" 9727a4d from bitcoin#17261, but it's safer to start checking now without waiting for that followup.
53fe0b7 Fix missing strFailReason in CreateTransaction (Russell Yanofsky) 4b28a05 Fix misplaced AssertLockHeld (Russell Yanofsky) 2632b1f doc: Clarify WalletStorage / Wallet relation (Russell Yanofsky) 628d11b Add back mistakenly removed AssertLockHeld (Russell Yanofsky) 52cf68f Refactor: Add GetLegacyScriptPubKeyMan helper (Russell Yanofsky) Pull request description: This PR implements suggested code cleanups from #17260 review comments ACKs for top commit: Sjors: ACK 53fe0b7 achow101: ACK 53fe0b7 MarcoFalke: ACK 53fe0b7 Tree-SHA512: a577b96cb21a9aa7185d7d900e4db0665c302adcd12097957b9d8e838a8548c7de8f901bcb83e7c46d231b841221345c9264f5e29ed069f3d9236896430f959b
53fe0b7 Fix missing strFailReason in CreateTransaction (Russell Yanofsky) 4b28a05 Fix misplaced AssertLockHeld (Russell Yanofsky) 2632b1f doc: Clarify WalletStorage / Wallet relation (Russell Yanofsky) 628d11b Add back mistakenly removed AssertLockHeld (Russell Yanofsky) 52cf68f Refactor: Add GetLegacyScriptPubKeyMan helper (Russell Yanofsky) Pull request description: This PR implements suggested code cleanups from bitcoin#17260 review comments ACKs for top commit: Sjors: ACK 53fe0b7 achow101: ACK 53fe0b7 MarcoFalke: ACK 53fe0b7 Tree-SHA512: a577b96cb21a9aa7185d7d900e4db0665c302adcd12097957b9d8e838a8548c7de8f901bcb83e7c46d231b841221345c9264f5e29ed069f3d9236896430f959b
This had the nice side effect of cutting peak memory use during compilation: |
So I might just be being lazy... But can you do a bit more documentation on this one? This breaks some of my outstanding work (not PR'd yet) and I'd like to better understand where I should be making this functionality live... |
I guess mostly it's just stuff moving into scriptpubkeyman? But do I need to replicate the logic elsewhere now? |
@JeremyRubin Have you read https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Class-Structure-Changes Basically a bunch of things are moving into LegacyScriptPubKeyMan, and some of those that were moved become generic interfaces in CWallet which call the appropriate ScriptPubKeyMan. |
Summary: bitcoin/bitcoin@ab053ec --- Depends on D7118 Partial backport of Core [[bitcoin/bitcoin#17260 | PR17260]] Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D6998
…o keyman file Summary: Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. bitcoin/bitcoin@6702048 --- Depends on D6998 Partial backport of Core [[bitcoin/bitcoin#17260 | PR17260]] Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D7006
…yMan and classes Summary: This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. --- bitcoin/bitcoin@f201ba5 Depends on D7006 Concludes backport of Core [[bitcoin/bitcoin#17260 | PR17260]] NOTE: some changes to wallet/ismine_tests.cpp should have been made in D6663, but due to PRs being done out of order I missed that many tests were moved into it from test/script_standard_tests.cpp. this diff fixes that oversight. Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D7119
Summary: Fix missing strFailReason in CreateTransaction (Russell Yanofsky) Fix misplaced AssertLockHeld (Russell Yanofsky) doc: Clarify WalletStorage / Wallet relation (Russell Yanofsky) Add back mistakenly removed AssertLockHeld (Russell Yanofsky) Refactor: Add GetLegacyScriptPubKeyMan helper (Russell Yanofsky) Pull request description: This PR implements suggested code cleanups from bitcoin/bitcoin#17260 review comments --- https://github.com/bitcoin/bitcoin/pull/17300/files Depends on D7119 Backport of Core [[bitcoin/bitcoin#17300 | PR17300]] Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D7128
53fe0b7 Fix missing strFailReason in CreateTransaction (Russell Yanofsky) 4b28a05 Fix misplaced AssertLockHeld (Russell Yanofsky) 2632b1f doc: Clarify WalletStorage / Wallet relation (Russell Yanofsky) 628d11b Add back mistakenly removed AssertLockHeld (Russell Yanofsky) 52cf68f Refactor: Add GetLegacyScriptPubKeyMan helper (Russell Yanofsky) Pull request description: This PR implements suggested code cleanups from bitcoin#17260 review comments ACKs for top commit: Sjors: ACK 53fe0b7 achow101: ACK 53fe0b7 MarcoFalke: ACK 53fe0b7 Tree-SHA512: a577b96cb21a9aa7185d7d900e4db0665c302adcd12097957b9d8e838a8548c7de8f901bcb83e7c46d231b841221345c9264f5e29ed069f3d9236896430f959b
Suggested by João Barbosa <joao.paulo.barbosa@gmail.com> bitcoin/bitcoin#17260 (comment)
Suggestion from MarcoFalke <falke.marco@gmail.com> bitcoin/bitcoin#17260 (comment)
Suggestion from MarcoFalke <falke.marco@gmail.com> bitcoin/bitcoin#17260 (comment)
Suggested by MarcoFalke <falke.marco@gmail.com> bitcoin/bitcoin#17260 (comment)
Suggestion from MarcoFalke <falke.marco@gmail.com> bitcoin/bitcoin#17260 (comment)
Suggested by MarcoFalke <falke.marco@gmail.com> bitcoin/bitcoin#17260 (comment)
Suggestion from MarcoFalke <falke.marco@gmail.com> bitcoin/bitcoin#17260 (comment)
Suggested by MarcoFalke <falke.marco@gmail.com> bitcoin/bitcoin#17260 (comment)
Moves key management functions into a new class LegacyScriptPubKeyMan. First two commits are move-only commits which move stuff out of wallet.{h/cpp} and into newly created scriptpubkeyman.{h/cpp}. Third commit changes several things in CWallet to use LegacyScriptPubKeyMan.
First step in the wallet boxes refactor. Note that LegacyScriptPubKeyMan and ScriptPubKeyMan cannot be used standalone yet and are still very much tied into CWallet with both accessing functions within each other. This PR is to help reduce review burden.