Skip to content

Commit f48211b

Browse files
committed
Bypass removeRecursive in removeForReorg
1 parent f08222e commit f48211b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/txmempool.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,24 +541,24 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
541541
{
542542
// Remove transactions spending a coinbase which are now immature and no-longer-final transactions
543543
LOCK(cs);
544-
list<CTransaction> transactionsToRemove;
544+
setEntries txToRemove;
545545
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
546546
const CTransaction& tx = it->GetTx();
547547
LockPoints lp = it->GetLockPoints();
548548
bool validLP = TestLockPointValidity(&lp);
549549
if (!CheckFinalTx(tx, flags) || !CheckSequenceLocks(tx, flags, &lp, validLP)) {
550550
// Note if CheckSequenceLocks fails the LockPoints may still be invalid
551551
// So it's critical that we remove the tx and not depend on the LockPoints.
552-
transactionsToRemove.push_back(tx);
552+
txToRemove.insert(it);
553553
} else if (it->GetSpendsCoinbase()) {
554554
BOOST_FOREACH(const CTxIn& txin, tx.vin) {
555555
indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
556556
if (it2 != mapTx.end())
557557
continue;
558558
const CCoins *coins = pcoins->AccessCoins(txin.prevout.hash);
559-
if (nCheckFrequency != 0) assert(coins);
559+
if (nCheckFrequency != 0) assert(coins);
560560
if (!coins || (coins->IsCoinBase() && ((signed long)nMemPoolHeight) - coins->nHeight < COINBASE_MATURITY)) {
561-
transactionsToRemove.push_back(tx);
561+
txToRemove.insert(it);
562562
break;
563563
}
564564
}
@@ -567,10 +567,11 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
567567
mapTx.modify(it, update_lock_points(lp));
568568
}
569569
}
570-
BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) {
571-
list<CTransaction> removed;
572-
removeRecursive(tx, removed);
570+
setEntries setAllRemoves;
571+
for (txiter it : txToRemove) {
572+
CalculateDescendants(it, setAllRemoves);
573573
}
574+
RemoveStaged(setAllRemoves, false);
574575
}
575576

576577
void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed)

0 commit comments

Comments
 (0)