From 0b3ec8c59b2b6d598531cd4e688eb276e597c825 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 23 Sep 2024 11:32:58 -0400 Subject: [PATCH] clusterlin: remove Cluster type --- src/cluster_linearize.h | 39 +--------------------------- src/test/cluster_linearize_tests.cpp | 14 +++++----- src/test/util/cluster_linearize.h | 37 -------------------------- 3 files changed, 8 insertions(+), 82 deletions(-) diff --git a/src/cluster_linearize.h b/src/cluster_linearize.h index a2450f54908..757c81f1083 100644 --- a/src/cluster_linearize.h +++ b/src/cluster_linearize.h @@ -19,14 +19,6 @@ namespace cluster_linearize { -/** Data type to represent cluster input. - * - * cluster[i].first is tx_i's fee and size. - * cluster[i].second[j] is true iff tx_i spends one or more of tx_j's outputs. - */ -template -using Cluster = std::vector>; - /** Data type to represent transaction indices in clusters. */ using ClusterIndex = uint32_t; @@ -54,7 +46,7 @@ class DepGraph Entry(const FeeFrac& f, const SetType& a, const SetType& d) noexcept : feerate(f), ancestors(a), descendants(d) {} }; - /** Data for each transaction, in the same order as the Cluster it was constructed from. */ + /** Data for each transaction. */ std::vector entries; /** Which positions are used. */ @@ -79,35 +71,6 @@ public: DepGraph& operator=(const DepGraph&) noexcept = default; DepGraph& operator=(DepGraph&&) noexcept = default; - /** Construct a DepGraph object for ntx transactions, with no dependencies. - * - * Complexity: O(N) where N=ntx. - **/ - explicit DepGraph(ClusterIndex ntx) noexcept - { - Assume(ntx <= SetType::Size()); - entries.resize(ntx); - for (ClusterIndex i = 0; i < ntx; ++i) { - entries[i].ancestors = SetType::Singleton(i); - entries[i].descendants = SetType::Singleton(i); - } - m_used = SetType::Fill(ntx); - } - - /** Construct a DepGraph object given a cluster. - * - * Complexity: O(N^2) where N=cluster.size(). - */ - explicit DepGraph(const Cluster& cluster) noexcept : DepGraph(cluster.size()) - { - for (ClusterIndex i = 0; i < cluster.size(); ++i) { - // Fill in fee and size. - entries[i].feerate = cluster[i].first; - // Fill in dependencies. - AddDependencies(cluster[i].second, i); - } - } - /** Construct a DepGraph object given another DepGraph and a mapping from old to new. * * @param depgraph The original DepGraph that is being remapped. diff --git a/src/test/cluster_linearize_tests.cpp b/src/test/cluster_linearize_tests.cpp index cb87dcbffbe..265ccdc805e 100644 --- a/src/test/cluster_linearize_tests.cpp +++ b/src/test/cluster_linearize_tests.cpp @@ -23,18 +23,18 @@ namespace { constexpr std::pair HOLE{FeeFrac{0, 0x3FFFFF}, {}}; template -void TestDepGraphSerialization(const Cluster& cluster, const std::string& hexenc) +void TestDepGraphSerialization(const std::vector>& cluster, const std::string& hexenc) { - DepGraph depgraph(cluster); - - // Run normal sanity and correspondence checks, which includes a round-trip test. - VerifyDepGraphFromCluster(cluster, depgraph); - - // Remove holes (which are expected to be present as HOLE entries in cluster). + // Construct DepGraph from cluster argument. + DepGraph depgraph; SetType holes; for (ClusterIndex i = 0; i < cluster.size(); ++i) { + depgraph.AddTransaction(cluster[i].first); if (cluster[i] == HOLE) holes.Set(i); } + for (ClusterIndex i = 0; i < cluster.size(); ++i) { + depgraph.AddDependencies(cluster[i].second, i); + } depgraph.RemoveTransactions(holes); // There may be multiple serializations of the same graph, but DepGraphFormatter's serializer diff --git a/src/test/util/cluster_linearize.h b/src/test/util/cluster_linearize.h index 44cd6590d38..871aa9d74ed 100644 --- a/src/test/util/cluster_linearize.h +++ b/src/test/util/cluster_linearize.h @@ -390,43 +390,6 @@ void SanityCheck(const DepGraph& depgraph) } } -/** Verify that a DepGraph corresponds to the information in a cluster. */ -template -void VerifyDepGraphFromCluster(const Cluster& cluster, const DepGraph& depgraph) -{ - // Sanity check the depgraph, which includes a check for correspondence between ancestors and - // descendants, so it suffices to check just ancestors below. - SanityCheck(depgraph); - // Verify transaction count. - assert(cluster.size() == depgraph.TxCount()); - // Verify feerates. - for (ClusterIndex i = 0; i < depgraph.TxCount(); ++i) { - assert(depgraph.FeeRate(i) == cluster[i].first); - } - // Verify ancestors. - for (ClusterIndex i = 0; i < depgraph.TxCount(); ++i) { - // Start with the transaction having itself as ancestor. - auto ancestors = SetType::Singleton(i); - // Add parents of ancestors to the set of ancestors until it stops changing. - while (true) { - const auto old_ancestors = ancestors; - for (auto ancestor : ancestors) { - ancestors |= cluster[ancestor].second; - } - if (old_ancestors == ancestors) break; - } - // Compare against depgraph. - assert(depgraph.Ancestors(i) == ancestors); - // Some additional sanity tests: - // - Every transaction has itself as ancestor. - assert(ancestors[i]); - // - Every transaction has its direct parents as ancestors. - for (auto parent : cluster[i].second) { - assert(ancestors[parent]); - } - } -} - /** Perform a sanity check on a linearization. */ template void SanityCheck(const DepGraph& depgraph, Span linearization)