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{ 15, 9 },252{ 16, 0 },253{ 17, 1 },254{ 18, 16 },255{ 19, 1 },256{ 20, 16 },257};258// clang-format on260// Test `CBlockIndex::BuildSkip()` and that the skip height conforms to expected logic.261// It tests that:262// - `pprev` field is set (to an earlier block index),263// - the skip is to the index as dictated by the `GetSkipHeight()` bit-manipulation logic,264// - `GetAncestor()` works as expected (indirectly).266// Build a chain (up to the highest test input value)267const auto max_test_input{std::ranges::max_element(TEST_DATA, [](auto& a, auto& b) { return a.first < b.first; })};268const int chain_size{max_test_input->first + 1};269std::vector<CBlockIndex> block_index(chain_size);270for (auto i{0}; i < chain_size; ++i) {271// pprev and nHeight are used by BuildSkip()272block_index[i].pprev = i == 0 ? nullptr : &block_index[i - 1];273block_index[i].nHeight = i;274block_index[i].BuildSkip();275BOOST_CHECK(block_index[i].pskip || i == 0);276}278for (auto& [input, expected] : TEST_DATA) {279BOOST_REQUIRE_LT(input, chain_size);280BOOST_REQUIRE_GT(input, 0);281BOOST_REQUIRE_LT(expected, input);282BOOST_REQUIRE(block_index[input].pskip);284const int skip_height{block_index[input].pskip->nHeight};285BOOST_CHECK_EQUAL(skip_height, expected);286}288// Special value: height 0 (genesis) has no skip289BOOST_CHECK(!block_index[0].pskip);290}292BOOST_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.