refactor: Move wallet methods out of chain.h and node.h #19099

pull ryanofsky wants to merge 3 commits into bitcoin:master from ryanofsky:pr/wclient changing 23 files +131 โˆ’158
  1. ryanofsky commented at 9:25 pm on May 28, 2020: member

    Add WalletClient interface so node interface is cleaner and don’t need wallet-specific methods.

    The new NodeContext::wallet_client pointer will also be needed to eliminate global wallet variables like ::vpwallets in #19101, because createWallet(), loadWallet(), getWallets(), etc methods called by the GUI need a way to get a reference to the list of open wallets if it is no longer a global variable.

  2. DrahtBot added the label GUI on May 28, 2020
  3. DrahtBot added the label Refactoring on May 28, 2020
  4. DrahtBot added the label Tests on May 28, 2020
  5. DrahtBot added the label Wallet on May 28, 2020
  6. DrahtBot commented at 6:48 am on May 29, 2020: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #19754 (wallet, gui: Reload previously loaded wallets on startup by achow101)
    • #19619 (Remove wallet.dat path handling from wallet.cpp, rpcwallet.cpp by ryanofsky)
    • #19461 (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
    • #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
    • #19160 (multiprocess: Add basic spawn and IPC support by ryanofsky)
    • #19077 (wallet: Add sqlite as an alternative wallet database and use it for new descriptor wallets by achow101)
    • #15719 (Wallet passive startup by ryanofsky)
    • #15454 (Remove the automatic creation and loading of the default wallet by achow101)
    • #10102 ([experimental] Multiprocess bitcoin by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  7. DrahtBot added the label Needs rebase on May 29, 2020
  8. ryanofsky force-pushed on May 29, 2020
  9. ryanofsky commented at 12:48 pm on May 29, 2020: member
    Rebased 771b0e36de7dad225e9b664a9fd1c2a55f94ed8b -> 05875a8bc8e500322f9a54f07d60e9ed1e295282 (pr/wclient.1 -> pr/wclient.2, compare) due to conflict with #17993, and including splashscreen init fix Rebased 05875a8bc8e500322f9a54f07d60e9ed1e295282 -> 7f6b16c00feae2b7fbed41d6e091b7a84ad75dbf (pr/wclient.2 -> pr/wclient.3, compare) on updated base #19098 with no changes. Fixes UndefinedBehaviorSanitizer error https://travis-ci.org/github/bitcoin/bitcoin/jobs/692541509#L4295 from base pr Rebased 7f6b16c00feae2b7fbed41d6e091b7a84ad75dbf -> 7e2da82eee3cea75ff61f9a869e2791d78a7fe41 (pr/wclient.3 -> pr/wclient.4, compare) on rebased base pr #19098 pr/qtx.4 Rebased 7e2da82eee3cea75ff61f9a869e2791d78a7fe41 -> f1afe0ac5d0a389e415e67f19f91d7e538b7ad18 (pr/wclient.4 -> pr/wclient.5, compare) on rebased base pr #19098 pr/qtx.5
  10. DrahtBot removed the label Needs rebase on May 29, 2020
  11. ryanofsky force-pushed on Jun 4, 2020
  12. DrahtBot added the label Needs rebase on Jun 9, 2020
  13. ryanofsky force-pushed on Jun 10, 2020
  14. DrahtBot removed the label Needs rebase on Jun 10, 2020
  15. DrahtBot added the label Needs rebase on Jun 18, 2020
  16. ryanofsky force-pushed on Jun 19, 2020
  17. DrahtBot removed the label Needs rebase on Jun 19, 2020
  18. in src/qt/splashscreen.cpp:194 in f1afe0ac5d outdated
    190+
    191+void SplashScreen::handleLoadWallet()
    192+{
    193 #ifdef ENABLE_WALLET
    194-    m_handler_load_wallet = m_node.handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) { ConnectWallet(std::move(wallet)); });
    195+    m_handler_load_wallet = m_node.walletClient().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) { ConnectWallet(std::move(wallet)); });
    


    promag commented at 11:01 pm on July 6, 2020:
    nit, inline SplashScreen::ConnectWallet here - remove from header and reduce ENABLE_WALLET usage.

    ryanofsky commented at 8:46 pm on July 8, 2020:

    re: #19099 (review)

    nit, inline SplashScreen::ConnectWallet here - remove from header and reduce ENABLE_WALLET usage.

    Inlined in followup commit

  19. in src/interfaces/wallet.h:310 in f1afe0ac5d outdated
    305@@ -303,6 +306,31 @@ class Wallet
    306     virtual CWallet* wallet() { return nullptr; }
    307 };
    308 
    309+class WalletClient : public ChainClient
    


    promag commented at 11:02 pm on July 6, 2020:
    nit, add the usual comment.

    ryanofsky commented at 8:46 pm on July 8, 2020:

    re: #19099 (review)

    nit, add the usual comment.

    Added doxygen comment

  20. promag commented at 11:04 pm on July 6, 2020: member
    Code review ACK after bases get merged and rebase. Nice work.
  21. DrahtBot added the label Needs rebase on Jul 7, 2020
  22. ryanofsky referenced this in commit 314395c17f on Jul 10, 2020
  23. ryanofsky force-pushed on Jul 10, 2020
  24. ryanofsky commented at 4:52 pm on July 10, 2020: member
    Rebased f1afe0ac5d0a389e415e67f19f91d7e538b7ad18 -> 314395c17f4fc02a72af790f8d959fe8941c51ad (pr/wclient.5 -> pr/wclient.6, compare) on top of #19098 pr/qtx.7 with suggestions Rebased 314395c17f4fc02a72af790f8d959fe8941c51ad -> 7d82b31f1ac8590d914968fcd9d455a0958d4ae4 (pr/wclient.6 -> pr/wclient.7, compare) on top of #19098 pr/qtx.8 due to conflicts with #18923 Rebased 7d82b31f1ac8590d914968fcd9d455a0958d4ae4 -> 75fc0cb723f06ec2d5144f99d55a2b844f1af080 (pr/wclient.7 -> pr/wclient.8, compare) after base PR #19098 merge Rebased 75fc0cb723f06ec2d5144f99d55a2b844f1af080 -> 9ccb7b3f2fe7e6d924f807275b5a7567d7b49b11 (pr/wclient.8 -> pr/wclient.9, compare) due to conflict with #19011 Rebased 9ccb7b3f2fe7e6d924f807275b5a7567d7b49b11 -> 72acd6bca3fd408c9c7ca4801de817c69d59aca5 (pr/wclient.9 -> pr/wclient.10, compare) due to conflict with #15937
  25. DrahtBot removed the label Needs rebase on Jul 10, 2020
  26. DrahtBot added the label Needs rebase on Jul 11, 2020
  27. ryanofsky referenced this in commit 2dbdb4355b on Jul 13, 2020
  28. ryanofsky referenced this in commit 86e2cbe8be on Jul 13, 2020
  29. ryanofsky referenced this in commit 7d82b31f1a on Jul 13, 2020
  30. ryanofsky force-pushed on Jul 13, 2020
  31. DrahtBot removed the label Needs rebase on Jul 13, 2020
  32. ryanofsky referenced this in commit edc316020e on Jul 21, 2020
  33. MarcoFalke referenced this in commit 4b705b1c98 on Aug 7, 2020
  34. DrahtBot added the label Needs rebase on Aug 7, 2020
  35. sidhujag referenced this in commit 1e78f38193 on Aug 7, 2020
  36. ryanofsky referenced this in commit 943edf50ba on Aug 7, 2020
  37. ryanofsky referenced this in commit 75fc0cb723 on Aug 7, 2020
  38. ryanofsky force-pushed on Aug 7, 2020
  39. DrahtBot removed the label Needs rebase on Aug 7, 2020
  40. DrahtBot added the label Needs rebase on Aug 13, 2020
  41. ryanofsky referenced this in commit f7308a8a63 on Aug 13, 2020
  42. ryanofsky referenced this in commit 9ccb7b3f2f on Aug 13, 2020
  43. ryanofsky force-pushed on Aug 13, 2020
  44. DrahtBot removed the label Needs rebase on Aug 14, 2020
  45. DrahtBot added the label Needs rebase on Aug 15, 2020
  46. ryanofsky referenced this in commit 72acd6bca3 on Aug 17, 2020
  47. ryanofsky force-pushed on Aug 17, 2020
  48. ryanofsky referenced this in commit 05cc5d5856 on Aug 17, 2020
  49. DrahtBot removed the label Needs rebase on Aug 17, 2020
  50. in src/bitcoind.cpp:154 in 72acd6bca3 outdated
    150@@ -152,6 +151,7 @@ static bool AppInit(int argc, char* argv[])
    151             // If locking the data directory failed, exit immediately
    152             return false;
    153         }
    154+        AppInitInterfaces(node);
    


    kallewoof commented at 5:29 am on August 26, 2020:

    Why ignore returned value (even if only true at this point)?

    0        if (!AppInitInterfaces(node)) return false;
    

    MarcoFalke commented at 8:09 am on August 31, 2020:
    seems to be addressed
  51. in src/interfaces/node.cpp:53 in 72acd6bca3 outdated
    48-std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings);
    49-WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, std::shared_ptr<CWallet>& result);
    50-std::unique_ptr<interfaces::Handler> HandleLoadWallet(interfaces::Node::LoadWalletFn load_wallet);
    51-
    52 namespace interfaces {
    53-
    


    kallewoof commented at 5:30 am on August 26, 2020:
    ฮผNit: This empty line looks nice, IMO.
  52. in src/interfaces/node.cpp:250 in 72acd6bca3 outdated
    274-    std::unique_ptr<Wallet> createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, WalletCreationStatus& status) override
    275-    {
    276-        std::shared_ptr<CWallet> wallet;
    277-        status = CreateWallet(*m_context->chain, passphrase, wallet_creation_flags, name, error, warnings, wallet);
    278-        return MakeWallet(wallet);
    279+        assert (m_context->wallet_client);
    


    kallewoof commented at 5:31 am on August 26, 2020:
    Style-nit: Usually no space before (.

    MarcoFalke commented at 8:09 am on August 31, 2020:
    seems to be addressed
  53. kallewoof commented at 5:43 am on August 26, 2020: member

    Conceptually looks like a good change, and codewise looks like a clean-up, but the PR description could use a bit more motivation as for why this is needed. It could simply be that I’m not aware of the bigger project, though.

    Code review ACK

  54. DrahtBot added the label Needs rebase on Aug 26, 2020
  55. ryanofsky referenced this in commit c6ac47451f on Aug 26, 2020
  56. ryanofsky force-pushed on Aug 26, 2020
  57. ryanofsky referenced this in commit 3b2908d754 on Aug 26, 2020
  58. refactor: Create interfaces earlier during initialization
    Add AppInitInterfaces function so wallet chain and chain client interfaces are
    created earlier during initialization. This is needed in the next commit to
    allow the gui splash screen to be able to register for wallet events through a
    dedicated WalletClient interface instead managing wallets indirectly through
    the Node interface. This only works if the wallet client interface is created
    before the splash screen needs to use it.
    b266b3e0bf
  59. refactor: Move wallet methods out of chain.h and node.h
    Add WalletClient interface so node interface is cleaner and don't need
    wallet-specific methods.
    
    The new NodeContext::wallet_client pointer will also be needed to eliminate
    global wallet variables like ::vpwallets, because createWallet(), loadWallet(),
    getWallets(), etc methods called by the GUI need a way to get a reference to
    the list of open wallets if it is no longer a global variable.
    
    Also tweaks splash screen registration for load wallet events to be delayed
    until after wallet client is created.
    e4f4350471
  60. gui refactor: Inline SplashScreen::ConnectWallet
    Suggested https://github.com/bitcoin/bitcoin/pull/19099#discussion_r450522201
    24bf17602c
  61. ryanofsky force-pushed on Aug 28, 2020
  62. ryanofsky referenced this in commit 1c4542135d on Aug 28, 2020
  63. DrahtBot removed the label Needs rebase on Aug 28, 2020
  64. promag commented at 11:26 pm on August 30, 2020: member

    Code review ACK 24bf17602c620445f76c3b407937751c8a894d37.

    (actually reviewed in #19101)

  65. MarcoFalke removed the label GUI on Aug 31, 2020
  66. MarcoFalke removed the label Tests on Aug 31, 2020
  67. MarcoFalke removed the label Wallet on Aug 31, 2020
  68. in src/wallet/init.cpp:134 in e4f4350471 outdated
    129@@ -129,5 +130,7 @@ void WalletInit::Construct(NodeContext& node) const
    130             settings.rw_settings["wallet"] = wallets;
    131         });
    132     }
    133-    node.chain_clients.emplace_back(interfaces::MakeWalletClient(*node.chain, args, args.GetArgs("-wallet")));
    134+    auto wallet_client = interfaces::MakeWalletClient(*node.chain, args, args.GetArgs("-wallet"));
    135+    node.wallet_client = wallet_client.get();
    


    MarcoFalke commented at 8:04 am on August 31, 2020:

    nit in e4f435047121886edb6e6a6c4e4998e44ed2e36a:

    Would be good to assert !node.wallet_client to avoid accidentally re-seating the reference

  69. in src/node/context.h:44 in e4f4350471 outdated
    40@@ -40,7 +41,11 @@ struct NodeContext {
    41     std::unique_ptr<BanMan> banman;
    42     ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
    43     std::unique_ptr<interfaces::Chain> chain;
    44+    //! List of all chain clients (wallet processes or other client) connected to node.
    


    MarcoFalke commented at 8:05 am on August 31, 2020:
    0    //! List of all chain clients (wallet client or other client) connected to node.
    

    nit in e4f4350:

    could simply say that there is at most a single wallet client in this list, not one for each wallet.

  70. MarcoFalke commented at 8:07 am on August 31, 2020: member

    ACK 24bf17602c620445f76c3b407937751c8a894d37 ๐Ÿš

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3ACK 24bf17602c620445f76c3b407937751c8a894d37 ๐Ÿš
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUjmewv/dJqaPdgxC1U3bn+w8eyykTimZGhO7qQeEkDFIM/KtzP62aCYhPeIUw4P
     85bvnVqwB7+xU6ulQ8bKQBfWIZQiyCehQ5xCrB6kdTO8U2jUnUqO4G3c3ypgqbUXd
     9oNhRKT2P+V3XtkpU2DbAz+7n+B5GeoJA7OxXksEN8U9q3EdymgmTVVfeBQB36gtt
    10GlfQYbCksyKl8cj6FN5l4D0pJKOqPgfS21jh7WEjHoKIPE8ttTLYelgXQeSijhci
    11Iuc4NTts7l0dwTescpwOpVqyk0Mz/k6TshEZSDGaf7fjY26s5wz7RZFUVtYtICf8
    12S2zYQDque8mwZTnaEs4dVo5wGG6dqpWK5fPEdQFDAskdsDiXLnumsYpZOH68V5ov
    1362cztTrLVECqErAPjT0P+P/mBTrp8oHoTagzvrSO71Y/pyoc3zoAdNimxmT1K8ya
    14GStgbd4W9ia6J8D1s/ov4rxmZBH2XPBBaTXpas4++8BYiPjmx+NkteVXjJsRNOX/
    15ZNWwcqg0
    16=TcZF
    17-----END PGP SIGNATURE-----
    

    Timestamp of file with hash 77e30443c0b09185b05b8ce84203f4afece67e0a8bb120e17ec2f352a85547ac -

  71. MarcoFalke merged this on Aug 31, 2020
  72. MarcoFalke closed this on Aug 31, 2020

  73. in src/interfaces/node.h:175 in 24bf17602c
    186-    //! with handleLoadWallet.
    187-    virtual std::unique_ptr<Wallet> loadWallet(const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) = 0;
    188-
    189-    //! Create a wallet from file
    190-    virtual std::unique_ptr<Wallet> createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, WalletCreationStatus& status) = 0;
    191+    //! Get wallet client.
    


    MarcoFalke commented at 4:22 pm on August 31, 2020:
    doc-nit: Should the docs say that this is not allowed to be called in a non-wallet build or when the wallet is disabled?
  74. sidhujag referenced this in commit bde41caa8d on Aug 31, 2020
  75. hebasto commented at 7:16 pm on October 9, 2020: member
    A regression introduced in this PR fixed in https://github.com/bitcoin-core/gui/pull/102.
  76. MarcoFalke referenced this in commit ec0453cd57 on Oct 13, 2020
  77. janus referenced this in commit f1d2238bc3 on Dec 7, 2020
  78. Fabcien referenced this in commit f70965d1ae on Sep 19, 2021
  79. Fabcien referenced this in commit 6523a23ee8 on Sep 19, 2021
  80. deadalnix referenced this in commit 3f2ca7e8da on Sep 19, 2021
  81. DrahtBot locked this on Feb 15, 2022

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-07-01 13:12 UTC

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