Problem
In the Mining IPC interface, block_reserved_weight (minimum 2,000 WU) and coinbase_output_max_additional_sigops must be chosen upfront in Mining.createNewBlock(options), and BlockTemplate.waitNext() reuses those captured options.
In practice, mining clients often don't want a static upfront guess:
- Changing coinbase size (#33575): When downstream payout outputs grow or shrink (e.g., Stratum V2
CoinbaseOutputConstraintsor dynamic pool payouts), the client has tointerruptWait()and callcreateNewBlock(), locking the mempool and rebuilding the entire template just to free or reclaim a few hundred/thousand WU. - Multiple downstream profiles (#33389 / #35675): A proxy serving both solo miners (~930 WU total header + coinbase) and multi-output pool channels (16,000+ WU) cannot share a single
BlockTemplatestream. - 2,000 WU static floor (#31384):
MINIMUM_BLOCK_RESERVED_WEIGHT(2,000 WU) includes a ~1,000+ WU human-error cushion for-blockreservedweightCLI users, which isn't needed when an IPC client knows the exact byte weight of its serialized coinbase.
Proposal
Add a method on BlockTemplate (or support inside BlockTemplateManager) that derives a new immutable BlockTemplate for a given coinbase weight and sigop budget by dropping enough low-feerate transactions/chunks from the existing template in memory, without re-locking cs_main or the mempool:
# src/ipc/capnp/mining.capnp (inside interface BlockTemplate)
trim [@11](/bitcoin-bitcoin/contributor/11/) (context :Proxy.Context, options: BlockCreateOptions) -> (result: BlockTemplate);
Concretely, this only needs to:
- Record cluster-chunk boundaries in
CBlockTemplateduringBlockAssembler::addChunks()so whole dependent chunks (or standalone transactions) are dropped cleanly without stranding low-fee CPFP parents. - Copy the kept
vtxslice into a newBlockTemplateImpl(leaving the original template and any activewaitNext()/submitSolution()calls untouched). - Subtract the dropped transaction fees from
CoinbaseTx::block_reward_remainingand call the existingBlockWitnessMerkleRoot()andCoinbaseMerklePath()helpers (~0.2 ms, lock-free).
Alternative proposal
If the requirement that the raw template be submittable before trimming is dropped, you can go one step further: have createNewBlock / BlockTemplateManager snapshot slightly more than 4,000,000 WU of linearized chunks from the mempool (say 4,050,000 WU, maybe ~15–30 extra chunks in memory) and only materialize the CoinbaseTx + Merkle commitments when the client calls finalize(exact_coinbase_weight, exact_sigops), exchanging enough transactions inside the 4 MWU limit with excess chunks to find the best fit.
This can work in conjuction with the above proposal for backwards compatibility (if needed for such a new interface), where createNewBlock can trim it to the requested size.
Questions for Feedback
- Does this belong as a method on
BlockTemplate, transparently insideBlockTemplateManager(#35675), or both? - Does it make sense to drop the 2,000 WU
MINIMUM_BLOCK_RESERVED_WEIGHTsafety cushion for the IPC path to the actual header + base-coinbase structural weight (~776 WU), letting the client trim the exact additional weight its coinbase needs?