Skip to content

btc(stratum): memoize per-job tx_data hex (H5 work_source.cpp:634 churn fix) - #124

Merged
frstrtr merged 1 commit into
masterfrom
btc/h5-tx-data-memo-seam
Jun 17, 2026
Merged

btc(stratum): memoize per-job tx_data hex (H5 work_source.cpp:634 churn fix)#124
frstrtr merged 1 commit into
masterfrom
btc/h5-tx-data-memo-seam

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 17, 2026

Copy link
Copy Markdown
Owner

What

Follow-up to the H5 tx_data retention work: lands the tx_data_memo seam + acceptance test + the work_source.cpp rewire as a distinct, additive PR off master (kept separate from #123, which stays segwit-SSOT-only).

build_connection_coinbase rebuilt the per-job tx-hex vector on every call, even when the mempool tx set was unchanged — the dominant churn/leak site in the 2026-06-02 heaptrack (work_source.cpp:634, ~768 MB across 1.2M calls).

How

  • src/impl/btc/stratum/tx_data_memo.hpp — standalone, unit-testable seam. Memoizes the shared_ptr in a single slot keyed to a fingerprint over the merkle leaf set (wd->m_hashes, in leaf order). A repeat call against the same tx set returns the cached shared_ptr (a refcount bump) instead of re-serializing the whole mempool. The key is the exact leaf set that built this job merkle, so a hit is atomic-with-merkle by construction (no stale-tx-vs-fresh-merkle mismatch on submit). Single slot ⇒ bounded memory (one tx set retained), self-evicting on tx-set roll.
  • work_source.cpp — rewires the a1 block to call the seam; guards the two new memo members (tx_data_fp_, tx_data_memo_) with template_mutex_ since the builder runs on connection threads (the call site does not otherwise hold it).
  • work_source.hpp — adds the two memo members next to template_mutex_.
  • src/impl/btc/test/tx_data_memo_test.cpp — standalone acceptance harness (style of template_parity_test.cpp, no btc/test CMake plumbing): proves pointer-identity reuse, correct invalidation on tx-set change, content correctness, and O(1) per-call cost on the unchanged path.

Scope / posture

  • BTC-only; no LTC/DGB/DASH branch (per-coin isolation), no behavioral change to other coins.
  • Signed commit, additive.
  • NOT built — staged only under the capacity-return hold.
  • PR-not-merge: merge stays operator-gated. Do not merge.

…rn fix)

build_connection_coinbase rebuilt the per-job tx-hex vector on every call,
even when the mempool tx set was unchanged -- the dominant churn/leak site in
the 2026-06-02 heaptrack (work_source.cpp:634, ~768MB across 1.2M calls).

Factor the rebuild into a standalone, unit-testable seam
(btc/stratum/tx_data_memo.hpp) that memoizes the shared_ptr in a single slot
keyed to a fingerprint over the merkle leaf set (wd->m_hashes, in leaf order).
A repeat call against the same tx set returns the cached shared_ptr (a refcount
bump) instead of re-serializing the whole mempool. The key is the exact leaf
set that built this job merkle, so a hit is atomic-with-merkle by construction
(no stale-tx-vs-fresh-merkle mismatch on submit). Single slot => bounded memory
(one tx set retained), self-evicting on tx-set roll.

Rewire build_connection_coinbase to call the seam, guarding the two new memo
members (tx_data_fp_, tx_data_memo_) with template_mutex_ since the builder
runs on connection threads. Adds a standalone acceptance harness
(tx_data_memo_test.cpp) proving pointer-identity reuse, correct invalidation on
tx-set change, content correctness, and O(1) per-call cost on the unchanged
path. BTC-only; no behavioral change to other coins.
@frstrtr
frstrtr force-pushed the btc/h5-tx-data-memo-seam branch from cff36c5 to 5a6d2aa Compare June 17, 2026 13:04
@frstrtr
frstrtr merged commit 317d368 into master Jun 17, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant