From 883df3648ee92841e515bb6d8d259cb7054493b1 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 28 Mar 2025 10:04:28 -0400 Subject: [PATCH] txgraph: Generalize GetClusterRefs to support subsections (preparation) This is preparation for a next commit which will need a way to extract Refs for just individual chunks from a cluster. --- src/txgraph.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/txgraph.cpp b/src/txgraph.cpp index 7f8c8bec8b1..8da1556909f 100644 --- a/src/txgraph.cpp +++ b/src/txgraph.cpp @@ -151,8 +151,9 @@ public: /** Process elements from the front of args that apply to this cluster, and append Refs for the * union of their descendants to output. */ void GetDescendantRefs(const TxGraphImpl& graph, std::span>& args, std::vector& output) noexcept; - /** Get a vector of Refs for all elements of this Cluster, in linearization order. */ - std::vector GetClusterRefs(const TxGraphImpl& graph) noexcept; + /** Populate range with refs for the transactions in this Cluster's linearization, from + * position start_pos until start_pos+range.size()-1, inclusive. */ + void GetClusterRefs(TxGraphImpl& graph, std::span range, LinearizationIndex start_pos) noexcept; /** Get the individual transaction feerate of a Cluster element. */ FeePerWeight GetIndividualFeerate(DepGraphIndex idx) noexcept; /** Modify the fee of a Cluster element. */ @@ -1632,17 +1633,16 @@ void Cluster::GetDescendantRefs(const TxGraphImpl& graph, std::span Cluster::GetClusterRefs(const TxGraphImpl& graph) noexcept +void Cluster::GetClusterRefs(TxGraphImpl& graph, std::span range, LinearizationIndex start_pos) noexcept { - std::vector ret; - ret.reserve(m_linearization.size()); - // Translate all transactions in the Cluster (in linearization order) to Refs. - for (auto idx : m_linearization) { - const auto& entry = graph.m_entries[m_mapping[idx]]; + // Translate the transactions in the Cluster (in linearization order, starting at start_pos in + // the linearization) to Refs, and fill them in range. + for (auto& ref : range) { + Assume(start_pos < m_linearization.size()); + const auto& entry = graph.m_entries[m_mapping[m_linearization[start_pos++]]]; Assume(entry.m_ref != nullptr); - ret.push_back(entry.m_ref); + ref = entry.m_ref; } - return ret; } FeePerWeight Cluster::GetIndividualFeerate(DepGraphIndex idx) noexcept @@ -1786,7 +1786,9 @@ std::vector TxGraphImpl::GetCluster(const Ref& arg, bool main_onl if (cluster == nullptr) return {}; // Make sure the Cluster has an acceptable quality level, and then dispatch to it. MakeAcceptable(*cluster); - return cluster->GetClusterRefs(*this); + std::vector ret(cluster->GetTxCount()); + cluster->GetClusterRefs(*this, ret, 0); + return ret; } TxGraph::GraphIndex TxGraphImpl::GetTransactionCount(bool main_only) noexcept