aboutsummaryrefslogtreecommitdiff
path: root/src/txmempool.cpp
diff options
context:
space:
mode:
authorMatt Corallo <git@bluematt.me>2014-11-18 14:57:20 -0800
committerMatt Corallo <git@bluematt.me>2014-12-08 14:09:58 -0800
commit7fd6219af7006fddc4b675236bcd43dd7a9eb553 (patch)
tree6397d687af17ebf52c854051e44e8d18458b060a /src/txmempool.cpp
parentb7b4318f3a65d6e55d44bff5da1091ec0b3a26d2 (diff)
Make CTxMemPool::remove more effecient by avoiding recursion
Diffstat (limited to 'src/txmempool.cpp')
-rw-r--r--src/txmempool.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index 6ecd64636b..840eb536ba 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -427,26 +427,32 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry)
}
-void CTxMemPool::remove(const CTransaction &tx, std::list<CTransaction>& removed, bool fRecursive)
+void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& removed, bool fRecursive)
{
// Remove transaction from memory pool
{
LOCK(cs);
- uint256 hash = tx.GetHash();
- if (fRecursive) {
- for (unsigned int i = 0; i < tx.vout.size(); i++) {
- std::map<COutPoint, CInPoint>::iterator it = mapNextTx.find(COutPoint(hash, i));
- if (it == mapNextTx.end())
- continue;
- remove(*it->second.ptx, removed, true);
- }
- }
- if (mapTx.count(hash))
+ std::deque<uint256> txToRemove;
+ txToRemove.push_back(origTx.GetHash());
+ while (!txToRemove.empty())
{
- removed.push_front(tx);
+ uint256 hash = txToRemove.front();
+ txToRemove.pop_front();
+ if (!mapTx.count(hash))
+ continue;
+ const CTransaction& tx = mapTx[hash].GetTx();
+ if (fRecursive) {
+ for (unsigned int i = 0; i < tx.vout.size(); i++) {
+ std::map<COutPoint, CInPoint>::iterator it = mapNextTx.find(COutPoint(hash, i));
+ if (it == mapNextTx.end())
+ continue;
+ txToRemove.push_back(it->second.ptx->GetHash());
+ }
+ }
BOOST_FOREACH(const CTxIn& txin, tx.vin)
mapNextTx.erase(txin.prevout);
+ removed.push_back(tx);
totalTxSize -= mapTx[hash].GetTxSize();
mapTx.erase(hash);
nTransactionsUpdated++;