bugfix: compare non-adjusted chunk weight against block weight limit #35580

pull ismaelsadeeq wants to merge 2 commits into bitcoin:master from ismaelsadeeq:07-2026-fix-chunk-weight-limit changing 3 files +51 −16
  1. ismaelsadeeq commented at 10:49 AM on June 22, 2026: member

    Partially fixes #35596

    When assembling a block template, BlockAssembler::addChunks() adds chunks of transactions until the block is close to being full. For each chunk, TestChunkBlockLimits() checks both the weight and the sigop-cost limits before the chunk is included.

    The weight check compared the chunk's sigops-adjusted weight against block_max_weight:

    if (nBlockWeight + chunk_feerate.size >= m_options.block_max_weight) {
        return false;
    }
    

    Whereas nBlockWeight accumulates the actual chunk weight.

    A chunk whose sigop-adjusted weight exceeds the actual weight can be wrongly skipped even though the block sigop limit is enforced independently on the next line, and that could pass. Those chunks pay higher fees, so this could potentially cause miners to needlessly forfeit some fees revenue.

    This PR fixes this by passing the chunk's real weight (sum of GetTxWeight(), accumulated in the same loop that already sums sigop cost) to TestChunkBlockLimits(). The separate sigop-cost check is unchanged.

    • The first commit adds TestSigOpsAdjustedWeightChunkLimit: it builds one sigop-dense transaction sized to fit by real weight but not by adjusted weight, and asserts that the tx is skipped and only the coinbase is mined.

    • The second commit applies the fix and flips the assertion to show the transaction is now included.

  2. DrahtBot commented at 10:49 AM on June 22, 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/35580.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35581 (node: add block template manager and track waitNext fee inflow by ismaelsadeeq)
    • #35569 (Encapsulation for CTransaction by purpleKarrot)
    • #35511 (RFC: consensus: Make CAmount a class by hodlinator)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. ismaelsadeeq renamed this:
    bugfix: compare non-adjusted chunk weight against block weight limit in `TestBlockChunklimit`
    bugfix: compare non-adjusted chunk weight against block weight limit
    on Jun 22, 2026
  4. DrahtBot added the label Needs rebase on Jun 23, 2026
  5. test: `TestChunkBlockLimits` uses incorrect weight for comparison
    addChunks() passes the chunk's sigops-adjusted fee rate to
    TestChunkBlockLimits() and the adjusted weight is used for block weight
    limit check while `nBlockWeight` accumulates real transaction weight.
    
    A sigop-dense chunk that fits the block by real weight is therefore
    checked against block_max_weight by its larger adjusted weight and wrongly
    skipped.
    
    Add a transaction sized to fit by real weight; but is left out of the
    template (only the coinbase is mined) due to this issue.
    
    The next commit fixes this and flips the assertion.
    1754401de4
  6. bugfix: compare real chunk weight against block weight limit
    TestChunkBlockLimits() compared the chunk's sigops-adjusted weight against
    block_max_weight, while nBlockWeight tracks real transaction weight. This
    over-counted sigop-dense chunks and could skip ones that actually fit,
    losing fees; the block sigop limit is enforced separately on the next line.
    
    Pass the chunk's real weight (sum of GetTxWeight()) instead, and update the
    test to show the chunk is now included.
    a9a4f7f2c9
  7. ismaelsadeeq force-pushed on Jun 24, 2026
  8. DrahtBot removed the label Needs rebase on Jun 24, 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-06-27 22:51 UTC

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