txgraph: expose memory usage estimate function (feature)

This commit is contained in:
Pieter Wuille
2025-08-05 11:06:15 -04:00
parent 7680bb8fd4
commit 04c808ac4c
3 changed files with 39 additions and 0 deletions

View File

@@ -629,6 +629,8 @@ public:
std::unique_ptr<BlockBuilder> GetBlockBuilder() noexcept final;
std::pair<std::vector<Ref*>, FeePerWeight> GetWorstMainChunk() noexcept final;
size_t GetMainMemoryUsage() noexcept final;
void SanityCheck() const final;
};
@@ -2980,6 +2982,21 @@ std::vector<TxGraph::Ref*> TxGraphImpl::Trim() noexcept
return ret;
}
size_t TxGraphImpl::GetMainMemoryUsage() noexcept
{
// Make sure splits/merges are applied, as memory usage may not be representative otherwise.
SplitAll(/*up_to_level=*/0);
ApplyDependencies(/*level=*/0);
// Compute memory usage
size_t usage = /* From clusters */
m_main_clusterset.m_cluster_usage +
/* From Entry objects. */
sizeof(Entry) * m_main_clusterset.m_txcount +
/* From the chunk index. */
memusage::DynamicUsage(m_main_chunkindex);
return usage;
}
} // namespace
TxGraph::Ref::~Ref()