[wallet] Clarify wallet initialization / destruction interface #10767

pull jnewbery wants to merge 8 commits into bitcoin:master from jnewbery:walletinit2 changing 5 files +66 −25
  1. jnewbery commented at 3:05 pm on July 7, 2017: member

    Apologies for the mostly code move only PR. This is a pre-req for both #10740 and #10762

    All wallet component initialization/destruction functions are now in their own wallet/init.cpp translation unit and are no longer static functions on the CWallet class. The bitcoin_server also no longer has any knowledge that there are multiple wallets in vpwallet.

    There should be no changes in behavior from this PR.

  2. fanquake added the label Wallet on Jul 7, 2017
  3. fanquake added the label Refactoring on Jul 7, 2017
  4. in src/init.cpp:191 in 3696ed0026 outdated
    186@@ -187,11 +187,6 @@ void Shutdown()
    187     StopREST();
    188     StopRPC();
    189     StopHTTPServer();
    190-#ifdef ENABLE_WALLET
    


    promag commented at 3:17 pm on July 7, 2017:
    Nothing replacing this code?

    jnewbery commented at 3:32 pm on July 7, 2017:

    Correct - I don’t believe the early wallet flush is necessary (although I may be wrong). See PR description:

    The most important one is that Flush() no longer gets called twice on shutdown. I think this is fine, and all the tests pass, but this probably requires some careful consideration from people who are more familiar with the wallet code.

  5. in src/init.cpp:245 in 3696ed0026 outdated
    224@@ -230,9 +225,7 @@ void Shutdown()
    225         pblocktree = NULL;
    226     }
    227 #ifdef ENABLE_WALLET
    


    promag commented at 3:24 pm on July 7, 2017:
    What about moving these #ifdef ENABLE_WALLET to walletinit.cpp?

    jnewbery commented at 3:30 pm on July 7, 2017:
    Because walletinit.cpp is in libbitcoin_wallet, so is not linked if ENABLE_WALLET isn’t defined. #10762 will remove the libbitcoin_server -> libbitcoin_wallet dependencies entirely from init.cpp.
  6. jnewbery renamed this:
    Clarify wallet initialization / destruction interface
    [wallet] Clarify wallet initialization / destruction interface
    on Jul 11, 2017
  7. practicalswift commented at 12:52 pm on July 17, 2017: contributor
    Rebase needed :-)
  8. jnewbery commented at 1:10 pm on July 17, 2017: member
    This isn’t going in until after 0.15. which includes some wallet changes. I’ll rebase after 0.15 has been cut.
  9. practicalswift commented at 1:19 pm on July 17, 2017: contributor
    @jnewbery Got it! Thanks for the clarification.
  10. jnewbery commented at 3:35 pm on August 14, 2017: member

    This overlaps significantly with #10976, which is easier to review since it’s mostly move-only.

    I’ll rebase this on #10976 once that gets merged.

  11. jnewbery force-pushed on Aug 28, 2017
  12. jnewbery commented at 6:12 pm on August 28, 2017: member

    Rebased on @ryanofsky’s #10976 and reduced scope. This PR now only moves the remaining wallet startup/shutdown functions to wallet/init.cpp in preparation for #10740 (dynamic loading/unloading of wallets) and #10762 (remove wallet dependencies from init.cpp).

    There should be no change in behavior from this PR.

  13. in src/wallet/init.h:26 in 789b5dd47f outdated
    21@@ -22,4 +22,7 @@ bool WalletVerify();
    22 //! Load wallet databases.
    23 bool InitLoadWallet();
    24 
    25+//! Flush all wallets in preparation for shutdown.
    26+//  Call with shutdown = true to actually shutdown the wallet.
    


    ryanofsky commented at 9:53 pm on August 28, 2017:

    In commit “[wallet] move wallet flush calls to wallet/init.cpp”

    I think you need to use //! prefix on each line of the comment for doxygen to pick it up.

  14. in src/init.cpp:268 in f977dcf74c outdated
    264@@ -265,10 +265,7 @@ void Shutdown()
    265     UnregisterAllValidationInterfaces();
    266     GetMainSignals().UnregisterBackgroundSignalScheduler();
    267 #ifdef ENABLE_WALLET
    268-    for (CWalletRef pwallet : vpwallets) {
    269-        delete pwallet;
    270-    }
    271-    vpwallets.clear();
    272+    DetachWallets();
    


    ryanofsky commented at 9:59 pm on August 28, 2017:

    In commit “[wallet] move wallet detach calls to wallet/init.cpp”

    Maybe go with “close” or “free” instead of “detach”. Detach sounds like it could be keeping the wallets open but handing them off.


    promag commented at 10:28 pm on August 28, 2017:
    👍 FreeWallets.
  15. ryanofsky commented at 10:08 pm on August 28, 2017: member
    utACK 3f425ee4263f66ab039c089d189b6cad0abbc23c. Looks like a simple cleanup with no change in behavior. FWIW I have similar functions in #10973, but am using {start, stop, shutdown} instead of {WalletCompleteStartup, FlushWallets, ShutdownWallets}. Links: declarations, definitions
  16. in src/wallet/init.h:9 in 3f425ee426 outdated
    5@@ -6,14 +6,22 @@
    6 #ifndef BITCOIN_WALLET_INIT_H
    7 #define BITCOIN_WALLET_INIT_H
    8 
    9+#include "wallet/rpcwallet.h"
    


    promag commented at 10:18 pm on August 28, 2017:
    Remove?
  17. in src/wallet/init.cpp:258 in 3f425ee426 outdated
    252@@ -245,3 +253,28 @@ bool InitLoadWallet()
    253 
    254     return true;
    255 }
    256+
    257+void WalletCompleteStartup(CScheduler& scheduler) {
    258+    for (CWalletRef pwallet : vpwallets) {
    


    promag commented at 10:21 pm on August 28, 2017:
    Offtopic, we could ditch CWalletRef.
  18. in src/wallet/init.h:43 in 3f425ee426 outdated
    38+
    39+//! Shutdown all wallets. Wallets will be flushed first.
    40+void ShutdownWallets();
    41+
    42+//! Detach all wallets
    43+void DetachWallets();
    


    promag commented at 10:29 pm on August 28, 2017:
    Newline after.
  19. in src/wallet/init.h:42 in 3f425ee426 outdated
    37+void FlushWallets();
    38+
    39+//! Shutdown all wallets. Wallets will be flushed first.
    40+void ShutdownWallets();
    41+
    42+//! Detach all wallets
    


    promag commented at 10:29 pm on August 28, 2017:
    Same as above.
  20. in src/wallet/init.h:33 in 3f425ee426 outdated
    29@@ -22,4 +30,15 @@ bool WalletVerify();
    30 //! Load wallet databases.
    31 bool InitLoadWallet();
    32 
    33+//! Complete startup of wallets
    


    promag commented at 10:29 pm on August 28, 2017:
    Same as above.
  21. in src/wallet/init.h:22 in 3f425ee426 outdated
    17 std::string GetWalletHelpString(bool showDebug);
    18 
    19 //! Wallets parameter interaction
    20 bool WalletParameterInteraction();
    21 
    22+//! Register wallet RPCs
    


    promag commented at 10:31 pm on August 28, 2017:
    Missing period?

    promag commented at 10:31 pm on August 28, 2017:
    Fix above too.
  22. jnewbery commented at 2:11 pm on August 29, 2017: member

    Re: naming of unload/close/free/detach wallet function. I want the wallet loading/unloading RPC verbs to be antonyms so it’s obvious they’re carrying out opposite actions. I started with load/unload, but dropped that to avoid any ambiguity with adding keys and addresses to an already open wallet. attach/detach is bad for the reason Russ mentioned. Is everyone happy with open/close?

    (I guess the name of the function doesn’t need to map exactly to the name of the RPC, but I think it makes sense to do that if we can)

  23. ryanofsky commented at 2:20 pm on August 29, 2017: member
    open/close or load/unload is what I would call it
  24. jnewbery force-pushed on Aug 29, 2017
  25. jnewbery commented at 4:21 pm on August 29, 2017: member
    I’ve addressed the comments and changed names a little. @ryanofsky do you mind taking a look?
  26. ryanofsky commented at 5:36 pm on August 29, 2017: member

    utACK ca94bf2c39b06f1ed643c24dfcd78ef5af00562a. Note that what you’re calling flush, I’m calling stop in #10973, and what you’re calling stop, I’m calling shutdown. But I’m not too worried about the names.

    #10973 links: declarations, definitions

  27. ryanofsky commented at 5:41 pm on August 29, 2017: member
    Also just a suggestion, but this might be easier to review if it were just 2 commits, one commit for RPC stuff and one commit for the start/stop/flush stuff, so you could see the related parts together.
  28. jnewbery commented at 6:15 pm on August 29, 2017: member

    Thanks @ryanofsky .

    Other reviewers/maintainers - I’m happy to rebase/squash as Russ suggests if that makes things easier to review. Please let me know if you want that.

  29. in src/init.cpp:47 in ca94bf2c39 outdated
    43@@ -44,7 +44,6 @@
    44 #include "validationinterface.h"
    45 #ifdef ENABLE_WALLET
    46 #include "wallet/init.h"
    47-#include "wallet/wallet.h"
    


    TheBlueMatt commented at 8:08 pm on September 7, 2017:
    Holy fuck yes, kill the imports.
  30. TheBlueMatt commented at 8:12 pm on September 7, 2017: member
    utACK ca94bf2c39b06f1ed643c24dfcd78ef5af00562a. I’m willing to bet this materially reduces the memory usage/compile time of init.cpp due to the wallet.h import removal.
  31. in src/init.cpp:1562 in ca94bf2c39 outdated
    1558@@ -1567,7 +1559,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
    1559 
    1560     // ********************************************************* Step 8: load wallet
    1561 #ifdef ENABLE_WALLET
    1562-    if (!InitLoadWallet())
    1563+    if (!OpenWallets())
    


    MarcoFalke commented at 8:18 pm on September 7, 2017:
    Can you add the rationale for rename in the commit message? Why not keep it?

    MarcoFalke commented at 11:19 pm on September 7, 2017:
    @jnewbery Or add it to the OP, so it can be seen in the merge commit.

    jnewbery commented at 11:24 pm on September 7, 2017:
    done!
  32. in src/wallet/init.h:25 in ca94bf2c39 outdated
    20+//! Register wallet RPCs.
    21+void RegisterWalletRPC(CRPCTable &tableRPC);
    22+
    23 //! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
    24 //  This function will perform salvage on the wallet if requested, as long as only one wallet is
    25 //  being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
    


    MarcoFalke commented at 8:26 pm on September 7, 2017:
    Comment should say “WalletParameterInteraction”

    jnewbery commented at 11:24 pm on September 7, 2017:
    added as trivial commit
  33. MarcoFalke commented at 8:30 pm on September 7, 2017: member
    utACK. Is mostly move-only
  34. laanwj assigned laanwj on Sep 7, 2017
  35. [wallet] Rename InitLoadWallet() to OpenWallets()
    Rationale:
    - this init function can now open multiple wallets (hence
      Wallet->Wallets)
    - This is named as the antonym to CloseWallets(), which carries out the
      opposite action.
    9c76ba18cd
  36. [wallet] Rename WalletVerify() to VerifyWallets()
    This function can now verify multiple wallets.
    1b9cee66e1
  37. [wallet] Add FlushWallets() function to wallet/init.cpp 2da5eafa47
  38. [wallet] Add StopWallets() function to wallet/init.cpp 77fe07c159
  39. [wallet] Add CloseWallets() function to wallet/init.cpp 062d63102e
  40. [wallet] Add RegisterWalletRPC() function to wallet/init.cpp 290f3c56d9
  41. [wallet] Add StartWallets() function to wallet/init.cpp 43b0e81d0f
  42. [trivial] fixup comment for VerifyWallets() 5d2a3995e7
  43. jnewbery force-pushed on Sep 7, 2017
  44. jnewbery commented at 11:24 pm on September 7, 2017: member
    @MarcoFalke - nits addressed. Should be ready for merge if Travis agrees.
  45. MarcoFalke commented at 11:29 pm on September 7, 2017: member
    re-utACK commit-by-commit 5d2a3995e7035b3607a11660a2c8330a548f733d
  46. MarcoFalke merged this on Sep 7, 2017
  47. MarcoFalke closed this on Sep 7, 2017

  48. MarcoFalke referenced this in commit 791a0e6dda on Sep 7, 2017
  49. jnewbery deleted the branch on Sep 10, 2017
  50. PastaPastaPasta referenced this in commit 358c4db77a on Dec 22, 2019
  51. PastaPastaPasta referenced this in commit 6c4c334350 on Jan 2, 2020
  52. PastaPastaPasta referenced this in commit 54e52012c2 on Jan 4, 2020
  53. PastaPastaPasta referenced this in commit 02e1fecfbd on Jan 4, 2020
  54. PastaPastaPasta referenced this in commit 6ef89566e0 on Jan 10, 2020
  55. PastaPastaPasta referenced this in commit 25d98e2bdd on Jan 10, 2020
  56. PastaPastaPasta referenced this in commit 99ccb6ebdd on Jan 10, 2020
  57. PastaPastaPasta referenced this in commit f6f455db81 on Jan 12, 2020
  58. ckti referenced this in commit 1bc9245138 on Mar 28, 2021
  59. gades referenced this in commit 4d034dc8cd on Jun 30, 2021
  60. 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-11-17 09:12 UTC

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