Skip to content

Conversation

promag
Copy link
Contributor

@promag promag commented Sep 25, 2017

This is a small step towards better multi wallet management. Starts by removing the global vpwallets and adding an interface to add/remove/retrieve wallets.

The way it is now it is possible to have, for instance, listunspent RPC and in parallel unload the wallet (once #10740 is merged) without blocking. Once the RPC finishes, the shared pointer will release the wallet.

It is also possible to get all existing wallets without blocking because the caller keeps a local list of shared pointers.

I would like to include either here or in follow ups:

  • kind of WalletManager class;
  • keep a weak pointer so when the app terminates it is possible to gracefully unload the wallet;
  • make the new interface thread safe.

Please consider this RFC.

This is related to #10615, #11383 and #10740.

@promag promag force-pushed the 2017-09-wallet-shared-pointer branch from f0e9d5b to 3191f84 Compare September 25, 2017 23:15
@@ -37,7 +37,36 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/thread.hpp>

std::vector<CWalletRef> vpwallets;
static std::vector<std::shared_ptr<CWallet>> vpwallets;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should typedef std::shared_ptr<CWallet> CWalletRef

std::vector<CWalletRef> vpwallets;
static std::vector<std::shared_ptr<CWallet>> vpwallets;

bool AddWallet(std::shared_ptr<CWallet> pwallet)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These all need locking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment no because wallets are added at startup. This is mentioned in the PR description:

make the new interface thread safe.

@promag promag force-pushed the 2017-09-wallet-shared-pointer branch from 57a0659 to 85b2b4f Compare September 26, 2017 13:35
@TheBlueMatt
Copy link
Contributor

Needs rebase. Maybe @jnewbery wants to give this a concept review in how it interacts (or doesnt) with #10740?

@promag
Copy link
Contributor Author

promag commented Dec 14, 2017

@jnewbery ping.

@jnewbery
Copy link
Contributor

What's the status of this PR now that #12587 is open?

@promag
Copy link
Contributor Author

promag commented Mar 27, 2018

I think both are valid. This PR changes the ownership of the wallets. For example this PR allows:

listunspent RPC and in parallel unload the wallet (once #10740 is merged) without blocking. Once the RPC finishes, the shared pointer will release the wallet.

I'm happy to update this once there is more positive feedback.

@promag promag changed the title [wallet] Use shared pointer for wallet instances Use shared pointer for wallet instances Apr 7, 2018
@promag
Copy link
Contributor Author

promag commented Apr 18, 2018

This PR includes some changes that are now in #13017. Please review that first.

@promag promag closed this Apr 23, 2018
@promag promag deleted the 2017-09-wallet-shared-pointer branch April 23, 2018 23:15
laanwj added a commit that referenced this pull request May 24, 2018
80b4910 wallet: Use shared pointer to retain wallet instance (João Barbosa)

Pull request description:

  Currently there are 3 places where it makes sense to retain a wallet shared pointer:
   - `vpwallets`;
   - `interfaces::Wallet` interface instance - used by the UI;
   - wallet RPC functions - given by `GetWalletForJSONRPCRequest`.

  The way it is now it is possible to have, for instance, listunspent RPC and in parallel unload the wallet (once #13111 is merged) without blocking. Once the RPC finishes, the shared pointer will release the wallet.

  It is also possible to get all existing wallets without blocking because the caller keeps a local list of shared pointers.

  This is mostly relevant for wallet unloading.

  This PR replaces #11402.

Tree-SHA512: b7e37c7e1ab56626085afe2d40b1628e8d4f0dbda08df01b7e618ecd2d894ce9b83d4219443f444ba889096286eff002f163cb0a48f37063b62e9ba4ccfa6cce
xdustinface pushed a commit to xdustinface/dash that referenced this pull request Mar 31, 2021
80b4910 wallet: Use shared pointer to retain wallet instance (João Barbosa)

Pull request description:

  Currently there are 3 places where it makes sense to retain a wallet shared pointer:
   - `vpwallets`;
   - `interfaces::Wallet` interface instance - used by the UI;
   - wallet RPC functions - given by `GetWalletForJSONRPCRequest`.

  The way it is now it is possible to have, for instance, listunspent RPC and in parallel unload the wallet (once bitcoin#13111 is merged) without blocking. Once the RPC finishes, the shared pointer will release the wallet.

  It is also possible to get all existing wallets without blocking because the caller keeps a local list of shared pointers.

  This is mostly relevant for wallet unloading.

  This PR replaces bitcoin#11402.

Tree-SHA512: b7e37c7e1ab56626085afe2d40b1628e8d4f0dbda08df01b7e618ecd2d894ce9b83d4219443f444ba889096286eff002f163cb0a48f37063b62e9ba4ccfa6cce
xdustinface pushed a commit to xdustinface/dash that referenced this pull request Mar 31, 2021
80b4910 wallet: Use shared pointer to retain wallet instance (João Barbosa)

Pull request description:

  Currently there are 3 places where it makes sense to retain a wallet shared pointer:
   - `vpwallets`;
   - `interfaces::Wallet` interface instance - used by the UI;
   - wallet RPC functions - given by `GetWalletForJSONRPCRequest`.

  The way it is now it is possible to have, for instance, listunspent RPC and in parallel unload the wallet (once bitcoin#13111 is merged) without blocking. Once the RPC finishes, the shared pointer will release the wallet.

  It is also possible to get all existing wallets without blocking because the caller keeps a local list of shared pointers.

  This is mostly relevant for wallet unloading.

  This PR replaces bitcoin#11402.

Tree-SHA512: b7e37c7e1ab56626085afe2d40b1628e8d4f0dbda08df01b7e618ecd2d894ce9b83d4219443f444ba889096286eff002f163cb0a48f37063b62e9ba4ccfa6cce
xdustinface pushed a commit to xdustinface/dash that referenced this pull request Mar 31, 2021
80b4910 wallet: Use shared pointer to retain wallet instance (João Barbosa)

Pull request description:

  Currently there are 3 places where it makes sense to retain a wallet shared pointer:
   - `vpwallets`;
   - `interfaces::Wallet` interface instance - used by the UI;
   - wallet RPC functions - given by `GetWalletForJSONRPCRequest`.

  The way it is now it is possible to have, for instance, listunspent RPC and in parallel unload the wallet (once bitcoin#13111 is merged) without blocking. Once the RPC finishes, the shared pointer will release the wallet.

  It is also possible to get all existing wallets without blocking because the caller keeps a local list of shared pointers.

  This is mostly relevant for wallet unloading.

  This PR replaces bitcoin#11402.

Tree-SHA512: b7e37c7e1ab56626085afe2d40b1628e8d4f0dbda08df01b7e618ecd2d894ce9b83d4219443f444ba889096286eff002f163cb0a48f37063b62e9ba4ccfa6cce
xdustinface pushed a commit to xdustinface/dash that referenced this pull request Apr 1, 2021
80b4910 wallet: Use shared pointer to retain wallet instance (João Barbosa)

Pull request description:

  Currently there are 3 places where it makes sense to retain a wallet shared pointer:
   - `vpwallets`;
   - `interfaces::Wallet` interface instance - used by the UI;
   - wallet RPC functions - given by `GetWalletForJSONRPCRequest`.

  The way it is now it is possible to have, for instance, listunspent RPC and in parallel unload the wallet (once bitcoin#13111 is merged) without blocking. Once the RPC finishes, the shared pointer will release the wallet.

  It is also possible to get all existing wallets without blocking because the caller keeps a local list of shared pointers.

  This is mostly relevant for wallet unloading.

  This PR replaces bitcoin#11402.

Tree-SHA512: b7e37c7e1ab56626085afe2d40b1628e8d4f0dbda08df01b7e618ecd2d894ce9b83d4219443f444ba889096286eff002f163cb0a48f37063b62e9ba4ccfa6cce
PastaPastaPasta pushed a commit to dashpay/dash that referenced this pull request Apr 1, 2021
)

80b4910 wallet: Use shared pointer to retain wallet instance (João Barbosa)

Pull request description:

  Currently there are 3 places where it makes sense to retain a wallet shared pointer:
   - `vpwallets`;
   - `interfaces::Wallet` interface instance - used by the UI;
   - wallet RPC functions - given by `GetWalletForJSONRPCRequest`.

  The way it is now it is possible to have, for instance, listunspent RPC and in parallel unload the wallet (once bitcoin#13111 is merged) without blocking. Once the RPC finishes, the shared pointer will release the wallet.

  It is also possible to get all existing wallets without blocking because the caller keeps a local list of shared pointers.

  This is mostly relevant for wallet unloading.

  This PR replaces bitcoin#11402.

Tree-SHA512: b7e37c7e1ab56626085afe2d40b1628e8d4f0dbda08df01b7e618ecd2d894ce9b83d4219443f444ba889096286eff002f163cb0a48f37063b62e9ba4ccfa6cce

Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com>
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants