-
Notifications
You must be signed in to change notification settings - Fork 37.7k
[Wallet] refactor wallet/init interaction #7691
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
Conversation
e7b65e7
to
c23db88
Compare
Concept ACK. Please remove the parameter interaction code from init; it seems you forgot to do this. |
c23db88
to
0a624e0
Compare
@MarcoFalke: thanks! Fixed. |
New warning:
|
Could In fact, I believe I got the idea from one of your older versions of this (and then @luke-jr suggested some improvements to std::vector<std::pair<std::string, std::string> > CStandardPolicy::GetOptionsHelp() that would allow him to create generic forms in qt that automatically extend themselves when new options are added). Concept ACK |
/* initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */ | ||
static CWallet* InitLoadWallet(bool fDisableWallet, const std::string& strWalletFile, std::string& warningString, std::string& errorString); | ||
/* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */ | ||
static bool InitLoadWallet(); |
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 static instead of calling it from the pwalletMain global (which could be moved to wallet)?
Or are we turning the global into a singleton?
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 static instead of calling it from the pwalletMain global (which could be moved to wallet)?
Or are we turning the global into a singleton?
Right. This is the direction where I'm heading to. But I work in very tiny steps (as you can see). For now it just moves "static code" to a static function in CWallet. Later it should be within the pwalletMain
context.
0a624e0
to
93df308
Compare
fSendFreeTransactions = GetBoolArg("-sendfreetransactions", DEFAULT_SEND_FREE_TRANSACTIONS); | ||
|
||
std::string strWalletFile = GetArg("-wallet", DEFAULT_WALLET_DAT); | ||
CWallet::ParameterInteraction(); |
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.
You can't drop the return value here.
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.
Right. Fixed.
93df308
to
b87c44b
Compare
You forgot to remove I really want to get this merged quick but I am concerned that reviewers are turned off by the diff containing both moves and refactors. |
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING); | ||
return true; | ||
} | ||
|
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.
I think this should be void, as the return value is not used as far as I can tell.
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 is mirroring bool static InitWarning()
, so probably fine. Still, the code duplication could be avoided somehow.
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.
I have thought about that and if we want to decouple the wallet, we probably need to accept short term duplications of some code. In that case, the factored out shared code is uiInterface.ThreadSafeMessageBox
. A duplicated entry point only used by CWallet should be okay.
But I agree with @mrbandrews: the return code should be switched to void
(for UIWarning
, keep it for UIError
for now).
Will fix that.
AmountErrMsg still used once in init.cpp at line 937 of the revised file. So it's defined as a static function in both wallet.cpp and init.cpp, which seems to work fine, although I don't know whether it's the best way to do it (maybe it is) |
fSendFreeTransactions = GetBoolArg("-sendfreetransactions", DEFAULT_SEND_FREE_TRANSACTIONS); | ||
|
||
std::string strWalletFile = GetArg("-wallet", DEFAULT_WALLET_DAT); | ||
|
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.
I think this line can be removed... the wallet file name is read at the beginning of InitLoadWallet.
Other than a couple of nits, this looks good to me. Code review ACK, concept ACK, and I tested it with an unpruned node, pruned node with wallet, and a pruned node with an outdated wallet - meaning it should suggest a reindex (qt) or shut down (bitcoind) - with no problems. So it's an ACK from me. |
b87c44b
to
25340b7
Compare
Fixed nits. |
@jonasschnelli I don't necessarily object to this but it seems like if you're eventually going to change these from static functions to methods called on pWalletMain, that you might as well make all those changes now instead of having to review twice. |
1005c47
to
094b8a4
Compare
Okay. Fair enough. Second commit is a cosmetic BDB version logprint change. A migration from the global Thanks for the reviews! |
Rejecting @morcos proposal to integrate the static-to-context change. Rolling back to original commit. This would get to big and not enough reviews. Further refactor can be done after this PR. |
094b8a4
to
25340b7
Compare
Great, thanks for addressing the other nits. utACK 25340b7 |
return true; | ||
} | ||
|
||
bool CWallet::ParameterInteraction() |
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 not pass mapArgs as parameter here?
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 goal was it to keep it at a tiny scope (almost moveonly). I would strongly advise to keep this PR as it is and refactor later.
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.
Appears out of scope for this pull.
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.
Never mind, it won't make much sense until you can explicitly pass it to GetArg(), like in 3d03f15#diff-b7702a084eb00fb47f9800fd68271951R315
utACK, all my nits can be solved later. |
utACK 25340b7
Seems like a useless intermediate step to me. |
25340b7 [Wallet] refactor wallet/init interaction (Jonas Schnelli)
25340b7 [Wallet] refactor wallet/init interaction (Jonas Schnelli)
Bitcoin wallet PRs 2 Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#7576 - bitcoin/bitcoin#7577 - bitcoin/bitcoin#7608 - bitcoin/bitcoin#7691 - bitcoin/bitcoin#7905
7e71759 Wallet: Split main logic from InitLoadWallet into CreateWalletFromFile (random-zebra) e585dad [Wallet] refactor wallet/init interaction (random-zebra) 49646b2 [Refactor] Nuke zwalletMain global object (random-zebra) f5f9df9 Wallet: Let the interval-flushing thread figure out the filename (Luke Dashjr) 74445e4 [wallet] Move hardcoded file name out of log messages (random-zebra) 3f1838d [Wallet] optimize return value of InitLoadWallet() (random-zebra) 539dea4 [Wallet] move "load wallet phase" to CWallet (random-zebra) 7644318 [Wallet] move wallet help string creation to CWallet (random-zebra) a9d69b8 [trivial] Reuse translation and cleanup DEFAULT_* values (random-zebra) cfd007a [Bug] Omit wallet-related options from -help when wallet not supported (random-zebra) da642e6 [Refactor] More constant default values cleanup (random-zebra) a45275a [Refactor] Implement CBaseChainParams::BaseParams(Network) (random-zebra) 09abb98 Constrain constant values to a single location in code (random-zebra) Pull request description: Adapts the following refactoring PRs: - bitcoin#6961 Constrain constant values to a single location in code - bitcoin#7576 [Wallet] move wallet help string creation to CWallet - bitcoin#7577 move "load wallet phase" to CWallet - bitcoin#7608 Move hardcoded file name out of log messages - bitcoin#7691 refactor wallet/init interaction - bitcoin#8776 Wallet refactoring leading up to multiwallet ACKs for top commit: furszy: re ACK 7e71759 Fuzzbawls: ACK 7e71759 Tree-SHA512: 5fad328b9ddf8187af97d3d5fb285d0b67e73d51ac1bc44a3d57d0af86bce8b34efaab539b7bdbc4f9a2fa575a936f83788cffcc9c6d6d04cd3e63b19d399400
This is another step to move the wallet code from
init.cpp
towallet.cpp
while keeping the behavior identical. Behavior simplification can be done once all code is available inwallet.cpp
.This is also a basic step into the direction of cloning the wallet, add BIP32 & multi-wallet in the second wallet implementation without introducing bugs in the current wallet implementation.