From 4eefdfc5b7d0b86a523683de2a90da910b77a106 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 21 Feb 2026 10:27:59 -0500 Subject: [PATCH] clusterlin: rescale costs (preparation) --- src/cluster_linearize.h | 4 ++-- src/test/fuzz/cluster_linearize.cpp | 4 ++-- src/test/util/cluster_linearize.h | 16 ++++++++-------- src/txmempool.h | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/cluster_linearize.h b/src/cluster_linearize.h index 57df4512697..ea0d6bd8346 100644 --- a/src/cluster_linearize.h +++ b/src/cluster_linearize.h @@ -486,9 +486,9 @@ public: inline void StartOptimizingBegin() noexcept {} inline void StartOptimizingEnd(int num_chunks) noexcept {} inline void ActivateBegin() noexcept {} - inline void ActivateEnd(int num_deps) noexcept { m_cost += num_deps + 1; } + inline void ActivateEnd(int num_deps) noexcept { m_cost += 38 * num_deps + 38; } inline void DeactivateBegin() noexcept {} - inline void DeactivateEnd(int num_deps) noexcept { m_cost += num_deps + 1; } + inline void DeactivateEnd(int num_deps) noexcept { m_cost += 38 * num_deps + 38; } inline void MergeChunksBegin() noexcept {} inline void MergeChunksMid(int num_txns) noexcept {} inline void MergeChunksEnd(int num_steps) noexcept {} diff --git a/src/test/fuzz/cluster_linearize.cpp b/src/test/fuzz/cluster_linearize.cpp index adee8f2ed90..9b07bf00eb2 100644 --- a/src/test/fuzz/cluster_linearize.cpp +++ b/src/test/fuzz/cluster_linearize.cpp @@ -1043,7 +1043,7 @@ FUZZ_TARGET(clusterlin_linearize) } // Invoke Linearize(). - max_cost &= 0x7ffff; + max_cost &= 0x3fffff; auto [linearization, optimal, cost] = Linearize( /*depgraph=*/depgraph, /*max_cost=*/max_cost, @@ -1242,7 +1242,7 @@ FUZZ_TARGET(clusterlin_postlinearize_tree) // Try to find an even better linearization directly. This must not change the diagram for the // same reason. - auto [opt_linearization, _optimal, _cost] = Linearize(depgraph_tree, 100000, rng_seed, IndexTxOrder{}, post_linearization); + auto [opt_linearization, _optimal, _cost] = Linearize(depgraph_tree, 1000000, rng_seed, IndexTxOrder{}, post_linearization); auto opt_chunking = ChunkLinearization(depgraph_tree, opt_linearization); auto cmp_opt = CompareChunks(opt_chunking, post_chunking); assert(cmp_opt == 0); diff --git a/src/test/util/cluster_linearize.h b/src/test/util/cluster_linearize.h index f50a51bd1a5..f8ffb5ea4e5 100644 --- a/src/test/util/cluster_linearize.h +++ b/src/test/util/cluster_linearize.h @@ -402,14 +402,14 @@ inline uint64_t MaxOptimalLinearizationCost(DepGraphIndex cluster_count) // *some* reasonable cost bound, optimal linearizations are always found. static constexpr uint64_t COSTS[65] = { 0, - 0, 4, 10, 34, 76, 156, 229, 380, - 441, 517, 678, 933, 1037, 1366, 1464, 1711, - 2111, 2542, 3068, 3116, 4029, 3467, 5324, 5402, - 6481, 7161, 7441, 8183, 8843, 9353, 11104, 11455, - 11791, 12570, 13480, 14259, 14525, 12426, 14477, 20201, - 18737, 16581, 23622, 28486, 30652, 33021, 32942, 32745, - 34046, 26227, 34662, 38019, 40814, 31113, 41448, 33968, - 35024, 59207, 42872, 41277, 42365, 51833, 63410, 67035 + 0, 176, 440, 1496, 3344, 6864, 10076, 16720, + 19404, 22748, 29832, 41052, 45628, 60104, 64416, 75284, + 92884, 111848, 134992, 137104, 177276, 152548, 234256, 237688, + 285164, 315084, 327404, 360052, 389092, 411532, 488576, 504020, + 518804, 553080, 593120, 627396, 639100, 546744, 636988, 888844, + 824428, 729564, 1039368, 1253384, 1348688, 1452924, 1449448, 1440780, + 1498024, 1153988, 1525128, 1672836, 1795816, 1368972, 1823712, 1494592, + 1541056, 2605108, 1886368, 1816188, 1864060, 2280652, 2790040, 2949540 }; assert(cluster_count < std::size(COSTS)); // Multiply the table number by two, to account for the fact that they are not absolutes. diff --git a/src/txmempool.h b/src/txmempool.h index 5a870f4cc32..d7b7de6e3b7 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -51,7 +51,7 @@ static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF; /** How much linearization cost required for TxGraph clusters to have * "acceptable" quality, if they cannot be optimally linearized with less cost. */ -static constexpr uint64_t ACCEPTABLE_COST = 1'700; +static constexpr uint64_t ACCEPTABLE_COST = 75'000; /** How much work we ask TxGraph to do after a mempool change occurs (either * due to a changeset being applied, a new block being found, or a reorg). */