Skip to content

Commit b685d32

Browse files
committed
txgraph: Add DoWork function (feature)
This can be called when the caller has time to spend now, and wants future operations to be fast.
1 parent 295a1ca commit b685d32

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/test/fuzz/txgraph.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ FUZZ_TARGET(txgraph)
526526
// these here without making more calls to real, which could affect its internal
527527
// state. A full comparison is done at the end.
528528
break;
529+
} else if (command-- == 0) {
530+
// DoWork.
531+
real->DoWork();
532+
break;
529533
}
530534
}
531535
}

src/txgraph.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ class TxGraphImpl final : public TxGraph
428428
void ApplyDependencies(int level) noexcept;
429429
/** Make a specified Cluster have quality ACCEPTABLE or OPTIMAL. */
430430
void MakeAcceptable(Cluster& cluster) noexcept;
431+
/** Make all Clusters at the specified level have quality ACCEPTABLE or OPTIMAL. */
432+
void MakeAllAcceptable(int level) noexcept;
431433

432434
// Implementations for the public TxGraph interface.
433435

@@ -436,6 +438,8 @@ class TxGraphImpl final : public TxGraph
436438
void AddDependency(const Ref& parent, const Ref& child) noexcept final;
437439
void SetTransactionFee(const Ref&, int64_t fee) noexcept final;
438440

441+
void DoWork() noexcept final;
442+
439443
void StartStaging() noexcept final;
440444
void CommitStaging() noexcept final;
441445
void AbortStaging() noexcept final;
@@ -1370,6 +1374,17 @@ void TxGraphImpl::MakeAcceptable(Cluster& cluster) noexcept
13701374
}
13711375
}
13721376

1377+
void TxGraphImpl::MakeAllAcceptable(int level) noexcept
1378+
{
1379+
ApplyDependencies(level);
1380+
auto& clusterset = GetClusterSet(level);
1381+
if (clusterset.m_oversized == true) return;
1382+
auto& queue = clusterset.m_clusters[int(QualityLevel::NEEDS_RELINEARIZE)];
1383+
while (!queue.empty()) {
1384+
MakeAcceptable(*queue.back().get());
1385+
}
1386+
}
1387+
13731388
Cluster::Cluster(TxGraphImpl& graph, const FeePerWeight& feerate, GraphIndex graph_index) noexcept
13741389
{
13751390
// Create a new transaction in the DepGraph, and remember its position in m_mapping.
@@ -1942,6 +1957,13 @@ void TxGraphImpl::SanityCheck() const
19421957
}
19431958
}
19441959

1960+
void TxGraphImpl::DoWork() noexcept
1961+
{
1962+
for (int level = 0; level <= GetTopLevel(); ++level) {
1963+
MakeAllAcceptable(level);
1964+
}
1965+
}
1966+
19451967
} // namespace
19461968

19471969
TxGraph::Ref::~Ref()

src/txgraph.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ class TxGraph
9191
* effect. */
9292
virtual void SetTransactionFee(const Ref& arg, int64_t fee) noexcept = 0;
9393

94+
/** TxGraph is internally lazy, and will not compute many things until they are needed.
95+
* Calling DoWork will compute everything now, so that future operations are fast. This can be
96+
* invoked while oversized. */
97+
virtual void DoWork() noexcept = 0;
98+
9499
/** Create a staging graph (which cannot exist already). This acts as if a full copy of
95100
* the transaction graph is made, upon which further modifications are made. This copy can
96101
* be inspected, and then either discarded, or the main graph can be replaced by it by

0 commit comments

Comments
 (0)