Skip to content

test: Kill validation mutants - #36827

Open
Zeegaths wants to merge 2 commits into
bitcoin:masterfrom
Zeegaths:kill-validation-mutants
Open

Zeegaths wants to merge 2 commits into
bitcoin:masterfrom
Zeegaths:kill-validation-mutants

Conversation

@Zeegaths

@Zeegaths Zeegaths commented Nov 10, 2026 •

Copy link
Copy Markdown

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

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 6bed39b..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());
             }
         }
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 6bed39b..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 6bed39b..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)
     //
@DrahtBot DrahtBot added the Tests label Nov 10, 2026
@DrahtBot

DrahtBot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

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 <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37094 (validation: validate assumeutxo snapshots with a single chainstate by fjahr)

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.

@fanquake

Copy link
Copy Markdown
Member

cc @brunoerg

@sedited

sedited commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

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

@Zeegaths

Copy link
Copy Markdown
Author

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

done

@maflcko

maflcko commented Nov 10, 2026

Copy link
Copy Markdown
Member

Moved CI failure to #36828

@brunoerg brunoerg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm ACK 190f103

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

return chainman.ActiveTip()->GetBlockHash());

auto prune_range = WITH_LOCK(::cs_main, return active_cs.GetPruneRange(active_cs.m_chain.Height()));
BOOST_CHECK_EQUAL(prune_range.first, 111);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ViniciusCestarii ViniciusCestarii left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 190f103

Nice! Verified it kills the mutants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants