Skip to content

dgb: wire worker->mint callback in run-loop (Phase B, stacked on #305) - #306

Merged
frstrtr merged 1 commit into
dgb/phase-b-mint-adapterfrom
dgb/phase-b-mint-runloop-bind
Jun 22, 2026
Merged

dgb: wire worker->mint callback in run-loop (Phase B, stacked on #305)#306
frstrtr merged 1 commit into
dgb/phase-b-mint-adapterfrom
dgb/phase-b-mint-runloop-bind

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Stacked on #305 (base dgb/phase-b-mint-adapter). Completes the Phase B worker->mint path.

What

#305 re-landed the mint_local_share_with_ratchet adapter but left set_mint_share_fn unbound in main_dgb — 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 it.

  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) 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. Durable defer-queue is a tracked follow-up. Duck-typed on the node (tracker()/tracker_mutex()).
  2. main_dgb.cpp — long-lived AutoRatchet (make_dgb_ratchet, base 35 / target 36, oracle 22761e7) declared ahead of work_source so it outlives the callback; bound via set_mint_share_fn. The ratchet is touched only inside the closure under the tracker lock → state serialized, no extra mutex. In-memory for now (persistence follow-up; a restart re-bootstraps to VOTING, which never regresses a crossed share).

The lock I take (per integrator's call-out)

std::unique_lock<std::shared_mutex>(p2p_node.tracker_mutex(), std::try_to_lock) — non-blocking; declines on contention. This is the deliberate thread-safety choice the adapter punted to the caller.

Tests / verification

  • share_test.cpp +2: declines without blocking & leaves the tracker untouched when the lock is held; acquires + releases (RAII) when free.
  • dgb_share_test 27/27 green; c2pool-dgb links.

Fence

src/impl/dgb/run_loop_mint.hpp, src/c2pool/main_dgb.cpp, src/impl/dgb/test/share_test.cpp only. No shared / bitcoin_family / src/core / other-coin touch. No new test target → no build.yml allowlist change.

HOLD merge — consumer-binds the ratchet (consensus-adjacent); surface for operator tap, do not self-merge. Stacked; land after #305.

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.
@frstrtr
frstrtr merged commit 2d78b84 into dgb/phase-b-mint-adapter Jun 22, 2026
@frstrtr
frstrtr deleted the dgb/phase-b-mint-runloop-bind branch June 22, 2026 08:28
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