Header-only support for waitNext() #33756

issue Sjors openend this issue on October 31, 2025
  1. Sjors commented at 4:38 pm on October 31, 2025: member

    I’d like to expand the waitNext() Mining IPC function to optionally (via BlockWaitOptions) return a (empty) new template as soon as we have a header with enough proof-of-work, pending block download and/or validation.

    https://github.com/bitcoin/bitcoin/blob/3cd4263bf66408760ec3b4ce6ccedcc87e0d53de/src/interfaces/mining.h#L63-L74

    I suspect there’s little benefit if compact block reconstruction succeeds, and IIUC we hold cs_main during this process anyway so there’s no way to generate a template.

    But if we need a round trip to our peer because compact block construction didn’t finish, it might be useful to create an empty block template and push it.

    This can hopefully be implemented without touching validation code, as long as the kernel can provide a notification. Currently it only notifies us of a better tip, not a better header.


    Closely related to this is the Stratum v2 concept of sending an empty (or optimistically filled) “future” template downstream for mining devices to load, followed by a prevhash messages when a new header is found. Whether that’s actually more performant than the above probably depends on the details of ASIC firmware.

    Implementation wise, we’d need the same kernel notification for it. At the interface level it might look like a getFuture() method on BlockTemplate which could return a FutureTemplate interface with a wait() method on it. That would return a prevhash once we validated a header. The client then sends that downstream and immediately calls waitNext() on the original template in order to get a fresh full block template as soon as we processed the full block.


    In both cases, we’d need a way to notify the TP if it the block turned out to be invalid. That way it can revert to the previous template.

  2. Fi3 commented at 4:47 pm on October 31, 2025: none

    it make sense for the TP to optimistically create templates as soon as there is a possible new block since this will reduce the time that a miner waste on stale jobs. Is kinda safe since the TP can stop following the optimistic path when 2 or more consecutive invalid blocks are received. If we leave it like it is now the miner will keep mine on the old job until the block template do not provide a new job.

    So worst case we waste a bunch of hundreds milliseconds mining invalid jobs, that we are still going to waste mining on old jobs.


Sjors Fi3


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-11-01 00:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me