Skip to content

Commit 5de2baa

Browse files
committed
Rename CTxMemPool::remove -> removeRecursive
remove is no longer called non-recursively, so simplify the logic and eliminate an unnecessary parameter
1 parent 7659438 commit 5de2baa

File tree

4 files changed

+19
-23
lines changed

4 files changed

+19
-23
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ bool static DisconnectTip(CValidationState& state, const Consensus::Params& cons
25022502
list<CTransaction> removed;
25032503
CValidationState stateDummy;
25042504
if (tx.IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL, true)) {
2505-
mempool.remove(tx, removed, true);
2505+
mempool.removeRecursive(tx, removed);
25062506
} else if (mempool.exists(tx.GetHash())) {
25072507
vHashUpdate.push_back(tx.GetHash());
25082508
}

src/test/mempool_tests.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
5757
std::list<CTransaction> removed;
5858

5959
// Nothing in pool, remove should do nothing:
60-
testPool.remove(txParent, removed, true);
60+
testPool.removeRecursive(txParent, removed);
6161
BOOST_CHECK_EQUAL(removed.size(), 0);
6262

6363
// Just the parent:
6464
testPool.addUnchecked(txParent.GetHash(), entry.FromTx(txParent));
65-
testPool.remove(txParent, removed, true);
65+
testPool.removeRecursive(txParent, removed);
6666
BOOST_CHECK_EQUAL(removed.size(), 1);
6767
removed.clear();
6868

@@ -74,16 +74,16 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
7474
testPool.addUnchecked(txGrandChild[i].GetHash(), entry.FromTx(txGrandChild[i]));
7575
}
7676
// Remove Child[0], GrandChild[0] should be removed:
77-
testPool.remove(txChild[0], removed, true);
77+
testPool.removeRecursive(txChild[0], removed);
7878
BOOST_CHECK_EQUAL(removed.size(), 2);
7979
removed.clear();
8080
// ... make sure grandchild and child are gone:
81-
testPool.remove(txGrandChild[0], removed, true);
81+
testPool.removeRecursive(txGrandChild[0], removed);
8282
BOOST_CHECK_EQUAL(removed.size(), 0);
83-
testPool.remove(txChild[0], removed, true);
83+
testPool.removeRecursive(txChild[0], removed);
8484
BOOST_CHECK_EQUAL(removed.size(), 0);
8585
// Remove parent, all children/grandchildren should go:
86-
testPool.remove(txParent, removed, true);
86+
testPool.removeRecursive(txParent, removed);
8787
BOOST_CHECK_EQUAL(removed.size(), 5);
8888
BOOST_CHECK_EQUAL(testPool.size(), 0);
8989
removed.clear();
@@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
9696
}
9797
// Now remove the parent, as might happen if a block-re-org occurs but the parent cannot be
9898
// put into the mempool (maybe because it is non-standard):
99-
testPool.remove(txParent, removed, true);
99+
testPool.removeRecursive(txParent, removed);
100100
BOOST_CHECK_EQUAL(removed.size(), 6);
101101
BOOST_CHECK_EQUAL(testPool.size(), 0);
102102
removed.clear();
@@ -281,11 +281,11 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
281281

282282
// Now try removing tx10 and verify the sort order returns to normal
283283
std::list<CTransaction> removed;
284-
pool.remove(pool.mapTx.find(tx10.GetHash())->GetTx(), removed, true);
284+
pool.removeRecursive(pool.mapTx.find(tx10.GetHash())->GetTx(), removed);
285285
CheckSort<descendant_score>(pool, snapshotOrder);
286286

287-
pool.remove(pool.mapTx.find(tx9.GetHash())->GetTx(), removed, true);
288-
pool.remove(pool.mapTx.find(tx8.GetHash())->GetTx(), removed, true);
287+
pool.removeRecursive(pool.mapTx.find(tx9.GetHash())->GetTx(), removed);
288+
pool.removeRecursive(pool.mapTx.find(tx8.GetHash())->GetTx(), removed);
289289
/* Now check the sort on the mining score index.
290290
* Final order should be:
291291
*

src/txmempool.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ void CTxMemPool::CalculateDescendants(txiter entryit, setEntries &setDescendants
461461
}
462462
}
463463

464-
void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& removed, bool fRecursive)
464+
void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list<CTransaction>& removed)
465465
{
466466
// Remove transaction from memory pool
467467
{
@@ -470,8 +470,8 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
470470
txiter origit = mapTx.find(origTx.GetHash());
471471
if (origit != mapTx.end()) {
472472
txToRemove.insert(origit);
473-
} else if (fRecursive) {
474-
// If recursively removing but origTx isn't in the mempool
473+
} else {
474+
// When recursively removing but origTx isn't in the mempool
475475
// be sure to remove any children that are in the pool. This can
476476
// happen during chain re-orgs if origTx isn't re-accepted into
477477
// the mempool for any reason.
@@ -485,12 +485,8 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
485485
}
486486
}
487487
setEntries setAllRemoves;
488-
if (fRecursive) {
489-
BOOST_FOREACH(txiter it, txToRemove) {
490-
CalculateDescendants(it, setAllRemoves);
491-
}
492-
} else {
493-
setAllRemoves.swap(txToRemove);
488+
BOOST_FOREACH(txiter it, txToRemove) {
489+
CalculateDescendants(it, setAllRemoves);
494490
}
495491
BOOST_FOREACH(txiter it, setAllRemoves) {
496492
removed.push_back(it->GetTx());
@@ -524,7 +520,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
524520
}
525521
BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) {
526522
list<CTransaction> removed;
527-
remove(tx, removed, true);
523+
removeRecursive(tx, removed);
528524
}
529525
}
530526

@@ -539,7 +535,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
539535
const CTransaction &txConflict = *it->second.ptx;
540536
if (txConflict != tx)
541537
{
542-
remove(txConflict, removed, true);
538+
removeRecursive(txConflict, removed);
543539
ClearPrioritisation(txConflict.GetHash());
544540
}
545541
}

src/txmempool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class CTxMemPool
428428
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate = true);
429429
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool fCurrentEstimate = true);
430430

431-
void remove(const CTransaction &tx, std::list<CTransaction>& removed, bool fRecursive = false);
431+
void removeRecursive(const CTransaction &tx, std::list<CTransaction>& removed);
432432
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
433433
void removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed);
434434
void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,

0 commit comments

Comments
 (0)