Skip to content

Commit 5801e0f

Browse files
committed
txgraph: Delay chunking while sub-acceptable (optimization)
Chunk-based information (primarily, chunk feerates) are never accessed without first bringing the relevant Clusters to an "acceptable" quality level. Thus, while operations are ongoing and Clusters are not acceptable, we can omit computing the chunkings and chunk feerates for Clusters.
1 parent 57f5499 commit 5801e0f

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

src/txgraph.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -331,23 +331,27 @@ void Cluster::Updated(TxGraphImpl& graph) noexcept
331331
auto& entry = graph.m_entries[m_mapping[idx]];
332332
entry.m_locator.SetPresent(this, idx);
333333
}
334-
335-
// Compute its chunking and store its information in the Entry's m_chunk_feerate.
336-
LinearizationChunking chunking(m_depgraph, m_linearization);
337-
LinearizationIndex lin_idx{0};
338-
// Iterate over the chunks.
339-
for (unsigned chunk_idx = 0; chunk_idx < chunking.NumChunksLeft(); ++chunk_idx) {
340-
auto chunk = chunking.GetChunk(chunk_idx);
341-
Assume(chunk.transactions.Any());
342-
// Iterate over the transactions in the linearization, which must match those in chunk.
343-
do {
344-
DepGraphIndex idx = m_linearization[lin_idx++];
345-
GraphIndex graph_idx = m_mapping[idx];
346-
auto& entry = graph.m_entries[graph_idx];
347-
entry.m_chunk_feerate = FeePerWeight::FromFeeFrac(chunk.feerate);
348-
Assume(chunk.transactions[idx]);
349-
chunk.transactions.Reset(idx);
350-
} while(chunk.transactions.Any());
334+
// If the Cluster's quality is ACCEPTABLE or OPTIMAL, compute its chunking and store its
335+
// information in the Entry's m_chunk_feerate. These fields are only accessed after making
336+
// the entire graph ACCEPTABLE, so it is pointless to compute these if we haven't reached that
337+
// quality level yet.
338+
if (IsAcceptable()) {
339+
LinearizationChunking chunking(m_depgraph, m_linearization);
340+
LinearizationIndex lin_idx{0};
341+
// Iterate over the chunks.
342+
for (unsigned chunk_idx = 0; chunk_idx < chunking.NumChunksLeft(); ++chunk_idx) {
343+
auto chunk = chunking.GetChunk(chunk_idx);
344+
Assume(chunk.transactions.Any());
345+
// Iterate over the transactions in the linearization, which must match those in chunk.
346+
do {
347+
DepGraphIndex idx = m_linearization[lin_idx++];
348+
GraphIndex graph_idx = m_mapping[idx];
349+
auto& entry = graph.m_entries[graph_idx];
350+
entry.m_chunk_feerate = FeePerWeight::FromFeeFrac(chunk.feerate);
351+
Assume(chunk.transactions[idx]);
352+
chunk.transactions.Reset(idx);
353+
} while(chunk.transactions.Any());
354+
}
351355
}
352356
}
353357

@@ -409,8 +413,6 @@ bool Cluster::Split(TxGraphImpl& graph) noexcept
409413
// The existing Cluster is an entire component. Leave it be, but update its quality.
410414
Assume(todo == m_depgraph.Positions());
411415
graph.SetClusterQuality(m_quality, m_setindex, QualityLevel::NEEDS_RELINEARIZE);
412-
// We need to recompute and cache its chunking.
413-
Updated(graph);
414416
return false;
415417
}
416418
first = false;
@@ -1262,12 +1264,12 @@ void Cluster::SanityCheck(const TxGraphImpl& graph) const
12621264
assert(entry.m_locator.cluster == this);
12631265
assert(entry.m_locator.index == lin_pos);
12641266
// Check linearization position and chunk feerate.
1265-
if (!linchunking.GetChunk(0).transactions[lin_pos]) {
1266-
linchunking.MarkDone(linchunking.GetChunk(0).transactions);
1267-
}
1268-
assert(entry.m_chunk_feerate == linchunking.GetChunk(0).feerate);
1269-
// If this Cluster has an acceptable quality level, its chunks must be connected.
12701267
if (IsAcceptable()) {
1268+
if (!linchunking.GetChunk(0).transactions[lin_pos]) {
1269+
linchunking.MarkDone(linchunking.GetChunk(0).transactions);
1270+
}
1271+
assert(entry.m_chunk_feerate == linchunking.GetChunk(0).feerate);
1272+
// If this Cluster has an acceptable quality level, its chunks must be connected.
12711273
assert(m_depgraph.IsConnected(linchunking.GetChunk(0).transactions));
12721274
}
12731275
}

0 commit comments

Comments
 (0)