dgb(stratum): score shares via scrypt digest in compute_share_difficulty (unstub 4b/4c)#753
Merged
Merged
Conversation
…ty embedded chain A freshly-stood-up c2pool-dgb :5025 node whose Scrypt-only HeaderChain has not yet ingested a tip (tip_hash()==nullopt) could supply NEITHER a previousblockhash NOR nBits: the header walk cannot reconstruct MultiShield-V4 (a 5-algo window == V37), and the embedded ingest that populates the tip lands later. Result: an EMPTY mining.notify prevhash on the live testnet. Add DGBWorkSource::set_gbt_tip_fn -- a std::function seam (mirrors set_pplns_inputs_fn and dash #726 dashd_fallback) bound in main_dgb.cpp to a lambda over NodeRPC::getblocktemplate. When the embedded chain has no tip, get_current_work_template() AND get_current_gbt_prevhash() (the notify-prevhash source) draw BOTH previousblockhash and the daemon-authoritative bits from ONE GBT snapshot (consistent height). A real embedded tip always wins; the RPC transport stays in main (stratum/ holds only the seam). Unbound / no digibyted creds / RPC failure -> both fields stay a truthful ABSENCE, byte-identical to the pre-wire path -- never a fabricated tip/bits. GBT previousblockhash is the u256_be_display_hex big-endian convention the embedded path emits, so it flows verbatim (width-guarded at the bind). TTL-cached (5s) so per-heartbeat template + prevhash polls do not each trigger a blocking getblocktemplate round-trip. External-daemon GBT fallback RETAINED (never removed), per V36. Scrypt-only; no shared-base / other-coin edit; per-coin isolation held. Tests: 3 new DgbWorkSource.GbtTip* (populate / unbound-absent / nullopt-absent) over the empty-chain fixture; full dgb_work_source_test 30/30 green.
…lty (unstub 4b/4c) DGBWorkSource::compute_share_difficulty was a Stage-4b/4c stub returning 0.0. The coin-agnostic StratumServer calls it BEFORE mining_submit and silently rejects any share scoring below the vardiff floor (stratum_server.cpp: error 23 Low difficulty share, no server-side log), so every accepted-looking share was dropped before the stage-4d classify+broadcaster ever ran -- the pool could never advance its tip. Implement it as a byte-for-byte mirror of mining_submit reconstruct: coinb1||en1||en2||coinb2 -> sha256d txid -> ascend merkle branches -> 80-byte header -> scrypt_1024_1_1_256, then bridge the coin-space u256 into core uint256 via the u256_be_display_hex SSOT and return chain::target_to_difficulty (diff-1 0x1d00ffff) -- unit-identical to the required_difficulty / pool_difficulty the gate compares. Malformed reconstruct (header != 80B) keeps the documented 0.0 not-scored sentinel. KAT: valid header scores a finite positive difficulty; malformed input still returns 0.0. 31/31 dgb_work_source_test green.
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.
Summary
DGBWorkSource::compute_share_difficultywas a Stage-4b/4c stub returning0.0.The coin-agnostic
StratumServercalls it beforemining_submitand silentlyrejects any share scoring below the vardiff floor (
stratum_server.cpp:1128,error 23 "Low difficulty share", no server-side log). Every otherwise-valid share
was dropped before the stage-4d classify + broadcaster path ever ran, so the DGB
pool could never advance its tip.
What this does
Implements
compute_share_difficultyas a byte-for-byte mirror of themining_submitreconstruct:coinb1 || en1 || en2 || coinb2-> sha256d txid -> ascend merkle branches ->80-byte header ->
scrypt_1024_1_1_256, then bridges the coin-space u256 intocore
uint256via theu256_be_display_hexSSOT and returnschain::target_to_difficultyagainst diff-10x1d00ffff— unit-identical to therequired_difficulty/pool_difficultythe gate compares against.Malformed reconstruct (header != 80 bytes) keeps the documented
0.0not-scored sentinel.
Test
ReturnsNotYetSentinelplaceholder atwork_source_test.cpp:342: valid header scores a finite positive difficulty.Live verification
Deployed to VM115 as
c2pool-dgb-csd(pid 56981), testnet, stratum:5025,rig hashing against it. Shares now score (0.001+) -> cross the vardiff gate
-> 15+
BLOCK FOUND-> dispatchsubmitblock.Follow-on (tracked separately, not a regression from this commit): on an
empty embedded chain
digibytedrejects the submitted block withbad-txnmrklroot— the reconstructed header merkleroot does not match theserialized coinbase. That is the Phase-B GBT-block-template gap; fix is to
source the full block template from
digibytedGBT when the embedded chainis empty.
Scope
src/impl/dgb/only. No shared-base orsrc/corechanges.