Skip to content

Track Bitcoin target in proxy channel from SetNewPrevHash nbits#20

Open
rx18-eng wants to merge 1 commit into
dmnd-pool:mainfrom
rx18-eng:fix/issue-111-bitcoin-target
Open

Track Bitcoin target in proxy channel from SetNewPrevHash nbits#20
rx18-eng wants to merge 1 commit into
dmnd-pool:mainfrom
rx18-eng:fix/issue-111-bitcoin-target

Conversation

@rx18-eng
Copy link
Copy Markdown

@rx18-eng rx18-eng commented Apr 27, 2026

Body

fixes the no-tp side of dmnd-pool/dmnd-client#111

so right now if youre running translator-style proxy with no TP connected, the non-jd branches in channel_factory just hardcode bitcoin_target = [0; 32]. which means OnNewShare::ShareMeetBitcoinTarget literally cant fire for us coz no hash is ever <= 0. so a share that actually finds a block looks like a normal share, hits the 70/min rate limiter on the dmnd-client side, and if were unlucky it just gets dropped. real block lost.

went with what @Fi3 suggested in the thread - just read nbits from the SetNewPrevHash the pool already sends us. we trust the pool for jobs+prev_hash anyway so its not a new trust assumption, no new deps, just a tiny nbits_to_target helper that wraps bitcoin::Target::from_compact and gives back a mining_sv2::Target.

actual diff is small btw - bits was already being extracted right under the [0;32] line and passed to check_target. i just moved the bitcoin_target line down a few lines so it can use bits, and dropped the .into() at the call site since the helper returns Target directly.

fail-open semantics preserved (the constraint @Fi3 flagged - wrong target must never block a share):

  • nbits=0 → Target::ZERO → no hash matches → share takes the normal path. nothing dropped.
  • super lax nbits like regtest → max target → some shares get classified as block-finds and go upstream un-gated. pool just sees em as normal low-hash shares. still nothing dropped.

so worst case wrong target = wrong classification, never a dropped share.

Tests i added (3 unit tests on the helper):

  • nbits_to_target_zero_yields_zero_target so malformed pool msgs cant produce false-positive blocks
  • nbits_to_target_matches_existing_test_helper cross-checks against the nbit_to_target fixture thats already in this same test module
  • nbits_to_target_regtest_max_is_greater_than_mainnet quick sanity check on Target ordering since check_target does hash <= bitcoin_target

the actual integration (the ShareMeetBitcoinTarget arm becoming reachable end to end) ill cover in the dmnd-client bridge PR - will link it back here once this merges. existing JD-path test test_complete_mining_round still passes so didn't break that side.

cc @jbesraa @Priceless-P @Fi3

Signed-off-by: rx18-eng <remopanda78@gmail.com>
@rx18-eng
Copy link
Copy Markdown
Author

@Fi3 @Priceless-P would appreciate your thoughts on this !

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