Skip to content

Commit 51f2783

Browse files
committed
Make removed and conflicted arguments optional to remove
1 parent f48211b commit 51f2783

7 files changed

+31
-35
lines changed

src/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,10 +2768,9 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara
27682768
std::vector<uint256> vHashUpdate;
27692769
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
27702770
// ignore validation errors in resurrected transactions
2771-
list<CTransaction> removed;
27722771
CValidationState stateDummy;
27732772
if (tx.IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL, true)) {
2774-
mempool.removeRecursive(tx, removed);
2773+
mempool.removeRecursive(tx);
27752774
} else if (mempool.exists(tx.GetHash())) {
27762775
vHashUpdate.push_back(tx.GetHash());
27772776
}
@@ -2840,7 +2839,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
28402839
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
28412840
LogPrint("bench", " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001);
28422841
// Remove conflicting transactions from the mempool.;
2843-
mempool.removeForBlock(pblock->vtx, pindexNew->nHeight, txConflicted, !IsInitialBlockDownload());
2842+
mempool.removeForBlock(pblock->vtx, pindexNew->nHeight, &txConflicted, !IsInitialBlockDownload());
28442843
// Update chainActive & related variables.
28452844
UpdateTip(pindexNew, chainparams);
28462845

src/test/blockencodings_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
8181
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2].GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1);
8282

8383
std::list<CTransaction> removed;
84-
pool.removeRecursive(block.vtx[2], removed);
84+
pool.removeRecursive(block.vtx[2], &removed);
8585
BOOST_CHECK_EQUAL(removed.size(), 1);
8686

8787
CBlock block2;

src/test/mempool_tests.cpp

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

6060
// Nothing in pool, remove should do nothing:
61-
testPool.removeRecursive(txParent, removed);
61+
testPool.removeRecursive(txParent, &removed);
6262
BOOST_CHECK_EQUAL(removed.size(), 0);
6363

6464
// Just the parent:
6565
testPool.addUnchecked(txParent.GetHash(), entry.FromTx(txParent));
66-
testPool.removeRecursive(txParent, removed);
66+
testPool.removeRecursive(txParent, &removed);
6767
BOOST_CHECK_EQUAL(removed.size(), 1);
6868
removed.clear();
6969

@@ -75,16 +75,16 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
7575
testPool.addUnchecked(txGrandChild[i].GetHash(), entry.FromTx(txGrandChild[i]));
7676
}
7777
// Remove Child[0], GrandChild[0] should be removed:
78-
testPool.removeRecursive(txChild[0], removed);
78+
testPool.removeRecursive(txChild[0], &removed);
7979
BOOST_CHECK_EQUAL(removed.size(), 2);
8080
removed.clear();
8181
// ... make sure grandchild and child are gone:
82-
testPool.removeRecursive(txGrandChild[0], removed);
82+
testPool.removeRecursive(txGrandChild[0], &removed);
8383
BOOST_CHECK_EQUAL(removed.size(), 0);
84-
testPool.removeRecursive(txChild[0], removed);
84+
testPool.removeRecursive(txChild[0], &removed);
8585
BOOST_CHECK_EQUAL(removed.size(), 0);
8686
// Remove parent, all children/grandchildren should go:
87-
testPool.removeRecursive(txParent, removed);
87+
testPool.removeRecursive(txParent, &removed);
8888
BOOST_CHECK_EQUAL(removed.size(), 5);
8989
BOOST_CHECK_EQUAL(testPool.size(), 0);
9090
removed.clear();
@@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
9797
}
9898
// Now remove the parent, as might happen if a block-re-org occurs but the parent cannot be
9999
// put into the mempool (maybe because it is non-standard):
100-
testPool.removeRecursive(txParent, removed);
100+
testPool.removeRecursive(txParent, &removed);
101101
BOOST_CHECK_EQUAL(removed.size(), 6);
102102
BOOST_CHECK_EQUAL(testPool.size(), 0);
103103
removed.clear();
@@ -281,12 +281,11 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
281281
BOOST_CHECK_EQUAL(pool.size(), 10);
282282

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

288-
pool.removeRecursive(pool.mapTx.find(tx9.GetHash())->GetTx(), removed);
289-
pool.removeRecursive(pool.mapTx.find(tx8.GetHash())->GetTx(), removed);
287+
pool.removeRecursive(pool.mapTx.find(tx9.GetHash())->GetTx());
288+
pool.removeRecursive(pool.mapTx.find(tx8.GetHash())->GetTx());
290289
/* Now check the sort on the mining score index.
291290
* Final order should be:
292291
*
@@ -413,8 +412,7 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
413412
/* after tx6 is mined, tx7 should move up in the sort */
414413
std::vector<CTransaction> vtx;
415414
vtx.push_back(tx6);
416-
std::list<CTransaction> dummy;
417-
pool.removeForBlock(vtx, 1, dummy, false);
415+
pool.removeForBlock(vtx, 1, NULL, false);
418416

419417
sortedOrder.erase(sortedOrder.begin()+1);
420418
sortedOrder.pop_back();
@@ -549,12 +547,11 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
549547
pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7, &pool));
550548

551549
std::vector<CTransaction> vtx;
552-
std::list<CTransaction> conflicts;
553550
SetMockTime(42);
554551
SetMockTime(42 + CTxMemPool::ROLLING_FEE_HALFLIFE);
555552
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000);
556553
// ... we should keep the same min fee until we get a block
557-
pool.removeForBlock(vtx, 1, conflicts);
554+
pool.removeForBlock(vtx, 1);
558555
SetMockTime(42 + 2*CTxMemPool::ROLLING_FEE_HALFLIFE);
559556
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), (maxFeeRateRemoved.GetFeePerK() + 1000)/2);
560557
// ... then feerate should drop 1/2 each halflife

