From 6f2c26a457d279138d23d0f321edf55cd6b1f72f Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Wed, 6 Aug 2014 23:58:19 -0400 Subject: Closely track mempool byte total. Add "getmempoolinfo" RPC. Goal: Gain live insight into the mempool. Groundwork for future work that caps mempool size. --- src/txmempool.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/txmempool.cpp') diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 29924fff09..80cae68244 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -402,6 +402,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry) for (unsigned int i = 0; i < tx.vin.size(); i++) mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i); nTransactionsUpdated++; + totalTxSize += entry.GetTxSize(); } return true; } @@ -426,6 +427,8 @@ void CTxMemPool::remove(const CTransaction &tx, std::list& removed removed.push_front(tx); BOOST_FOREACH(const CTxIn& txin, tx.vin) mapNextTx.erase(txin.prevout); + + totalTxSize -= mapTx[hash].GetTxSize(); mapTx.erase(hash); nTransactionsUpdated++; } @@ -477,6 +480,7 @@ void CTxMemPool::clear() LOCK(cs); mapTx.clear(); mapNextTx.clear(); + totalTxSize = 0; ++nTransactionsUpdated; } @@ -487,9 +491,12 @@ void CTxMemPool::check(CCoinsViewCache *pcoins) const LogPrint("mempool", "Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size()); + uint64_t checkTotal = 0; + LOCK(cs); for (std::map::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { unsigned int i = 0; + checkTotal += it->second.GetTxSize(); const CTransaction& tx = it->second.GetTx(); BOOST_FOREACH(const CTxIn &txin, tx.vin) { // Check that every mempool transaction's inputs refer to available coins, or other mempool tx's. @@ -518,6 +525,8 @@ void CTxMemPool::check(CCoinsViewCache *pcoins) const assert(tx.vin.size() > it->second.n); assert(it->first == it->second.ptx->vin[it->second.n].prevout); } + + assert(totalTxSize == checkTotal); } void CTxMemPool::queryHashes(vector& vtxid) -- cgit v1.2.3