#35923 mempool: count unbroadcast txids in memory usage

full analysis

https://github.com/bitcoin/bitcoin/pull/35923 · l0rinc · +18/-1 in 2 files, 2 commits · labels: Mempool

Goal

  • Include unbroadcast transactions in mempool memory calculations
  • Prevents slightly undercounting memory against limits for locally submitted transactions

This PR includes `m_unbroadcast_txids` in `CTxMemPool::DynamicMemoryUsage()` and adds a unit test verifying that memory usage increases when an unbroadcast transaction is registered and decreases when removed.

Problem: The mempool dynamic memory calculation omitted the txid set tracking unbroadcast local transactions, resulting in a minor undercounting in `getmempoolinfo` and `-maxmempool` enforcement.

Category: Mempool and policy (#10 of 10)

P4 · bug fix

  • P4 because the undercounted memory footprint is negligible compared to overall mempool usage
  • It only affects locally submitted transactions awaiting their first broadcast

P4 because it fixes a minor memory undercount that only affects locally submitted unbroadcast transactions. Because the unbroadcast set typically holds very few entries (each ~80 bytes), the omitted usage is negligible compared to the default 300 MB mempool limit.

Membership: Modifies `CTxMemPool::DynamicMemoryUsage()` in `src/txmempool.cpp`.

Factors: security/stability 0, bug 1, performance 0, user value 0, leverage 0

Reviewability: Ready

  • Ready to review with clean CI and no pending changes

The patch is small, cleanly rebased, passes CI, and has no open requests or pending changes.

Author status: Active, submitted PR and has not needed to respond further.

Agreement: Strong

  • Strong support with no objections
  • Verified by testing memory usage and confirming test fails without fix (jeanpablojp)

Supported by jeanpablojp with testing; no objections.

The PR has received a tested ACK from jeanpablojp confirming the accounting fix and test coverage, with no concerns raised.

  • jeanpablojp: 'ACK db21e03c9d ... I have tested the code. m_unbroadcast_txids is a std::set<Txid> that memusage.h handles, 80 bytes per txid on my build, and it was not counted elsewhere in DynamicMemoryUsage()'

Objections: none enumerated.

Support:

  • jeanpablojp: Verified that m_unbroadcast_txids allocates ~80 bytes per txid, confirmed it was uncounted, and verified the added unit test catches omissions.

Participants: jeanpablojp (support)

State derived from the lists: substantive support, no open objection (jeanpablojp)

Review verdicts (DrahtBot): 1

Files

17 lines under test/bench/ci.

  • src/test/mempool_tests.cpp +17/-0
  • src/txmempool.cpp +1/-1

Card

This PR adds `m_unbroadcast_txids` into `CTxMemPool::DynamicMemoryUsage()` so that mempool memory accounting accounts for locally submitted transactions awaiting broadcast. The omitted memory is small (roughly 80 bytes per unbroadcast transaction), so the fix has minimal real-world impact on mempool limit enforcement. The PR has a tested ACK from jeanpablojp and is ready for merge.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T21:44, confidence high, input hash 9ee0d8aa4893aed9