Skip to content

Conversation

jonasschnelli
Copy link
Contributor

This PR moves manipulation and knowledge of vpwallet (the vector holding the CWallet* pointers) into CWalletManager. All access will go through the global g_wallet_manager (similar to g_connman).
This should it make easier to later add concurrency protection for wallet adding (loading) / unloading as well as it cleans up the code.

There is a lot of room for optimisation, but, to make faster progress, the scope of this PR should not be widened.

@jonasschnelli jonasschnelli force-pushed the 2018/03/dyn_wallet branch 3 times, most recently from ec44883 to e510ec4 Compare March 6, 2018 05:35
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

In #11402 I've changed to shared pointer to manage the lifecycle of wallets. Maybe that's out of scope?

// in Qt, use always the wallet with index 0 when running with multiple wallets
QByteArray encodedName = QUrl::toPercentEncoding(QString::fromStdString(vpwallets[0]->GetName()));
QByteArray encodedName = QUrl::toPercentEncoding(QString::fromStdString(g_wallet_manager->GetWalletAtPos(0)->GetName()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Between the above call HasWallets() and GetWalletAtPos() the wallet can be unloaded. Not possible at the moment, but maybe we should take the opportunity to add a lock to g_wallet_manager?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. The locking would be the next step (not only for this case). But its out of scope for this PR.

@@ -1274,10 +1271,10 @@ std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key);
class WalletRescanReserver
{
private:
CWalletRef m_wallet;
CWallet *m_wallet;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, CWallet* m_wallet;

#include <wallet/walletmanager.h>
#include <wallet/wallet.h>

std::unique_ptr<CWalletManager> g_wallet_manager;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be initialized here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Fixed.

unsigned int CountWallets();

template<typename Callable>
void ForEachWallet(Callable&& func)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just return a copy of the array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think a lambda is more flexible... same reason we use it in CNode/g_conman.

Copy link
Contributor

Choose a reason for hiding this comment

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

In g_connman makes sense because cs_vNodes is held all the time. Here we don't have locks. Even when we add dynamic wallets, IMHO the same pattern doesn't apply here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, once we add the locking (not the scope of this PR), then it makes more sense to keep the locking inside of the manager instead of returning a copy.

@jonasschnelli
Copy link
Contributor Author

Rebased. Fixed points reported by @promag and the travis issue.

@promag
Copy link
Contributor

promag commented Mar 26, 2018

Needs rebase.

@jonasschnelli
Copy link
Contributor Author

Rebased.

@jonasschnelli
Copy link
Contributor Author

I guess this makes no longer sense after #10762. Closing.

@promag promag mentioned this pull request Apr 20, 2018
@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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants