txgraph: abstract out creation of empty Clusters (refactor)

This commit is contained in:
Pieter Wuille committed 2025-10-11 17:32:35 -04:00
1 parent 6baf12621f
commit e93b0f09cc
1 file changed
+15 -3
+15 -3
View File
@@ -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<GenericClusterImpl> CreateEmptyGenericCluster() noexcept
{
return std::make_unique<GenericClusterImpl>(m_next_sequence_counter++);
}
/** Create an empty Cluster of the appropriate implementation for the specified (maximum) tx
* count. */
std::unique_ptr<Cluster> CreateEmptyCluster(DepGraphIndex tx_count) noexcept
{
(void)tx_count;
return CreateEmptyGenericCluster();
}
// Functions for handling Refs.
@@ -945,7 +957,7 @@ std::vector<Cluster*> TxGraphImpl::GetConflicts() const noexcept
Cluster* GenericClusterImpl::CopyToStaging(TxGraphImpl& graph) const noexcept
{
// Construct an empty Cluster.
auto ret = std::make_unique<GenericClusterImpl>(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<GenericClusterImpl>(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<GenericClusterImpl>(m_next_sequence_counter++);
auto cluster = CreateEmptyCluster(1);
cluster->AppendTransaction(idx, feerate);
auto cluster_ptr = cluster.get();
int level = GetTopLevel();