Change CChain::FindFork() to take ref

The internal null-guard in FindFork() was removed in favor of adding any missing guards at call sites.
This commit is contained in:
optout
2026-02-03 11:18:01 +01:00
parent 20b58e281a
commit c5eb283bca
8 changed files with 14 additions and 14 deletions

View File

@@ -96,13 +96,13 @@ BOOST_AUTO_TEST_CASE(findfork_tests)
const auto check_same{[](const CChain& chain, const auto& blocks) {
for (const auto& block : blocks) {
BOOST_CHECK_EQUAL(chain.FindFork(&block), &block);
BOOST_CHECK_EQUAL(chain.FindFork(block), &block);
}
}};
const auto check_fork_point{[](const CChain& chain, const auto& blocks, const CBlockIndex& fork_point) {
for (const auto& block : blocks) {
BOOST_CHECK_EQUAL(chain.FindFork(&block), &fork_point);
BOOST_CHECK_EQUAL(chain.FindFork(block), &fork_point);
}
}};
@@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(findfork_tests)
// Invalid test case. Mixing chains is not supported
CBlockIndex block_on_unrelated_chain;
BOOST_CHECK_EQUAL(chain_long.FindFork(&block_on_unrelated_chain), nullptr);
BOOST_CHECK_EQUAL(chain_long.FindFork(block_on_unrelated_chain), nullptr);
}
BOOST_AUTO_TEST_CASE(chain_test)

View File

@@ -102,7 +102,7 @@ FUZZ_TARGET(block_index_tree, .init = initialize_block_index_tree)
assert(best_tip); // Should at least return current tip
if (best_tip == chain.Tip()) break; // Nothing to do
// Rewind chain to forking point
const CBlockIndex* fork = chain.FindFork(best_tip);
const CBlockIndex* fork = chain.FindFork(*best_tip);
// If we can't go back to the fork point due to pruned data, abort this run. In reality, a pruned node would also currently just crash in this scenario.
// This is very unlikely to happen due to the minimum pruning threshold of 550MiB.
CBlockIndex* it = chain.Tip();