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.
3502// Compute resource counts.3503uint32_t new_count = 1;3504uint64_t new_size = entry.m_tx_size;3505for (TrimTxData* ptr : current_deps) {3506new_count += ptr->m_uf_count;3507new_size += ptr->m_uf_size;3508}3509// Skip the entry if this would violate any limit.3510if (new_count > m_max_cluster_count || new_size > m_max_cluster_size) continue;3512// Union the partitions this transaction and all its dependencies are in together.3513auto rep = &entry;3514for (TrimTxData* ptr : current_deps) rep = union_fn(ptr, rep);3515// Mark the entry as included (so the loop below will not remove the transaction).3516entry.m_deps_left = uint32_t(-1);3517// Mark each to-be-added dependency involving this transaction as parent satisfied.3518for (auto& [par, chl] : std::span{deps_by_parent}.subspan(entry.m_children_offset, entry.m_children_count)) {3519Assume(par == entry.m_index);3520auto chl_it = locate_fn(chl);3521// Reduce the number of unmet dependencies of chl_it, and if that brings the number3522// to zero, add it to the heap of includable transactions.3523Assume(chl_it->m_deps_left > 0);3524if (--chl_it->m_deps_left == 0) {3525trim_heap.push_back(chl_it);3526std::push_heap(trim_heap.begin(), trim_heap.end(), cmp_fn);3527}3528}3529}3531// Remove all the transactions that were not processed above. Because nothing gets3532// processed until/unless all its dependencies are met, this automatically guarantees3533// that if a transaction is removed, all its descendants, or would-be descendants, are3534// removed as well.3535for (const auto& trim_entry : trim_data) {3536if (trim_entry.m_deps_left != uint32_t(-1)) {3537ret.push_back(m_entries[trim_entry.m_index].m_ref);3538clusterset.m_to_remove.push_back(trim_entry.m_index);3539}3540}3541}3542clusterset.m_group_data.reset();3543clusterset.m_oversized = false;3544Assume(!ret.empty());3545return ret;3546}3548size_t TxGraphImpl::GetMainMemoryUsage() noexcept3549{3550// Make sure splits/merges are applied, as memory usage may not be representative otherwise.3551SplitAll(/*up_to_level=*/0);3552ApplyDependencies(/*level=*/0);3553// Compute memory usage3554size_t usage = /* From clusters */3555m_main_clusterset.m_cluster_usage +3556/* From Entry objects. */3557sizeof(Entry) * m_main_clusterset.m_txcount +3558/* From the chunk index. */3559memusage::DynamicUsage(m_main_chunkindex);3560return usage;3561}3563} // namespace3565TxGraph::Ref::~Ref()3566{3567if (m_graph) {3568// Inform the TxGraph about the Ref being destroyed.3569m_graph->UnlinkRef(m_index);3570m_graph = nullptr;3571}3572}3574TxGraph::Ref::Ref(Ref&& other) noexcept3575{3576// Inform the TxGraph of other that its Ref is being moved.3577if (other.m_graph) other.m_graph->UpdateRef(other.m_index, *this);3578// Actually move the contents.3579std::swap(m_graph, other.m_graph);3580std::swap(m_index, other.m_index);3581}3583std::unique_ptr<TxGraph> MakeTxGraph(3584unsigned max_cluster_count,3585uint64_t max_cluster_size,3586uint64_t acceptable_cost,3587const std::function<std::strong_ordering(const TxGraph::Ref&, const TxGraph::Ref&)>& fallback_order) noexcept3588{3589return std::make_unique<TxGraphImpl>(3590/*max_cluster_count=*/max_cluster_count,3591/*max_cluster_size=*/max_cluster_size,3592/*acceptable_cost=*/acceptable_cost,3593/*fallback_order=*/fallback_order);3594}
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.