Skip to content

Commit 0b3ec8c

Browse files
committed
clusterlin: remove Cluster type
1 parent 1c24c62 commit 0b3ec8c

File tree

3 files changed

+8
-82
lines changed

3 files changed

+8
-82
lines changed

src/cluster_linearize.h

+1-38
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919

2020
namespace cluster_linearize {
2121

22-
/** Data type to represent cluster input.
23-
*
24-
* cluster[i].first is tx_i's fee and size.
25-
* cluster[i].second[j] is true iff tx_i spends one or more of tx_j's outputs.
26-
*/
27-
template<typename SetType>
28-
using Cluster = std::vector<std::pair<FeeFrac, SetType>>;
29-
3022
/** Data type to represent transaction indices in clusters. */
3123
using ClusterIndex = uint32_t;
3224

@@ -54,7 +46,7 @@ class DepGraph
5446
Entry(const FeeFrac& f, const SetType& a, const SetType& d) noexcept : feerate(f), ancestors(a), descendants(d) {}
5547
};
5648

57-
/** Data for each transaction, in the same order as the Cluster it was constructed from. */
49+
/** Data for each transaction. */
5850
std::vector<Entry> entries;
5951

6052
/** Which positions are used. */
@@ -79,35 +71,6 @@ class DepGraph
7971
DepGraph& operator=(const DepGraph&) noexcept = default;
8072
DepGraph& operator=(DepGraph&&) noexcept = default;
8173

82-
/** Construct a DepGraph object for ntx transactions, with no dependencies.
83-
*
84-
* Complexity: O(N) where N=ntx.
85-
**/
86-
explicit DepGraph(ClusterIndex ntx) noexcept
87-
{
88-
Assume(ntx <= SetType::Size());
89-
entries.resize(ntx);
90-
for (ClusterIndex i = 0; i < ntx; ++i) {
91-
entries[i].ancestors = SetType::Singleton(i);
92-
entries[i].descendants = SetType::Singleton(i);
93-
}
94-
m_used = SetType::Fill(ntx);
95-
}
96-
97-
/** Construct a DepGraph object given a cluster.
98-
*
99-
* Complexity: O(N^2) where N=cluster.size().
100-
*/
101-
explicit DepGraph(const Cluster<SetType>& cluster) noexcept : DepGraph(cluster.size())
102-
{
103-
for (ClusterIndex i = 0; i < cluster.size(); ++i) {
104-
// Fill in fee and size.
105-
entries[i].feerate = cluster[i].first;
106-
// Fill in dependencies.
107-
AddDependencies(cluster[i].second, i);
108-
}
109-
}
110-
11174
/** Construct a DepGraph object given another DepGraph and a mapping from old to new.
11275
*
11376
* @param depgraph The original DepGraph that is being remapped.

src/test/cluster_linearize_tests.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ namespace {
2323
constexpr std::pair<FeeFrac, TestBitSet> HOLE{FeeFrac{0, 0x3FFFFF}, {}};
2424

2525
template<typename SetType>
26-
void TestDepGraphSerialization(const Cluster<SetType>& cluster, const std::string& hexenc)
26+
void TestDepGraphSerialization(const std::vector<std::pair<FeeFrac, SetType>>& cluster, const std::string& hexenc)
2727
{
28-
DepGraph depgraph(cluster);
29-
30-
// Run normal sanity and correspondence checks, which includes a round-trip test.
31-
VerifyDepGraphFromCluster(cluster, depgraph);
32-
33-
// Remove holes (which are expected to be present as HOLE entries in cluster).
28+
// Construct DepGraph from cluster argument.
29+
DepGraph<SetType> depgraph;
3430
SetType holes;
3531
for (ClusterIndex i = 0; i < cluster.size(); ++i) {
32+
depgraph.AddTransaction(cluster[i].first);
3633
if (cluster[i] == HOLE) holes.Set(i);
3734
}
35+
for (ClusterIndex i = 0; i < cluster.size(); ++i) {
36+
depgraph.AddDependencies(cluster[i].second, i);
37+
}
3838
depgraph.RemoveTransactions(holes);
3939

4040
// There may be multiple serializations of the same graph, but DepGraphFormatter's serializer

src/test/util/cluster_linearize.h

-37
Original file line numberDiff line numberDiff line change
@@ -390,43 +390,6 @@ void SanityCheck(const DepGraph<SetType>& depgraph)
390390
}
391391
}
392392

393-
/** Verify that a DepGraph corresponds to the information in a cluster. */
394-
template<typename SetType>
395-
void VerifyDepGraphFromCluster(const Cluster<SetType>& cluster, const DepGraph<SetType>& depgraph)
396-
{
397-
// Sanity check the depgraph, which includes a check for correspondence between ancestors and
398-
// descendants, so it suffices to check just ancestors below.
399-
SanityCheck(depgraph);
400-
// Verify transaction count.
401-
assert(cluster.size() == depgraph.TxCount());
402-
// Verify feerates.
403-
for (ClusterIndex i = 0; i < depgraph.TxCount(); ++i) {
404-
assert(depgraph.FeeRate(i) == cluster[i].first);
405-
}
406-
// Verify ancestors.
407-
for (ClusterIndex i = 0; i < depgraph.TxCount(); ++i) {
408-
// Start with the transaction having itself as ancestor.
409-
auto ancestors = SetType::Singleton(i);
410-
// Add parents of ancestors to the set of ancestors until it stops changing.
411-
while (true) {
412-
const auto old_ancestors = ancestors;
413-
for (auto ancestor : ancestors) {
414-
ancestors |= cluster[ancestor].second;
415-
}
416-
if (old_ancestors == ancestors) break;
417-
}
418-
// Compare against depgraph.
419-
assert(depgraph.Ancestors(i) == ancestors);
420-
// Some additional sanity tests:
421-
// - Every transaction has itself as ancestor.
422-
assert(ancestors[i]);
423-
// - Every transaction has its direct parents as ancestors.
424-
for (auto parent : cluster[i].second) {
425-
assert(ancestors[parent]);
426-
}
427-
}
428-
}
429-
430393
/** Perform a sanity check on a linearization. */
431394
template<typename SetType>
432395
void SanityCheck(const DepGraph<SetType>& depgraph, Span<const ClusterIndex> linearization)

0 commit comments

Comments
 (0)