test: check AddToBlockIndex keeps first-seen header on equal work #36684

pull brunoerg wants to merge 1 commits into bitcoin:master from brunoerg:2026-10-test-blockindex-best-header changing 1 files +24 −0
  1. brunoerg commented at 1:28 PM on October 28, 2026: contributor

    BlockManager::AddToBlockIndex only replaces best_header when the new header has strictly more chain work. Add a unit test that adds two sibling headers with equal work and checks that best_header keeps pointing to the first one.

    Kills the following mutant (https://mutanthub.space/mutants/3806):

    diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
    index 2ee13aa417..aad52d6d61 100644
    --- a/src/node/blockstorage.cpp
    +++ b/src/node/blockstorage.cpp
    @@ -246,7 +246,7 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block, CBlockInde
         pindexNew->nTimeMax = (pindexNew->pprev ? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) : pindexNew->nTime);
         pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
         pindexNew->RaiseValidity(BLOCK_VALID_TREE);
    -    if (best_header == nullptr || best_header->nChainWork < pindexNew->nChainWork) {
    +    if (best_header == nullptr || best_header->nChainWork <= pindexNew->nChainWork) {
             best_header = pindexNew;
         }
    
  2. test: check AddToBlockIndex keeps first-seen header on equal work
    BlockManager::AddToBlockIndex only replaces best_header when the new
    header has strictly more chain work. Add a unit test that adds two
    sibling headers with equal work and checks that best_header keeps
    pointing to the first one.
    701545e5b5
  3. DrahtBot added the label Tests on Oct 28, 2026
  4. DrahtBot commented at 1:28 PM on October 28, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    Type Reviewers
    ACK maflcko, ViniciusCestarii, KY-U

    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-->

  5. maflcko commented at 1:59 PM on October 28, 2026: member

    lgtm ACK 701545e5b5750aa24cfc87b2db93f4f81accb67c

  6. ViniciusCestarii commented at 2:13 PM on October 28, 2026: contributor

    ACK 701545e5b5750aa24cfc87b2db93f4f81accb67c

  7. KY-U commented at 2:17 PM on October 28, 2026: contributor

    tACK https://github.com/bitcoin/bitcoin/commit/701545e5b5750aa24cfc87b2db93f4f81accb67c

    Introduced the mutant and verified the added test kills it.

  8. fanquake merged this on Oct 28, 2026
  9. fanquake closed this on Oct 28, 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-10-29 06:51 UTC

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