Inside Bitcoin
Opening the selected file…
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) 2022-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#ifndef BITCOIN_NODE_TXRECONCILIATION_H6#define BITCOIN_NODE_TXRECONCILIATION_H8#include <net.h>9#include <sync.h>11#include <memory>12#include <tuple>14/** Supported transaction reconciliation protocol version */15inline constexpr uint32_t TXRECONCILIATION_VERSION{1};17enum class ReconciliationRegisterResult {18NOT_FOUND,19SUCCESS,20ALREADY_REGISTERED,21PROTOCOL_VIOLATION,22};24/**25* Transaction reconciliation is a way for nodes to efficiently announce transactions.26* This object keeps track of all txreconciliation-related communications with the peers.27* The high-level protocol is:28* 0. Txreconciliation protocol handshake.29* 1. Once we receive a new transaction, add it to the set instead of announcing immediately.30* 2. At regular intervals, a txreconciliation initiator requests a sketch from a peer, where a31* sketch is a compressed representation of short form IDs of the transactions in their set.32* 3. Once the initiator received a sketch from the peer, the initiator computes a local sketch,33* and combines the two sketches to attempt finding the difference in *sets*.34* 4a. If the difference was not larger than estimated, see SUCCESS below.35* 4b. If the difference was larger than estimated, initial txreconciliation fails. The initiator36* requests a larger sketch via an extension round (allowed only once).37* - If extension succeeds (a larger sketch is sufficient), see SUCCESS below.38* - If extension fails (a larger sketch is insufficient), see FAILURE below.39*40* SUCCESS. The initiator knows full symmetrical difference and can request what the initiator is41* missing and announce to the peer what the peer is missing.42*43* FAILURE. The initiator notifies the peer about the failure and announces all transactions from44* the corresponding set. Once the peer received the failure notification, the peer45* announces all transactions from their set.47* This is a modification of the Erlay protocol (https://arxiv.org/abs/1905.10518) with two48* changes (sketch extensions instead of bisections, and an extra INV exchange round), both49* are motivated in BIP-330.50*/51class TxReconciliationTracker52{53private:54class Impl;55const std::unique_ptr<Impl> m_impl;57public:58explicit TxReconciliationTracker(uint32_t recon_version);59~TxReconciliationTracker();61/**62* Step 0. Generates initial part of the state (salt) required to reconcile txs with the peer.63* The salt is used for short ID computation required for txreconciliation.64* The function returns the salt.65* A peer can't participate in future txreconciliations without this call.66* This function must be called only once per peer.67*/68uint64_t PreRegisterPeer(NodeId peer_id);70/**71* Step 0. Once the peer agreed to reconcile txs with us, generate the state required to track72* ongoing reconciliations. Must be called only after pre-registering the peer and only once.73*/74ReconciliationRegisterResult RegisterPeer(NodeId peer_id, bool is_peer_inbound,75uint32_t peer_recon_version, uint64_t remote_salt);77/**78* Attempts to forget txreconciliation-related state of the peer (if we previously stored any).79* After this, we won't be able to reconcile transactions with the peer.80*/81void ForgetPeer(NodeId peer_id);83/**84* Check if a peer is registered to reconcile transactions with us.85*/86bool IsPeerRegistered(NodeId peer_id) const;87};89#endif // BITCOIN_NODE_TXRECONCILIATION_H
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.