dgb: wire worker->mint callback in run-loop (Phase B, stacked on #305) - #306
Merged
Merged
Conversation
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.
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.
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_ratchetadapter but leftset_mint_share_fnunbound inmain_dgb— a Scrypt submission classifiedShareAcceptreachedtry_mint_share, found no callback, and earned no sharechain credit (loud no-op, never a silent drop). This binds it.run_loop_mint.hpp— newmint_local_share_locked(node, ...)helper. The mint fires on the Stratum-submission thread, not the compute (think()) thread — so unlike them_on_block_foundwon-block path it does not already hold the tracker lock, andcreate_local_shareis a tracker write. Per theNodeImpllocking discipline (node.hpp:83-92, mirrored bynode.cppprocessing_shares_phase2) the helper takesunique_lock(try_to_lock)and never blocks the io_context onthink()'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()).main_dgb.cpp— long-livedAutoRatchet(make_dgb_ratchet, base 35 / target 36, oracle22761e7) declared ahead ofwork_sourceso it outlives the callback; bound viaset_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_test27/27 green;c2pool-dgblinks.Fence
src/impl/dgb/run_loop_mint.hpp,src/c2pool/main_dgb.cpp,src/impl/dgb/test/share_test.cpponly. No shared /bitcoin_family/src/core/ other-coin touch. No new test target → nobuild.ymlallowlist change.HOLD merge — consumer-binds the ratchet (consensus-adjacent); surface for operator tap, do not self-merge. Stacked; land after #305.