dgb: extract work-template assembly into build_work_template SSOT (Stage 4c) - #219
Merged
Conversation
…rk template (Stage 4c) HeaderSample gains a sha256d block-id slot (block_hash, u256; 0 == not populated here, the same sentinel pow_hash uses) and HeaderChain gains a tip_hash() accessor returning the newest header's id or nullopt when the chain is empty / the tip carries no hash. get_current_work_template emits previousblockhash as GBT-conventional big-endian display hex ONLY when tip_hash() is present -- a truthful conditional, never a fabricated hash. The embedded P2P header-download -> validate_and_append ingest that populates block_hash lands in a following slice; until then tip_hash() is nullopt and previousblockhash is held back exactly as before. bits stays HELD BACK: the only embedded next-target source is the DigiShield damped multiply, which DGB Core runs as MultiShield V4 (a global window across all 5 algos == V37); a Scrypt-only walk cannot reconstruct it, so the ingest path demotes that gate to a no-op. Emitting a digishield-derived bits would be a known-wrong value. The authoritative bits is the external-daemon GBT value, not plumbed into this embedded path yet -- surfaced as [decision-needed]. Fenced to src/impl/dgb (4 files); test cases added to existing targets header_chain_test (31 -> 35) and dgb_work_source_test (15 -> 16), no new gtest target so the build.yml allowlist is unchanged. Both green.
The Stage-4b prevhash getter still returned {} while get_current_work_template
emits previousblockhash from chain_.tip_hash() (#216). Route the getter through
the SAME tip_hash() accessor and u256_be_display_hex formatter so the dedicated
getter and the assembled template cannot silently diverge: one truthful source.
Empty string when tip_hash() == nullopt (empty chain / unpopulated block_hash
sentinel) -- a truthful absence, never a fabricated id. Non-consensus read-only
getter, fenced to src/impl/dgb. +1 test asserting getter == template field on a
seeded tip and joint-absence with no tip; dgb_work_source_test 17/17.
…age 4c) Lift the GBT-shaped template assembly out of DGBWorkSource::get_current_work_template() into a free function dgb::coin::build_work_template() in coin/template_builder.hpp, so the stratum work source and the embedded path emit ONE template object and cannot diverge. Pure non-consensus shaping: the consensus-bearing coinbasevalue is still resolved by the caller through the #207 resolve_coinbase_value -> subsidy_func SSOT and passed in verbatim; the builder never recomputes or scales it. version (Scrypt lane pin via DGB_BLOCK_VERSION_SCRYPT), mintime (MTP+1, 0 on empty chain), curtime, empty transactions[] and the truthful conditional previousblockhash all move into the builder unchanged. bits stays held back (MultiShield V4 next-target is V37). Behaviour-preserving: dgb_work_source_test 17/17 unchanged (incl the prevhash getter == template field joint-absence assertion). New guard-weight dgb_template_builder_test 7/7 pins the invariants (Scrypt pin, coinbasevalue pass-through, mintime/empty-chain, empty transactions + no bits, prevhash conditional, determinism). Wired into ctest + both build.yml allowlists (#143 NOT_BUILT trap avoided).
frstrtr
added a commit
that referenced
this pull request
Jun 19, 2026
Wire the build_work_template SSOT (Stage 4c, #219) into the embedded work path so it has a REAL second caller. Until now build_work_template had a single caller (DGBWorkSource::get_current_work_template), leaving its "the embedded path and the stratum path cannot emit a divergent template" claim theoretical; the embedded path being the second caller proves it. New coin/embedded_coin_node.hpp: EmbeddedCoinNode implements the existing CoinNodeInterface::getwork() (coin/template_builder.hpp) by assembling a GBT-compatible template ENTIRELY from in-process embedded chain state -- the HeaderChain (next_block_height / median_time_past / tip_hash) plus the coin subsidy schedule -- with NO external RPC. make_inputs(curtime) is split out so the assembly is deterministically testable; getwork() supplies std::time(nullptr) exactly as the stratum caller does. Consensus discipline identical to the stratum caller (pure non-consensus shaping): - coinbasevalue resolved through the #207 resolve_coinbase_value -> subsidy_func SSOT. Embedded path has no external GBT figure, so it is derived as subsidy_func(height)+total_fees (total_fees 0 until embedded mempool tx selection is wired). The external-daemon GBT fallback (NodeRPC::getwork) is a SEPARATE path and stays untouched. - version pins the Scrypt lane; transactions[] empty (no fabrication); previousblockhash emitted ONLY when tip_hash() carries a real id; bits HELD BACK (MultiShield V4 next-target == V37). New coin/hash_format.hpp lifts u256_be_display_hex out of work_source.cpp into a dgb::coin SSOT so the stratum and embedded callers render previousblockhash in one byte-encoding -- the same anti-divergence intent. work_source.cpp now consumes it via a using-declaration; behaviour preserved (dgb_work_source_test 17/17 unchanged, dgb_template_builder_test 7/7 unchanged). New dgb_embedded_coin_node_test 5/5: SSOT routing (node == build_work_template for the same inputs), coinbasevalue via subsidy_func, prevhash truthful absence + byte-identical emit, getwork no-fabrication. Wired into ctest + both build.yml --target allowlists (#143 NOT_BUILT trap avoided). Fenced to src/impl/dgb only; build EXIT=0.
frstrtr
force-pushed
the
dgb/stage-4c-template-builder-ssot
branch
from
June 19, 2026 16:47
d67ca9d to
4a87b9e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #217 (dgb/stage-4b-prevhash-getter). HOLD merge — lands in stack order #211 -> #216 -> #217 -> this, all behind the #211 operator tap.
What
Lift the GBT-shaped template assembly out of
DGBWorkSource::get_current_work_template()into a free functiondgb::coin::build_work_template()incoin/template_builder.hpp, so the stratum work source and the embedded path emit ONE template object and cannot diverge (the green-lit next pillar from the #217 / #216 review threads).Non-consensus, fenced
resolve_coinbase_value -> subsidy_funcSSOT and passed in verbatim; the builder never recomputes or scales it. No subsidy_func value or output-script change — pure JSON shaping.src/impl/dgb(no shared-base touch).bitsstays held back (MultiShield V4 next-target is V37, per the dgb: tip_hash() accessor + previousblockhash wire (Stage 4c) #216 [decision-needed] approval);previousblockhashstays a truthful conditional emit;transactions[]stays empty.Tests
dgb_work_source_test17/17 unchanged (behaviour-preserving — incl the prevhash-getter == template-field joint-absence assertion).dgb_template_builder_test7/7: Scrypt lane pin, coinbasevalue pass-through, mintime (MTP+1) + empty-chain (0), empty transactions + no bits, prevhash conditional, determinism.