diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2023-09-29 15:42:15 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2024-02-07 18:15:38 -0300 |
commit | 86960cdb7f75eaa2ae150914c54240d1d5ef96d1 (patch) | |
tree | f3e160b116e33fade6ba35174d0e7fff3e5d22fd /src/wallet/wallet.cpp | |
parent | 342c45f80e32b0320829ce380b5854844cd74bc8 (diff) | |
download | bitcoin-86960cdb7f75eaa2ae150914c54240d1d5ef96d1.tar.xz |
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.
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index aae876a819..5c19a44fb4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2395,8 +2395,13 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s bool CWallet::DelAddressBook(const CTxDestination& address) { - const std::string& dest = EncodeDestination(address); WalletBatch batch(GetDatabase()); + return DelAddressBookWithDB(batch, address); +} + +bool CWallet::DelAddressBookWithDB(WalletBatch& batch, const CTxDestination& address) +{ + const std::string& dest = EncodeDestination(address); { LOCK(cs_wallet); // If we want to delete receiving addresses, we should avoid calling EraseAddressData because it will delete the previously_spent value. Could instead just erase the label so it becomes a change address, and keep the data. @@ -4079,14 +4084,17 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error) } // Remove the things to delete in this wallet + WalletBatch local_wallet_batch(GetDatabase()); + local_wallet_batch.TxnBegin(); if (dests_to_delete.size() > 0) { for (const auto& dest : dests_to_delete) { - if (!DelAddressBook(dest)) { + if (!DelAddressBookWithDB(local_wallet_batch, dest)) { error = _("Error: Unable to remove watchonly address book data"); return false; } } } + local_wallet_batch.TxnCommit(); // Connect the SPKM signals ConnectScriptPubKeyManNotifiers(); |