Skip to content

Commit db35bd8

Browse files
TheBlueMattrandom-zebra
authored andcommitted
Get the set of now-uncacheable-txn from CTxMemPool::TrimToSize
1 parent 15e0321 commit db35bd8

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/txmempool.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ void CTxMemPool::trackPackageRemoved(const CFeeRate& rate)
940940
}
941941
}
942942

943-
void CTxMemPool::TrimToSize(size_t sizelimit)
943+
void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<uint256>* pvNoSpendsRemaining)
944944
{
945945
LOCK(cs);
946946
unsigned nTxnRemoved = 0;
@@ -959,8 +959,26 @@ void CTxMemPool::TrimToSize(size_t sizelimit)
959959

960960
setEntries stage;
961961
CalculateDescendants(mapTx.project<0>(it), stage);
962-
RemoveStaged(stage);
963962
nTxnRemoved += stage.size();
963+
964+
std::vector<CTransaction> txn;
965+
if (pvNoSpendsRemaining) {
966+
txn.reserve(stage.size());
967+
for (txiter it: stage)
968+
txn.push_back(it->GetTx());
969+
}
970+
RemoveStaged(stage);
971+
if (pvNoSpendsRemaining) {
972+
for (const CTransaction& tx: txn) {
973+
for (const CTxIn& txin: tx.vin) {
974+
if (exists(txin.prevout.hash))
975+
continue;
976+
std::map<COutPoint, CInPoint>::iterator it = mapNextTx.lower_bound(COutPoint(txin.prevout.hash, 0));
977+
if (it == mapNextTx.end() || it->first.hash != txin.prevout.hash)
978+
pvNoSpendsRemaining->push_back(txin.prevout.hash);
979+
}
980+
}
981+
}
964982
}
965983

966984
if (maxFeeRateRemoved > CFeeRate(0))

src/txmempool.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,11 @@ class CTxMemPool
478478
*/
479479
CFeeRate GetMinFee(size_t sizelimit) const;
480480

481-
/** Remove transactions from the mempool until its dynamic size is <= sizelimit. */
482-
void TrimToSize(size_t sizelimit);
481+
/** Remove transactions from the mempool until its dynamic size is <= sizelimit.
482+
* pvNoSpendsRemaining, if set, will be populated with the list of transactions
483+
* which are not in mempool which no longer have any spends in this mempool.
484+
*/
485+
void TrimToSize(size_t sizelimit, std::vector<uint256>* pvNoSpendsRemaining=NULL);
483486

484487
/** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */
485488
int Expire(int64_t time);

0 commit comments

Comments
 (0)