Skip to content

Conversation

promag
Copy link
Contributor

@promag promag commented Apr 18, 2018

This is a small step towards dynamic wallet load/unload. The wallets registry vpwallets is used in several places. With these new functions all vpwallets usage are removed and vpwallets is now a static variable (no external linkage).

The typedef CWalletRef is also removed as it is narrowly used.

@promag promag force-pushed the 2018-04-vpwallets branch from cb09fd3 to 8df99f9 Compare April 18, 2018 12:41
@promag promag changed the title Add AddWallet, RemoveWallet, GetWallet and GetWallets Add wallet management functions Apr 18, 2018
@promag promag force-pushed the 2018-04-vpwallets branch from b1fdc87 to 4187365 Compare April 18, 2018 12:48
@promag promag changed the title Add wallet management functions Add wallets management functions Apr 18, 2018
@maflcko
Copy link
Member

maflcko commented Apr 18, 2018

Make sure to align this with the discussion in #10740 (comment)

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

void AddWallet(CWallet* wallet)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to provide guarantees that GetWallets returns no nullptrs? Could check here for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added assertions in AddWallet and RemoveWallet. Also added a check to prevent adding the same wallet (RemoveWallet already checks if wallet exists).

@Empact
Copy link
Contributor

Empact commented Apr 18, 2018

If we're doing shared ptrs alal #11402, CWalletRef would be preferable to auto IMO. #11402 (comment)

@promag
Copy link
Contributor Author

promag commented Apr 18, 2018

@MarcoFalke afaiu yes. Having vpwallets centralised helps in adding concurrency, signals/notifications and eventually switching to shared pointers. I've also kept these as global functions as I'm not sure if these can belong to WalletInitInterface (imo no).

@Empact thanks for the review. I'm not saying we should use auto (it's not used at the moment). I'm not sure if consensus is to use CWalletRef instead of std::shared_ptr<CWallet> (when that happens). I can remove that commit if it's controversial.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

Tested ACK 689de7c08605643ebe48096c59e6810fbe3dc605.

Nice cleanup, one comment inline. Please squash final commit.

extern std::vector<CWalletRef> vpwallets;
void AddWallet(CWallet* wallet);
void RemoveWallet(CWallet* wallet);
bool HasWallets();
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be more correctly named HasWallet(), since it returns true if there's a single wallet

Copy link
Contributor Author

@promag promag Apr 18, 2018

Choose a reason for hiding this comment

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

Maybe unsigned int CountWallets() is preferable?

Copy link
Contributor

Choose a reason for hiding this comment

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

no need to overcomplicate it. HasWallets() is fine. I was just pointing out that the name could be a little bit more precise 🙂

@promag promag force-pushed the 2018-04-vpwallets branch from 689de7c to ac0de44 Compare April 18, 2018 17:41
@promag
Copy link
Contributor Author

promag commented Apr 18, 2018

@jnewbery squashed.

throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded");
CWallet* pwallet = GetWallet(requestedWallet);
if (!pwallet) throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded");
return pwallet;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewers, I've switched these instructions. Inverted condition to throw the error.

@Empact
Copy link
Contributor

Empact commented Apr 18, 2018

Could you clang-format? Some whitespace inconsistencies.

@promag promag force-pushed the 2018-04-vpwallets branch from ac0de44 to a2ea288 Compare April 18, 2018 21:02
@promag
Copy link
Contributor Author

promag commented Apr 18, 2018

@Empact done, sorry.

promag added 2 commits April 18, 2018 22:07
With these new functions all vpwallets usage are removed
and vpwallets is now a static variable (no external linkage).
@promag promag force-pushed the 2018-04-vpwallets branch from a2ea288 to 3c058fd Compare April 18, 2018 21:08
@promag
Copy link
Contributor Author

promag commented Apr 18, 2018

Latests changes are:

  • fix include order and whitespace
  • removed auto usage
  • added return bool to AddWallet and RemoveWallet.

@jnewbery
Copy link
Contributor

ACK 3c058fd.

@Empact
Copy link
Contributor

Empact commented Apr 18, 2018

utACK 3c058fd

Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

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

utACK 3c058fd

Nice clean-up. Agree about removing CWalletRef as it is mostly unused (and ambiguous -- I assumed it was a std::shared_ptr<CWallet> like CTransactionRef).

