Browse Source

Bypass removeRecursive in removeForReorg

0.14
Pieter Wuille 8 years ago
parent
commit
f48211b700
  1. 15
      src/txmempool.cpp

15
src/txmempool.cpp

@ -541,7 +541,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
{ {
// Remove transactions spending a coinbase which are now immature and no-longer-final transactions // Remove transactions spending a coinbase which are now immature and no-longer-final transactions
LOCK(cs); LOCK(cs);
list<CTransaction> transactionsToRemove; setEntries txToRemove;
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
const CTransaction& tx = it->GetTx(); const CTransaction& tx = it->GetTx();
LockPoints lp = it->GetLockPoints(); LockPoints lp = it->GetLockPoints();
@ -549,16 +549,16 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
if (!CheckFinalTx(tx, flags) || !CheckSequenceLocks(tx, flags, &lp, validLP)) { if (!CheckFinalTx(tx, flags) || !CheckSequenceLocks(tx, flags, &lp, validLP)) {
// Note if CheckSequenceLocks fails the LockPoints may still be invalid // Note if CheckSequenceLocks fails the LockPoints may still be invalid
// So it's critical that we remove the tx and not depend on the LockPoints. // So it's critical that we remove the tx and not depend on the LockPoints.
transactionsToRemove.push_back(tx); txToRemove.insert(it);
} else if (it->GetSpendsCoinbase()) { } else if (it->GetSpendsCoinbase()) {
BOOST_FOREACH(const CTxIn& txin, tx.vin) { BOOST_FOREACH(const CTxIn& txin, tx.vin) {
indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash); indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
if (it2 != mapTx.end()) if (it2 != mapTx.end())
continue; continue;
const CCoins *coins = pcoins->AccessCoins(txin.prevout.hash); const CCoins *coins = pcoins->AccessCoins(txin.prevout.hash);
if (nCheckFrequency != 0) assert(coins); if (nCheckFrequency != 0) assert(coins);
if (!coins || (coins->IsCoinBase() && ((signed long)nMemPoolHeight) - coins->nHeight < COINBASE_MATURITY)) { if (!coins || (coins->IsCoinBase() && ((signed long)nMemPoolHeight) - coins->nHeight < COINBASE_MATURITY)) {
transactionsToRemove.push_back(tx); txToRemove.insert(it);
break; break;
} }
} }
@ -567,10 +567,11 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
mapTx.modify(it, update_lock_points(lp)); mapTx.modify(it, update_lock_points(lp));
} }
} }
BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) { setEntries setAllRemoves;
list<CTransaction> removed; for (txiter it : txToRemove) {
removeRecursive(tx, removed); CalculateDescendants(it, setAllRemoves);
} }
RemoveStaged(setAllRemoves, false);
} }
void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed) void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed)

Loading…
Cancel
Save