dgb: wire embedded P2P header feed into HeaderChain (live validate_and_append) - #230
Merged
Conversation
This was referenced Jun 19, 2026
…d_append) wire_header_ingest (coin/header_ingest.hpp) subscribes a HeaderChain to dgb::interfaces::Node::new_headers -- the feed coin/p2p_node.hpp fires from ADD_P2P_HANDLER(headers) -- and routes every announced BlockHeaderType through the make_header_sample SSOT (#227) into HeaderChain::validate_and_append. This is what turns the chain from a unit-test fixture into one that advances on LIVE wire headers, lighting up tip_hash() -> previousblockhash for the embedded work template. The connector adds NO policy: disposition (Scrypt validate / continuity / reject) stays in validate_and_append, the single SSOT. Feeding real-shaped headers surfaced a latent SIGFPE in work_from_target: it divides UINT64_MAX by target.low64(), but a real-difficulty target has its significant bits high in the 256-bit word (genesis target ~2^224 -> low64()==0), an integer div-by-zero. Prior tests only used small uint64-range targets, so it never fired. Guarded: an unrepresentable-in-uint64 target credits 0 proxy work instead of crashing. cumulative_work is unconsumed by any V36 consensus path (retarget demoted to no-op; PPLNS scores shares); true 2^256/(target+1) work lands at the embedded-daemon work-accounting boundary alongside scrypt->pow_hash. dgb_header_ingest_test 5/5 (routing, batch arrival-order, driver-only, reject-delegation, empty-tip); header_chain_test 35/35 (no regression). Test wired into BOTH build.yml --target allowlists (#143 NOT_BUILT trap). Fenced to src/impl/dgb/; no shared-base touch.
frstrtr
force-pushed
the
dgb/embedded-header-ingest
branch
from
June 19, 2026 20:53
79970c7 to
24ea265
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 #227 (make_header_sample). Retarget to master once #227 lands.
What: wire_header_ingest (coin/header_ingest.hpp) subscribes a HeaderChain to dgb::interfaces::Node::new_headers (fired by coin/p2p_node.hpp ADD_P2P_HANDLER(headers)) and routes each announced header through the make_header_sample SSOT (#227) into HeaderChain::validate_and_append. The live wire path now advances the chain -> tip_hash() -> previousblockhash for the embedded work template. Connector adds NO policy; disposition stays in validate_and_append (the single SSOT).
Latent bug fixed (surfaced by real-shaped headers): work_from_target did UINT64_MAX / target.low64(); a real-difficulty target (~2^224) has low64()==0 -> integer div-by-zero (SIGFPE). Prior tests only used small uint64-range targets. Guarded to credit 0 proxy work; cumulative_work is unconsumed by any V36 consensus path (retarget demoted to no-op, PPLNS scores shares). True 2^256/(target+1) deferred to embedded-daemon work-accounting boundary (with scrypt->pow_hash).
Tests: dgb_header_ingest_test 5/5; header_chain_test 35/35 (no regression). Wired into BOTH build.yml --target allowlists (#143 trap). Fenced to src/impl/dgb/; no shared-base touch. GPG-signed.
HOLD merge (fenced auto-merge on full-matrix green, after #227).