Skip to content

underfill: port near-empty-template guard to DGB, BTC, BCH (+ KATs)#728

Merged
frstrtr merged 2 commits into
masterfrom
fix/underfill-guard-dgb-btc-bch
Jul 17, 2026
Merged

underfill: port near-empty-template guard to DGB, BTC, BCH (+ KATs)#728
frstrtr merged 2 commits into
masterfrom
fix/underfill-guard-dgb-btc-bch

Conversation

@frstrtr

@frstrtr frstrtr commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Completes the block-underfill guard across all coins — it was on LTC/DOGE/DASH, now DGB/BTC/BCH. Mirrors the LTC/DOGE guard (50kB fill pins; near-empty template + non-empty fee-paying mempool backlog => LOG_WARNING, log-only, empty mempools never trip).

  • BTC (src/impl/btc/coin/template_builder.hpp): near-verbatim LTC twin; guard after the tx loop, evaluated vs pool.byte_size()/total_fees(). Additive out-param seam; existing callers unchanged.
  • BCH (src/impl/bch/coin/template_builder.hpp): guard after the CTOR-sorted loop; counts canonical (witness-free) bytes matching the mempool cap + ABLA budget. CTOR/ABLA/submit paths untouched. Guard+test compile only under -DCOIN_BCH=ON.
  • DGB (embedded_tx_select.cpp + template_builder.hpp): DGB's build_work_template has NO mempool access (txs are a pass-through), so the guard evaluates at make_mempool_tx_source() — the one mempool-visible point feeding both the stratum and embedded callers. Respects the ci: build test_dgb_subsidy in both Linux test jobs (fix master-red NOT_BUILT) #143 SCC guard-weight discipline (cstdint-only header).
  • Tests: test_{btc,dgb,bch}_underfill_guard.cpp mirroring test_dash_underfill_guard.cpp (predicate + wiring through the real build path, coin-specific projection asserted unchanged). Registered in test/CMakeLists.txt.

Not compile-checked by author (no toolchain) — CI validates. The 3 new gtests need adding to the build.yml --target allowlists (workflow scope) or they show 'Not Run'. Follow-up: NMC's embedded template path (src/impl/nmc/coin/template_builder.hpp) also lacks the guard.

frstrtr and others added 2 commits July 17, 2026 15:16
Port the v36 template-underfill guard (near-empty template on a non-empty
fee-paying mempool, LOG-ONLY WARNING) from LTC/DOGE to the three coins that
were missing it, in the DASH free-predicate form (underfill_guard_trips +
50 kB UNDERFILL_MIN_FILL_BYTES / UNDERFILL_BACKLOG_SLACK pins):

- btc: guard inside TemplateBuilder::build_template (template_builder.hpp),
  SAFE-ADDITIVE trailing bool* underfill_tripped seam; GBT JSON untouched.
- bch: same, after the CTOR re-sort; ABLA budget / sizelimit untouched.
- dgb: build_work_template() is a pure shaper with no mempool access, so the
  guard evaluates in make_mempool_tx_source (embedded_tx_select.cpp) — the
  one mempool-visible point feeding BOTH template callers (stratum
  DGBWorkSource + EmbeddedCoinNode); predicate/thresholds pinned in
  coin/template_builder.hpp.

KATs per coin (test/test_{btc,dgb,bch}_underfill_guard.cpp, mirroring
test_dash_underfill_guard.cpp): threshold pins, boundary strictness,
empty/fee-unknown/drained no-trip, and real-build wiring via the seam
(stale-input-guard-emptied selection over a fee-paying backlog).
Registered in test/CMakeLists.txt (bch entry gated on COIN_BCH like
bch_coin). New targets still need the build.yml --target allowlist
(main leg: btc+dgb; BCH leg: bch) or CTest shows the NOT_BUILT sentinel.
test_btc_underfill_guard + test_dgb_underfill_guard -> main-leg --target
lists (build_ci + build_asan); test_bch_underfill_guard -> BCH-leg lists
(build_bch build + run, COIN_BCH). Without these the new KATs register as
NOT_BUILT CTest sentinels and Not-Run on Linux/ASan. Same pattern as #721/#724.
@frstrtr
frstrtr merged commit 33ee005 into master Jul 17, 2026
27 checks passed
@frstrtr
frstrtr deleted the fix/underfill-guard-dgb-btc-bch branch July 17, 2026 12:36
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