Merge bitcoin/bitcoin#33768: refactor: remove dead branches in SingletonClusterImpl

2d23820ee1 refactor: remove dead branches in `SingletonClusterImpl` (Lőrinc)

Pull request description:

  Found during review: [cluster mempool: control/optimize TxGraph memory usage](https://github.com/bitcoin/bitcoin/pull/33157#discussion_r2423058928)

  ### Fixes
  `SplitAll()` always calls `ApplyRemovals()` first, for a singleton, it empties the cluster, therefore any `SingletonClusterImpl` passed to `Split()` must be empty.

  `TxGraphImpl::ApplyDependencies()` first merges each dependency group and asserts the group has at least one dependency. Since `parent` != `child`, `TxGraphImpl::Merge()` upgrades the merge target to `GenericClusterImpl`, therefore the `ApplyDependencies()` is never dispatched to `SingletonClusterImpl`.

  ### Coverage proof:
  * https://maflcko.github.io/b-c-cov/fuzz.coverage/src/txgraph.cpp.gcov.html#L1446
  * https://storage.googleapis.com/oss-fuzz-coverage/bitcoin-core/reports/20251103/linux/src/bitcoin-core/src/txgraph.cpp.html#L1446

ACKs for top commit:
  instagibbs:
    ACK 2d23820ee1
  sipa:
    ACK 2d23820ee1

Tree-SHA512: 5135913206c800d5344df61c6654f00917cb85567bc5b821576c7891805cf7689bf47968434a06517d09183dadfefc257d24c42b55a7b99486a4c9b11fc523af
This commit is contained in:
merge-script committed 2025-11-07 10:10:50 +00:00
commit 2b9c351198
1 file changed
+7 -18
+7 -18
View File
@@ -1437,16 +1437,9 @@ bool GenericClusterImpl::Split(TxGraphImpl& graph, int level) noexcept
bool SingletonClusterImpl::Split(TxGraphImpl& graph, int level) noexcept bool SingletonClusterImpl::Split(TxGraphImpl& graph, int level) noexcept
{ {
Assume(NeedsSplitting()); Assume(NeedsSplitting());
if (GetTxCount() == 0) { Assume(!GetTxCount());
// The cluster is now empty. graph.GetClusterSet(level).m_cluster_usage -= TotalMemoryUsage();
graph.GetClusterSet(level).m_cluster_usage -= TotalMemoryUsage(); return true;
return true;
} else {
// Nothing changed.
graph.SetClusterQuality(level, m_quality, m_setindex, QualityLevel::OPTIMAL);
Updated(graph, level);
return false;
}
} }
void GenericClusterImpl::Merge(TxGraphImpl& graph, int level, Cluster& other) noexcept void GenericClusterImpl::Merge(TxGraphImpl& graph, int level, Cluster& other) noexcept
@@ -1482,10 +1475,9 @@ void GenericClusterImpl::Merge(TxGraphImpl& graph, int level, Cluster& other) no
}); });
} }
void SingletonClusterImpl::Merge(TxGraphImpl& graph, int level, Cluster& other_abstract) noexcept void SingletonClusterImpl::Merge(TxGraphImpl&, int, Cluster&) noexcept
{ {
// Nothing can be merged into a singleton; it should have been converted to GenericClusterImpl // Nothing can be merged into a singleton; it should have been converted to GenericClusterImpl first.
// first.
Assume(false); Assume(false);
} }
@@ -1537,13 +1529,10 @@ void GenericClusterImpl::ApplyDependencies(TxGraphImpl& graph, int level, std::s
Updated(graph, level); Updated(graph, level);
} }
void SingletonClusterImpl::ApplyDependencies(TxGraphImpl& graph, int level, std::span<std::pair<GraphIndex, GraphIndex>> to_apply) noexcept void SingletonClusterImpl::ApplyDependencies(TxGraphImpl&, int, std::span<std::pair<GraphIndex, GraphIndex>>) noexcept
{ {
// Nothing can actually be applied. // Nothing can actually be applied.
for (auto& [par, chl] : to_apply) { Assume(false);
Assume(par == m_graph_index);
Assume(chl == m_graph_index);
}
} }
TxGraphImpl::~TxGraphImpl() noexcept TxGraphImpl::~TxGraphImpl() noexcept