2323#include < core/log.hpp>
2424
2525#include < ctime>
26+ #include < string>
2627#include < limits>
2728
2829namespace dgb ::stratum {
2930
31+ namespace {
32+
33+ // Render a u256 as the GBT-conventional big-endian block-hash display hex:
34+ // most-significant limb first, 64 lowercase hex digits, no 0x prefix. Mirrors
35+ // uint256::GetHex() ordering for a hash stored with limb[0] least-significant.
36+ // Header-only u256 has no GetHex(), and this TU must not depend on btclibs'
37+ // uint256, so we format the limbs directly.
38+ std::string u256_be_display_hex (const dgb::coin::u256& v)
39+ {
40+ static constexpr char H[] = " 0123456789abcdef" ;
41+ std::string out;
42+ out.reserve (64 );
43+ for (int li = 3 ; li >= 0 ; --li) {
44+ const uint64_t w = v.limb [li];
45+ for (int sh = 60 ; sh >= 0 ; sh -= 4 )
46+ out.push_back (H[(w >> sh) & 0xF ]);
47+ }
48+ return out;
49+ }
50+
51+ } // namespace
52+
3053DGBWorkSource::DGBWorkSource (c2pool::dgb::HeaderChain& chain,
3154 dgb::coin::Mempool& mempool,
3255 bool is_testnet,
@@ -184,11 +207,26 @@ nlohmann::json DGBWorkSource::get_current_work_template() const
184207 // so no transactions are fabricated and fees stay 0
185208 // (consistent with the total_fees=0 coinbasevalue above).
186209 //
187- // Deliberately NOT emitted yet — they need accessors the Scrypt-only
188- // HeaderSample does not carry, and land in the following Stage 4c/4d slices:
189- // previousblockhash — the tip block hash (HeaderSample stores no hash yet)
190- // bits — the next-block compact target off the DigiShield
191- // retarget window
210+ // previousblockhash — the tip block id. Emitted ONLY when the HeaderChain
211+ // carries a real tip hash (tip_hash() accessor): the
212+ // Scrypt-only HeaderSample now carries a block_hash slot,
213+ // but the embedded P2P header-download -> validate_and_append
214+ // ingest that POPULATES it lands in a following slice, so on
215+ // today's chain state tip_hash() is nullopt and the field is
216+ // held back -- a truthful absence, never a fabricated hash.
217+ // bits — HELD BACK. The only embedded next-target source is the
218+ // DigiShield/MultiShield damped multiply, which DGB Core
219+ // runs as MultiShield V4: a GLOBAL window across all 5 algos
220+ // with per-algo adjust + MTP deltas. A Scrypt-only header
221+ // walk cannot reconstruct that window (== V37, 5-algo
222+ // validation), so the ingest path deliberately demotes the
223+ // retarget gate to a no-op (see header_chain.hpp). Emitting
224+ // a digishield_next_target()-derived bits would be a
225+ // KNOWN-WRONG value -- the same fabrication the empty
226+ // transactions[] and total_fees=0 avoid. The authoritative
227+ // bits is the external-daemon GBT value, which is not
228+ // plumbed into this embedded template path yet; bits stays
229+ // absent until then. [decision-needed] surfaced to integrator.
192230 // and the per-connection coinbase (gentx + ShareTracker ref_hash + PPLNS
193231 // payout map) assembles in build_connection_coinbase() — that output is
194232 // consensus-bearing and surfaces for an operator tap, not in this field wire.
@@ -209,6 +247,11 @@ nlohmann::json DGBWorkSource::get_current_work_template() const
209247 tmpl[" curtime" ] = curtime;
210248 tmpl[" mintime" ] = mintime;
211249 tmpl[" transactions" ] = nlohmann::json::array ();
250+
251+ // previousblockhash: truthful conditional emit (see field notes above).
252+ if (auto th = chain_.tip_hash ())
253+ tmpl[" previousblockhash" ] = u256_be_display_hex (*th);
254+
212255 return tmpl;
213256}
214257
0 commit comments