Skip to content
Prev Previous commit
Next Next commit
kernel: Add dynamic memory usage to mempool interface
  • Loading branch information
sedited committed Jun 4, 2026
commit b6faf853f9f103004f41800eacf5512314ef7815
3 changes: 3 additions & 0 deletions src/kernel/mempool_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef BITCOIN_KERNEL_MEMPOOL_INTERFACE_H
#define BITCOIN_KERNEL_MEMPOOL_INTERFACE_H

#include <cstddef>

class CBlock;
class CTransaction;

Expand All @@ -21,6 +23,7 @@ class Mempool

virtual void removeRecursive(const CTransaction& tx) {}
virtual void removeForBlock(const CBlock& block, unsigned int block_height) {}
virtual size_t measureExternalDynamicMemoryUsage() { return 0; }
};

} // namespace kernel
Expand Down
5 changes: 5 additions & 0 deletions src/node/kernel_mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ void KernelMempool::removeForBlock(const CBlock& block, unsigned int block_heigh
m_mempool.removeForBlock(block.vtx, block_height);
}

size_t KernelMempool::measureExternalDynamicMemoryUsage()
{
return m_mempool.DynamicMemoryUsage();
}

} // namespace node
1 change: 1 addition & 0 deletions src/node/kernel_mempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class KernelMempool: public kernel::Mempool

void removeRecursive(const CTransaction& tx) override;
void removeForBlock(const CBlock& block, unsigned int nBlockHeight) override;
size_t measureExternalDynamicMemoryUsage() override;

private:
CTxMemPool& m_mempool;
Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@ CoinsCacheSizeState Chainstate::GetCoinsCacheSizeState(
size_t max_mempool_size_bytes)
{
AssertLockHeld(::cs_main);
const int64_t nMempoolUsage = m_mempool ? m_mempool->DynamicMemoryUsage() : 0;
const int64_t nMempoolUsage = m_mempool ? m_chainman.GetMempool().measureExternalDynamicMemoryUsage() : 0;
int64_t cacheSize = CoinsTip().DynamicMemoryUsage();
int64_t nTotalSpace =
max_coins_cache_size_bytes + std::max<int64_t>(int64_t(max_mempool_size_bytes) - nMempoolUsage, 0);
Expand Down