{
assert(wallet);
std::vector<CWallet*>::const_iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
if (i != vpwallets.end()) return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

μNit: Maybe you could add an

inline bool HasWallet(CWallet* wallet)
{
    assert(wallet);
    return std::find(vpwallets.begin(), vpwallets.end(), wallet) != vpwallets.end();
}

and use that here and below (also removing the assert in both places since it's done inline here).

Copy link
Contributor Author

@promag promag Apr 19, 2018

Choose a reason for hiding this comment

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

Your suggestion "conflicts" with adding a critical section here (which will come next). If I do as you say then the lock will be recursive, something we want to avoid AFAICK. So I'd avoid calls between these functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a pity, but no big deal.

@promag
Copy link
Contributor Author

promag commented Apr 19, 2018

Thanks for the review @kallewoof. Like @MarcoFalke said, this is a small piece of a large feature and I'd like to keep the PR scope on focus.

@@ -268,7 +271,7 @@ class CMerkleTx
//Get the marginal bytes of spending the specified output
int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* pwallet);

/**
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 can remove these whitespace change if that is controversial.

Copy link
Contributor

Choose a reason for hiding this comment

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

no - please don't invalidate reviewer ACKs unnecessarily

laanwj added a commit that referenced this pull request Apr 30, 2018
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in #13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in #10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 14, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 14, 2020
Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 14, 2020
…et and GetWallets

With these new functions all vpwallets usage are removed
and vpwallets is now a static variable (no external linkage).

Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 14, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 14, 2020
Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 14, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 15, 2020
Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 15, 2020
Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 15, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 15, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 15, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 15, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 16, 2020
Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 16, 2020
Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 16, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 16, 2020
Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 16, 2020
Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 16, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 17, 2020
3c058fd wallet: Add HasWallets (João Barbosa)
373aee2 wallet: Add AddWallet, RemoveWallet, GetWallet and GetWallets (João Barbosa)
6efd964 refactor: Drop CWalletRef typedef (João Barbosa)

Pull request description:

  This is a small step towards dynamic wallet load/unload. The wallets *registry* `vpwallets` is used in several places. With these new functions all `vpwallets` usage are removed and `vpwallets` is now a static variable (no external linkage).

  The typedef `CWalletRef` is also removed as it is narrowly used.

Tree-SHA512: 2ea19da2e17b521ad678bfe10f3257e497ccaf7ab9fd0b6647f9d829f1d6131cfa68db8e8492421711c6da399859432b963a568bdd4ca40a77dd95b597839423
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 18, 2020
3c058fd wallet: Add HasWallets (João Barbosa)
373aee2 wallet: Add AddWallet, RemoveWallet, GetWallet and GetWallets (João Barbosa)
6efd964 refactor: Drop CWalletRef typedef (João Barbosa)

Pull request description:

  This is a small step towards dynamic wallet load/unload. The wallets *registry* `vpwallets` is used in several places. With these new functions all `vpwallets` usage are removed and `vpwallets` is now a static variable (no external linkage).

  The typedef `CWalletRef` is also removed as it is narrowly used.

Tree-SHA512: 2ea19da2e17b521ad678bfe10f3257e497ccaf7ab9fd0b6647f9d829f1d6131cfa68db8e8492421711c6da399859432b963a568bdd4ca40a77dd95b597839423
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 18, 2020
3c058fd wallet: Add HasWallets (João Barbosa)
373aee2 wallet: Add AddWallet, RemoveWallet, GetWallet and GetWallets (João Barbosa)
6efd964 refactor: Drop CWalletRef typedef (João Barbosa)

Pull request description:

  This is a small step towards dynamic wallet load/unload. The wallets *registry* `vpwallets` is used in several places. With these new functions all `vpwallets` usage are removed and `vpwallets` is now a static variable (no external linkage).

  The typedef `CWalletRef` is also removed as it is narrowly used.

Tree-SHA512: 2ea19da2e17b521ad678bfe10f3257e497ccaf7ab9fd0b6647f9d829f1d6131cfa68db8e8492421711c6da399859432b963a568bdd4ca40a77dd95b597839423
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Apr 23, 2020
3c058fd wallet: Add HasWallets (João Barbosa)
373aee2 wallet: Add AddWallet, RemoveWallet, GetWallet and GetWallets (João Barbosa)
6efd964 refactor: Drop CWalletRef typedef (João Barbosa)

Pull request description:

  This is a small step towards dynamic wallet load/unload. The wallets *registry* `vpwallets` is used in several places. With these new functions all `vpwallets` usage are removed and `vpwallets` is now a static variable (no external linkage).

  The typedef `CWalletRef` is also removed as it is narrowly used.

Tree-SHA512: 2ea19da2e17b521ad678bfe10f3257e497ccaf7ab9fd0b6647f9d829f1d6131cfa68db8e8492421711c6da399859432b963a568bdd4ca40a77dd95b597839423
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 23, 2020
3c058fd wallet: Add HasWallets (João Barbosa)
373aee2 wallet: Add AddWallet, RemoveWallet, GetWallet and GetWallets (João Barbosa)
6efd964 refactor: Drop CWalletRef typedef (João Barbosa)

Pull request description:

  This is a small step towards dynamic wallet load/unload. The wallets *registry* `vpwallets` is used in several places. With these new functions all `vpwallets` usage are removed and `vpwallets` is now a static variable (no external linkage).

  The typedef `CWalletRef` is also removed as it is narrowly used.

Tree-SHA512: 2ea19da2e17b521ad678bfe10f3257e497ccaf7ab9fd0b6647f9d829f1d6131cfa68db8e8492421711c6da399859432b963a568bdd4ca40a77dd95b597839423
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 23, 2020
3c058fd wallet: Add HasWallets (João Barbosa)
373aee2 wallet: Add AddWallet, RemoveWallet, GetWallet and GetWallets (João Barbosa)
6efd964 refactor: Drop CWalletRef typedef (João Barbosa)

Pull request description:

  This is a small step towards dynamic wallet load/unload. The wallets *registry* `vpwallets` is used in several places. With these new functions all `vpwallets` usage are removed and `vpwallets` is now a static variable (no external linkage).

  The typedef `CWalletRef` is also removed as it is narrowly used.

Tree-SHA512: 2ea19da2e17b521ad678bfe10f3257e497ccaf7ab9fd0b6647f9d829f1d6131cfa68db8e8492421711c6da399859432b963a568bdd4ca40a77dd95b597839423
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 26, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 10, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 10, 2020
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
@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.

9 participants