What changed, and why it matters
This commit only adds a new unit test and fixes a couple of comment typos. It does not change any production code, so it cannot introduce a security vulnerability or fix one directly. The test documents when Bitcoin Core considers itself to have finished Initial Block Download (IBD).
No security action needed. Treat as routine test coverage improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds BOOST_FIXTURE_TEST_CASE(chainstatemanager_ibd_exit_after_loading_blocks, ChainTestingSetup) in src/test/validation_chainstatemanager_tests.cpp. It exhaustively varies five boolean inputs (cached_finished_ibd, loading_blocks, tip_exists, enough_work, tip_recent) and asserts that IsInitialBlockDownload() matches the expected boolean expression. It also corrects two comment typos in an existing test. No consensus, networking, wallet, or validation logic is modified.
Changed components
src/test/validation_chainstatemanager_tests.cppInspect captured patch +40 / −3
diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp
index 24122bd3..d0b731b3 100644
--- a/src/test/validation_chainstatemanager_tests.cpp
+++ b/src/test/validation_chainstatemanager_tests.cpp
@@ -143,11 +143,11 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_rebalance_caches, TestChain100Setup)
/*cache_size_bytes=*/1 << 23, /*in_memory=*/true, /*should_wipe=*/false);
// Reset IBD state so IsInitialBlockDownload() returns true and causes
- // MaybeRebalancesCaches() to prioritize the snapshot chainstate, giving it
+ // MaybeRebalanceCaches() to prioritize the snapshot chainstate, giving it
// more cache space than the snapshot chainstate. Calling ResetIbd() is
// necessary because m_cached_finished_ibd is already latched to true before
- // the test starts due to the test setup. After ResetIbd() is called.
- // IsInitialBlockDownload will return true because at this point the active
+ // the test starts due to the test setup. After ResetIbd() is called,
+ // IsInitialBlockDownload() will return true because at this point the active
// chainstate has a null chain tip.
static_cast<TestChainstateManager&>(manager).ResetIbd();
@@ -163,6 +163,43 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_rebalance_caches, TestChain100Setup)
BOOST_CHECK_CLOSE(double(c2.m_coinsdb_cache_size_bytes), max_cache * 0.95, 1);
}
+BOOST_FIXTURE_TEST_CASE(chainstatemanager_ibd_exit_after_loading_blocks, ChainTestingSetup)
+{
+ CBlockIndex tip;
+ ChainstateManager& chainman{*Assert(m_node.chainman)};
+ auto apply{[&](bool cached_finished_ibd, bool loading_blocks, bool tip_exists, bool enough_work, bool tip_recent) {
+ LOCK(::cs_main);
+ chainman.ResetChainstates();
+ chainman.InitializeChainstate(m_node.mempool.get());
+
+ const auto recent_time{Now<NodeSeconds>() - chainman.m_options.max_tip_age};
+
+ chainman.m_cached_finished_ibd.store(cached_finished_ibd, std::memory_order_relaxed);
+ chainman.m_blockman.m_importing = loading_blocks;
+ if (tip_exists) {
+ tip.nChainWork = chainman.MinimumChainWork() - (enough_work ? 0 : 1);
+ tip.nTime = (recent_time - (tip_recent ? 0h : 100h)).time_since_epoch().count();
+ chainman.ActiveChain().SetTip(tip);
+ } else {
+ assert(!chainman.ActiveChain().Tip());
+ }
+ }};
+
+ for (const bool cached_finished_ibd : {false, true}) {
+ for (const bool loading_blocks : {false, true}) {
+ for (const bool tip_exists : {false, true}) {
+ for (const bool enough_work : {false, true}) {
+ for (const bool tip_recent : {false, true}) {
+ apply(cached_finished_ibd, loading_blocks, tip_exists, enough_work, tip_recent);
+ const bool expected_ibd = !cached_finished_ibd && (loading_blocks || !tip_exists || !enough_work || !tip_recent);
+ BOOST_CHECK_EQUAL(chainman.IsInitialBlockDownload(), expected_ibd);
+ }
+ }
+ }
+ }
+ }
+}
+
struct SnapshotTestSetup : TestChain100Setup {
// Run with coinsdb on the filesystem to support, e.g., moving invalidated
// chainstate dirs to "*_invalid".
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.