Skip to content

Commit d26a285

Browse files
committed
wallet: batch ZapSelectTx db operations
To ensure consistency and enhance performance, remove all tx records within a single atomic db batch operation. Optimizing the removal of watch-only transactions during the wallet migration process.
1 parent 89e6d12 commit d26a285

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/wallet/wallet.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,16 +2326,18 @@ void CWallet::ClearTxns(const std::vector<uint256>& tx_hashes)
23262326
DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn)
23272327
{
23282328
AssertLockHeld(cs_wallet);
2329-
DBErrors nZapSelectTxRet = WalletBatch(GetDatabase()).ZapSelectTx(vHashIn);
2330-
// Remove transactions from the memory map
2331-
ClearTxns(vHashIn);
23322329

2333-
if (nZapSelectTxRet != DBErrors::LOAD_OK)
2334-
return nZapSelectTxRet;
2330+
WalletBatch batch(GetDatabase());
2331+
if (!batch.TxnBegin()) return DBErrors::NONCRITICAL_ERROR;
2332+
DBErrors db_status = batch.ZapSelectTx(vHashIn);
2333+
// All deletions should have been added to the db txn, otherwise we abort the process.
2334+
if (db_status != DBErrors::LOAD_OK) return db_status;
23352335

2336+
// Apply db changes and remove transactions from the memory map
2337+
if (!batch.TxnCommit()) return DBErrors::NONCRITICAL_ERROR;
2338+
ClearTxns(vHashIn);
23362339
MarkDirty();
2337-
2338-
return DBErrors::LOAD_OK;
2340+
return db_status;
23392341
}
23402342

23412343
bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::optional<AddressPurpose>& new_purpose)

0 commit comments

Comments
 (0)