This PR adds the IPC equivalent of the getblocktemplate
RPC in proposal
mode.
In order to do so it moves TestBlockValidity
to ChainstateManager
and has is return error reasons as a string instead of BlockValidationState
. This avoids complexity in IPC code for handling the latter struct.
The new Mining interface method is used in miner_tests
and the getblocktemplate
and generateblock
RPC calls, so it has test coverage.
The inconclusive-not-best-prevblk
check is moved from RPC
code to TestBlockValidity
.
Test coverage is increased by mining_template_verification.py
.
Superseedes #31564
Background
Verifying block templates (no PoW)
Stratum v2 allows miners to generate their own block template. Pools may wish (or need) to verify these templates. This typically involves comparing mempools, asking miners to providing missing transactions and then reconstructing the proposed block.1 This is not sufficient to ensure a proposed block is actually valid. In some schemes miners could take advantage of incomplete validation2.
The Stratum Reference Implementation (SRI), currently the only Stratum v2 implementation, collects all missing mempool transactions, but does not yet fully verify the block.3. It could use the getblocktemplate
RPC in proposal
mode, but using IPC is more performant, as it avoids serialising up to 4 MB of transaction data as JSON.
(although SRI could use this PR, the Template Provider role doesn’t need it, so this is not part of #31098)