clusterlin: remove unused FixLinearization (cleanup)
This commit is contained in:
1 parent
34a77138b7
commit
1808b5aaf7
2 files changed
-54
No files matched your search
@@ -1575,16 +1575,6 @@ void PostLinearize(const DepGraph<SetType>& depgraph, std::span<DepGraphIndex> l
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make linearization topological, reusing information from the old linearization where possible. */
|
|
||||||
template<typename SetType>
|
|
||||||
void FixLinearization(const DepGraph<SetType>& depgraph, std::span<DepGraphIndex> linearization) noexcept
|
|
||||||
{
|
|
||||||
// TODO: update call sites to use Linearize directly.
|
|
||||||
auto [new_lin, _opt, _steps] = Linearize(depgraph, /*max_iterations=*/0, /*rng_seed=*/0, linearization, /*is_topological=*/false);
|
|
||||||
Assume(new_lin.size() == linearization.size());
|
|
||||||
std::copy(new_lin.begin(), new_lin.end(), linearization.begin());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace cluster_linearize
|
} // namespace cluster_linearize
|
||||||
|
|
||||||
#endif // BITCOIN_CLUSTER_LINEARIZE_H
|
#endif // BITCOIN_CLUSTER_LINEARIZE_H
|
||||||
@@ -58,8 +58,6 @@
|
|||||||
* - clusterlin_postlinearize
|
* - clusterlin_postlinearize
|
||||||
* - clusterlin_postlinearize_tree
|
* - clusterlin_postlinearize_tree
|
||||||
* - clusterlin_postlinearize_moved_leaf
|
* - clusterlin_postlinearize_moved_leaf
|
||||||
* - FixLinearization tests:
|
|
||||||
* - clusterlin_fix_linearization
|
|
||||||
* - MakeConnected tests (a test-only function):
|
* - MakeConnected tests (a test-only function):
|
||||||
* - clusterlin_make_connected
|
* - clusterlin_make_connected
|
||||||
*/
|
*/
|
||||||
@@ -1202,45 +1200,3 @@ FUZZ_TARGET(clusterlin_postlinearize_moved_leaf)
|
|||||||
auto cmp = CompareChunks(new_chunking, old_chunking);
|
auto cmp = CompareChunks(new_chunking, old_chunking);
|
||||||
assert(cmp >= 0);
|
assert(cmp >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
FUZZ_TARGET(clusterlin_fix_linearization)
|
|
||||||
{
|
|
||||||
// Verify expected properties of FixLinearization() on arbitrary linearizations.
|
|
||||||
|
|
||||||
// Retrieve a depgraph from the fuzz input.
|
|
||||||
SpanReader reader(buffer);
|
|
||||||
DepGraph<TestBitSet> depgraph;
|
|
||||||
try {
|
|
||||||
reader >> Using<DepGraphFormatter>(depgraph);
|
|
||||||
} catch (const std::ios_base::failure&) {}
|
|
||||||
|
|
||||||
// Construct an arbitrary linearization (not necessarily topological for depgraph).
|
|
||||||
std::vector<DepGraphIndex> linearization = ReadLinearization(depgraph, reader, /*topological=*/false);
|
|
||||||
assert(linearization.size() == depgraph.TxCount());
|
|
||||||
|
|
||||||
// Determine what prefix of linearization is topological, i.e., the position of the first entry
|
|
||||||
// in linearization which corresponds to a transaction that is not preceded by all its
|
|
||||||
// ancestors.
|
|
||||||
size_t topo_prefix = 0;
|
|
||||||
auto todo = depgraph.Positions();
|
|
||||||
while (topo_prefix < linearization.size()) {
|
|
||||||
DepGraphIndex idx = linearization[topo_prefix];
|
|
||||||
todo.Reset(idx);
|
|
||||||
if (todo.Overlaps(depgraph.Ancestors(idx))) break;
|
|
||||||
++topo_prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then make a fixed copy of linearization.
|
|
||||||
auto linearization_fixed = linearization;
|
|
||||||
FixLinearization(depgraph, linearization_fixed);
|
|
||||||
// Sanity check it (which includes testing whether it is topological).
|
|
||||||
SanityCheck(depgraph, linearization_fixed);
|
|
||||||
|
|
||||||
// If linearization was entirely topological, FixLinearization cannot worsen it.
|
|
||||||
if (topo_prefix == linearization.size()) {
|
|
||||||
auto chunking = ChunkLinearization(depgraph, linearization);
|
|
||||||
auto chunking_fixed = ChunkLinearization(depgraph, linearization_fixed);
|
|
||||||
auto cmp = CompareChunks(chunking_fixed, chunking);
|
|
||||||
assert(cmp >= 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user