wallet: batch and simplify addressbook migration process #26836

pull furszy wants to merge 6 commits into bitcoin:master from furszy:2022_wallet_finish_addressbook_encapsulation changing 2 files +111 −72
  1. furszy commented at 1:05 pm on January 6, 2023: member

    Commits decoupled from #28574, focused on the address book cloning process

    Includes:

    1. DB batch operations and flow simplification for the address book migration process.
    2. Code improvements to CWallet::DelAddressBook and Wallet::SetAddrBookWithDB methods.

    These changes will let us consolidate all individual write operations that take place during the wallet migration process into a single db txn in the future.

  2. DrahtBot commented at 1:05 pm on January 6, 2023: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK achow101, josibake
    Concept ACK rserranon, hernanmarino
    Approach ACK w0xlt
    Stale ACK pablomartin4btc

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29403 (wallet: batch erase procedures and improve ‘EraseRecords’ performance by furszy)

    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.

  3. DrahtBot added the label Wallet on Jan 6, 2023
  4. w0xlt commented at 12:38 pm on January 9, 2023: contributor
    Approach ACK. I will review soon.
  5. in src/wallet/wallet.h:484 in 093203ecc2 outdated
    479@@ -480,6 +480,12 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
    480 
    481     //! Adds a destination data tuple to the store, without saving it to disk
    482     void LoadDestData(const CTxDestination& dest, const std::string& key, const std::string& value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
    483+    //! Adds destination label to the store, without saving it to disk
    484+    void LoadAddrbookEntryLabel(const CTxDestination& dest, const std::string& label) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
    


    rserranon commented at 8:12 pm on February 24, 2023:
    Nit: Shouldn’t be better to use the capital B in LoadAddrBookEntryLablel and LoadAddrBookEntryPurpose as in GetAddrBookSize and ListAddrBookAddreses ?

    furszy commented at 2:03 pm on February 27, 2023:
    done
  6. in src/wallet/wallet.cpp:2462 in ea6b17d1ae outdated
    2393@@ -2394,31 +2394,42 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
    2394 
    2395 bool CWallet::DelAddressBook(const CTxDestination& address)
    2396 {
    2397-    bool is_mine;
    2398+    isminetype is_mine;
    2399+    const std::string& dest = EncodeDestination(address);
    


    rserranon commented at 11:38 pm on February 24, 2023:
    Nice optimization!
  7. rserranon commented at 11:38 pm on February 24, 2023: none

    Concept ACK,

    I understand this may become a separate commit, but why not encapsulate the other calls to wallet->m_address_book[addr_pair.first].purpose = purpose ?

    0src/wallet/wallet.cpp:3980:                            data.watchonly_wallet->m_address_book[addr_pair.first].purpose = purpose;
    1src/wallet/wallet.cpp:3996:                            data.solvable_wallet->m_address_book[addr_pair.first].purpose = purpose;
    2src/wallet/wallet.cpp:4017:                    data.watchonly_wallet->m_address_book[addr_pair.first].purpose = purpose;
    3src/wallet/wallet.cpp:4030:                    data.solvable_wallet->m_address_book[addr_pair.first].purpose = purpose;
    

    If m_address_book has been encapsulated, why not make it private or protected?

  8. furszy commented at 1:53 pm on February 27, 2023: member

    Thanks @rserranon.

    why not encapsulate the other calls to wallet->m_address_book[addr_pair.first].purpose = purpose ?

    Good catch. I did this changes prior the wallet migration PR merge. Will add those too and make the addressbook member private so we don’t keep adding more in the future.

  9. furszy force-pushed on Feb 27, 2023
  10. furszy force-pushed on Feb 27, 2023
  11. furszy commented at 2:13 pm on February 27, 2023: member

    Updated per feedback. Now we no longer access the wallet’s addressbook member externally.

    Plus, improvements to the address book migration process:

    1. Fixed a bug where we don’t copy the “send” records to all the wallets.
    2. Have re-written the process with no code duplication.
    3. Batched db writes so the disk dump is done all at once.
  12. furszy requested review from rserranon on Mar 6, 2023
  13. rserranon approved
  14. rserranon commented at 1:13 am on March 7, 2023: none

    tAck

    • unit tests
    • functional tests
    • qt & bitcoin-cli manual tests
  15. furszy requested review from w0xlt on Mar 12, 2023
  16. hernanmarino approved
  17. hernanmarino commented at 11:31 pm on March 26, 2023: contributor
    tested ACK, both unit and functional tests.
  18. in src/wallet/wallet.cpp:4045 in 0053949919 outdated
    4058-                    data.solvable_wallet->m_address_book[addr_pair.first].SetLabel(label);
    4059+    for (const auto& [dest, record] : m_address_book) {
    4060+        // Append "receive" data to other wallets only if not mine.
    4061+        // Labels for everything else ("send") should be cloned to all.
    4062+        bool require_is_mine = record.purpose == "receive" && !IsMine(dest);
    4063+        bool copied = false;
    


    pablomartin4btc commented at 4:33 am on March 27, 2023:

    nit:

    0        bool require_is_mine{record.purpose == "receive" && !IsMine(dest)};
    1        bool copied{false};
    

    furszy commented at 3:21 pm on March 27, 2023:
    I prefer the current code, it’s more readable. The curly braces initializer is primarily useful to prevent narrowing (which is the implicit conversion of arithmetic values). Here, there is no loss of accuracy, we are simply initializing a boolean from a logical statement.
  19. in src/wallet/wallet.cpp:2462 in 0053949919 outdated
    2409@@ -2394,31 +2410,42 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
    2410 
    2411 bool CWallet::DelAddressBook(const CTxDestination& address)
    2412 {
    2413-    bool is_mine;
    2414+    isminetype is_mine;
    2415+    const std::string& dest = EncodeDestination(address);
    


    pablomartin4btc commented at 4:34 am on March 27, 2023:
    0    const std::string& dest{EncodeDestination(address)};
    

    furszy commented at 3:36 pm on March 27, 2023:
    Thanks but same as above, I prefer current code as it’s more readable and there is no possible narrowing issue here.
  20. pablomartin4btc commented at 4:44 am on March 27, 2023: member
    Approach ACK. I’ll perform some testing soon.
  21. pablomartin4btc approved
  22. pablomartin4btc commented at 3:11 pm on April 5, 2023: member
    tested ACK. On the code review, went thru the different commits of the PR. Performed manual testing using bitcoin-qt.
  23. DrahtBot added the label Needs rebase on Apr 12, 2023
  24. furszy force-pushed on Apr 12, 2023
  25. DrahtBot removed the label Needs rebase on Apr 12, 2023
  26. furszy force-pushed on Apr 12, 2023
  27. furszy commented at 4:12 pm on April 12, 2023: member
    Rebased, conflicts solved. Plus, per #26761 (review) request, added coverage for wallet address book migration process.
  28. pablomartin4btc commented at 3:14 pm on April 21, 2023: member
    re-ACK 8fa0db1d487d76e3fa5ace0bd4d9a8b6bf8dbde1
  29. DrahtBot removed review request from w0xlt on Apr 21, 2023
  30. furszy force-pushed on May 1, 2023
  31. furszy commented at 12:32 pm on May 1, 2023: member
    rebased post #27224 merge, conflicts solved.
  32. furszy renamed this:
    wallet: finish addressbook encapsulation
    wallet: finish addressbook encapsulation and ApplyMigrationData code simplification
    on May 1, 2023
  33. furszy renamed this:
    wallet: finish addressbook encapsulation and ApplyMigrationData code simplification
    wallet: finish addressbook encapsulation and simplify addressbook migration
    on May 4, 2023
  34. DrahtBot added the label Needs rebase on May 27, 2023
  35. furszy force-pushed on May 31, 2023
  36. furszy commented at 3:37 pm on May 31, 2023: member
    rebased
  37. DrahtBot removed the label Needs rebase on May 31, 2023
  38. DrahtBot added the label Needs rebase on Jun 20, 2023
  39. furszy force-pushed on Jun 21, 2023
  40. furszy renamed this:
    wallet: finish addressbook encapsulation and simplify addressbook migration
    wallet: simplify addressbook migration and encapsulate access
    on Jun 21, 2023
  41. DrahtBot removed the label Needs rebase on Jun 21, 2023
  42. furszy commented at 3:19 pm on June 21, 2023: member
    rebased, conflicts solved.
  43. DrahtBot added the label Needs rebase on Jun 28, 2023
  44. furszy renamed this:
    wallet: simplify addressbook migration and encapsulate access
    wallet: simplify and add coverage for addressbook migration
    on Jun 28, 2023
  45. furszy force-pushed on Jun 28, 2023
  46. DrahtBot removed the label Needs rebase on Jun 28, 2023
  47. furszy force-pushed on Jul 5, 2023
  48. furszy renamed this:
    wallet: simplify and add coverage for addressbook migration
    wallet: fix bug, simplify and add coverage for addressbook migration
    on Jul 5, 2023
  49. DrahtBot added the label CI failed on Jul 5, 2023
  50. achow101 commented at 3:42 pm on July 6, 2023: member
    This PR ends up doing a lot of different things that are only tangentially related. I think it could be split up into a few smaller PRs, e.g. one for the migration fix, one for the migration refactoring, and one for the other refactors.
  51. furszy commented at 3:52 pm on July 6, 2023: member

    This PR ends up doing a lot of different things that are only tangentially related. I think it could be split up into a few smaller PRs, e.g. one for the migration fix, one for the migration refactoring, and one for the other refactors.

    sure, will work on it.

  52. DrahtBot removed the label CI failed on Jul 6, 2023
  53. DrahtBot added the label Needs rebase on Jul 7, 2023
  54. furszy force-pushed on Jul 12, 2023
  55. furszy renamed this:
    wallet: fix bug, simplify and add coverage for addressbook migration
    wallet: simplify addressbook migration process
    on Jul 12, 2023
  56. DrahtBot removed the label Needs rebase on Jul 12, 2023
  57. furszy force-pushed on Jul 18, 2023
  58. DrahtBot added the label Needs rebase on Sep 19, 2023
  59. achow101 marked this as a draft on Sep 20, 2023
  60. furszy force-pushed on Jan 21, 2024
  61. furszy commented at 4:12 pm on January 21, 2024: member
    In response to feedback, the PR scope has been shortened, omitting the address book encapsulation commits. The current version includes only the subset of commits related to the address book from #28574. Decoupling this PR into two is also possible upon request.
  62. furszy marked this as ready for review on Jan 21, 2024
  63. DrahtBot removed the label Needs rebase on Jan 21, 2024
  64. furszy renamed this:
    wallet: simplify addressbook migration process
    wallet: batch and simplify addressbook migration process
    on Jan 24, 2024
  65. in src/wallet/wallet.cpp:2395 in da3b8f927c outdated
    2384@@ -2385,6 +2385,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
    2385 
    


    josibake commented at 7:52 pm on February 2, 2024:

    in “wallet: clean redundancies in DelAddressBook” (https://github.com/bitcoin/bitcoin/pull/26836/commits/da3b8f927c2da5b7761e36fe548eb8ade29171d7):

    nit: your commit message mentions “Call IsMine only once (instead of two)” but I don’t see any IsMine related changes in the commit?


    furszy commented at 1:18 pm on February 5, 2024:
    Because I made this commit before e83babe (#27217), which removed the IsMine calls, and I forgot to update the commit description after the rebase. Will clean it, thanks.
  66. in src/wallet/wallet.cpp:2376 in 0b83c8691b outdated
    2367@@ -2368,13 +2368,21 @@ bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& add
    2368             purpose = m_address_book[address].purpose;
    2369         }
    2370     }
    2371+
    2372+    if (new_purpose && !batch.WritePurpose(EncodeDestination(address), PurposeToString(*new_purpose))) {
    2373+        WalletLogPrintf("%s error writing purpose\n", __func__);
    2374+        return false;
    2375+    }
    2376+    if (!batch.WriteName(EncodeDestination(address), strName)) {
    


    josibake commented at 7:57 pm on February 2, 2024:

    in “refactor: SetAddrBookWithDB, signal only if write succeeded” (https://github.com/bitcoin/bitcoin/pull/26836/commits/0b83c8691b277d407e61a8ffca807e65866f4ded):

    Maybe do encoded_dest = EncodeDestination(address) and then use that to avoid calling EncodeDestination twice?


    furszy commented at 1:22 pm on February 5, 2024:
    sure
  67. in src/wallet/wallet.cpp:2362 in 10f9639fd6 outdated
    2358@@ -2359,14 +2359,15 @@ bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& add
    2359     {
    2360         LOCK(cs_wallet);
    2361         std::map<CTxDestination, CAddressBookData>::iterator mi = m_address_book.find(address);
    2362-        fUpdated = (mi != m_address_book.end() && !mi->second.IsChange());
    2363-        m_address_book[address].SetLabel(strName);
    2364+        fUpdated = mi != m_address_book.end() && !mi->second.IsChange();
    


    josibake commented at 8:02 pm on February 2, 2024:

    in “refactor: SetAddressBookWithDB, minimize number of map lookups” (https://github.com/bitcoin/bitcoin/pull/26836/commits/10f9639fd6332cdd440f540c2202082044aab98c):

    nit: unnecessary formatting change


    furszy commented at 1:37 pm on February 5, 2024:
    As we will never merge a PR solely removing the extra parentheses, we can either clean them now while working on this function or we keep them for another decade. I prefer to clean them now, but np in reverting the line if it conflicts with the review process.
  68. in src/wallet/wallet.cpp:4058 in 8b331613bf outdated
    4038+
    4039+            copied = true;
    4040+            // Only delete 'receive' records that are no longer part of the original wallet
    4041+            if (require_transfer) {
    4042+                dests_to_delete.push_back(dest);
    4043+                break;
    


    josibake commented at 8:45 pm on February 2, 2024:

    in “refactor: wallet, simplify addressbook migration” (https://github.com/bitcoin/bitcoin/pull/26836/commits/8b331613bf79ab614850e71a603dd444d6bb3a48):

    This is a pretty thorny block of code with all of the booleans, let me summarize just to make sure I’m following:

    • If the destination requires_transfer but isn’t ours, go to the next wallet. If this happens for both wallets, copy will never be set and we will fail
    • If it requires transfer and does belong to the current wallet in the loop, continue and set copy = true, and add the destination to dests_to_delete. Do not check the next wallet. I’m assuming the assumption here is it can only belong to one of the wallets, and if it does end up happening to belong to both wallets this is not an issue?
    • If it does not require transfer, we always copy it, and copy is always set to true, so we are fine for the next block

    Might be worth adding a comment explaining why its okay to break early? That’s the part that kinda threw me.


    furszy commented at 2:26 pm on February 5, 2024:

    If the destination requires_transfer but isn’t ours, go to the next wallet. If this happens for both wallets, copy will never be set and we will fail

    If the destination requires transfer (a “receive” addr that is no longer part of the main wallet), the process checks to which wallet the entry belongs to. And, when the entry does not belong to any of the created wallets, it means that the key/script-to-descriptor migration process failed. This is because “receive” entries must always be tracked by the wallet.

    If it requires transfer and does belong to the current wallet in the loop, continue and set copy = true, and add the destination to dests_to_delete. Do not check the next wallet. I’m assuming the assumption here is it can only belong to one of the wallets, and if it does end up happening to belong to both wallets this is not an issue?

    Yes, thats the existing assumption. If you check the previous code, will see that I did not change this part of the flow on purpose. This is what we had before:

     0if (purpose == "RECEIVE" && not_mine_anymore) {
     1
     2    // check if it is part of the watch-only wallet
     3    if (watch_only_wallet.IsMine(dest)) {
     4        store_address(watch_only_wallet, dest);
     5        add_to_pending_to_delete(dest);
     6        continue; // --> this skips the next wallet.
     7    } 
     8
     9    // check if it is part of the solvables wallet
    10    if (solvables_wallet.IsMine(dest)) {
    11        store_address(solvables_wallet, dest);
    12        add_to_pending_to_delete(dest);
    13        continue; // --> skips any following-up check
    14    } 
    15
    16    // We only reach here if the entry wasn't added to any wallet
    17    error out...
    18}
    

    The only diff between the new code and the previous one is that we had a continue instead of a break statement.

    Might be worth adding a comment explaining why it’s okay to break early? That’s the part that kinda threw me.

    We should double-check if we could ever have the same no-longer ours “receive” entry in both wallets (the watch-only and the solvables ones). If we find a way to achieve this, then the bug predates this PR.

  69. in src/wallet/wallet.cpp:2401 in 3aff6d5b4f outdated
    2393@@ -2394,8 +2394,13 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
    2394 
    2395 bool CWallet::DelAddressBook(const CTxDestination& address)
    2396 {
    2397-    const std::string& dest = EncodeDestination(address);
    2398     WalletBatch batch(GetDatabase());
    2399+    return DelAddressBookWithDb(batch, address);
    2400+}
    2401+
    2402+bool CWallet::DelAddressBookWithDb(WalletBatch& batch, const CTxDestination& address)
    


    josibake commented at 8:54 pm on February 2, 2024:

    in “wallet: migration, batch addressbook records removal” (https://github.com/bitcoin/bitcoin/pull/26836/commits/3aff6d5b4f3fd32ad1285b259db0ef1580518e39):

    nit: most other places in the codebase we use DB in functions names (as opposed to Db)


    furszy commented at 2:34 pm on February 5, 2024:
    sure
  70. in src/wallet/wallet.cpp:4068 in 8b331613bf outdated
    4068-            if (data.solvable_wallet) {
    4069-                LOCK(data.solvable_wallet->cs_wallet);
    4070-                // Add to the solvable. Copy the entire address book entry
    4071-                data.solvable_wallet->m_address_book[addr_pair.first] = addr_pair.second;
    4072+            // Skip invalid/non-watched scripts that will not be migrated
    4073+            if (not_migrated_dests.count(dest) > 0) {
    


    josibake commented at 9:00 pm on February 2, 2024:

    in “refactor: wallet, simplify addressbook migration” (https://github.com/bitcoin/bitcoin/pull/26836/commits/8b331613bf79ab614850e71a603dd444d6bb3a48):

    nit: C++20 has .contains(arg) for sets (yay!). No performance difference, but semantically I think it makes a lot more sense to use when testing for existence.

  71. josibake approved
  72. josibake commented at 9:04 pm on February 2, 2024: member

    crACK https://github.com/bitcoin/bitcoin/pull/26836/commits/3aff6d5b4f3fd32ad1285b259db0ef1580518e39

    Looks good! Code reviewed, didn’t verify the bench numbers. Left some nits, feel free to ignore

  73. DrahtBot requested review from w0xlt on Feb 2, 2024
  74. DrahtBot requested review from rserranon on Feb 2, 2024
  75. DrahtBot requested review from pablomartin4btc on Feb 2, 2024
  76. DrahtBot requested review from hernanmarino on Feb 2, 2024
  77. DrahtBot removed review request from w0xlt on Feb 2, 2024
  78. DrahtBot removed review request from rserranon on Feb 2, 2024
  79. DrahtBot removed review request from hernanmarino on Feb 2, 2024
  80. DrahtBot requested review from rserranon on Feb 2, 2024
  81. DrahtBot requested review from hernanmarino on Feb 2, 2024
  82. DrahtBot requested review from w0xlt on Feb 2, 2024
  83. furszy commented at 2:30 pm on February 5, 2024: member
    Updated per feedback, thanks for the review josie!
  84. DrahtBot removed review request from rserranon on Feb 5, 2024
  85. DrahtBot removed review request from hernanmarino on Feb 5, 2024
  86. DrahtBot removed review request from w0xlt on Feb 5, 2024
  87. DrahtBot requested review from w0xlt on Feb 5, 2024
  88. DrahtBot requested review from hernanmarino on Feb 5, 2024
  89. DrahtBot requested review from rserranon on Feb 5, 2024
  90. DrahtBot removed review request from w0xlt on Feb 5, 2024
  91. DrahtBot removed review request from hernanmarino on Feb 5, 2024
  92. DrahtBot removed review request from rserranon on Feb 5, 2024
  93. DrahtBot requested review from w0xlt on Feb 5, 2024
  94. DrahtBot requested review from rserranon on Feb 5, 2024
  95. DrahtBot requested review from hernanmarino on Feb 5, 2024
  96. furszy force-pushed on Feb 5, 2024
  97. josibake commented at 7:43 pm on February 5, 2024: member
  98. DrahtBot removed review request from w0xlt on Feb 5, 2024
  99. DrahtBot removed review request from rserranon on Feb 5, 2024
  100. DrahtBot removed review request from hernanmarino on Feb 5, 2024
  101. DrahtBot requested review from hernanmarino on Feb 5, 2024
  102. DrahtBot requested review from w0xlt on Feb 5, 2024
  103. DrahtBot requested review from rserranon on Feb 5, 2024
  104. furszy force-pushed on Feb 7, 2024
  105. furszy commented at 2:13 pm on February 7, 2024: member
    Updated per @maflcko review in #29403 (review). Small diff.
  106. furszy force-pushed on Feb 7, 2024
  107. DrahtBot commented at 2:17 pm on February 7, 2024: contributor

    🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the documentation.

    Possibly this is due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    Leave a comment here, if you need help tracking down a confusing failure.

    Debug: https://github.com/bitcoin/bitcoin/runs/21320950165

  108. DrahtBot added the label CI failed on Feb 7, 2024
  109. furszy commented at 3:21 pm on February 7, 2024: member
    Green CI. Ready to go.
  110. DrahtBot removed the label CI failed on Feb 7, 2024
  111. in src/wallet/wallet.cpp:2374 in c154e0940b outdated
    2367@@ -2368,13 +2368,22 @@ bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& add
    2368             purpose = m_address_book[address].purpose;
    2369         }
    2370     }
    2371+
    2372+    const std::string& encoded_dest = EncodeDestination(address);
    2373+    if (new_purpose && !batch.WritePurpose(encoded_dest, PurposeToString(*new_purpose))) {
    2374+        WalletLogPrintf("%s error writing entry purpose\n", __func__);
    


    achow101 commented at 7:57 pm on February 7, 2024:

    In c154e0940b6518487e29de96eb24ecf1839bd3fe “refactor: SetAddrBookWithDB, signal only if write succeeded”

    nit: __func__ is not necessary


    furszy commented at 9:19 pm on February 7, 2024:
    Sure. __func__ removed.
  112. in src/wallet/wallet.cpp:2378 in c154e0940b outdated
    2373+    if (new_purpose && !batch.WritePurpose(encoded_dest, PurposeToString(*new_purpose))) {
    2374+        WalletLogPrintf("%s error writing entry purpose\n", __func__);
    2375+        return false;
    2376+    }
    2377+    if (!batch.WriteName(encoded_dest, strName)) {
    2378+        WalletLogPrintf("%s error writing entry name\n", __func__);
    


    achow101 commented at 7:57 pm on February 7, 2024:

    In c154e0940b6518487e29de96eb24ecf1839bd3fe “refactor: SetAddrBookWithDB, signal only if write succeeded”

    nit: __func__ is not necessary


    furszy commented at 9:19 pm on February 7, 2024:
    Sure. __func__ removed.
  113. achow101 commented at 8:16 pm on February 7, 2024: member
    ACK 1f177ff9a6ab229bd6486941e46daa92ab22b622
  114. DrahtBot removed review request from hernanmarino on Feb 7, 2024
  115. DrahtBot removed review request from w0xlt on Feb 7, 2024
  116. DrahtBot removed review request from rserranon on Feb 7, 2024
  117. DrahtBot requested review from w0xlt on Feb 7, 2024
  118. DrahtBot requested review from josibake on Feb 7, 2024
  119. DrahtBot requested review from rserranon on Feb 7, 2024
  120. DrahtBot requested review from hernanmarino on Feb 7, 2024
  121. DrahtBot removed review request from w0xlt on Feb 7, 2024
  122. DrahtBot removed review request from rserranon on Feb 7, 2024
  123. DrahtBot removed review request from hernanmarino on Feb 7, 2024
  124. DrahtBot requested review from rserranon on Feb 7, 2024
  125. DrahtBot requested review from hernanmarino on Feb 7, 2024
  126. DrahtBot requested review from w0xlt on Feb 7, 2024
  127. DrahtBot removed review request from josibake on Feb 7, 2024
  128. DrahtBot removed review request from rserranon on Feb 7, 2024
  129. DrahtBot removed review request from hernanmarino on Feb 7, 2024
  130. DrahtBot removed review request from w0xlt on Feb 7, 2024
  131. DrahtBot requested review from w0xlt on Feb 7, 2024
  132. DrahtBot requested review from hernanmarino on Feb 7, 2024
  133. DrahtBot requested review from rserranon on Feb 7, 2024
  134. wallet: clean redundancies in DelAddressBook
    1) Encode destination only once (instead of three).
    2) Fail if the entry's linked data cannot be removed.
    3) Don't remove entry from memory if db write fail.
    4) Notify GUI only if removal succeeded
    97b0753923
  135. refactor: SetAddrBookWithDB, signal only if write succeeded bba4f8dcb5
  136. refactor: SetAddressBookWithDB, minimize number of map lookups d0943315b1
  137. refactor: wallet, simplify addressbook migration
    Same process written in a cleaner manner.
    Removing code duplication.
    595bbe6e81
  138. wallet: addressbook migration, batch db writes
    Optimizing the process performance and consistency.
    342c45f80e
  139. wallet: migration, batch addressbook records removal
    Instead of doing one db transaction per removed record,
    we now batch all removals in a single db transaction.
    
    Speeding up the process and preventing the wallet from entering
    an inconsistent state when any of the intermediate writes fail.
    86960cdb7f
  140. furszy force-pushed on Feb 7, 2024
  141. furszy commented at 9:23 pm on February 7, 2024: member

    Updated per feedback. Thanks achow!. Small diff.

    Two changes:

    1. Removed __func__ usages in the logging messages (comment_1 and comment_2).
    2. Have divided the purpose and name erasing lines per request.
  142. bitcoin deleted a comment on Feb 7, 2024
  143. achow101 commented at 10:26 pm on February 7, 2024: member
    ACK 86960cdb7f75eaa2ae150914c54240d1d5ef96d1
  144. DrahtBot removed review request from w0xlt on Feb 7, 2024
  145. DrahtBot removed review request from hernanmarino on Feb 7, 2024
  146. DrahtBot removed review request from rserranon on Feb 7, 2024
  147. DrahtBot requested review from hernanmarino on Feb 7, 2024
  148. DrahtBot requested review from w0xlt on Feb 7, 2024
  149. DrahtBot requested review from josibake on Feb 7, 2024
  150. DrahtBot requested review from rserranon on Feb 7, 2024
  151. josibake commented at 8:42 am on February 8, 2024: member
  152. DrahtBot removed review request from hernanmarino on Feb 8, 2024
  153. DrahtBot removed review request from w0xlt on Feb 8, 2024
  154. DrahtBot removed review request from josibake on Feb 8, 2024
  155. DrahtBot removed review request from rserranon on Feb 8, 2024
  156. DrahtBot requested review from rserranon on Feb 8, 2024
  157. DrahtBot requested review from hernanmarino on Feb 8, 2024
  158. DrahtBot requested review from w0xlt on Feb 8, 2024
  159. in src/wallet/wallet.cpp:2365 in d0943315b1 outdated
    2358@@ -2359,14 +2359,15 @@ bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& add
    2359     {
    2360         LOCK(cs_wallet);
    2361         std::map<CTxDestination, CAddressBookData>::iterator mi = m_address_book.find(address);
    2362-        fUpdated = (mi != m_address_book.end() && !mi->second.IsChange());
    2363-        m_address_book[address].SetLabel(strName);
    2364+        fUpdated = mi != m_address_book.end() && !mi->second.IsChange();
    2365+
    2366+        CAddressBookData& record = mi != m_address_book.end() ? mi->second : m_address_book[address];
    2367+        record.SetLabel(strName);
    


    ryanofsky commented at 2:30 pm on February 8, 2024:

    In commit “refactor: SetAddressBookWithDB, minimize number of map lookups” (d0943315b1d00905fe7f4513b2f3f47b88a99e8f)

    This isn’t actually minimizing the number of lookups since it is doing two lookups in the insert case. Would replace:

    0std::map<CTxDestination, CAddressBookData>::iterator mi = m_address_book.find(address);
    1fUpdated = mi != m_address_book.end() && !mi->second.IsChange();
    2CAddressBookData& record = mi != m_address_book.end() ? mi->second : m_address_book[address];
    

    with:

    0auto [it, inserted] = m_address_book.emplace(std::piecewise_construct, std::forward_as_tuple(address), std::tuple{});
    1fUpdated = !inserted && !it->second.IsChange();
    2CAddressBookData& record = it->second;
    
  160. achow101 merged this on Feb 8, 2024
  161. achow101 closed this on Feb 8, 2024

  162. furszy deleted the branch on Feb 8, 2024
  163. in src/wallet/wallet.cpp:4015 in 595bbe6e81 outdated
    4033-                    }
    4034-                }
    4035+    for (const auto& [dest, record] : m_address_book) {
    4036+        // Ensure "receive" entries that are no longer part of the original wallet are transferred to another wallet
    4037+        // Entries for everything else ("send") will be cloned to all wallets.
    4038+        bool require_transfer = record.purpose == AddressPurpose::RECEIVE && !IsMine(dest);
    


    ryanofsky commented at 3:04 pm on February 8, 2024:

    In commit “refactor: wallet, simplify addressbook migration” (595bbe6e81885d35179aba6137dc63d0e652cc1f)

    IMO, this would be less confusing if require_transfer bool was replaced by an copy_to_all bool with the opposite meaning, because the thing require_transfer is used for in the loop below is to determining whether the address book entry is copied to all wallets or is moved from the *this wallet to one of the other two.

    The name require_transfer is also misleading because the transfer is not required if dest is in not_migrated_dests.

  164. in src/wallet/wallet.cpp:4024 in 342c45f80e outdated
    4019+        }
    4020+        wallets_vec.emplace_back(ext_wallet, std::move(batch));
    4021+    }
    4022+
    4023+    // Write address book entry to disk
    4024+    auto func_store_addr = [](WalletBatch& batch, const CTxDestination& dest, const CAddressBookData& entry) {
    


    ryanofsky commented at 3:23 pm on February 8, 2024:

    In commit “wallet: addressbook migration, batch db writes” (342c45f80e32b0320829ce380b5854844cd74bc8)

    write_address_book would be a more descriptive name than func_store_addr and watchonly_wallets would be more descriptive than wallet_vec. The _vec suffix and and func_ prefix do not do anything to help a reader of the code, IMO.

  165. ryanofsky commented at 3:30 pm on February 8, 2024: contributor
    Post-merge code review ACK 86960cdb7f75eaa2ae150914c54240d1d5ef96d1. Nice code cleanups, and use of batches to speed things up

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-11-17 00:12 UTC

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