mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-10 15:47:17 +02:00
wallet: fix removeprunedfunds bug with conflicting transactions
removeprunedfunds removes all entries from mapTxSpends for the inputs of the pruned tx. However, this is incorrect, because there could be multiple entries from conflicting transactions (that shouldn't be removed as well). This could lead to the wallet creating invalid transactions, trying to double spend utxos. The bug persists when the conflicting tx was mined, because the wallet trusts its internal accounting instead of calling AddToSpends again.
This commit is contained in:
@@ -2398,8 +2398,15 @@ util::Result<void> CWallet::RemoveTxs(WalletBatch& batch, std::vector<Txid>& txs
|
||||
for (const auto& it : erased_txs) {
|
||||
const Txid hash{it->first};
|
||||
wtxOrdered.erase(it->second.m_it_wtxOrdered);
|
||||
for (const auto& txin : it->second.tx->vin)
|
||||
mapTxSpends.erase(txin.prevout);
|
||||
for (const auto& txin : it->second.tx->vin) {
|
||||
auto range = mapTxSpends.equal_range(txin.prevout);
|
||||
for (auto iter = range.first; iter != range.second; ++iter) {
|
||||
if (iter->second == hash) {
|
||||
mapTxSpends.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (unsigned int i = 0; i < it->second.tx->vout.size(); ++i) {
|
||||
m_txos.erase(COutPoint(hash, i));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user