Skip to content

Commit

Permalink
Merge bitcoin#30857: cluster mempool: extend DepGraph functionality
Browse files Browse the repository at this point in the history
0b3ec8c clusterlin: remove Cluster type (Pieter Wuille)
1c24c62 clusterlin: merge two DepGraph fuzz tests into simulation test (Pieter Wuille)
0606e66 clusterlin: add DepGraph::RemoveTransactions and support for holes in DepGraph (Pieter Wuille)
75b5d42 clusterlin: make DepGraph::AddDependency support multiple dependencies at once (Pieter Wuille)
abf5064 clusterlin: simplify DepGraphFormatter::Ser (Pieter Wuille)
eaab55f clusterlin: rework DepGraphFormatter::Unser (Pieter Wuille)
5901cf7 clusterlin: abstract out DepGraph::GetReduced{Parents,Children} (Pieter Wuille)

Pull request description:

  Part of cluster mempool: bitcoin#30289

  This adds:
  * `DepGraph::AddDependencies` to add 0 or more dependencies to a single transaction at once (identical to calling `DepGraph::AddDependency` once for each, but more efficient).
  * `DepGraph::RemoveTransactions` to remove 0 or more transactions from a depgraph.
  * `DepGraph::GetReducedParents` (and `DepGraph::GetReducedChildren`) to get the (reduced) direct parents and children of a transaction in a depgraph.

  After which, the `Cluster` type is removed.

  This is the result of fleshing out the design for the "intermediate layer" ("TxGraph", no PR yet) between the cluster linearization layer and the mempool layer. My earlier thinking was that TxGraph would store `Cluster` objects (vectors of pairs of `FeeFrac`s and sets of parents), and convert them to `DepGraph` on the fly whenever needed. However, after more consideration, it seems better to have TxGraph store `DepGraph` objects, and manipulate them directly without constantly re-creating them. This requires `DepGraph` to have some additional functionality.

  The bulk of the complexity here is the addition of `DepGraph::RemoveTransactions`, which leaves the remaining transactions' positions within the `DepGraph` untouched (we want existing identifiers to remain valid), so this implies that graphs can now have "holes" (positions that are unused, but followed by positions that are used). To enable that, an extension of the fuzz/test serialization format `DepGraphFormatter` is included to deal with such holes.

ACKs for top commit:
  sdaftuar:
    reACK 0b3ec8c
  instagibbs:
    reACK 0b3ec8c
  ismaelsadeeq:
    reACK 0b3ec8c
  glozow:
    ACK 0b3ec8c, reviewed range-diff from  aab53dd and `clusterlin_depgraph_sim`

Tree-SHA512: a804b7f26d544c5cb0847322e235c810525cb0607737be6116c3156d582da3ba3352af8ea48e74eed5268f9c3eca63b30181d01b23a6dd0be1b99191f81cceb0
  • Loading branch information
glozow committed Oct 10, 2024
2 parents 9f45062 + 0b3ec8c commit 489e5aa
Show file tree
Hide file tree
Showing 8 changed files with 543 additions and 280 deletions.
24 changes: 12 additions & 12 deletions src/bench/cluster_linearize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ DepGraph<SetType> MakeLinearGraph(ClusterIndex ntx)
DepGraph<SetType> depgraph;
for (ClusterIndex i = 0; i < ntx; ++i) {
depgraph.AddTransaction({-int32_t(i), 1});
if (i > 0) depgraph.AddDependency(i - 1, i);
if (i > 0) depgraph.AddDependencies(SetType::Singleton(i - 1), i);
}
return depgraph;
}
Expand All @@ -43,7 +43,7 @@ DepGraph<SetType> MakeWideGraph(ClusterIndex ntx)
DepGraph<SetType> depgraph;
for (ClusterIndex i = 0; i < ntx; ++i) {
depgraph.AddTransaction({int32_t(i) + 1, 1});
if (i > 0) depgraph.AddDependency(0, i);
if (i > 0) depgraph.AddDependencies(SetType::Singleton(0), i);
}
return depgraph;
}
Expand All @@ -70,19 +70,19 @@ DepGraph<SetType> MakeHardGraph(ClusterIndex ntx)
depgraph.AddTransaction({1, 2});
} else if (i == 1) {
depgraph.AddTransaction({14, 2});
depgraph.AddDependency(0, 1);
depgraph.AddDependencies(SetType::Singleton(0), 1);
} else if (i == 2) {
depgraph.AddTransaction({6, 1});
depgraph.AddDependency(2, 1);
depgraph.AddDependencies(SetType::Singleton(2), 1);
} else if (i == 3) {
depgraph.AddTransaction({5, 1});
depgraph.AddDependency(2, 3);
depgraph.AddDependencies(SetType::Singleton(2), 3);
} else if ((i & 1) == 0) {
depgraph.AddTransaction({7, 1});
depgraph.AddDependency(i - 1, i);
depgraph.AddDependencies(SetType::Singleton(i - 1), i);
} else {
depgraph.AddTransaction({5, 1});
depgraph.AddDependency(i, 4);
depgraph.AddDependencies(SetType::Singleton(i), 4);
}
} else {
// Even cluster size.
Expand All @@ -98,16 +98,16 @@ DepGraph<SetType> MakeHardGraph(ClusterIndex ntx)
depgraph.AddTransaction({1, 1});
} else if (i == 1) {
depgraph.AddTransaction({3, 1});
depgraph.AddDependency(0, 1);
depgraph.AddDependencies(SetType::Singleton(0), 1);
} else if (i == 2) {
depgraph.AddTransaction({1, 1});
depgraph.AddDependency(0, 2);
depgraph.AddDependencies(SetType::Singleton(0), 2);
} else if (i & 1) {
depgraph.AddTransaction({4, 1});
depgraph.AddDependency(i - 1, i);
depgraph.AddDependencies(SetType::Singleton(i - 1), i);
} else {
depgraph.AddTransaction({0, 1});
depgraph.AddDependency(i, 3);
depgraph.AddDependencies(SetType::Singleton(i), 3);
}
}
}
Expand Down Expand Up @@ -195,7 +195,7 @@ void BenchMergeLinearizationsWorstCase(ClusterIndex ntx, benchmark::Bench& bench
DepGraph<SetType> depgraph;
for (ClusterIndex i = 0; i < ntx; ++i) {
depgraph.AddTransaction({i, 1});
if (i) depgraph.AddDependency(0, i);
if (i) depgraph.AddDependencies(SetType::Singleton(0), i);
}
std::vector<ClusterIndex> lin1;
std::vector<ClusterIndex> lin2;
Expand Down
Loading

0 comments on commit 489e5aa

Please sign in to comment.