From e93b0f09cc2ad7b743f896a09c48d584dfcc2787 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 7 Sep 2025 10:12:36 -0400 Subject: [PATCH] txgraph: abstract out creation of empty Clusters (refactor) --- src/txgraph.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/txgraph.cpp b/src/txgraph.cpp index 6d45fb891a..a09754abb2 100644 --- a/src/txgraph.cpp +++ b/src/txgraph.cpp @@ -578,6 +578,18 @@ public: void ClearChunkData(Entry& entry) noexcept; /** Give an Entry a ChunkData object. */ void CreateChunkData(GraphIndex idx, LinearizationIndex chunk_count) noexcept; + /** Create an empty GenericClusterImpl object. */ + std::unique_ptr CreateEmptyGenericCluster() noexcept + { + return std::make_unique(m_next_sequence_counter++); + } + /** Create an empty Cluster of the appropriate implementation for the specified (maximum) tx + * count. */ + std::unique_ptr CreateEmptyCluster(DepGraphIndex tx_count) noexcept + { + (void)tx_count; + return CreateEmptyGenericCluster(); + } // Functions for handling Refs. @@ -945,7 +957,7 @@ std::vector TxGraphImpl::GetConflicts() const noexcept Cluster* GenericClusterImpl::CopyToStaging(TxGraphImpl& graph) const noexcept { // Construct an empty Cluster. - auto ret = std::make_unique(graph.m_next_sequence_counter++); + auto ret = graph.CreateEmptyGenericCluster(); auto ptr = ret.get(); // Copy depgraph, mapping, and linearization/ ptr->m_depgraph = m_depgraph; @@ -1136,7 +1148,7 @@ bool GenericClusterImpl::Split(TxGraphImpl& graph, int level) noexcept } first = false; // Construct a new Cluster to hold the found component. - auto new_cluster = std::make_unique(graph.m_next_sequence_counter++); + auto new_cluster = graph.CreateEmptyCluster(component_size); new_clusters.push_back(new_cluster.get()); // Remember that all the component's transactions go to this new Cluster. The positions // will be determined below, so use -1 for now. @@ -1855,7 +1867,7 @@ TxGraph::Ref TxGraphImpl::AddTransaction(const FeePerWeight& feerate) noexcept GetRefIndex(ret) = idx; // Construct a new singleton Cluster (which is necessarily optimally linearized). bool oversized = uint64_t(feerate.size) > m_max_cluster_size; - auto cluster = std::make_unique(m_next_sequence_counter++); + auto cluster = CreateEmptyCluster(1); cluster->AppendTransaction(idx, feerate); auto cluster_ptr = cluster.get(); int level = GetTopLevel();