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.
751for (unsigned tx = 0; tx < NUM_TX; ++tx) {752bool sim_have_tx = have_tx_fn(tx);753if (sim_have_tx) {754orphan_usage += GetTransactionWeight(*txn[tx]);755total_latency_score += txn[tx]->vin.size() / 10;756}757unique_orphans += sim_have_tx;758auto orphans_it = std::find_if(all_orphans.begin(), all_orphans.end(), [&](auto& orph) { return orph.tx->GetWitnessHash() == txn[tx]->GetWitnessHash(); });759// GetOrphanTransactions (OrphanBase existence)760assert((orphans_it != all_orphans.end()) == sim_have_tx);761// HaveTx762bool have_tx = real->HaveTx(txn[tx]->GetWitnessHash());763assert(have_tx == sim_have_tx);764// GetTx765auto txref = real->GetTx(txn[tx]->GetWitnessHash());766assert(!!txref == sim_have_tx);767if (sim_have_tx) assert(txref->GetWitnessHash() == txn[tx]->GetWitnessHash());769for (NodeId peer = 0; peer < NUM_PEERS; ++peer) {770auto it_sim_ann = find_announce_fn(tx, peer);771bool sim_have_ann = it_sim_ann != sim_announcements.end();772if (sim_have_ann) usage_by_peer[peer] += GetTransactionWeight(*txn[tx]);773count_by_peer[peer] += sim_have_ann;774// GetOrphanTransactions (announcers presence)775if (sim_have_ann) assert(sim_have_tx);776if (sim_have_tx) assert(orphans_it->announcers.count(peer) == sim_have_ann);777// HaveTxFromPeer778bool have_ann = real->HaveTxFromPeer(txn[tx]->GetWitnessHash(), peer);779assert(sim_have_ann == have_ann);780// GetChildrenFromSamePeer781auto children_from_peer = real->GetChildrenFromSamePeer(txn[tx], peer);782auto it = children_from_peer.rbegin();783for (int phase = 0; phase < 2; ++phase) {784// First expect all children which have reconsiderable announcement from peer, then the others.785for (auto& ann : sim_announcements) {786if (ann.announcer != peer) continue;787if (ann.reconsider != (phase == 1)) continue;788bool matching_parent{false};789for (const auto& vin : txn[ann.tx]->vin) {790if (vin.prevout.hash == txn[tx]->GetHash()) matching_parent = true;791}792if (!matching_parent) continue;793// Found an announcement from peer which is a child of txn[tx].794assert(it != children_from_peer.rend());795assert((*it)->GetWitnessHash() == txn[ann.tx]->GetWitnessHash());796++it;797}798}799assert(it == children_from_peer.rend());800}801}802// TotalOrphanUsage803assert(orphan_usage == real->TotalOrphanUsage());804for (NodeId peer = 0; peer < NUM_PEERS; ++peer) {805bool sim_have_reconsider = have_reconsider_fn(peer);806// HaveTxToReconsider807bool have_reconsider = real->HaveTxToReconsider(peer);808assert(have_reconsider == sim_have_reconsider);809// UsageByPeer810assert(usage_by_peer[peer] == real->UsageByPeer(peer));811// AnnouncementsFromPeer812assert(count_by_peer[peer] == real->AnnouncementsFromPeer(peer));813}814// CountAnnouncements815assert(sim_announcements.size() == real->CountAnnouncements());816// CountUniqueOrphans817assert(unique_orphans == real->CountUniqueOrphans());818// MaxGlobalLatencyScore819assert(max_global_latency_score == real->MaxGlobalLatencyScore());820// ReservedPeerUsage821assert(reserved_peer_usage == real->ReservedPeerUsage());822// MaxPeerLatencyScore823auto present_peers = count_peers_fn();824assert(max_global_latency_score / std::max<unsigned>(1, present_peers) == real->MaxPeerLatencyScore());825// MaxGlobalUsage826assert(reserved_peer_usage * std::max<unsigned>(1, present_peers) == real->MaxGlobalUsage());827// TotalLatencyScore.828assert(real->TotalLatencyScore() == total_latency_score);829}
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.