Skip to content

coinbaser: Request a new block's coinbaser split when its empty work job is published - #25

Closed
iohzrd wants to merge 1 commit into
CONVOYMining:masterfrom
iohzrd:coinbaser-prefetch
Closed

iohzrd wants to merge 1 commit into
CONVOYMining:masterfrom
iohzrd:coinbaser-prefetch

Conversation

@iohzrd

@iohzrd iohzrd commented Oct 5, 2026 •

Copy link
Copy Markdown

Replaces the previous version of this PR (99a2871). That version sent the request from the template thread through a pending-request slot shared with the coinbaser thread's fetch. Two requests could be outstanding at once, so a reply could be matched to the wrong request, and an unanswered request blocked later fetches for the same template. This version keeps the coinbaser thread as the only sender and does not change datum_protocol_coinbaser_fetch.

On a new block or an urgent work update, update_stratum_job publishes a JOB_STATE_EMPTY_PLUS job, waits up to 4 s for its empty work to be sent, then publishes a JOB_STATE_FULL_PRIORITY_WAIT_COINBASER job from the same template. The coinbaser request was sent only after the second job was published, so its round trip to the pool did not overlap the empty work send. Miners mine on a coinbase that pays only the pool until the reply is applied.

  • datum_coinbaser_prefetch: when the coinbaser thread sees an EMPTY_PLUS job, it fetches the split for that job's value and previous block into a static job. Skipped unless datum_protocol_is_active(), the same condition as a job's own fetch.
  • datum_coinbaser_prefetch_take: the next FULL_PRIORITY_WAIT_COINBASER job copies the outputs and coinbaser id if its value, previous block and DATUM session generation match. Otherwise it sends its own request, as before. Each take clears the stored split, so at most one job uses it.
  • datum_protocol_session_generation() returns the session counter, so a split fetched on one session is not used on the next.
  • When the first request is answered, one request is sent per block, the same as before.
  • Tests: the matching job takes the split once; another session, previous block, value or job state does not; a fetch with no outputs is not taken; a non-matching job clears it.

Unchanged: the reply carries only the value, so a late reply to an earlier request with the same value and a different previous block is accepted, as on master.

Merges without conflicts with #9, #13, #21 and #24 separately, and with #9, #13 and #21 together. -Wall -Werror build and --test pass on each. With #9, the fetch used here also catches a reply that arrives before the wait starts.

…job is published

On a new block or an urgent work update, update_stratum_job publishes a
JOB_STATE_EMPTY_PLUS job, waits up to 4 s for its empty work to be sent,
then publishes a JOB_STATE_FULL_PRIORITY_WAIT_COINBASER job from the same
template. The coinbaser request was sent only after the second job was
published, so its round trip to the pool did not overlap the empty work
send. Miners mine on a coinbase that pays only the pool until the reply is
applied.

The coinbaser thread now fetches the split for the EMPTY_PLUS job's value
and previous block when it sees that job, into a static job. The next
FULL_PRIORITY_WAIT_COINBASER job copies it if the value, previous block
and DATUM session generation match, and otherwise sends its own request.
Each take clears the stored split. The coinbaser thread remains the only
sender of coinbaser requests.
@iohzrd
iohzrd force-pushed the coinbaser-prefetch branch from 99a2871 to f3aa644 Compare October 5, 2026 23:08
@iohzrd iohzrd changed the title protocol: Request a template's coinbaser split when the template is parsed coinbaser: Request a new block's coinbaser split when its empty work job is published Oct 5, 2026
@iohzrd

iohzrd commented Oct 5, 2026

Copy link
Copy Markdown
Author

Closing. The prefetch saves at most the shorter of the empty work send time and the round trip to the pool, which is a few milliseconds per block. The case that costs the split is a coinbaser reply that arrives after the 5 s timeout: the reply is discarded and miners keep the pool-only coinbase until the next standard job. That needs a separate change.

@iohzrd iohzrd closed this Oct 5, 2026
@iohzrd
iohzrd deleted the coinbaser-prefetch branch October 6, 2026 04:37
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