mining: include chunks that exactly fill block limits #36156

pull l0rinc wants to merge 2 commits into bitcoin:master from l0rinc:l0rinc/mine-exact-limit-chunks changing 2 files +16 −8
  1. l0rinc commented at 4:28 AM on September 3, 2026: contributor

    Draft to get conceptual reviews first.


    Problem: BlockAssembler fills block templates with mempool chunks that fit the configured weight and sigops limits, but currently rejects a chunk when it makes either total equal to its limit. Equality is valid: block_max_weight is the maximum block weight, and BIP 141 defines both consensus limits using . The >= checks can therefore leave valid capacity unused and omit a fee-paying chunk.

    Fix: Use strict greater-than comparisons so exact-limit chunks are included. Extend the existing chunk-limit test to cover equality for both weight and sigops.

    This addresses issue 1 in #35596.

  2. test: characterize exact-limit chunk underfill
    Record that `BlockAssembler` omits a one-transaction chunk that brings the block exactly to `block_max_weight` or `MAX_BLOCK_SIGOPS_COST`.
    96ee80f7eb
  3. mining: include exact-limit chunks
    `BlockAssembler` rejects a chunk that brings the block exactly to `block_max_weight` or `MAX_BLOCK_SIGOPS_COST`,
    although consensus accepts a block that reaches its limits exactly, so a valid fee-paying chunk is left out of the template.
    
    Compare both limits with strict greater-than so block assembly accepts equality like consensus does.
    dc73908d7f
  4. DrahtBot added the label Mining on Sep 3, 2026
  5. DrahtBot commented at 4:28 AM on September 3, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36156.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK ismaelsadeeq

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  6. ajtowns commented at 1:41 PM on September 3, 2026: contributor

    This seems backwards to me: the risk of a mistake here is that the block becomes invalid losing all possible reward from mining it, while the benefit of success is perhaps a single larger / additional transaction at the bottom of the block. Currently the bottom transaction in a block seems to pay less than 1000sats in total fees, so generously, that's less than 80c per block, as compared to the subsidy of around $240k per block.

  7. ismaelsadeeq commented at 2:12 PM on September 3, 2026: member

    Concept ACK

    Looks correct to me.

    This seems backwards to me: the risk of a mistake here is that the block becomes invalid losing all possible reward from mining it, while the benefit of success is perhaps a single larger / additional transaction at the bottom of the block.

    This fix seems straightforward and correct, with good tests. Will the mistake come from the individual chunks sigops or weight accounting error? If indeed we do have that error, we still could end up creating an invalid block even without this fix.

    If we are confident that our accounting of weight and sigops is correct without this PR, and that the block assembler will not create an invalid block, then fixing this issue is okay.

    Currently the bottom transaction in a block seems to pay less than 1000sats in total fees, so generously, that's less than 80c per block, as compared to the subsidy of around $240k per block.

    I think it's less about the revenue but more about making the block assembler code correct and reflect consensus allowed limits, and making it explicit that filled blocks may be created, are valid and will be accepted as part of the blockchain.

    For me the more risky part is when we allow this minor bugs in the code, it incentivise pool companies to patch the code themselves to fix it, fwiw F2Pool did fix these bugs and have their custom binaries which create filled blocks.

  8. ajtowns commented at 5:44 PM on September 3, 2026: contributor

    For me the more risky part is when we allow this minor bugs in the code, it incentivise pool companies to patch the code themselves to fix it, fwiw F2Pool did fix these bugs and have their custom binaries which create filled blocks.

    The issue you're referencing was in regards to 500vb of wasted space, versus this PR which is a delta of 1vb of space. The block you're referring to has a 2127 WU unused:

    $ bitcoin-cli getblock 00000000000000000001eac8304428ea2fc5fc56e9ffefec848efde3c5a4f279 | jq 4e6-.weight
    2127
    

    It's certainly bad if mining pools introduce bugs in their software that invalidate blocks while trying to get to the very edge of valid behaviour, but at least it only impacts a single pool that way. I don't see why we would want to play the same stupid game and risk winning the same stupid prize. Off by one errors are common; removing a defensive buffer against that might be appropriate if there was a significant win to be had, but there isn't here.

    Anyway, I've said my piece, I'll unsubscribe.


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-09-04 08:51 UTC

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