Skip to content

dgb: re-land worker->mint adapter (run_loop_mint.hpp) — Phase B consumer seam#305

Merged
frstrtr merged 1 commit into
masterfrom
dgb/phase-b-mint-adapter
Jun 22, 2026
Merged

dgb: re-land worker->mint adapter (run_loop_mint.hpp) — Phase B consumer seam#305
frstrtr merged 1 commit into
masterfrom
dgb/phase-b-mint-adapter

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Phase B — pool/share run-loop standup (slice 1: consumer adapter)

Re-lands the #294 mint_local_share_with_ratchet helper, which was lost from master in the #292/#293/#294 stacked squash-merge: there is no #294 merge commit on origin/master (only #295/#297), and src/impl/dgb/run_loop_mint.hpp is absent — though the primitives it composes (dgb_select_mint_versions, create_local_share) both survive. DGBWorkSource::set_mint_share_fn is consequently never bound (no caller in main_dgb), so the worker->mint ShareAccept branch is a no-op today.

What this does

The consumer adapter DGBWorkSource::MintShareFn binds to (per work_source.hpp:197 contract). On a ShareAccept submission (Scrypt PoW meets SHARE target, not block target) it:

  1. parses the 80-byte reconstructed header into SmallBlockHeaderType,
  2. asks the live AutoRatchet for the {mint, vote} version pair via dgb_select_mint_versions (anchored at the sharechain tip = new shareʼs parent),
  3. inserts via create_local_share, returning the minted hash (NULL on malformed header — fail-closed).

Authored against masterʼs create_local_share signature (authoritative). Duck-typed on the inputs so the header doesnʼt pull the stratum work_source TU in. Pure adapter — tracker-insertion thread-safety is the caller (main_dgb bind) point concern, handled in the next slice.

Scope / safety

  • Fenced to src/impl/dgb/ (new header + KAT only). No shared base / other coin tree touched.
  • No behavior change: nothing calls the helper yet (the main_dgb bind is the follow-up slice). New unused header + test-only.
  • KAT in existing dgb_share_test (no new exe, no build.yml allowlist churn): header parse round-trip, short-buffer fail-closed, adapter fail-closed + create_local_share template drift-guard. 25/25 green locally.

Surface-for-tap — HOLD merge for integrator (no self-merge).

…mer seam

Re-lands the #294 mint_local_share_with_ratchet helper, which was lost from
master in the #292/#293/#294 stacked squash-merge (no #294 merge commit reaches
origin/master; the primitives dgb_select_mint_versions + create_local_share
survive). This is the consumer adapter DGBWorkSource::MintShareFn binds to
(work_source.hpp:197): on a ShareAccept submission it parses the 80-byte
reconstructed header, asks the live AutoRatchet for the {mint, vote} version
pair, and inserts the share via create_local_share, returning the minted hash
(NULL on a malformed header / fail-closed).

Authored against master createlocal_share signature (authoritative). Duck-typed
on the inputs so the header does not pull the stratum work_source TU in. Pure
adapter: tracker-insertion thread-safety is the caller bind point concern.

KAT (dgb_share_test, no new exe): 80-byte header parse round-trip, short-buffer
fail-closed, and adapter fail-closed + template instantiation drift-guard
against create_local_share. 25/25 green.
@frstrtr frstrtr merged commit d4b7379 into master Jun 22, 2026
9 checks passed
frstrtr added a commit that referenced this pull request Jun 22, 2026
#306)

Complete the worker->mint sharechain-accept path. #305 re-landed the
mint_local_share_with_ratchet adapter but left set_mint_share_fn UNBOUND
in main_dgb -- so a Scrypt submission classified ShareAccept reached
try_mint_share, found no callback, and earned no sharechain credit
(loud no-op, never a silent drop). This binds the callback.

Two parts:

1. run_loop_mint.hpp: new mint_local_share_locked(node, ...) helper.
   The mint fires on the Stratum-submission thread, NOT the compute
   (think()) thread -- so, unlike the m_on_block_found won-block path, it
   does NOT already hold the tracker lock, and create_local_share is a
   tracker WRITE. Per the NodeImpl locking discipline (node.hpp:83-92,
   mirrored by node.cpp processing_shares_phase2) the helper takes
   unique_lock(try_to_lock) on the tracker mutex and NEVER blocks the
   io_context on think()'s exclusive hold: if the tracker is busy the mint
   is DECLINED this round (NULL, the worker earns no credit until its next
   submission), never blocked, never a racy write. A durable defer-queue
   is a tracked follow-up. Duck-typed on the node (tracker()/tracker_mutex()).

2. main_dgb.cpp: declare a long-lived AutoRatchet (make_dgb_ratchet, base
   35 / target 36, oracle 22761e7) ahead of work_source so it outlives the
   callback, and bind set_mint_share_fn to mint_local_share_locked. The
   ratchet is touched ONLY inside the closure under the tracker lock, so its
   state is serialized -- no extra mutex. In-memory for now (persistence
   follow-up; a restart re-bootstraps to VOTING, which never regresses a
   crossed share).

Tests (share_test.cpp, +2): pin the lock discipline -- declines without
blocking and leaves the tracker untouched when the lock is held; acquires
and releases (RAII) when free. dgb_share_test 27/27; c2pool-dgb links.

Fenced to src/impl/dgb/ + src/c2pool/main_dgb.cpp; no shared/bitcoin_family/
src/core/other-coin touch. No new test target -> no build.yml allowlist change.

Co-authored-by: frstrtr <frstrtr@users.noreply.github.com>
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