From f48211b700d171f7bcee7d3088269fdaaf1b5c13 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 15 Aug 2016 12:20:13 +0200 Subject: Bypass removeRecursive in removeForReorg --- src/txmempool.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/txmempool.cpp') diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 0f1c166ab..9816c9dcb 100644 --- a/src/txmempool.cpp +++ b/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 LOCK(cs); - list transactionsToRemove; + setEntries txToRemove; for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { const CTransaction& tx = it->GetTx(); 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)) { // 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. - transactionsToRemove.push_back(tx); + txToRemove.insert(it); } else if (it->GetSpendsCoinbase()) { BOOST_FOREACH(const CTxIn& txin, tx.vin) { indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash); if (it2 != mapTx.end()) continue; 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)) { - transactionsToRemove.push_back(tx); + txToRemove.insert(it); break; } } @@ -567,10 +567,11 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem mapTx.modify(it, update_lock_points(lp)); } } - BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) { - list removed; - removeRecursive(tx, removed); + setEntries setAllRemoves; + for (txiter it : txToRemove) { + CalculateDescendants(it, setAllRemoves); } + RemoveStaged(setAllRemoves, false); } void CTxMemPool::removeConflicts(const CTransaction &tx, std::list& removed) -- cgit v1.2.3 From 51f278329d43398428d60f5986f8d29a2041d28d Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 15 Aug 2016 13:10:57 +0200 Subject: Make removed and conflicted arguments optional to remove --- src/txmempool.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/txmempool.cpp') diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 9816c9dcb..193542ee5 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -503,7 +503,7 @@ void CTxMemPool::CalculateDescendants(txiter entryit, setEntries &setDescendants } } -void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list& removed) +void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list* removed) { // Remove transaction from memory pool { @@ -530,8 +530,10 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, std::listGetTx()); + if (removed) { + BOOST_FOREACH(txiter it, setAllRemoves) { + removed->push_back(it->GetTx()); + } } RemoveStaged(setAllRemoves, false); } @@ -574,7 +576,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem RemoveStaged(setAllRemoves, false); } -void CTxMemPool::removeConflicts(const CTransaction &tx, std::list& removed) +void CTxMemPool::removeConflicts(const CTransaction &tx, std::list* removed) { // Remove transactions which depend on inputs of tx, recursively LOCK(cs); @@ -595,7 +597,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list * Called when a block is connected. Removes from mempool and updates the miner fee estimator. */ void CTxMemPool::removeForBlock(const std::vector& vtx, unsigned int nBlockHeight, - std::list& conflicts, bool fCurrentEstimate) + std::list* conflicts, bool fCurrentEstimate) { LOCK(cs); std::vector entries; -- cgit v1.2.3 From 4100499db4e886d7a9ad2dcf4007ce44fb2c1a62 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 15 Aug 2016 12:57:10 +0200 Subject: Return shared_ptr from mempool removes --- src/txmempool.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/txmempool.cpp') diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 193542ee5..e5d28ac2e 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -503,7 +503,7 @@ void CTxMemPool::CalculateDescendants(txiter entryit, setEntries &setDescendants } } -void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list* removed) +void CTxMemPool::removeRecursive(const CTransaction &origTx, std::vector>* removed) { // Remove transaction from memory pool { @@ -532,7 +532,7 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, std::listpush_back(it->GetTx()); + removed->emplace_back(it->GetSharedTx()); } } RemoveStaged(setAllRemoves, false); @@ -576,7 +576,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem RemoveStaged(setAllRemoves, false); } -void CTxMemPool::removeConflicts(const CTransaction &tx, std::list* removed) +void CTxMemPool::removeConflicts(const CTransaction &tx, std::vector>* removed) { // Remove transactions which depend on inputs of tx, recursively LOCK(cs); @@ -597,7 +597,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list * Called when a block is connected. Removes from mempool and updates the miner fee estimator. */ void CTxMemPool::removeForBlock(const std::vector& vtx, unsigned int nBlockHeight, - std::list* conflicts, bool fCurrentEstimate) + std::vector>* conflicts, bool fCurrentEstimate) { LOCK(cs); std::vector entries; -- cgit v1.2.3