@@ -427,26 +427,32 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry)
427
427
}
428
428
429
429
430
- void CTxMemPool::remove (const CTransaction &tx , std::list<CTransaction>& removed, bool fRecursive )
430
+ void CTxMemPool::remove (const CTransaction &origTx , std::list<CTransaction>& removed, bool fRecursive )
431
431
{
432
432
// Remove transaction from memory pool
433
433
{
434
434
LOCK (cs);
435
- uint256 hash = tx.GetHash ();
436
- if (fRecursive ) {
437
- for (unsigned int i = 0 ; i < tx.vout .size (); i++) {
438
- std::map<COutPoint, CInPoint>::iterator it = mapNextTx.find (COutPoint (hash, i));
439
- if (it == mapNextTx.end ())
440
- continue ;
441
- remove (*it->second .ptx , removed, true );
442
- }
443
- }
444
- if (mapTx.count (hash))
435
+ std::deque<uint256> txToRemove;
436
+ txToRemove.push_back (origTx.GetHash ());
437
+ while (!txToRemove.empty ())
445
438
{
446
- removed.push_front (tx);
439
+ uint256 hash = txToRemove.front ();
440
+ txToRemove.pop_front ();
441
+ if (!mapTx.count (hash))
442
+ continue ;
443
+ const CTransaction& tx = mapTx[hash].GetTx ();
444
+ if (fRecursive ) {
445
+ for (unsigned int i = 0 ; i < tx.vout .size (); i++) {
446
+ std::map<COutPoint, CInPoint>::iterator it = mapNextTx.find (COutPoint (hash, i));
447
+ if (it == mapNextTx.end ())
448
+ continue ;
449
+ txToRemove.push_back (it->second .ptx ->GetHash ());
450
+ }
451
+ }
447
452
BOOST_FOREACH (const CTxIn& txin, tx.vin )
448
453
mapNextTx.erase (txin.prevout );
449
454
455
+ removed.push_back (tx);
450
456
totalTxSize -= mapTx[hash].GetTxSize ();
451
457
mapTx.erase (hash);
452
458
nTransactionsUpdated++;
0 commit comments