This method is called from two places, one of which is dropping the pre-cacululated cluster level that we could access through FindClusterAndLevel - the other call doesn’t seem to, I guess that’s why you decided to always recalculate.
It seems to me it wouldn’t complicate much to provide it when it’s available and recalculate when it’s not, something like:
0diff --git a/src/txgraph.cpp b/src/txgraph.cpp
1--- a/src/txgraph.cpp (revision 262762bbb6f7157ba8c54972909c9214448c304b)
2+++ b/src/txgraph.cpp (date 1760144001634)
3@@ -722,7 +722,7 @@
4 /** If cluster is not in staging, copy it there, and return a pointer to it.
5 * Staging must exist, and this modifies the locators of its
6 * transactions from inherited (P,M) to explicit (P,P). */
7- Cluster* PullIn(Cluster* cluster) noexcept;
8+ Cluster* PullIn(Cluster* cluster, int level) noexcept;
9 /** Apply all removals queued up in m_to_remove to the relevant Clusters (which get a
10 * NEEDS_SPLIT* QualityLevel) up to the specified level. */
11 void ApplyRemovals(int up_to_level) noexcept;
12@@ -1634,11 +1634,12 @@
13 return {nullptr, -1};
14 }
15
16-Cluster* TxGraphImpl::PullIn(Cluster* cluster) noexcept
17+Cluster* TxGraphImpl::PullIn(Cluster* cluster, int cluster_level) noexcept
18 {
19 int to_level = GetTopLevel();
20 Assume(to_level == 1);
21 int level = cluster->GetLevel(*this);
22+ Assert(level == cluster_level); // TODO use parent call calculations instead
23 Assume(level <= to_level);
24 // Copy the Cluster from main to staging, if it's not already there.
25 if (level == 0) {
26@@ -1661,8 +1662,8 @@
27 // Pull in all Clusters that are not in staging.
28 if (level == 1) {
29 for (GraphIndex index : to_remove) {
30- auto cluster = FindCluster(index, level);
31- if (cluster != nullptr) PullIn(cluster);
32+ auto [cluster, cluster_level] = FindClusterAndLevel(index, level);
33+ if (cluster != nullptr) PullIn(cluster, cluster_level);
34 }
35 }
36 // Group the set of to-be-removed entries by Cluster::m_sequence.
37@@ -2067,7 +2068,7 @@
38 // Pull in all the Clusters that contain dependencies.
39 if (level == 1) {
40 for (Cluster*& cluster : cluster_span) {
41- cluster = PullIn(cluster);
42+ cluster = PullIn(cluster, cluster->GetLevel(*this));
43 }
44 }
45 // Invoke Merge() to merge them into a single Cluster.
Note that this would move the only remaing non-sanity-check call of GetLevel higher up.