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 <node/txreconciliation.h>7#include <test/util/common.h>8#include <test/util/setup_common.h>10#include <boost/test/unit_test.hpp>12BOOST_FIXTURE_TEST_SUITE(txreconciliation_tests, BasicTestingSetup)14BOOST_AUTO_TEST_CASE(RegisterPeerTest)15{16TxReconciliationTracker tracker(TXRECONCILIATION_VERSION);17const uint64_t salt = 0;19// Prepare a peer for reconciliation.20tracker.PreRegisterPeer(0);22// Invalid version.23BOOST_CHECK_EQUAL(tracker.RegisterPeer(/*peer_id=*/0, /*is_peer_inbound=*/true,24/*peer_recon_version=*/0, salt),25ReconciliationRegisterResult::PROTOCOL_VIOLATION);27// Valid registration (inbound and outbound peers).28BOOST_REQUIRE(!tracker.IsPeerRegistered(0));29BOOST_REQUIRE_EQUAL(tracker.RegisterPeer(0, true, 1, salt), ReconciliationRegisterResult::SUCCESS);30BOOST_CHECK(tracker.IsPeerRegistered(0));31BOOST_REQUIRE(!tracker.IsPeerRegistered(1));32tracker.PreRegisterPeer(1);33BOOST_REQUIRE(tracker.RegisterPeer(1, false, 1, salt) == ReconciliationRegisterResult::SUCCESS);34BOOST_CHECK(tracker.IsPeerRegistered(1));36// Reconciliation version is higher than ours, should be able to register.37BOOST_REQUIRE(!tracker.IsPeerRegistered(2));38tracker.PreRegisterPeer(2);39BOOST_REQUIRE(tracker.RegisterPeer(2, true, 2, salt) == ReconciliationRegisterResult::SUCCESS);40BOOST_CHECK(tracker.IsPeerRegistered(2));42// Try registering for the second time.43BOOST_REQUIRE(tracker.RegisterPeer(1, false, 1, salt) == ReconciliationRegisterResult::ALREADY_REGISTERED);45// Do not register if there were no pre-registration for the peer.46BOOST_REQUIRE_EQUAL(tracker.RegisterPeer(100, true, 1, salt), ReconciliationRegisterResult::NOT_FOUND);47BOOST_CHECK(!tracker.IsPeerRegistered(100));48}50BOOST_AUTO_TEST_CASE(ForgetPeerTest)51{52TxReconciliationTracker tracker(TXRECONCILIATION_VERSION);53NodeId peer_id0 = 0;55// Removing peer after pre-registering works and does not let to register the peer.56tracker.PreRegisterPeer(peer_id0);57tracker.ForgetPeer(peer_id0);58BOOST_CHECK_EQUAL(tracker.RegisterPeer(peer_id0, true, 1, 1), ReconciliationRegisterResult::NOT_FOUND);60// Removing peer after it is registered works.61tracker.PreRegisterPeer(peer_id0);62BOOST_REQUIRE(!tracker.IsPeerRegistered(peer_id0));63BOOST_REQUIRE_EQUAL(tracker.RegisterPeer(peer_id0, true, 1, 1), ReconciliationRegisterResult::SUCCESS);64BOOST_CHECK(tracker.IsPeerRegistered(peer_id0));65tracker.ForgetPeer(peer_id0);66BOOST_CHECK(!tracker.IsPeerRegistered(peer_id0));67}69BOOST_AUTO_TEST_CASE(IsPeerRegisteredTest)70{71TxReconciliationTracker tracker(TXRECONCILIATION_VERSION);72NodeId peer_id0 = 0;74BOOST_REQUIRE(!tracker.IsPeerRegistered(peer_id0));75tracker.PreRegisterPeer(peer_id0);76BOOST_REQUIRE(!tracker.IsPeerRegistered(peer_id0));78BOOST_REQUIRE_EQUAL(tracker.RegisterPeer(peer_id0, true, 1, 1), ReconciliationRegisterResult::SUCCESS);79BOOST_CHECK(tracker.IsPeerRegistered(peer_id0));81tracker.ForgetPeer(peer_id0);82BOOST_CHECK(!tracker.IsPeerRegistered(peer_id0));83}85BOOST_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.