File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed
Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff 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 ))
Original file line number Diff line number Diff 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);
You can’t perform that action at this time.
0 commit comments