wallet: batch and simplify addressbook migration process#26836
wallet: batch and simplify addressbook migration process#26836achow101 merged 6 commits intobitcoin:masterfrom
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
w0xlt
left a comment
There was a problem hiding this comment.
Approach ACK.
I will review soon.
There was a problem hiding this comment.
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 ?
src/wallet/wallet.cpp:3980: data.watchonly_wallet->m_address_book[addr_pair.first].purpose = purpose;
src/wallet/wallet.cpp:3996: data.solvable_wallet->m_address_book[addr_pair.first].purpose = purpose;
src/wallet/wallet.cpp:4017: data.watchonly_wallet->m_address_book[addr_pair.first].purpose = purpose;
src/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?
|
Thanks @rserranon.
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. |
cb82845 to
0053949
Compare
|
Updated per feedback. Now we no longer access the wallet's addressbook member externally. Plus, improvements to the address book migration process:
|
rserranon
left a comment
There was a problem hiding this comment.
tAck
- unit tests
- functional tests
- qt & bitcoin-cli manual tests
hernanmarino
left a comment
There was a problem hiding this comment.
tested ACK, both unit and functional tests.
pablomartin4btc
left a comment
There was a problem hiding this comment.
Approach ACK.
I'll perform some testing soon.
0053949 to
819c0bc
Compare
3aff6d5 to
238993e
Compare
|
reACK 238993e verified the diff, thanks for taking the suggestions! |
furszy
left a comment
There was a problem hiding this comment.
Updated per @maflcko review in #29403 (comment). Small diff.
|
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
|
Green CI. Ready to go. |
achow101
left a comment
There was a problem hiding this comment.
ACK 1f177ff9a6ab229bd6486941e46daa92ab22b622
|
reACK 1f177ff |
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
Same process written in a cleaner manner. Removing code duplication.
Optimizing the process performance and consistency.
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.
There was a problem hiding this comment.
Updated per feedback. Thanks achow!. Small diff.
Two changes:
|
ACK 86960cd |
|
reACK 86960cd Verified the diff, looks good. |
| fUpdated = mi != m_address_book.end() && !mi->second.IsChange(); | ||
|
|
||
| CAddressBookData& record = mi != m_address_book.end() ? mi->second : m_address_book[address]; | ||
| record.SetLabel(strName); |
There was a problem hiding this comment.
In commit "refactor: SetAddressBookWithDB, minimize number of map lookups" (d094331)
This isn't actually minimizing the number of lookups since it is doing two lookups in the insert case. Would replace:
std::map<CTxDestination, CAddressBookData>::iterator mi = m_address_book.find(address);
fUpdated = mi != m_address_book.end() && !mi->second.IsChange();
CAddressBookData& record = mi != m_address_book.end() ? mi->second : m_address_book[address];with:
auto [it, inserted] = m_address_book.emplace(std::piecewise_construct, std::forward_as_tuple(address), std::tuple{});
fUpdated = !inserted && !it->second.IsChange();
CAddressBookData& record = it->second;| for (const auto& [dest, record] : m_address_book) { | ||
| // Ensure "receive" entries that are no longer part of the original wallet are transferred to another wallet | ||
| // Entries for everything else ("send") will be cloned to all wallets. | ||
| bool require_transfer = record.purpose == AddressPurpose::RECEIVE && !IsMine(dest); |
There was a problem hiding this comment.
In commit "refactor: wallet, simplify addressbook migration" (595bbe6)
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.
| } | ||
|
|
||
| // Write address book entry to disk | ||
| auto func_store_addr = [](WalletBatch& batch, const CTxDestination& dest, const CAddressBookData& entry) { |
There was a problem hiding this comment.
In commit "wallet: addressbook migration, batch db writes" (342c45f)
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.
Commits decoupled from #28574, focused on the address book cloning process
Includes:
CWallet::DelAddressBookandWallet::SetAddrBookWithDBmethods.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.