Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251// it goes out of scope, so the overlay can be reused for a subsequent block.252// Flush must also clear all per-block state to be reused.253BOOST_AUTO_TEST_CASE(fetch_state_is_reusable_after_teardown)254{255const auto block{CreateBlock()};256CCoinsViewDB db{{.path = "", .cache_bytes = 1_MiB, .memory_only = true}, {}};257CCoinsViewCache main_cache{&db};258PopulateView(block, main_cache);259CoinsViewOverlay view{&main_cache, MakeStartedThreadPool()};261for (const bool use_flush : {false, true, false}) {262{263const auto reset_guard{view.StartFetching(block)};264CheckCache(block, view);265BOOST_CHECK_GT(view.GetCacheSize(), 0U);266if (use_flush) {267view.SetBestBlock(uint256::ONE);268view.Flush();269}270}271BOOST_CHECK_EQUAL(view.GetCacheSize(), 0U);272}273}275BOOST_AUTO_TEST_SUITE_END()277BOOST_AUTO_TEST_SUITE(coinsviewoverlay_tests_noworkers)279// Test that disabled input fetching falls back to normal cache lookups via base->PeekCoin.280BOOST_AUTO_TEST_CASE(fetch_unstarted_thread_pool)281{282const auto block{CreateBlock()};283CCoinsViewDB db{{.path = "", .cache_bytes = 1_MiB, .memory_only = true}, {}};284CCoinsViewCache main_cache{&db};285PopulateView(block, main_cache);286auto thread_pool{std::make_shared<ThreadPool>("fetch_none")};287CoinsViewOverlay view{&main_cache, thread_pool};288const auto reset_guard{view.StartFetching(block)};289CheckCache(block, view);290}292// Test that an interrupted thread pool falls back to normal cache lookups via base->PeekCoin.293BOOST_AUTO_TEST_CASE(fetch_interrupted_thread_pool_uses_normal_lookup)294{295const auto block{CreateBlock()};296CCoinsViewDB db{{.path = "", .cache_bytes = 1_MiB, .memory_only = true}, {}};297CCoinsViewCache main_cache{&db};298PopulateView(block, main_cache);300auto thread_pool{std::make_shared<ThreadPool>("fetch_intr")};301thread_pool->Start(DEFAULT_PREVOUTFETCH_THREADS);302thread_pool->Interrupt();303CoinsViewOverlay view{&main_cache, thread_pool};304const auto reset_guard{view.StartFetching(block)};305CheckCache(block, view);306}308BOOST_AUTO_TEST_SUITE_END()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.