[wallet] Remove Wallet dependencies from init.cpp #10762

pull jnewbery wants to merge 4 commits into bitcoin:master from jnewbery:walletinit changing 8 files +124 −64
  1. jnewbery commented at 10:04 am on July 7, 2017: member

    This continues the work of #7965. This PR, along with several others, would remove the remaining dependencies from libbitcoin_server.a on libbitcoin_wallet.a.

    To create the interface, I’ve just translated all the old init.cpp wallet function calls into an interface class. I’ve not done any thinking about whether it makes sense to change that interface by combining/splitting those calls. This is a purely internal interface, so there’s no problem in changing it later.

  2. fanquake added the label Refactoring on Jul 7, 2017
  3. fanquake added the label Wallet on Jul 7, 2017
  4. jnewbery force-pushed on Jul 7, 2017
  5. promag commented at 10:42 am on July 7, 2017: member
    Will take a look.
  6. jnewbery commented at 10:44 am on July 7, 2017: member
    Thanks @promag - this is very rough-and-ready at the moment. It builds and passes tests, but is not ready for code review. I’d be very happy to get feedback about general concept though.
  7. jnewbery commented at 10:45 am on July 7, 2017: member
    I see that @theuni has opened #10756 to replace CNodeSignals with an interface class. Would that be a better approach here?
  8. ryanofsky commented at 11:33 am on July 7, 2017: member

    I see that @theuni has opened #10756 to replace CNodeSignals with an interface class. Would that be a better approach here?

    Yeah I was just about to make this suggestion. You could delete the WalletInitSignals struct and replace the WalletInitSignals global variable with a std::unique_ptr<WalletInitInterface> global. This would get rid of all the boost signals code and make the control flow simpler.

    Also you should prefix global variables with g_. And I think this PR would be less error prone and simpler to review if you just left the init code in wallet.cpp for now and moved the relevant functions to walletinit.cpp in followup MOVEONLY PR.

  9. jnewbery commented at 1:28 pm on July 7, 2017: member

    I think this PR would be less error prone and simpler to review if you just left the init code in wallet.cpp for now and moved the relevant functions to walletinit.cpp in followup MOVEONLY PR.

    Thanks @ryanofsky, you’ve convinced me - I’ll split this PR into two. But I think I’ll do it the other way round - first move the wallet initialization/destruction functions into their own walletinit translation unit, and then introduce the interface class in a second PR. The reason is that #10740 is built on walletinit.cpp so this PR and #10740 will no longer be interdependent.

  10. jnewbery renamed this:
    [WIP] Remove Wallet dependencies from init.cpp
    [WIP] [wallet] Remove Wallet dependencies from init.cpp
    on Jul 11, 2017
  11. MarcoFalke referenced this in commit 791a0e6dda on Sep 7, 2017
  12. jnewbery force-pushed on Sep 29, 2017
  13. jnewbery commented at 3:20 pm on September 29, 2017: member

    Rebased on master. I haven’t swapped out the boost signals for an interface class yet. Still looking for high-level feedback on this approach.

    The first three commits in this PR are shared with #10740

  14. jonasschnelli commented at 4:30 am on September 30, 2017: contributor

    Concept ACK on the general direction, though unsure about the implementation (haven’t checked the code in detail).

    I was following a similar approach in #6008 (relatively old closed PR) (check commit: https://github.com/bitcoin/bitcoin/pull/6008/commits/fa6a5b28fcaa612c6512c6028184df6b346fdad4).

    Maybe, init/the-core only knows about modules. Some signal/hooks would allow initialising, shutdown of such modules. The wallet could be one, the miner another one, etc. It would also allow to run with multiple wallet implementations (my idea was once to replace BDB with an append only file-format and removing all legacy code,… put this in a second wallet implementation and label it experimental).

    If possible, I would prefer a more generic approach (a module interface rather then a wallet interface).

  15. TheBlueMatt commented at 8:26 pm on October 2, 2017: member
    Concept ACK, generally. Agree that I’d really prefer no boost::signals (especially in the header!).
  16. MarcoFalke commented at 2:14 am on January 14, 2018: member
    Needs rebase
  17. PierreRochard commented at 8:28 pm on February 12, 2018: contributor
    Concept ACK
  18. jnewbery force-pushed on Feb 20, 2018
  19. jnewbery commented at 9:00 pm on February 20, 2018: member
    Rebased. Feedback not yet addressed.
  20. jnewbery force-pushed on Feb 21, 2018
  21. jnewbery force-pushed on Feb 21, 2018
  22. jnewbery commented at 9:54 pm on February 22, 2018: member
    I’ve reimplemented this as an interface class. Should be ready for review.
  23. jnewbery renamed this:
    [WIP] [wallet] Remove Wallet dependencies from init.cpp
    [wallet] Remove Wallet dependencies from init.cpp
    on Feb 22, 2018
  24. in src/wallet/init.cpp:308 in 284de22fb1 outdated
    306     }
    307 }
    308 
    309-void StopWallets() {
    310+void WalletInit::StopWallets() {
    311+    if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) return;
    


    ryanofsky commented at 10:01 pm on February 22, 2018:

    In commit “[wallet] Move wallet init functions into WalletInit class.”

    Is adding this line here intentional? It doesn’t seem to fit in with other changes in this commit, and seems unnecessary. Should add a comment describing rationale if it is useful to keep.


    jnewbery commented at 7:07 pm on February 23, 2018:
    Yes, removed. This is a vestige of a previous branch.
  25. in src/walletinitinterface.h:13 in 535009641d outdated
     6+#define WALLETINITINTERFACE_H
     7+
     8+class CScheduler;
     9+class CRPCTable;
    10+
    11+class WalletInitInterface {
    


    ryanofsky commented at 10:12 pm on February 22, 2018:

    In commit “[wallet] Create wallet init interface.”

    Just FYI, this PR is very similar to 6626e2fe114ce2aa861be1eeda84f0c9faa60527 from #10973 and the WalletInitInterface added here is basically identical to the Chain::Client interface added there:

    https://github.com/bitcoin/bitcoin/blob/6626e2fe114ce2aa861be1eeda84f0c9faa60527/src/interface/chain.h#L18-L40

    Probably would replace this interface with that more generic one if this is merged first.


    jnewbery commented at 7:08 pm on February 23, 2018:
    Thanks for the heads up!
  26. in src/walletinitinterface.h:8 in 89d1d6ca29 outdated
    4@@ -5,6 +5,8 @@
    5 #ifndef WALLETINITINTERFACE_H
    6 #define WALLETINITINTERFACE_H
    7 
    8+#include <string>
    


    ryanofsky commented at 10:21 pm on February 22, 2018:

    In commit “[wallet] Use global g_wallet_init_interface to init/destroy the wallet.”

    This change would make a little more sense in the previous commit adding the file.


    jnewbery commented at 7:11 pm on February 23, 2018:
    Agree. Fixed
  27. ryanofsky commented at 10:23 pm on February 22, 2018: member
    Looks good, conditional utACK 89d1d6ca293f602b88bf47fc2c3da37ddf6d4650 if you address the WalletInit::StopWallets comment below and also update the PR description to no longer refer to boost signals.
  28. in src/walletinitinterface.h:16 in 89d1d6ca29 outdated
    11+class CRPCTable;
    12+
    13+class WalletInitInterface {
    14+public:
    15+    /** Get wallet help string */
    16+    virtual std::string GetWalletHelpString(bool showDebug) {return (std::string)"";}
    


    MarcoFalke commented at 10:31 pm on February 22, 2018:
    style-nit: Instead of casting a literal, you could directly return an empty std::string{};

    jnewbery commented at 7:23 pm on February 23, 2018:
    better. Thanks!
  29. jnewbery force-pushed on Feb 23, 2018
  30. jnewbery force-pushed on Feb 23, 2018
  31. jnewbery commented at 7:09 pm on March 21, 2018: member

    Updated PR description to no longer reference boost signals.

    This is ready for review. It’s a fairly small changeset, and removes one of the last server->wallet dependencies.

  32. laanwj added this to the "Blockers" column in a project

  33. in src/init.cpp:419 in d44f4e5085 outdated
    414@@ -415,9 +415,9 @@ std::string HelpMessage(HelpMessageMode mode)
    415     strUsage += HelpMessageOpt("-whitelist=<IP address or network>", _("Whitelist peers connecting from the given IP address (e.g. 1.2.3.4) or CIDR notated network (e.g. 1.2.3.0/24). Can be specified multiple times.") +
    416         " " + _("Whitelisted peers cannot be DoS banned and their transactions are always relayed, even if they are already in the mempool, useful e.g. for a gateway"));
    417 
    418-#ifdef ENABLE_WALLET
    419-    strUsage += GetWalletHelpString(showDebug);
    420-#endif
    421+    if (g_wallet_init_interface) {
    422+        g_wallet_init_interface->GetWalletHelpString(showDebug);
    


    jimpo commented at 9:14 pm on March 22, 2018:
    This should be strUsage += ... I believe.

    jnewbery commented at 7:01 pm on March 23, 2018:
    You’re right. Fixed
  34. sipa commented at 9:20 pm on March 22, 2018: member
    Concept ACK
  35. in src/walletinitinterface.h:13 in d44f4e5085 outdated
     8+#include <string>
     9+
    10+class CScheduler;
    11+class CRPCTable;
    12+
    13+class WalletInitInterface {
    


    jimpo commented at 9:23 pm on March 22, 2018:

    Every method name in this interface has “Wallet” or “Wallets” in it, which is rather redundant given that this is a WalletInitInterface. I’d say drop them all, so “GetWalletHelpString” => “GetHelpString”, “WalletParameterInteraction” => “CheckParameterInteraction”, “RegisterWalletRPC” => “RegisterRPC”.

    That alone would go a long way towards making this a generalized init module interface.


    jnewbery commented at 7:02 pm on March 23, 2018:

    I’ve updated the function names, since as you point out, “Wallet” is redundant.

    See my comment below about a generalized module init interface.


    l2a5b1 commented at 9:11 pm on March 23, 2018:

    If WalletInitInterface is an interface class, maybe we can have an interface without method definitions. Have you considered an interface with pure virtual functions?

     0    /** Get wallet help string */
     1    virtual std::string GetWalletHelpString(bool showDebug) = 0;
     2    /** Check wallet parameter interaction */
     3    virtual bool WalletParameterInteraction() = 0;
     4    /** Register wallet RPC*/
     5    virtual void RegisterWalletRPC(CRPCTable &) = 0;
     6    /** Verify wallets */
     7    virtual bool VerifyWallets() = 0;
     8    /** Open wallets*/
     9    virtual bool OpenWallets() = 0;
    10    /** Start wallets*/
    11    virtual void StartWallets(CScheduler& scheduler) = 0;
    12    /** Flush Wallets*/
    13    virtual void FlushWallets() = 0;
    14    /** Stop Wallets*/
    15    virtual void StopWallets() = 0;
    16    /** Close wallets */
    17    virtual void CloseWallets() = 0;
    

    jnewbery commented at 5:26 pm on March 26, 2018:
    Thanks! Done.
  36. jimpo commented at 9:25 pm on March 22, 2018: contributor

    Definitely an improvement, though I agree with @jonasschnelli that I’d rather see this be a general interface for init modules, rather than one specific to wallet initialization.

    One way to do it is to name methods to correspond to their place in the init lifecycle, like BeforeDBOpen, AfterDBClose, BeforeNetStart, AfterNetStop, etc.

  37. jnewbery commented at 6:43 pm on March 23, 2018: member

    I’d rather see this be a general interface for init modules

    Do you think that’s a hard requirement before this PR gets merged? This PR is simply changing function calls to an internal interface class, which can be updated or replaced later. It seems to me that creating a brand new general interface for modules is outside the scope of this.

    Just merging this PR has a real benefit now - it removes one of the last remaining server -> wallet dependencies.

  38. jnewbery force-pushed on Mar 23, 2018
  39. jnewbery commented at 7:03 pm on March 23, 2018: member
    Pushed a new branch. The only changes are in the final commit, which addresses @jimpo’s comments above.
  40. in src/walletinitinterface.h:15 in ff29f04040 outdated
    10+class CScheduler;
    11+class CRPCTable;
    12+
    13+class WalletInitInterface {
    14+public:
    15+    /** Get wallet help string */
    


    l2a5b1 commented at 9:18 pm on March 23, 2018:

    Implement a virtual destructor to protect against undefined behavior in the event that an instance of a derived WalletInitInterface instance is destroyed through a pointer to this interface.

    0virtual ~WalletInitInterface() {}
    

    jnewbery commented at 5:26 pm on March 26, 2018:
    Added
  41. l2a5b1 commented at 9:21 pm on March 23, 2018: contributor
    Concept ACK.
  42. jimpo commented at 9:56 pm on March 24, 2018: contributor
    @jnewbery Hmm, I see the benefit, but generally when introducing interfaces I’d rather design it well up front (as opposed to, say, leaving a hack in some implementation until it can be cleaned up later). Especially if there’s another proposal for a similar, general interface in #10973, I think this could warrant some more thought. On the other hand, it might be easier to design the right general interface later when extracting other things behind interfaces. @ryanofsky Thoughts on how easy/likely it will be to switch the WalletInitInterface out for a more general one at a future date?
  43. [wallet] Move wallet init functions into WalletInit class. 5fb54210a6
  44. [wallet] Create wallet init interface. caaf9722f3
  45. jnewbery force-pushed on Mar 26, 2018
  46. jnewbery commented at 5:26 pm on March 26, 2018: member
    Addressed review comments from @251Labs.
  47. l2a5b1 commented at 2:04 pm on March 27, 2018: contributor
    Thanks @jnewbery! ACK caaf972.
  48. jnewbery commented at 2:36 pm on March 27, 2018: member
    Thanks for the review @251Labs. I’ve added a fixup commit to add override specifiers to the member functions in WalletInit. Let me know what you think. I’ll squash it into the previous commit if you agree.
  49. jamesob commented at 2:50 pm on March 27, 2018: member

    Tested ACK https://github.com/bitcoin/bitcoin/pull/10762/commits/b3e482c65c5c4697b38bba6006dbcdc3c1bba836

    • Encrypt existing wallet (Settings -> Encrypt Wallet…)
    • Change wallet passphrase (Settings -> Change Passphrase…)
    • Tested sending a transaction to self with automatic coin selection (Send)
    • Backup wallet & start with -wallet=/path/to/backup (File -> Backup wallet…)
  50. ryanofsky commented at 2:55 pm on March 27, 2018: member
    utACK b3e482c65c5c4697b38bba6006dbcdc3c1bba836. Changes since previous review: removing Wallet from WalletInit method names, switching to pure virtual methods, removing -disablewallet check in StopWallets, fixing GetWalletHelpString bug.
  51. ryanofsky commented at 2:58 pm on March 27, 2018: member
    utACK d8a53d0eb5d168947544d2b2ce6abccef4e5950c for new commit adding overrides
  52. in src/init.h:16 in d8a53d0eb5 outdated
    11 
    12 class CScheduler;
    13 class CWallet;
    14 
    15+class WalletInitInterface;
    16+extern std::unique_ptr<WalletInitInterface> g_wallet_init_interface;
    


    TheBlueMatt commented at 4:49 pm on March 27, 2018:
    Hmm, can we avoid yet more globals and just pass the wallet_init_interface in to the AppInit* functions?
  53. in src/init.cpp:191 in d8a53d0eb5 outdated
    187@@ -189,9 +188,9 @@ void Shutdown()
    188     StopREST();
    189     StopRPC();
    190     StopHTTPServer();
    191-#ifdef ENABLE_WALLET
    192-    FlushWallets();
    193-#endif
    194+    if (g_wallet_init_interface) {
    


    TheBlueMatt commented at 4:50 pm on March 27, 2018:
    Can we just make this always non-nullptr and call it directly? The mess of if (g_…) g_…->DoThing() in init.cpp is starting to get very repetitive.

    ryanofsky commented at 5:11 pm on March 27, 2018:
    FWIW, in my followup, there can be multiple clients, so the if statements turn into for loops. Would be fine to change this, but it’s unclear what the benefits would be.
  54. jimpo commented at 4:54 pm on March 27, 2018: contributor
    utACK d8a53d0eb5d168947544d2b2ce6abccef4e5950c
  55. [wallet] Use global g_wallet_init_interface to init/destroy the wallet.
    This commit creates a global g_wallet_init_interface, which is created
    in bitcoind and bitcoin-qt. g_wallet_init_interface is used to init
    and destroy the wallet.
    
    This removes the dependency from init.cpp on the wallet library.
    49baa4a462
  56. jnewbery force-pushed on Mar 27, 2018
  57. jnewbery commented at 6:49 pm on March 27, 2018: member
    Squashed the fixup commit. d8a53d0 -> 49baa4a462193d8d82b51d464740aa5f1114edf1 should be identical
  58. [wallet] Add dummy wallet init class c7ec524389
  59. jnewbery commented at 7:39 pm on March 27, 2018: member

    Added a dummy wallet init class as requested here: #10762 (review)

    I started trying to implement the suggestion of passing the wallet_init_interface into the AppInit* functions, but it ended up being a much larger change than I was expecting, since the wallet interface is called from several different functions in init.cpp, which are called from various places in qt.

    I’m going to leave it as a global, since it’s limited to the init.cpp file, and this PR already has 4 ACKs. The global can be removed in a future PR if necessary.

  60. Sjors commented at 11:20 am on March 28, 2018: member

    I did some light testing in QT on macOS. I also rebased on master to see if multiwallet behaves, which it seems to.

    Travis failure seems to be due to #12806.

  61. in src/init.cpp:1604 in c7ec524389
    1581@@ -1597,12 +1582,7 @@ bool AppInitMain()
    1582     fFeeEstimatesInitialized = true;
    1583 
    1584     // ********************************************************* Step 8: load wallet
    1585-#ifdef ENABLE_WALLET
    1586-    if (!OpenWallets())
    1587-        return false;
    1588-#else
    1589-    LogPrintf("No wallet support compiled in!\n");
    


    PierreRochard commented at 3:32 pm on March 28, 2018:
    Should this logging be added to the DummyWalletInit Open function?

    jnewbery commented at 4:01 pm on March 28, 2018:
    Good idea. This PR seems to have enough ACKs for merging. Let’s save this for a follow-up PR?

    MarcoFalke commented at 3:09 pm on March 29, 2018:
    ^ This is now up for grabs

    moneyball commented at 9:12 pm on March 29, 2018:
    I’ll take a stab as my first PR
  62. TheBlueMatt commented at 3:47 pm on March 28, 2018: member
    utACK c7ec5243892c38f9f77781b0e24a237942e7c776
  63. PierreRochard commented at 4:12 pm on March 28, 2018: contributor
    Tested ACK c7ec5243892c38f9f77781b0e24a237942e7c776
  64. ajtowns commented at 7:59 am on March 29, 2018: member
    utACK c7ec5243892c38f9f77781b0e24a237942e7c776
  65. promag commented at 9:14 am on March 29, 2018: member
    Tested ACK c7ec524. @jnewbery please see b3bcb3f, IMO it improves the separation, hides the interface implementations WalletInitInterface and DummyWalletInit and statically initializes g_wallet_init_interface.
  66. jnewbery commented at 2:19 pm on March 29, 2018: member
    @promag thanks for the review. Can we leave your suggestion for a follow-up PR in order not to invalidate the ACKs?
  67. laanwj commented at 2:53 pm on March 29, 2018: member
    This is nice. utACK c7ec5243892c38f9f77781b0e24a237942e7c776
  68. laanwj merged this on Mar 29, 2018
  69. laanwj closed this on Mar 29, 2018

  70. laanwj referenced this in commit 6d53663a43 on Mar 29, 2018
  71. fanquake removed this from the "Blockers" column in a project

  72. jnewbery deleted the branch on Mar 29, 2018
  73. moneyball referenced this in commit 9db2e125a7 on Mar 30, 2018
  74. moneyball referenced this in commit 7acf301391 on Mar 31, 2018
  75. MarcoFalke referenced this in commit d454e39f2a on Apr 1, 2018
  76. moneyball referenced this in commit 0af6a9558c on Apr 6, 2018
  77. moneyball referenced this in commit 23abfb7b7f on Apr 9, 2018
  78. MarcoFalke referenced this in commit 7ee6fc58f8 on Apr 9, 2018
  79. stamhe referenced this in commit 052eb24edf on Jun 27, 2018
  80. HashUnlimited referenced this in commit 91778c528d on Sep 5, 2018
  81. HashUnlimited referenced this in commit a4baf5bfdc on Sep 5, 2018
  82. lionello referenced this in commit 6c97a7462b on Nov 7, 2018
  83. joemphilips referenced this in commit eb5af6844b on Nov 9, 2018
  84. markblundeberg referenced this in commit fa27c55b41 on Jun 7, 2019
  85. jtoomim referenced this in commit 45a75d303b on Jun 29, 2019
  86. jonspock referenced this in commit b127610f8c on Jul 4, 2019
  87. jonspock referenced this in commit 2c1056d027 on Jul 4, 2019
  88. proteanx referenced this in commit 4d52f0671d on Jul 5, 2019
  89. jonspock referenced this in commit 0b4a16fa7a on Jul 9, 2019
  90. PastaPastaPasta referenced this in commit 358c4db77a on Dec 22, 2019
  91. PastaPastaPasta referenced this in commit 6c4c334350 on Jan 2, 2020
  92. PastaPastaPasta referenced this in commit 54e52012c2 on Jan 4, 2020
  93. PastaPastaPasta referenced this in commit 02e1fecfbd on Jan 4, 2020
  94. PastaPastaPasta referenced this in commit 6ef89566e0 on Jan 10, 2020
  95. PastaPastaPasta referenced this in commit 25d98e2bdd on Jan 10, 2020
  96. PastaPastaPasta referenced this in commit 99ccb6ebdd on Jan 10, 2020
  97. PastaPastaPasta referenced this in commit f6f455db81 on Jan 12, 2020
  98. PastaPastaPasta referenced this in commit 0ae2a12ba0 on Mar 14, 2020
  99. PastaPastaPasta referenced this in commit 4879de76ef on Mar 19, 2020
  100. PastaPastaPasta referenced this in commit 599df2b325 on Mar 21, 2020
  101. PastaPastaPasta referenced this in commit 5fc1686919 on Mar 24, 2020
  102. PastaPastaPasta referenced this in commit 925865c66c on Apr 14, 2020
  103. PastaPastaPasta referenced this in commit f475316ba9 on Apr 16, 2020
  104. PastaPastaPasta referenced this in commit 2fa9f27b75 on Apr 16, 2020
  105. UdjinM6 referenced this in commit 97742a14d8 on Apr 18, 2020
  106. PastaPastaPasta referenced this in commit f22126d858 on Dec 16, 2020
  107. PastaPastaPasta referenced this in commit f256d65e4b on Dec 18, 2020
  108. ckti referenced this in commit 1bc9245138 on Mar 28, 2021
  109. ckti referenced this in commit 6efccd83cb on Mar 28, 2021
  110. ckti referenced this in commit 7ce38d8cd2 on Mar 28, 2021
  111. gades referenced this in commit 4d034dc8cd on Jun 30, 2021
  112. gades referenced this in commit 368a862171 on Jun 30, 2021
  113. MarcoFalke 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 06:12 UTC

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