txgraph: make number of acceptable iterations configurable (feature)

This commit is contained in:
Pieter Wuille 2025-04-13 11:16:26 -04:00
parent b074308e6f
commit 79ef423f42
3 changed files with 13 additions and 7 deletions

View file

@ -272,9 +272,11 @@ FUZZ_TARGET(txgraph)
auto max_count = provider.ConsumeIntegralInRange<DepGraphIndex>(1, MAX_CLUSTER_COUNT_LIMIT); auto max_count = provider.ConsumeIntegralInRange<DepGraphIndex>(1, MAX_CLUSTER_COUNT_LIMIT);
// And the maximum combined size of transactions per cluster. // And the maximum combined size of transactions per cluster.
auto max_size = provider.ConsumeIntegralInRange<uint64_t>(1, 0x3fffff * MAX_CLUSTER_COUNT_LIMIT); auto max_size = provider.ConsumeIntegralInRange<uint64_t>(1, 0x3fffff * MAX_CLUSTER_COUNT_LIMIT);
// And the number of iterations to consider a cluster acceptably linearized.
auto acceptable_iters = provider.ConsumeIntegralInRange<uint64_t>(0, 10000);
// Construct a real graph, and a vector of simulated graphs (main, and possibly staging). // Construct a real graph, and a vector of simulated graphs (main, and possibly staging).
auto real = MakeTxGraph(max_count, max_size); auto real = MakeTxGraph(max_count, max_size, acceptable_iters);
std::vector<SimTxGraph> sims; std::vector<SimTxGraph> sims;
sims.reserve(2); sims.reserve(2);
sims.emplace_back(max_count, max_size); sims.emplace_back(max_count, max_size);

View file

@ -247,6 +247,8 @@ private:
const DepGraphIndex m_max_cluster_count; const DepGraphIndex m_max_cluster_count;
/** This TxGraphImpl's maximum cluster size limit. */ /** This TxGraphImpl's maximum cluster size limit. */
const uint64_t m_max_cluster_size; const uint64_t m_max_cluster_size;
/** The number of linearization improvements steps needed for it to be considered acceptable. */
const uint64_t m_acceptable_iters;
/** Information about one group of Clusters to be merged. */ /** Information about one group of Clusters to be merged. */
struct GroupEntry struct GroupEntry
@ -443,9 +445,10 @@ private:
public: public:
/** Construct a new TxGraphImpl with the specified limits. */ /** Construct a new TxGraphImpl with the specified limits. */
explicit TxGraphImpl(DepGraphIndex max_cluster_count, uint64_t max_cluster_size) noexcept : explicit TxGraphImpl(DepGraphIndex max_cluster_count, uint64_t max_cluster_size, uint64_t acceptable_iters) noexcept :
m_max_cluster_count(max_cluster_count), m_max_cluster_count(max_cluster_count),
m_max_cluster_size(max_cluster_size), m_max_cluster_size(max_cluster_size),
m_acceptable_iters(acceptable_iters),
m_main_chunkindex(ChunkOrder(this)) m_main_chunkindex(ChunkOrder(this))
{ {
Assume(max_cluster_count >= 1); Assume(max_cluster_count >= 1);
@ -1671,7 +1674,7 @@ uint64_t TxGraphImpl::MakeAcceptable(Cluster& cluster) noexcept
uint64_t cost{0}; uint64_t cost{0};
// Relinearize the Cluster if needed. // Relinearize the Cluster if needed.
if (!cluster.NeedsSplitting() && !cluster.IsAcceptable() && !cluster.IsOversized()) { if (!cluster.NeedsSplitting() && !cluster.IsAcceptable() && !cluster.IsOversized()) {
cost += cluster.Relinearize(*this, 10000); cost += cluster.Relinearize(*this, m_acceptable_iters);
} }
return cost; return cost;
} }
@ -2896,7 +2899,7 @@ TxGraph::Ref::Ref(Ref&& other) noexcept
std::swap(m_index, other.m_index); std::swap(m_index, other.m_index);
} }
std::unique_ptr<TxGraph> MakeTxGraph(unsigned max_cluster_count, uint64_t max_cluster_size) noexcept std::unique_ptr<TxGraph> MakeTxGraph(unsigned max_cluster_count, uint64_t max_cluster_size, uint64_t acceptable_iters) noexcept
{ {
return std::make_unique<TxGraphImpl>(max_cluster_count, max_cluster_size); return std::make_unique<TxGraphImpl>(max_cluster_count, max_cluster_size, acceptable_iters);
} }

View file

@ -247,7 +247,8 @@ public:
/** Construct a new TxGraph with the specified limit on transactions within a cluster, and the /** Construct a new TxGraph with the specified limit on transactions within a cluster, and the
* specified limit on the sum of transaction sizes within a cluster. max_cluster_count cannot * specified limit on the sum of transaction sizes within a cluster. max_cluster_count cannot
* exceed MAX_CLUSTER_COUNT_LIMIT. */ * exceed MAX_CLUSTER_COUNT_LIMIT. acceptable_iters controls how many linearization optimization
std::unique_ptr<TxGraph> MakeTxGraph(unsigned max_cluster_count, uint64_t max_cluster_size) noexcept; * steps will be performed before it is considered to be of acceptable quality. */
std::unique_ptr<TxGraph> MakeTxGraph(unsigned max_cluster_count, uint64_t max_cluster_size, uint64_t acceptable_iters) noexcept;
#endif // BITCOIN_TXGRAPH_H #endif // BITCOIN_TXGRAPH_H