Add wallets management functions #13017

pull promag wants to merge 3 commits into bitcoin:master from promag:2018-04-vpwallets changing 9 files +80 −41
  1. promag commented at 12:38 pm on April 18, 2018: member

    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.

  2. fanquake added the label Refactoring on Apr 18, 2018
  3. fanquake added the label Wallet on Apr 18, 2018
  4. refactor: Drop CWalletRef typedef 6efd9644cf
  5. promag force-pushed on Apr 18, 2018
  6. promag renamed this:
    Add AddWallet, RemoveWallet, GetWallet and GetWallets
    Add wallet management functions
    on Apr 18, 2018
  7. promag force-pushed on Apr 18, 2018
  8. promag renamed this:
    Add wallet management functions
    Add wallets management functions
    on Apr 18, 2018
  9. MarcoFalke commented at 12:49 pm on April 18, 2018: member
    Make sure to align this with the discussion in #10740 (comment)
  10. in src/wallet/wallet.cpp:39 in 418736582d outdated
    35 #include <boost/algorithm/string/replace.hpp>
    36 
    37-std::vector<CWalletRef> vpwallets;
    38+static std::vector<CWallet*> vpwallets;
    39+
    40+void AddWallet(CWallet* wallet)
    


    Empact commented at 12:53 pm on April 18, 2018:
    Do we want to provide guarantees that GetWallets returns no nullptrs? Could check here for that.

    promag commented at 1:01 pm on April 18, 2018:
    Added assertions in AddWallet and RemoveWallet. Also added a check to prevent adding the same wallet (RemoveWallet already checks if wallet exists).
  11. Empact commented at 12:59 pm on April 18, 2018: member
    If we’re doing shared ptrs alal #11402, CWalletRef would be preferable to auto IMO. #11402 (review)
  12. promag commented at 1:10 pm on April 18, 2018: member
    @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.
  13. in src/wallet/wallet.h:37 in 689de7c086 outdated
    31@@ -32,8 +32,11 @@
    32 #include <utility>
    33 #include <vector>
    34 
    35-typedef CWallet* CWalletRef;
    36-extern std::vector<CWalletRef> vpwallets;
    37+void AddWallet(CWallet* wallet);
    38+void RemoveWallet(CWallet* wallet);
    39+bool HasWallets();
    


    jnewbery commented at 2:55 pm on April 18, 2018:
    This might be more correctly named HasWallet(), since it returns true if there’s a single wallet

    promag commented at 4:19 pm on April 18, 2018:
    Maybe unsigned int CountWallets() is preferable?

    jnewbery commented at 4:28 pm on April 18, 2018:
    no need to overcomplicate it. HasWallets() is fine. I was just pointing out that the name could be a little bit more precise :slightly_smiling_face:
  14. jnewbery commented at 3:15 pm on April 18, 2018: member

    Tested ACK 689de7c08605643ebe48096c59e6810fbe3dc605.

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

  15. promag force-pushed on Apr 18, 2018
  16. promag commented at 8:24 pm on April 18, 2018: member
    @jnewbery squashed.
  17. in src/wallet/rpcwallet.cpp:51 in ac0de44a2f outdated
    52-            }
    53-        }
    54-        throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded");
    55+        CWallet* pwallet = GetWallet(requestedWallet);
    56+        if (!pwallet) throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded");
    57+        return pwallet;
    


    promag commented at 8:27 pm on April 18, 2018:
    Note to reviewers, I’ve switched these instructions. Inverted condition to throw the error.
  18. Empact commented at 8:39 pm on April 18, 2018: member
    Could you clang-format? Some whitespace inconsistencies.
  19. promag force-pushed on Apr 18, 2018
  20. promag commented at 9:03 pm on April 18, 2018: member
    @Empact done, sorry.
  21. wallet: Add AddWallet, RemoveWallet, GetWallet and GetWallets
    With these new functions all vpwallets usage are removed
    and vpwallets is now a static variable (no external linkage).
    373aee26c3
  22. wallet: Add HasWallets 3c058fdcc8
  23. promag force-pushed on Apr 18, 2018
  24. promag commented at 9:13 pm on April 18, 2018: member

    Latests changes are:

    • fix include order and whitespace
    • removed auto usage
    • added return bool to AddWallet and RemoveWallet.
  25. jnewbery commented at 9:22 pm on April 18, 2018: member
    ACK 3c058fdcc8a71d17296973cb7f09e44a310df22e.
  26. Empact commented at 10:06 pm on April 18, 2018: member
    utACK 3c058fd
  27. in src/wallet/wallet.cpp:43 in 3c058fdcc8
    39+
    40+bool AddWallet(CWallet* wallet)
    41+{
    42+    assert(wallet);
    43+    std::vector<CWallet*>::const_iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
    44+    if (i != vpwallets.end()) return false;
    


    kallewoof commented at 1:06 am on April 19, 2018:

    μNit: Maybe you could add an

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

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


    promag commented at 1:11 am on April 19, 2018:
    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.

    kallewoof commented at 1:16 am on April 19, 2018:
    That’s a pity, but no big deal.
  28. kallewoof approved
  29. kallewoof commented at 1:08 am on April 19, 2018: member

    utACK 3c058fdcc8a71d17296973cb7f09e44a310df22e

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

  30. promag commented at 1:15 am on April 19, 2018: member
    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.
  31. in src/wallet/wallet.h:271 in 3c058fdcc8
    270@@ -268,7 +271,7 @@ class CMerkleTx
    271 //Get the marginal bytes of spending the specified output
    272 int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* pwallet);
    273 
    274-/** 
    


    promag commented at 1:51 pm on April 19, 2018:
    I can remove these whitespace change if that is controversial.

    jnewbery commented at 2:46 pm on April 19, 2018:
    no - please don’t invalidate reviewer ACKs unnecessarily
  32. practicalswift commented at 2:01 pm on April 19, 2018: contributor
    Concept ACK
  33. MarcoFalke commented at 2:39 pm on April 19, 2018: member
    utACK 3c058fdcc8a71d17296973cb7f09e44a310df22e
  34. laanwj assigned laanwj on Apr 19, 2018
  35. laanwj commented at 9:26 am on April 20, 2018: member

    ACK on adding wallet management functions.

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

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

    I think this part still needs discussion. CWalletRef was introduced very recently as a generalized handle for wallets, to be able to turn it into some kind of smart pointer later. Hardcoding CWallet* complicates that.

  36. promag commented at 9:55 am on April 20, 2018: member

    I think this part still needs discussion. CWalletRef was introduced very recently

    Introduced in #8694, ping @luke-jr.

    Hardcoding CWallet* complicates that.

    Switching to shared pointers is not a matter of just changing the typedef.

    Anyway, if the commit is controversial I prefer to remove it, request re-ACK and defer this discussion, it’s really out of scope here.

  37. MarcoFalke commented at 4:24 pm on April 20, 2018: member
    It has been used in 12 instances or so, so not something to have a huge discussion about, imo.
  38. luke-jr commented at 6:29 pm on April 20, 2018: member
    CWalletRef shouldn’t be removed. It was specifically added to eventually become a shared_ptr when we have dynamic wallet loading/unloading.
  39. jnewbery commented at 6:42 pm on April 20, 2018: member

    CWalletRef shouldn’t be removed. It was specifically added to eventually become a shared_ptr when we have dynamic wallet loading/unloading.

    This PR doesn’t make changing to shared pointers any more or less difficult.

    #10740 builds on this. Like @MarcoFalke says, this is only used in a very few places, so let’s not hold up this PR for this.

  40. laanwj commented at 5:56 am on April 23, 2018: member

    it’s really out of scope here.

    Yes, that’s how I felt about that commit in the first place. Whether to have CWalletRef or not is not part of “Add wallets management functions”. Anyhow, I’ll merge this is if there is broad agreement.

  41. laanwj merged this on Apr 23, 2018
  42. laanwj closed this on Apr 23, 2018

  43. laanwj referenced this in commit 65d7083f15 on Apr 23, 2018
  44. laanwj referenced this in commit 783bb6455e on Apr 30, 2018
  45. PastaPastaPasta referenced this in commit a3386a3fda on Apr 14, 2020
  46. PastaPastaPasta referenced this in commit b0f08ae73f on Apr 14, 2020
  47. PastaPastaPasta referenced this in commit 11a45714e5 on Apr 14, 2020
  48. PastaPastaPasta referenced this in commit 10182d0444 on Apr 14, 2020
  49. PastaPastaPasta referenced this in commit b66df99b3f on Apr 14, 2020
  50. PastaPastaPasta referenced this in commit e4b122fbf7 on Apr 14, 2020
  51. PastaPastaPasta referenced this in commit 1688ad2f35 on Apr 15, 2020
  52. PastaPastaPasta referenced this in commit 4a9b935367 on Apr 15, 2020
  53. PastaPastaPasta referenced this in commit 5d02fa540e on Apr 15, 2020
  54. PastaPastaPasta referenced this in commit bdf4fb3cfc on Apr 15, 2020
  55. PastaPastaPasta referenced this in commit 93248e49d4 on Apr 15, 2020
  56. PastaPastaPasta referenced this in commit c0c46932d5 on Apr 15, 2020
  57. PastaPastaPasta referenced this in commit 2c986395d3 on Apr 16, 2020
  58. PastaPastaPasta referenced this in commit 4abf395478 on Apr 16, 2020
  59. PastaPastaPasta referenced this in commit af06fb5cd6 on Apr 16, 2020
  60. PastaPastaPasta referenced this in commit 5454e86f12 on Apr 16, 2020
  61. PastaPastaPasta referenced this in commit 1f98f82b33 on Apr 16, 2020
  62. PastaPastaPasta referenced this in commit 1217f87cb7 on Apr 16, 2020
  63. PastaPastaPasta referenced this in commit cd9f7e946d on Apr 17, 2020
  64. PastaPastaPasta referenced this in commit 4d1511483c on Apr 18, 2020
  65. PastaPastaPasta referenced this in commit a499f53a27 on Apr 18, 2020
  66. UdjinM6 referenced this in commit d3da914237 on Apr 23, 2020
  67. PastaPastaPasta referenced this in commit 852b46fb41 on Apr 23, 2020
  68. PastaPastaPasta referenced this in commit 4dcd8d1bea on Apr 23, 2020
  69. PastaPastaPasta referenced this in commit 2d8a3d1295 on Apr 26, 2020
  70. PastaPastaPasta referenced this in commit 35fa9feec2 on May 10, 2020
  71. PastaPastaPasta referenced this in commit 3d73de3381 on May 10, 2020
  72. ckti referenced this in commit a0b12ba5a3 on Mar 28, 2021
  73. ckti referenced this in commit ea688a5fbd on Mar 28, 2021
  74. MarcoFalke locked this on Sep 8, 2021

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-03 10:13 UTC

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