test: Kill validation mutants #36827

pull Zeegaths wants to merge 2 commits into bitcoin:master from Zeegaths:kill-validation-mutants changing 1 files +5 −0
  1. Zeegaths commented at 2:27 PM on November 10, 2026: none

    This PR kills 3 mutants from https://mutanthub.space/mutants in validation.cpp I batched them together because the assertions are within the same test

    Mutants killed:

    Mutant 4388: validation.cpp ActivateBestChains, && → ||

    @@ -6482,7 +6482,7 @@ util::Result<void> ChainstateManager::ActivateBestChains()
             for (const auto& chainstate : m_chainstates) {
    -            if (chainstate && chainstate->m_assumeutxo != Assumeutxo::INVALID && !chainstate->m_target_utxohash) {
    +            if (chainstate || chainstate->m_assumeutxo != Assumeutxo::INVALID && !chainstate->m_target_utxohash) {
                     chainstates.push_back(chainstate.get());
    

    Mutant 4385: validation.cpp GetPruneRange, + 1 → - 1

    @@ -6447,7 +6447,7 @@ std::pair<int, int> Chainstate::GetPruneRange(int last_height_can_prune) const
    -        prune_start = Assert(SnapshotBase())->nHeight + 1;
    +        prune_start = Assert(SnapshotBase())->nHeight - 1;
    

    Mutant 4386: validation.cpp GetPruneRange, - → + MIN_BLOCKS_TO_KEEP

    @@ -6451,7 +6451,7 @@ std::pair<int, int> Chainstate::GetPruneRange(int last_height_can_prune) const
         int max_prune = std::max<int>(
    -        0, m_chain.Height() - static_cast<int>(MIN_BLOCKS_TO_KEEP));
    +        0, m_chain.Height() + static_cast<int>(MIN_BLOCKS_TO_KEEP));
    
  2. test: check ActivateBestChains skips validated chainstate
    catches validated chainstates being passed
    to ActivateBestChains, which previously went undetected.
    
    kills mutant https://mutanthub.space/mutants/4388
    
    diff --git a/src/validation.cpp b/src/validation.cpp
    index 6bed39ba5f..d965254192 100644
    --- a/src/validation.cpp
    +++ b/src/validation.cpp
    @@ -6482,7 +6482,7 @@ util::Result<void> ChainstateManager::ActivateBestChains()
             LOCK(GetMutex());
             chainstates.reserve(m_chainstates.size());
             for (const auto& chainstate : m_chainstates) {
    -            if (chainstate && chainstate->m_assumeutxo != Assumeutxo::INVALID && !chainstate->m_target_utxohash) {
    +            if (chainstate || chainstate->m_assumeutxo != Assumeutxo::INVALID && !chainstate->m_target_utxohash) {
                     chainstates.push_back(chainstate.get());
                 }
             }
    d8a6314193
  3. test: check GetPruneRange on unvalidated snapshot
    kills mutants https://mutanthub.space/mutants/4385 and
    https://mutanthub.space/mutants/4386
    
    checks prune range before a snapshot chain gets validated
    ensures that pruning does not start before the snapshot block or
    within the last 288 blocks.
    
    diff --git a/src/validation.cpp b/src/validation.cpp
    index 6bed39ba5f..a51e1595aa 100644
    --- a/src/validation.cpp
    +++ b/src/validation.cpp
    @@ -6447,7 +6447,7 @@ std::pair<int, int> Chainstate::GetPruneRange(int last_height_can_prune) const
             // Only prune blocks _after_ the snapshot if this is a snapshot chain
             // that has not been fully validated yet. The earlier blocks need to be
             // kept to validate the snapshot
    -        prune_start = Assert(SnapshotBase())->nHeight + 1;
    +        prune_start = Assert(SnapshotBase())->nHeight - 1;
         }
    
         int max_prune = std::max<int>(
    diff --git a/src/validation.cpp b/src/validation.cpp
    index 6bed39ba5f..99238dfa73 100644
    --- a/src/validation.cpp
    +++ b/src/validation.cpp
    @@ -6451,7 +6451,7 @@ std::pair<int, int> Chainstate::GetPruneRange(int last_height_can_prune) const
         }
    
         int max_prune = std::max<int>(
    -        0, m_chain.Height() - static_cast<int>(MIN_BLOCKS_TO_KEEP));
    +        0, m_chain.Height() + static_cast<int>(MIN_BLOCKS_TO_KEEP));
    
         // last block to prune is the lesser of (caller-specified height, MIN_BLOCKS_TO_KEEP from the tip)
         //
    190f103a63
  4. DrahtBot added the label Tests on Nov 10, 2026
  5. DrahtBot commented at 2:27 PM on November 10, 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 brunoerg, ViniciusCestarii

    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.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36543 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36543.svg"></sub> (validation: check the most recent AssumeUTXO commitment during IBD by l0rinc)

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

  6. fanquake commented at 2:28 PM on November 10, 2026: member
  7. sedited commented at 2:53 PM on November 10, 2026: contributor

    Can you drop all those html tags in the PR description? It makes it hard to read anywhere else.

  8. Zeegaths commented at 3:06 PM on November 10, 2026: none

    Can you drop all those html tags in the PR description? It makes it hard to read anywhere else.

    done

  9. DrahtBot added the label CI failed on Nov 10, 2026
  10. maflcko commented at 4:42 PM on November 10, 2026: member
  11. brunoerg approved
  12. brunoerg commented at 5:07 PM on November 10, 2026: contributor

    lgtm ACK 190f103a63b026d11a1ec90dd42133a910a2dce2

    verified these cases kill the mutants. left one nit (feel free to ignore)

  13. in src/test/validation_chainstatemanager_tests.cpp:820 in 190f103a63
     815 | @@ -816,8 +816,13 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_snapshot_completion, SnapshotTestSetup
     816 |      const uint256 snapshot_tip_hash = WITH_LOCK(chainman.GetMutex(),
     817 |          return chainman.ActiveTip()->GetBlockHash());
     818 |  
     819 | +    auto prune_range = WITH_LOCK(::cs_main, return active_cs.GetPruneRange(active_cs.m_chain.Height()));
     820 | +    BOOST_CHECK_EQUAL(prune_range.first, 111);
    


    brunoerg commented at 5:08 PM on November 10, 2026:

    nit: I'd add a comment explaining these expected numbers. 111 only makes sense if you know the snapshot base is at 110, for example.

  14. ViniciusCestarii commented at 7:23 PM on November 10, 2026: contributor

    ACK 190f103a63b026d11a1ec90dd42133a910a2dce2

    Nice! Verified it kills the mutants.

  15. DrahtBot removed the label CI failed on Nov 11, 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-11-18 16:51 UTC

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