From b2e74bd292460ca00fefc6356594318307365397 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 21 Oct 2015 17:44:00 -0700 Subject: Get the set of now-uncacheable-txn from CTxMemPool::TrimToSize --- src/txmempool.cpp | 22 ++++++++++++++++++++-- src/txmempool.h | 7 +++++-- 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 35be216287..fea5da8029 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -944,7 +944,7 @@ void CTxMemPool::trackPackageRemoved(const CFeeRate& rate) { } } -void CTxMemPool::TrimToSize(size_t sizelimit) { +void CTxMemPool::TrimToSize(size_t sizelimit, std::vector* pvNoSpendsRemaining) { LOCK(cs); unsigned nTxnRemoved = 0; @@ -963,8 +963,26 @@ void CTxMemPool::TrimToSize(size_t sizelimit) { setEntries stage; CalculateDescendants(mapTx.project<0>(it), stage); - RemoveStaged(stage); nTxnRemoved += stage.size(); + + std::vector txn; + if (pvNoSpendsRemaining) { + txn.reserve(stage.size()); + BOOST_FOREACH(txiter it, stage) + txn.push_back(it->GetTx()); + } + RemoveStaged(stage); + if (pvNoSpendsRemaining) { + BOOST_FOREACH(const CTransaction& tx, txn) { + BOOST_FOREACH(const CTxIn& txin, tx.vin) { + if (exists(txin.prevout.hash)) + continue; + std::map::iterator it = mapNextTx.lower_bound(COutPoint(txin.prevout.hash, 0)); + if (it == mapNextTx.end() || it->first.hash != txin.prevout.hash) + pvNoSpendsRemaining->push_back(txin.prevout.hash); + } + } + } } if (maxFeeRateRemoved > CFeeRate(0)) diff --git a/src/txmempool.h b/src/txmempool.h index 5652969f4b..9203171868 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -483,8 +483,11 @@ public: */ CFeeRate GetMinFee(size_t sizelimit) const; - /** Remove transactions from the mempool until its dynamic size is <= sizelimit. */ - void TrimToSize(size_t sizelimit); + /** Remove transactions from the mempool until its dynamic size is <= sizelimit. + * pvNoSpendsRemaining, if set, will be populated with the list of transactions + * which are not in mempool which no longer have any spends in this mempool. + */ + void TrimToSize(size_t sizelimit, std::vector* pvNoSpendsRemaining=NULL); /** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */ int Expire(int64_t time); -- cgit v1.2.3