clusterlin: make MergeSequence take SetIdx (simplification)
What changed, and why it matters
This is a small internal code cleanup in Bitcoin Core's transaction clustering/linearization logic. It changes a helper function so it returns chunk indexes directly instead of having callers look them up afterward. There is no user-facing behavior change, no network change, and no security fix.
No security action needed. Treat as ordinary code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors DependencyGraph::Deactivate in src/cluster_linearize.h to return std::pair<SetIdx, SetIdx> (the parent and child chunk indexes produced by deactivation). It updates MergeSequence to accept a SetIdx rather than a TxIdx, and updates callers in Split and the public optimization path to use the returned indexes directly. A guard is added so MergeSequence<true> is skipped if the child chunk was already merged. This is a simplification/preparatory refactor for future work.
Changed components
src/cluster_linearize.hInspect captured patch +14 / −12
diff --git a/src/cluster_linearize.h b/src/cluster_linearize.h
index 58a7b8b1..47caf1f3 100644
--- a/src/cluster_linearize.h
+++ b/src/cluster_linearize.h
@@ -821,8 +821,9 @@ private:
return child_chunk_idx;
}
- /** Make a specified active dependency inactive. */
- void Deactivate(TxIdx parent_idx, TxIdx child_idx) noexcept
+ /** Make a specified active dependency inactive. Returns the created parent and child chunk
+ * indexes. */
+ std::pair<SetIdx, SetIdx> Deactivate(TxIdx parent_idx, TxIdx child_idx) noexcept
{
// Gather and check information about the parent transactions.
auto& parent_data = m_tx_data[parent_idx];
@@ -853,6 +854,8 @@ private:
// Compute the new sets of reachable transactions for each new chunk.
m_reachable[child_chunk_idx] = GetReachable(bottom_info.transactions);
m_reachable[parent_chunk_idx] = GetReachable(top_info.transactions);
+ // Return the two new set idxs.
+ return {parent_chunk_idx, child_chunk_idx};
}
/** Activate a dependency from the bottom set to the top set. Return the index of the merged
@@ -961,11 +964,11 @@ private:
return chunk_idx;
}
- /** Perform an upward or downward merge sequence on the specified transaction. */
+ /** Perform an upward or downward merge sequence on the specified chunk. */
template<bool DownWard>
- void MergeSequence(TxIdx tx_idx) noexcept
+ void MergeSequence(SetIdx chunk_idx) noexcept
{
- auto chunk_idx = m_tx_data[tx_idx].chunk_idx;
+ Assume(m_chunk_idxs[chunk_idx]);
while (true) {
auto merged_chunk_idx = MergeStep<DownWard>(chunk_idx);
if (merged_chunk_idx == INVALID_SET_IDX) break;
@@ -981,7 +984,7 @@ private:
{
// Deactivate the specified dependency, splitting it into two new chunks: a top containing
// the parent, and a bottom containing the child. The top should have a higher feerate.
- Deactivate(parent_idx, child_idx);
+ auto [parent_chunk_idx, child_chunk_idx] = Deactivate(parent_idx, child_idx);
// At this point we have exactly two chunks which may violate topology constraints (the
// parent chunk and child chunk that were produced by deactivation). We can fix
@@ -990,9 +993,10 @@ private:
// Merge the top chunk with lower-feerate chunks it depends on (which may be the bottom it
// was just split from, or other pre-existing chunks).
- MergeSequence<false>(parent_idx);
- // Merge the bottom chunk with higher-feerate chunks that depend on it.
- MergeSequence<true>(child_idx);
+ MergeSequence<false>(parent_chunk_idx);
+ // Merge the bottom chunk with higher-feerate chunks that depend on it (if it wasn't merged
+ // with the top already).
+ if (m_chunk_idxs[child_chunk_idx]) MergeSequence<true>(child_chunk_idx);
}
/** Determine the next chunk to optimize, or INVALID_SET_IDX if none. */
@@ -1242,9 +1246,7 @@ public:
}
// Otherwise, deactivate the dependency that was found.
- Deactivate(candidate_dep.first, candidate_dep.second);
- auto parent_chunk_idx = m_tx_data[candidate_dep.first].chunk_idx;
- auto child_chunk_idx = m_tx_data[candidate_dep.second].chunk_idx;
+ auto [parent_chunk_idx, child_chunk_idx] = Deactivate(candidate_dep.first, candidate_dep.second);
// Try to activate a dependency between the new bottom and the new top (opposite from the
// dependency that was just deactivated).
auto merged_chunk_idx = MergeChunks(child_chunk_idx, parent_chunk_idx);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.