mining: add BlockTemplate::checkSolution() to pre-validate custom coinbases without getBlock() #37012

issue mutatrum opened this issue on November 29, 2026
  1. mutatrum commented at 10:22 PM on November 29, 2026: contributor

    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:

    1. Call BlockTemplate::getBlock() on every template refresh (transferring 1 to 4 MB over IPC and retaining the raw block in client RAM),
    2. Parse out the offset of vtx[1] and splice in the candidate coinbase, and
    3. 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.
  2. mutatrum added the label Feature on Nov 29, 2026

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: 2026-11-30 04:51 UTC

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