clusterlin: remove Cluster type

This commit is contained in:
Pieter Wuille 2024-09-23 11:32:58 -04:00
parent 1c24c62510
commit 0b3ec8c59b
3 changed files with 8 additions and 82 deletions

View File

@ -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<typename SetType>
using Cluster = std::vector<std::pair<FeeFrac, SetType>>;
/** 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<Entry> 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<SetType>& 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.

View File

@ -23,18 +23,18 @@ namespace {
constexpr std::pair<FeeFrac, TestBitSet> HOLE{FeeFrac{0, 0x3FFFFF}, {}};
template<typename SetType>
void TestDepGraphSerialization(const Cluster<SetType>& cluster, const std::string& hexenc)
void TestDepGraphSerialization(const std::vector<std::pair<FeeFrac, SetType>>& 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<SetType> 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

View File

@ -390,43 +390,6 @@ void SanityCheck(const DepGraph<SetType>& depgraph)
}
}
/** Verify that a DepGraph corresponds to the information in a cluster. */
template<typename SetType>
void VerifyDepGraphFromCluster(const Cluster<SetType>& cluster, const DepGraph<SetType>& 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<typename SetType>
void SanityCheck(const DepGraph<SetType>& depgraph, Span<const ClusterIndex> linearization)