src/test/miner_tests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
137137
// Test that packages above the min relay fee do get included, even if one
138138
// of the transactions is below the min relay fee
139139
// Remove the low fee transaction and replace with a higher fee transaction
140-
std::list<CTransaction> dummy;
141-
mempool.removeRecursive(tx, dummy);
140+
mempool.removeRecursive(tx);
142141
tx.vout[0].nValue -= 2; // Now we should be just over the min relay fee
143142
hashLowFeeTx = tx.GetHash();
144143
mempool.addUnchecked(hashLowFeeTx, entry.Fee(feeToUse+2).FromTx(tx));

src/test/policyestimator_tests.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
4646
for (unsigned int i = 0; i < 128; i++)
4747
garbage.push_back('X');
4848
CMutableTransaction tx;
49-
std::list<CTransaction> dummyConflicted;
5049
tx.vin.resize(1);
5150
tx.vin[0].scriptSig = garbage;
5251
tx.vout.resize(1);
@@ -81,7 +80,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
8180
txHashes[9-h].pop_back();
8281
}
8382
}
84-
mpool.removeForBlock(block, ++blocknum, dummyConflicted);
83+
mpool.removeForBlock(block, ++blocknum);
8584
block.clear();
8685
if (blocknum == 30) {
8786
// At this point we should need to combine 5 buckets to get enough data points
@@ -125,7 +124,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
125124
// Mine 50 more blocks with no transactions happening, estimates shouldn't change
126125
// We haven't decayed the moving average enough so we still have enough data points in every bucket
127126
while (blocknum < 250)
128-
mpool.removeForBlock(block, ++blocknum, dummyConflicted);
127+
mpool.removeForBlock(block, ++blocknum);
129128

130129
for (int i = 1; i < 10;i++) {
131130
BOOST_CHECK(mpool.estimateFee(i).GetFeePerK() < origFeeEst[i-1] + deltaFee);
@@ -146,7 +145,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
146145
txHashes[j].push_back(hash);
147146
}
148147
}
149-
mpool.removeForBlock(block, ++blocknum, dummyConflicted);
148+
mpool.removeForBlock(block, ++blocknum);
150149
}
151150

152151
int answerFound;
@@ -167,7 +166,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
167166
txHashes[j].pop_back();
168167
}
169168
}
170-
mpool.removeForBlock(block, 265, dummyConflicted);
169+
mpool.removeForBlock(block, 265);
171170
block.clear();
172171
for (int i = 1; i < 10;i++) {
173172
BOOST_CHECK(mpool.estimateFee(i).GetFeePerK() > origFeeEst[i-1] - deltaFee);
@@ -187,7 +186,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
187186
block.push_back(*ptx);
188187
}
189188
}
190-
mpool.removeForBlock(block, ++blocknum, dummyConflicted);
189+
mpool.removeForBlock(block, ++blocknum);
191190
block.clear();
192191
}
193192
for (int i = 1; i < 10; i++) {

src/txmempool.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void CTxMemPool::CalculateDescendants(txiter entryit, setEntries &setDescendants
503503
}
504504
}
505505

506-
void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list<CTransaction>& removed)
506+
void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list<CTransaction>* removed)
507507
{
508508
// Remove transaction from memory pool
509509
{
@@ -530,8 +530,10 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list<CTransact
530530
BOOST_FOREACH(txiter it, txToRemove) {
531531
CalculateDescendants(it, setAllRemoves);
532532
}
533-
BOOST_FOREACH(txiter it, setAllRemoves) {
534-
removed.push_back(it->GetTx());
533+
if (removed) {
534+
BOOST_FOREACH(txiter it, setAllRemoves) {
535+
removed->push_back(it->GetTx());
536+
}
535537
}
536538
RemoveStaged(setAllRemoves, false);
537539
}
@@ -574,7 +576,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
574576
RemoveStaged(setAllRemoves, false);
575577
}
576578

577-
void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed)
579+
void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>* removed)
578580
{
579581
// Remove transactions which depend on inputs of tx, recursively
580582
LOCK(cs);
@@ -595,7 +597,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
595597
* Called when a block is connected. Removes from mempool and updates the miner fee estimator.
596598
*/
597599
void CTxMemPool::removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
598-
std::list<CTransaction>& conflicts, bool fCurrentEstimate)
600+
std::list<CTransaction>* conflicts, bool fCurrentEstimate)
599601
{
600602
LOCK(cs);
601603
std::vector<CTxMemPoolEntry> entries;

src/txmempool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,11 @@ class CTxMemPool
521521
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate = true);
522522
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool fCurrentEstimate = true);
523523

524-
void removeRecursive(const CTransaction &tx, std::list<CTransaction>& removed);
524+
void removeRecursive(const CTransaction &tx, std::list<CTransaction>* removed = NULL);
525525
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
526-
void removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed);
526+
void removeConflicts(const CTransaction &tx, std::list<CTransaction>* removed = NULL);
527527
void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
528-
std::list<CTransaction>& conflicts, bool fCurrentEstimate = true);
528+
std::list<CTransaction>* conflicts = NULL, bool fCurrentEstimate = true);
529529
void clear();
530530
void _clear(); //lock free
531531
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);

0 commit comments

Comments
 (0)