Auto merge of #4306 - oxarbitrage:issue4224, r=daira
Compute more structures in CTxMemPool::DynamicMemoryUsage() Closes https://github.com/zcash/zcash/issues/4224 Added more structures to the computation of the mempool memory size as indicated in the issue. RPC call `getmempoolinfo` is the only place where this is used to get the `usage` result.
This commit is contained in:
commit
1f5de9cae2
|
@ -88,8 +88,8 @@ static inline size_t DynamicUsage(const std::set<X>& s)
|
|||
return MallocUsage(sizeof(stl_tree_node<X>)) * s.size();
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
static inline size_t DynamicUsage(const std::map<X, Y>& m)
|
||||
template<typename X, typename Y, typename C>
|
||||
static inline size_t DynamicUsage(const std::map<X, Y, C>& m)
|
||||
{
|
||||
return MallocUsage(sizeof(stl_tree_node<std::pair<const X, Y> >)) * m.size();
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue