@@ -153,8 +153,9 @@ class Cluster
153
153
* union of their descendants to output. */
154
154
void GetDescendantRefs (const TxGraphImpl& graph, std::span<std::pair<Cluster*, DepGraphIndex>>& args, std::vector<TxGraph::Ref*>& output) noexcept ;
155
155
/* * Populate range with refs for the transactions in this Cluster's linearization, from
156
- * position start_pos until start_pos+range.size()-1, inclusive. */
157
- void GetClusterRefs (TxGraphImpl& graph, std::span<TxGraph::Ref*> range, LinearizationIndex start_pos) noexcept ;
156
+ * position start_pos until start_pos+range.size()-1, inclusive. Returns whether that
157
+ * range includes the last transaction in the linearization. */
158
+ bool GetClusterRefs (TxGraphImpl& graph, std::span<TxGraph::Ref*> range, LinearizationIndex start_pos) noexcept ;
158
159
/* * Get the individual transaction feerate of a Cluster element. */
159
160
FeePerWeight GetIndividualFeerate (DepGraphIndex idx) noexcept ;
160
161
/* * Modify the fee of a Cluster element. */
@@ -586,6 +587,8 @@ class BlockBuilderImpl final : public TxGraph::BlockBuilder
586
587
/* * Which cluster the current chunk belongs to, so we can exclude further transactions from it
587
588
* when that chunk is skipped. */
588
589
Cluster* m_cur_cluster;
590
+ /* * Whether we know that m_cur_iter points to the last chunk of m_cur_cluster. */
591
+ bool m_known_end_of_cluster;
589
592
590
593
// Move m_cur_iter / m_cur_cluster to the next acceptable chunk.
591
594
void Next () noexcept ;
@@ -1692,7 +1695,7 @@ void Cluster::GetDescendantRefs(const TxGraphImpl& graph, std::span<std::pair<Cl
1692
1695
}
1693
1696
}
1694
1697
1695
- void Cluster::GetClusterRefs (TxGraphImpl& graph, std::span<TxGraph::Ref*> range, LinearizationIndex start_pos) noexcept
1698
+ bool Cluster::GetClusterRefs (TxGraphImpl& graph, std::span<TxGraph::Ref*> range, LinearizationIndex start_pos) noexcept
1696
1699
{
1697
1700
// Translate the transactions in the Cluster (in linearization order, starting at start_pos in
1698
1701
// the linearization) to Refs, and fill them in range.
@@ -1702,6 +1705,8 @@ void Cluster::GetClusterRefs(TxGraphImpl& graph, std::span<TxGraph::Ref*> range,
1702
1705
Assume (entry.m_ref != nullptr );
1703
1706
ref = entry.m_ref ;
1704
1707
}
1708
+ // Return whether start_pos has advanced to the end of the Cluster.
1709
+ return start_pos == m_linearization.size ();
1705
1710
}
1706
1711
1707
1712
FeePerWeight Cluster::GetIndividualFeerate (DepGraphIndex idx) noexcept
@@ -2338,6 +2343,7 @@ void BlockBuilderImpl::Next() noexcept
2338
2343
const auto & chunk_data = *m_cur_iter;
2339
2344
const auto & chunk_end_entry = m_graph->m_entries [chunk_data.m_graph_index ];
2340
2345
m_cur_cluster = chunk_end_entry.m_locator [0 ].cluster ;
2346
+ m_known_end_of_cluster = false ;
2341
2347
// If we previously skipped a chunk from this cluster we cannot include more from it.
2342
2348
if (!m_excluded_clusters.contains (m_cur_cluster)) break ;
2343
2349
}
@@ -2354,7 +2360,7 @@ std::optional<std::pair<std::vector<TxGraph::Ref*>, FeePerWeight>> BlockBuilderI
2354
2360
ret->first .resize (chunk_data.m_chunk_count );
2355
2361
auto start_pos = chunk_end_entry.m_main_lin_index + 1 - chunk_data.m_chunk_count ;
2356
2362
Assume (m_cur_cluster);
2357
- m_cur_cluster->GetClusterRefs (*m_graph, ret->first , start_pos);
2363
+ m_known_end_of_cluster = m_cur_cluster->GetClusterRefs (*m_graph, ret->first , start_pos);
2358
2364
ret->second = chunk_end_entry.m_main_chunk_feerate ;
2359
2365
}
2360
2366
return ret;
@@ -2397,8 +2403,12 @@ void BlockBuilderImpl::Include() noexcept
2397
2403
void BlockBuilderImpl::Skip () noexcept
2398
2404
{
2399
2405
// When skipping a chunk we need to not include anything more of the cluster, as that could make
2400
- // the result topologically invalid.
2401
- if (m_cur_cluster != nullptr ) m_excluded_clusters.insert (m_cur_cluster);
2406
+ // the result topologically invalid. However, don't do this if the chunk is known to be the last
2407
+ // chunk of the cluster. This may significantly reduce the size of m_excluded_clusters,
2408
+ // especially when many singleton clusters are ignored.
2409
+ if (m_cur_cluster != nullptr && !m_known_end_of_cluster) {
2410
+ m_excluded_clusters.insert (m_cur_cluster);
2411
+ }
2402
2412
Next ();
2403
2413
}
2404
2414
0 commit comments