Skip to content

Conversation

jonasschnelli
Copy link
Contributor

This is another step to move the wallet code from init.cpp to wallet.cpp while keeping the behavior identical. Behavior simplification can be done once all code is available in wallet.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.

@maflcko
Copy link
Member

maflcko commented Mar 15, 2016

Concept ACK. Please remove the parameter interaction code from init; it seems you forgot to do this.

@jonasschnelli
Copy link
Contributor Author

@MarcoFalke: thanks! Fixed.

@paveljanik
Copy link
Contributor

New warning:

wallet/wallet.cpp:3222:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.

@jtimon
Copy link
Contributor

jtimon commented Mar 16, 2016

Could CWallet::ParameterInteraction() take a const std::map<std::string, std::string>& mapArgs as parameter instead of using the mapArgs global from util.h like in jtimon@3d03f15 ?

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();
Copy link
Contributor

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?

Copy link
Contributor Author

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.

fSendFreeTransactions = GetBoolArg("-sendfreetransactions", DEFAULT_SEND_FREE_TRANSACTIONS);

std::string strWalletFile = GetArg("-wallet", DEFAULT_WALLET_DAT);
CWallet::ParameterInteraction();
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. Fixed.

@maflcko
Copy link
Member

maflcko commented Mar 18, 2016

You forgot to remove AmountErrMsg from init as well. Maybe it would help to create two separate commits or even pulls: One addressing the move-only and the other the refactoring Warning/Error messages?

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;
}

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@mrbandrews
Copy link
Contributor

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);

Copy link
Contributor

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.

@mrbandrews
Copy link
Contributor

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.

@jonasschnelli
Copy link
Contributor Author

Fixed nits.
Should be ready for merge.

@morcos
Copy link
Contributor

morcos commented Mar 22, 2016

@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.
If you feel like its cleaner to break it up, perhaps it could be 2 commits in the same PR, but why not move closer to where you're trying to go.

@jonasschnelli
Copy link
Contributor Author

Okay. Fair enough.
Added two commits.
First added commit will refactor the static methods to take them into the CWallet instance context. This looks much cleaner now.

Second commit is a cosmetic BDB version logprint change.

A migration from the global pwalletMain (called from everywhere) to a singleton is out-of-scope for now.

Thanks for the reviews!

@jonasschnelli
Copy link
Contributor Author

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.

@maflcko
Copy link
Member

maflcko commented Mar 24, 2016

Great, thanks for addressing the other nits.

utACK 25340b7

return true;
}

bool CWallet::ParameterInteraction()
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

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

@jtimon
Copy link
Contributor

jtimon commented Mar 29, 2016

utACK, all my nits can be solved later.

@laanwj
Copy link
Member

laanwj commented Apr 2, 2016

utACK 25340b7

A migration from the global pwalletMain (called from everywhere) to a singleton is out-of-scope for now.

Seems like a useless intermediate step to me.
Singletons are just nicely dressed-up globals.
But we'd like to get rid of a single, global wallet, in any form. Just pass the thing around when you need it.

@laanwj laanwj merged commit 25340b7 into bitcoin:master Apr 2, 2016
laanwj added a commit that referenced this pull request Apr 2, 2016
25340b7 [Wallet] refactor wallet/init interaction (Jonas Schnelli)
vlamer added a commit to vlamer/bitcoin that referenced this pull request Apr 2, 2016
codablock pushed a commit to codablock/dash that referenced this pull request Dec 19, 2017
25340b7 [Wallet] refactor wallet/init interaction (Jonas Schnelli)
zkbot added a commit to zcash/zcash that referenced this pull request Dec 18, 2019
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Aug 25, 2020
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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.

7 participants