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.
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.