[Wallet] refactor wallet/init interaction #7691

pull jonasschnelli wants to merge 1 commits into bitcoin:master from jonasschnelli:2016/03/wallet_mod changing 5 files +118 −125
  1. jonasschnelli commented at 9:35 am on March 15, 2016: 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.

  2. jonasschnelli added the label Brainstorming on Mar 15, 2016
  3. jonasschnelli added the label Block storage on Mar 15, 2016
  4. jonasschnelli added the label Refactoring on Mar 15, 2016
  5. jonasschnelli added the label Wallet on Mar 15, 2016
  6. jonasschnelli removed the label Block storage on Mar 15, 2016
  7. jonasschnelli removed the label Brainstorming on Mar 15, 2016
  8. jonasschnelli force-pushed on Mar 15, 2016
  9. MarcoFalke commented at 12:26 pm on March 15, 2016: member
    Concept ACK. Please remove the parameter interaction code from init; it seems you forgot to do this.
  10. jonasschnelli force-pushed on Mar 15, 2016
  11. jonasschnelli commented at 12:37 pm on March 15, 2016: contributor
    @MarcoFalke: thanks! Fixed.
  12. paveljanik commented at 7:42 pm on March 15, 2016: contributor

    New warning:

    0wallet/wallet.cpp:3222:1: warning: control may reach end of non-void function [-Wreturn-type]
    1}
    2^
    31 warning generated.
    
  13. jtimon commented at 6:27 pm on March 16, 2016: contributor

    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 https://github.com/jtimon/bitcoin/commit/3d03f15126b79bd9f22ccd27f1d8ca43d9e16bf5 ?

    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

  14. in src/wallet/wallet.h: in 0a624e0266 outdated
    876@@ -875,8 +877,11 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
    877     /* Returns the wallets help message */
    878     static std::string GetWalletHelpString(bool showDebug);
    879 
    880-    /* initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
    881-    static CWallet* InitLoadWallet(bool fDisableWallet, const std::string& strWalletFile, std::string& warningString, std::string& errorString);
    882+    /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
    883+    static bool InitLoadWallet();
    


    jtimon commented at 6:30 pm on March 16, 2016:
    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?

    jonasschnelli commented at 7:57 am on March 17, 2016:

    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.

  15. jonasschnelli force-pushed on Mar 17, 2016
  16. in src/init.cpp: in 93df3082c2 outdated
    991-    nTxConfirmTarget = GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
    992-    bSpendZeroConfChange = GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
    993-    fSendFreeTransactions = GetBoolArg("-sendfreetransactions", DEFAULT_SEND_FREE_TRANSACTIONS);
    994-
    995-    std::string strWalletFile = GetArg("-wallet", DEFAULT_WALLET_DAT);
    996+    CWallet::ParameterInteraction();
    


    MarcoFalke commented at 10:32 am on March 17, 2016:
    You can’t drop the return value here.

    jonasschnelli commented at 12:10 pm on March 17, 2016:
    Right. Fixed.
  17. jonasschnelli force-pushed on Mar 17, 2016
  18. MarcoFalke commented at 5:44 pm on March 18, 2016: member

    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.

  19. in src/wallet/wallet.cpp: in b87c44b6eb outdated
    375+bool static UIWarning(const std::string &str)
    376+{
    377+    uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
    378+    return true;
    379+}
    380+
    


    mrbandrews commented at 3:32 pm on March 21, 2016:
    I think this should be void, as the return value is not used as far as I can tell.

    MarcoFalke commented at 4:24 pm on March 21, 2016:
    It is mirroring bool static InitWarning(), so probably fine. Still, the code duplication could be avoided somehow.

    jonasschnelli commented at 4:37 pm on March 21, 2016:

    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.

  20. mrbandrews commented at 3:37 pm on March 21, 2016: 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)
  21. in src/wallet/wallet.cpp: in b87c44b6eb outdated
    3218+    nTxConfirmTarget = GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
    3219+    bSpendZeroConfChange = GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
    3220+    fSendFreeTransactions = GetBoolArg("-sendfreetransactions", DEFAULT_SEND_FREE_TRANSACTIONS);
    3221+
    3222+    std::string strWalletFile = GetArg("-wallet", DEFAULT_WALLET_DAT);
    3223+
    


    mrbandrews commented at 5:29 pm on March 21, 2016:
    I think this line can be removed… the wallet file name is read at the beginning of InitLoadWallet.
  22. in src/wallet/wallet.cpp: in b87c44b6eb outdated
    3016@@ -2992,8 +3017,10 @@ std::string CWallet::GetWalletHelpString(bool showDebug)
    3017     return strUsage;
    3018 }
    3019 
    3020-CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWalletFile, std::string& warningString, std::string& errorString)
    3021+bool CWallet::InitLoadWallet()
    3022 {
    3023+    std::string strWalletFile = GetArg("-wallet", DEFAULT_WALLET_DAT);
    3024+
    


    mrbandrews commented at 5:34 pm on March 21, 2016:
    Nit: this local variable has the same name as the class member variable (I guess it is not a problem here since the compiler knows it can’t access the class member from a static method?) Not a big deal but maybe want to give it a different name.
  23. mrbandrews commented at 5:44 pm on March 21, 2016: 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.
  24. [Wallet] refactor wallet/init interaction 25340b7cd5
  25. jonasschnelli force-pushed on Mar 22, 2016
  26. jonasschnelli commented at 7:48 am on March 22, 2016: contributor
    Fixed nits. Should be ready for merge.
  27. morcos commented at 1:58 pm on March 22, 2016: member
    @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.
  28. jonasschnelli force-pushed on Mar 23, 2016
  29. jonasschnelli commented at 9:47 am on March 23, 2016: contributor

    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!

  30. jonasschnelli commented at 8:00 pm on March 24, 2016: contributor
    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.
  31. jonasschnelli force-pushed on Mar 24, 2016
  32. MarcoFalke commented at 8:01 pm on March 24, 2016: member

    Great, thanks for addressing the other nits.

    utACK 25340b7

  33. in src/wallet/wallet.cpp: in 25340b7cd5
    3161@@ -3150,7 +3162,62 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
    3162     }
    3163     walletInstance->SetBroadcastTransactions(GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST));
    3164 
    3165-    return walletInstance;
    3166+    pwalletMain = walletInstance;
    3167+    return true;
    3168+}
    3169+
    3170+bool CWallet::ParameterInteraction()
    


    jtimon commented at 12:51 pm on March 29, 2016:
    Why not pass mapArgs as parameter here?

    jonasschnelli commented at 12:54 pm on March 29, 2016:
    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.

    MarcoFalke commented at 12:55 pm on March 29, 2016:
    Appears out of scope for this pull.

    jtimon commented at 12:55 pm on March 29, 2016:
    Never mind, it won’t make much sense until you can explicitly pass it to GetArg(), like in https://github.com/bitcoin/bitcoin/pull/6423/commits/3d03f15126b79bd9f22ccd27f1d8ca43d9e16bf5#diff-b7702a084eb00fb47f9800fd68271951R315
  34. jtimon commented at 12:55 pm on March 29, 2016: contributor
    utACK, all my nits can be solved later.
  35. laanwj commented at 6:22 am on April 2, 2016: member

    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.

  36. laanwj merged this on Apr 2, 2016
  37. laanwj closed this on Apr 2, 2016

  38. laanwj referenced this in commit 30c2dd8d05 on Apr 2, 2016
  39. vlamer referenced this in commit 4451ecbe62 on Apr 2, 2016
  40. codablock referenced this in commit e10502c3f6 on Sep 16, 2017
  41. codablock referenced this in commit 5b40773b70 on Sep 19, 2017
  42. codablock referenced this in commit 11cc04a139 on Dec 9, 2017
  43. codablock referenced this in commit eae6a4c98d on Dec 19, 2017
  44. codablock referenced this in commit 298224b3b7 on Dec 19, 2017
  45. zkbot referenced this in commit fa341bcff0 on Dec 18, 2019
  46. random-zebra referenced this in commit e89e20eca1 on Aug 25, 2020
  47. DrahtBot locked this on Sep 8, 2021

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-12-18 15:12 UTC

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