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: contributor

    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. ryanofsky cross-referenced this on May 28, 2020 from issue refactor: remove ::vpwallets and related global variables by ryanofsky
  3. DrahtBot added the label GUI on May 28, 2020
  4. DrahtBot added the label Refactoring on May 28, 2020
  5. DrahtBot added the label Tests on May 28, 2020
  6. DrahtBot added the label Wallet on May 28, 2020
  7. DrahtBot cross-referenced this on May 29, 2020 from issue wallet: Introduce and use DummyDatabase instead of dummy BerkeleyDatabase by achow101
  8. DrahtBot commented at 6:48 AM on May 29, 2020: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    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.

  9. DrahtBot cross-referenced this on May 29, 2020 from issue wallet: Add sqlite as an alternative wallet database and use it for new descriptor wallets by achow101
  10. DrahtBot cross-referenced this on May 29, 2020 from issue Reduce cs_main lock accumulation during GUI startup by jonasschnelli
  11. DrahtBot cross-referenced this on May 29, 2020 from issue wallet: Refactor the classes in wallet/db.{cpp/h} by achow101
  12. DrahtBot cross-referenced this on May 29, 2020 from issue wallet: Never schedule MaybeCompactWalletDB when -flushwallet is off by MarcoFalke
  13. DrahtBot added the label Needs rebase on May 29, 2020
  14. DrahtBot cross-referenced this on May 29, 2020 from issue Use shared pointers only in validation interface by bvbfan
  15. DrahtBot cross-referenced this on May 29, 2020 from issue net: Add NAT-PMP port forwarding support by hebasto
  16. DrahtBot cross-referenced this on May 29, 2020 from issue gui: Balance/TxStatus polling update based on last block hash. by furszy
  17. DrahtBot cross-referenced this on May 29, 2020 from issue qt, refactor: Make BitcoinUnits::Unit a scoped enum by hebasto
  18. ryanofsky force-pushed on May 29, 2020
  19. ryanofsky commented at 12:48 PM on May 29, 2020: contributor

    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

  20. DrahtBot removed the label Needs rebase on May 29, 2020
  21. DrahtBot cross-referenced this on May 30, 2020 from issue test: Remove duplicate NodeContext hacks by ryanofsky
  22. DrahtBot cross-referenced this on Jun 2, 2020 from issue wallettool: Add dump and createfromdump commands by achow101
  23. DrahtBot cross-referenced this on Jun 2, 2020 from issue Wallet passive startup by ryanofsky
  24. DrahtBot cross-referenced this on Jun 2, 2020 from issue Multiprocess bitcoin by ryanofsky
  25. DrahtBot cross-referenced this on Jun 4, 2020 from issue multiprocess: Add basic spawn and IPC support by ryanofsky
  26. ryanofsky force-pushed on Jun 4, 2020
  27. DrahtBot cross-referenced this on Jun 5, 2020 from issue refactor: Error message bilingual_str consistency by laanwj
  28. DrahtBot added the label Needs rebase on Jun 9, 2020
  29. ryanofsky force-pushed on Jun 10, 2020
  30. DrahtBot removed the label Needs rebase on Jun 10, 2020
  31. DrahtBot cross-referenced this on Jun 11, 2020 from issue Replace automatic bans with discouragement filter by sipa
  32. DrahtBot cross-referenced this on Jun 11, 2020 from issue UI external signer support (e.g. hardware wallet) by Sjors
  33. DrahtBot cross-referenced this on Jun 17, 2020 from issue wallet: BerkeleyDatabase make BerkeleyDatabase::Create, CreateMock, and CreateDummy non-static functions by achow101
  34. DrahtBot cross-referenced this on Jun 17, 2020 from issue wallet: Handle concurrent wallet loading by promag
  35. DrahtBot added the label Needs rebase on Jun 18, 2020
  36. ryanofsky force-pushed on Jun 19, 2020
  37. DrahtBot removed the label Needs rebase on Jun 19, 2020
  38. DrahtBot cross-referenced this on Jun 20, 2020 from issue build: Do not include server symbols in wallet by MarcoFalke
  39. DrahtBot cross-referenced this on Jun 25, 2020 from issue Remove the automatic creation and loading of the default wallet by achow101
  40. DrahtBot cross-referenced this on Jun 26, 2020 from issue Add loadwallet and createwallet load_on_startup options by ryanofsky
  41. 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

  42. 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

  43. promag commented at 11:04 PM on July 6, 2020: member

    Code review ACK after bases get merged and rebase. Nice work.

  44. DrahtBot added the label Needs rebase on Jul 7, 2020
  45. ryanofsky referenced this in commit 314395c17f on Jul 10, 2020
  46. ryanofsky force-pushed on Jul 10, 2020
  47. ryanofsky commented at 4:52 PM on July 10, 2020: contributor

    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

  48. DrahtBot removed the label Needs rebase on Jul 10, 2020
  49. DrahtBot cross-referenced this on Jul 11, 2020 from issue util: Make default arg values more specific by hebasto
  50. DrahtBot cross-referenced this on Jul 11, 2020 from issue multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky
  51. DrahtBot cross-referenced this on Jul 11, 2020 from issue multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky
  52. DrahtBot added the label Needs rebase on Jul 11, 2020
  53. ryanofsky referenced this in commit 2dbdb4355b on Jul 13, 2020
  54. ryanofsky referenced this in commit 86e2cbe8be on Jul 13, 2020
  55. ryanofsky referenced this in commit 7d82b31f1a on Jul 13, 2020
  56. ryanofsky force-pushed on Jul 13, 2020
  57. DrahtBot removed the label Needs rebase on Jul 13, 2020
  58. DrahtBot cross-referenced this on Jul 20, 2020 from issue Remove mempool global by MarcoFalke
  59. ryanofsky referenced this in commit edc316020e on Jul 21, 2020
  60. DrahtBot cross-referenced this on Jul 21, 2020 from issue refactor: Get rid of more redundant chain methods by ryanofsky
  61. DrahtBot cross-referenced this on Jul 29, 2020 from issue Remove wallet.dat path handling from wallet.cpp, rpcwallet.cpp by ryanofsky
  62. DrahtBot cross-referenced this on Jul 30, 2020 from issue Disable fee estimation in blocksonly mode (by removing the fee estimates global) by darosior
  63. MarcoFalke referenced this in commit 4b705b1c98 on Aug 7, 2020
  64. DrahtBot added the label Needs rebase on Aug 7, 2020
  65. sidhujag referenced this in commit 1e78f38193 on Aug 7, 2020
  66. ryanofsky referenced this in commit 943edf50ba on Aug 7, 2020
  67. ryanofsky referenced this in commit 75fc0cb723 on Aug 7, 2020
  68. ryanofsky force-pushed on Aug 7, 2020
  69. DrahtBot removed the label Needs rebase on Aug 7, 2020
  70. DrahtBot added the label Needs rebase on Aug 13, 2020
  71. ryanofsky referenced this in commit f7308a8a63 on Aug 13, 2020
  72. ryanofsky referenced this in commit 9ccb7b3f2f on Aug 13, 2020
  73. ryanofsky force-pushed on Aug 13, 2020
  74. DrahtBot removed the label Needs rebase on Aug 14, 2020
  75. DrahtBot added the label Needs rebase on Aug 15, 2020
  76. ryanofsky referenced this in commit 72acd6bca3 on Aug 17, 2020
  77. ryanofsky force-pushed on Aug 17, 2020
  78. ryanofsky referenced this in commit 05cc5d5856 on Aug 17, 2020
  79. DrahtBot removed the label Needs rebase on Aug 17, 2020
  80. DrahtBot cross-referenced this on Aug 20, 2020 from issue wallet, gui: Reload previously loaded wallets on startup by achow101
  81. DrahtBot cross-referenced this on Aug 22, 2020 from issue Remove gArgs global from init by MarcoFalke
  82. 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)?

            if (!AppInitInterfaces(node)) return false;
    

    MarcoFalke commented at 8:09 AM on August 31, 2020:

    seems to be addressed

  83. 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.

  84. 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

  85. 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

  86. DrahtBot added the label Needs rebase on Aug 26, 2020
  87. ryanofsky referenced this in commit c6ac47451f on Aug 26, 2020
  88. ryanofsky force-pushed on Aug 26, 2020
  89. ryanofsky referenced this in commit 3b2908d754 on Aug 26, 2020
  90. 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
  91. 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
  92. gui refactor: Inline SplashScreen::ConnectWallet
    Suggested https://github.com/bitcoin/bitcoin/pull/19099#discussion_r450522201
    24bf17602c
  93. ryanofsky force-pushed on Aug 28, 2020
  94. ryanofsky referenced this in commit 1c4542135d on Aug 28, 2020
  95. DrahtBot removed the label Needs rebase on Aug 28, 2020
  96. promag commented at 11:26 PM on August 30, 2020: member

    Code review ACK 24bf17602c620445f76c3b407937751c8a894d37.

    (actually reviewed in #19101)

  97. MarcoFalke removed the label GUI on Aug 31, 2020
  98. MarcoFalke removed the label Tests on Aug 31, 2020
  99. MarcoFalke removed the label Wallet on Aug 31, 2020
  100. 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

  101. 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:
        //! 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.

  102. MarcoFalke commented at 8:07 AM on August 31, 2020: member

    ACK 24bf17602c620445f76c3b407937751c8a894d37 ๐Ÿš

    <details><summary>Show signature and timestamp</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    ACK 24bf17602c620445f76c3b407937751c8a894d37 ๐Ÿš
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUjmewv/dJqaPdgxC1U3bn+w8eyykTimZGhO7qQeEkDFIM/KtzP62aCYhPeIUw4P
    5bvnVqwB7+xU6ulQ8bKQBfWIZQiyCehQ5xCrB6kdTO8U2jUnUqO4G3c3ypgqbUXd
    oNhRKT2P+V3XtkpU2DbAz+7n+B5GeoJA7OxXksEN8U9q3EdymgmTVVfeBQB36gtt
    GlfQYbCksyKl8cj6FN5l4D0pJKOqPgfS21jh7WEjHoKIPE8ttTLYelgXQeSijhci
    Iuc4NTts7l0dwTescpwOpVqyk0Mz/k6TshEZSDGaf7fjY26s5wz7RZFUVtYtICf8
    S2zYQDque8mwZTnaEs4dVo5wGG6dqpWK5fPEdQFDAskdsDiXLnumsYpZOH68V5ov
    62cztTrLVECqErAPjT0P+P/mBTrp8oHoTagzvrSO71Y/pyoc3zoAdNimxmT1K8ya
    GStgbd4W9ia6J8D1s/ov4rxmZBH2XPBBaTXpas4++8BYiPjmx+NkteVXjJsRNOX/
    ZNWwcqg0
    =TcZF
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash 77e30443c0b09185b05b8ce84203f4afece67e0a8bb120e17ec2f352a85547ac -

    </details>

  103. MarcoFalke merged this on Aug 31, 2020
  104. MarcoFalke closed this on Aug 31, 2020

  105. 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?

  106. sidhujag referenced this in commit bde41caa8d on Aug 31, 2020
  107. hebasto cross-referenced this on Oct 9, 2020 from issue Fix SplashScreen crash when run with -disablewallet by hebasto
  108. 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.

  109. MarcoFalke referenced this in commit ec0453cd57 on Oct 13, 2020
  110. janus referenced this in commit f1d2238bc3 on Dec 7, 2020
  111. Fabcien referenced this in commit f70965d1ae on Sep 19, 2021
  112. Fabcien referenced this in commit 6523a23ee8 on Sep 19, 2021
  113. deadalnix referenced this in commit 3f2ca7e8da on Sep 19, 2021
  114. bitcoin 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: 2026-05-20 06:54 UTC