Skip to content

dgb: wire embedded P2P header feed into HeaderChain (live validate_and_append) - #230

Merged
frstrtr merged 1 commit into
masterfrom
dgb/embedded-header-ingest
Jun 19, 2026
Merged

dgb: wire embedded P2P header feed into HeaderChain (live validate_and_append)#230
frstrtr merged 1 commit into
masterfrom
dgb/embedded-header-ingest

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 19, 2026

Copy link
Copy Markdown
Owner

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).

…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
frstrtr force-pushed the dgb/embedded-header-ingest branch from 79970c7 to 24ea265 Compare June 19, 2026 20:53
@frstrtr
frstrtr merged commit c417041 into master Jun 19, 2026
28 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