2 suggestions
Optional improvements
[suggestion] · Trim can retain a lower-feerate sibling instead of a higher-feerate child
When a higher-feerate child waits on a low-fee re-added block parent, removing the linearization chain can let a lower-feerate sibling consume the cluster capacity first.
Location: src/txgraph.cpp:1420 (head).
Details and suggested fix
For a graph-level example, use count limit 3 and transaction sizes 100. Materialize the existing cluster P→A and P→Z, with fees P=10, A=8, Z=3 and linearization P,A,Z. Then add singleton R with fee 1 and queue R→A. The heap still uses pre-merge chunk feerates, so head includes P,Z,R before considering A. A would join partitions {P,Z} and {R}, giving count 4, so Trim removes it and any descendants. Base's implicit A→Z edge instead makes the order P,R,A,Z and removes Z. Both remove one transaction, but retained fees fall from 19 to 14 even though R+A has a higher package feerate than Z. UpdateTransactionsFromBlock supplies block-parent→mempool-child dependencies before calling Trim, matching this reorg dependency shape; no specific production occurrence under default limits was identified. Trim promises only best effort, so this is a fee-quality tradeoff rather than a contract violation. Document that choice, replace the “merge sort” description that implies preserved within-cluster chunk order, and add a delayed-low-fee-parent unit case that pins the intended survivors.
[suggestion] · Trim fuzz coverage still assumes approximation-induced cycles
With real dependencies, the valid fuzz graphs are acyclic, so the special branch's removal-count bound can also strengthen the general Trim branch and its cycle rationale is obsolete.
Location: src/test/fuzz/txgraph.cpp:927 (head).
Details and suggested fix
The harness rejects cycle-creating dependencies and closes removals under ancestors or descendants. Reduced existing parents plus pending real dependencies therefore cannot produce the apparent cycles described here or by the remaining “approximation” comment. The general Trim branch checks descendant closure, overlap with oversized components, and final limits, but none bounds how much of an oversized component disappears. Compute the existing max_removed bound from top_sim.GetComponents() before the general Trim call and assert it there too. For an acyclic component, the first limit-based rejection requires at least K retained transactions, where any K transactions fit; an individually oversized transaction gives K=0. This would detect excess removals such as whole components disappearing through reintroduced cyclic ordering edges. It is not a minimality oracle: both new five-transaction/count-three fixtures allow two removals under this bound, so their stricter unit assertions remain necessary. Reword the special branch's rationale around joining separate clusters into oversized groups, and update txgraph.cpp's cycle explanation to identify invalid AddDependency use rather than a distinction between reorgs and other valid callers.