3 suggestions
Optional improvements
[suggestion] · New txgraph tests prepare the graph before calling GetMainOrder
The new unit and fuzz checks would still pass without GetMainOrder's preparation step because their reference readers prepare the graph first.
Location: src/test/txgraph_tests.cpp:442 (head).
Details and suggested fix
In check_main_order, constructing the BlockBuilder calls MakeAllAcceptable(0) before GetMainOrder runs. The fuzz check likewise follows the CompareMainOrder sorts, which apply pending dependencies and prepare the compared clusters. This masks a missing preparation call, even though unprepared clusters can lack chunk-index entries and therefore be omitted. Save GetMainOrder() at the start of the unit-test helper, before constructing the builder, and compare that saved result afterwards. This exercises preparation on the existing dependency additions. The mempool check() totals provide indirect coverage, but the new txgraph checks currently do not.
[suggestion] · New sort in check() duplicates the existing ordering assertion
When mempool consistency checks run, the added copy and std::sort cost an extra O(N log N) comparator pass without strengthening the existing adjacent-pair ordering check.
Location: src/txmempool.cpp:456 (head).
Details and suggested fix
The loop below already asserts m_txgraph->CompareMainOrder(**last_iter, *it) < 0 for every consecutive pair of score_with_topo, which now comes directly from GetMainOrder. Under this total order, passing those assertions means sorting the same elements must leave the vector unchanged. Sorting a copy cannot detect missing entries either; the existing totals assertions cover omissions. Drop the new copy, sort and equality assertion and retain the adjacent-pair check.
[suggestion] · Unit-test fees miss interleaved chunks and cross-cluster feerate ties
The deterministic unit test cannot distinguish chunk-index expansion from emitting whole clusters because its chain becomes a single chunk before either unrelated transaction is added.
Location: src/test/txgraph_tests.cpp:457 (head).
Details and suggested fix
For the chain's fees {2,1,2,4}, all with weight 10, adding D produces one ABCD chunk at 9/40. The earlier multi-chunk states contain no other cluster. Once E and F exist, their feerates are 0.3 and 0.2, neither equal to the chain chunk's 0.225. Use fees {4,1,3,1,3,2} instead, retaining weight 10: the chain then has chunks A at 0.4, BC at 0.2 and D at 0.1, interleaved with E at 0.3 and tied with F at 0.2. Also compare against a vector sorted with CompareMainOrder, rather than only a BlockBuilder using the same chunk index. The fuzz target already supplies that comparator cross-check; this strengthens the deterministic test.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Ralph's inferences
The pre-existing ordering contract is a topology-respecting total order aimed at fee maximization, not a guarantee of an optimal or canonical order. Its chunks are highest-feerate prefixes of the remaining linearization, and each chunk must be connected and confined to one cluster.
These are the structural premises for expanding chunks into a global transaction order. They explain why within-chunk linearization matters, but do not by themselves establish that chunk-index traversal uses the same tie-breakers as CompareMainOrder.
Lazy comparison and bulk preparation share the same preparation primitive. CompareMainOrder first applies pending main-graph dependencies, makes both participating clusters acceptable, then delegates to CompareMainTransactions. MakeAllAcceptable likewise applies dependencies, then drains the NEEDS_FIX and NEEDS_RELINEARIZE queues through MakeAcceptable.
The proposed traversal does not introduce a different acceptable-quality threshold. However, it changes which clusters are prepared first, from comparison-driven selection to quality-queue order. Shared preparation logic alone is insufficient to prove schedule-independent output.
Acceptable-state preparation is idempotent for clusters that are already acceptable: MakeAcceptable does not relinearize them. For clusters needing preparation, relinearization may replace the stored linearization and updates the associated entry data.
Bulk preparation does not inherently reshuffle already-acceptable clusters. The compatibility question is concentrated on pending work and on whether preparing those clusters in a different sequence yields the same resulting linearizations and ordering keys.
Preparation order can affect the random seeds assigned to clusters: each GenericClusterImpl::Relinearize call draws a seed from the graph's shared RNG and passes it, the existing linearization, and the fallback comparator to Linearize. PostLinearize then processes the result. The inspected record therefore does not establish that bulk preparation and lazy comparison produce identical observable order from the same initially unprepared state.
This distinguishes two separate equivalence questions: whether the index and comparator agree after preparation, and whether changing the preparation schedule preserves the order that the previous lazy sort would have produced. Seed allocation is a concrete dependency that must be accounted for in the latter question; it is not evidence by itself that an order difference occurs.