diff --git a/src/memusage.h b/src/memusage.h index e3e60d0a0..98d03fd63 100644 --- a/src/memusage.h +++ b/src/memusage.h @@ -88,8 +88,8 @@ static inline size_t DynamicUsage(const std::set& s) return MallocUsage(sizeof(stl_tree_node)) * s.size(); } -template -static inline size_t DynamicUsage(const std::map& m) +template +static inline size_t DynamicUsage(const std::map& m) { return MallocUsage(sizeof(stl_tree_node >)) * m.size(); } diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 91d5079c7..9326a1089 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -790,8 +790,37 @@ bool CCoinsViewMemPool::HaveCoins(const uint256 &txid) const { size_t CTxMemPool::DynamicMemoryUsage() const { LOCK(cs); - // Estimate the overhead of mapTx to be 6 pointers + an allocation, as no exact formula for boost::multi_index_contained is implemented. - return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 6 * sizeof(void*)) * mapTx.size() + memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas) + cachedInnerUsage; + + size_t total = 0; + + // Estimate the overhead of mapTx to be 6 pointers + an allocation, as no exact formula for + // boost::multi_index_contained is implemented. + total += memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 6 * sizeof(void*)) * mapTx.size(); + + // Two metadata maps inherited from Bitcoin Core + total += memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas); + + // Saves iterating over the full map + total += cachedInnerUsage; + + // Wallet notification + total += memusage::DynamicUsage(mapRecentlyAddedTx); + + // Nullifier set tracking + total += memusage::DynamicUsage(mapSproutNullifiers) + memusage::DynamicUsage(mapSaplingNullifiers); + + // DoS mitigation + total += memusage::DynamicUsage(recentlyEvicted) + memusage::DynamicUsage(weightedTxTree); + + // Insight-related structures + size_t insight; + insight += memusage::DynamicUsage(mapAddress); + insight += memusage::DynamicUsage(mapAddressInserted); + insight += memusage::DynamicUsage(mapSpent); + insight += memusage::DynamicUsage(mapSpentInserted); + total += insight; + + return total; } void CTxMemPool::SetMempoolCostLimit(int64_t totalCostLimit, int64_t evictionMemorySeconds) {