Tracking: #33777
Motivation
Mining::checkBlock(block, options) (#31981) allows IPC clients to consensus-validate a candidate block with checkPow = false before a winning share is found. This is very useful for mining servers that allow miners or pools to construct custom coinbase transactions (custom payout scriptPubKeys, OP_RETURN commitments, or scriptSig graffiti) and want to catch consensus errors on low-difficulty shares.
However, because checkBlock() takes a full serialized block: Data, an IPC client that obtains its templates via Mining::createNewBlock() / BlockTemplate::waitNext() currently has to:
- Call
BlockTemplate::getBlock()on every template refresh (transferring 1 to 4 MB over IPC and retaining the raw block in client RAM), - Parse out the offset of
vtx[1]and splice in the candidate coinbase, and - Send the full 1 to 4 MB serialized block back to
Mining::checkBlock().
Meanwhile, BlockTemplate already holds the template's transactions in memory and BlockTemplate::submitSolution(version, timestamp, nonce, coinbase) already assembles the candidate CBlock from just the header fields and coinbase.
Proposal
Add a checkSolution() method to BlockTemplate mirroring submitSolution(), accepting BlockCheckOptions:
interface BlockTemplate {
...
checkSolution [@11](/bitcoin-bitcoin/contributor/11/) (
context :Proxy.Context,
version :UInt32,
timestamp :UInt32,
nonce :UInt32,
coinbase :Data,
options :BlockCheckOptions
) -> (reason :Text, debug :Text, result :Bool);
}
Internally this can reuse the same block-assembly path as submitSolution() (updating nVersion, nTime, nNonce, vtx[0], and recomputing hashMerkleRoot if options.checkMerkleRoot is set) and run TestBlockValidity() with options.checkPow.
Benefits
- Eliminates calling
getBlock()(1 to 4 MB per template) for clients that only need to validate custom coinbases against Bitcoin Core's own templates. - Cuts both IPC bandwidth and client memory footprint for retained templates (#33899).
- Backward-compatible additive change to
BlockTemplate.