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.
1// Copyright (c) 2021-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <minisketch.h>6#include <node/minisketchwrapper.h>7#include <random.h>8#include <test/util/common.h>9#include <test/util/random.h>10#include <test/util/setup_common.h>12#include <boost/test/unit_test.hpp>14#include <utility>16using node::MakeMinisketch32;18BOOST_FIXTURE_TEST_SUITE(minisketch_tests, BasicTestingSetup)20BOOST_AUTO_TEST_CASE(minisketch_test)21{22for (int i = 0; i < 100; ++i) {23uint32_t errors = 0 + m_rng.randrange(11);24uint32_t start_a = 1 + m_rng.randrange(1000000000);25uint32_t a_not_b = m_rng.randrange(errors + 1);26uint32_t b_not_a = errors - a_not_b;27uint32_t both = m_rng.randrange(10000);28uint32_t end_a = start_a + a_not_b + both;29uint32_t start_b = start_a + a_not_b;30uint32_t end_b = start_b + both + b_not_a;32Minisketch sketch_a = MakeMinisketch32(10);33for (uint32_t a = start_a; a < end_a; ++a) sketch_a.Add(a);34Minisketch sketch_b = MakeMinisketch32(10);35for (uint32_t b = start_b; b < end_b; ++b) sketch_b.Add(b);37Minisketch sketch_ar = MakeMinisketch32(10);38Minisketch sketch_br = MakeMinisketch32(10);39sketch_ar.Deserialize(sketch_a.Serialize());40sketch_br.Deserialize(sketch_b.Serialize());42Minisketch sketch_c = std::move(sketch_ar);43sketch_c.Merge(sketch_br);44auto dec = sketch_c.Decode(errors);45BOOST_REQUIRE(dec.has_value());46auto sols = std::move(*dec);47std::sort(sols.begin(), sols.end());48for (uint32_t i = 0; i < a_not_b; ++i) BOOST_CHECK_EQUAL(sols[i], start_a + i);49for (uint32_t i = 0; i < b_not_a; ++i) BOOST_CHECK_EQUAL(sols[i + a_not_b], start_b + both + i);50}51}53BOOST_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.