feefrac: drop comparison and operator{<<,>>} for sorted wrappers #34669

pull sipa wants to merge 2 commits into bitcoin:master from sipa:wip_feefrac_order changing 15 files +245 −185
  1. sipa commented at 4:39 PM on February 25, 2026: member

    Instead of having an unintuitive but strong implicit sort order on FeeFrac (first increasing feerate, then decreasing size), and separate overloaded operator<< and operator>> that implement a weak ordering that only looks at feerate, replace these with explicit wrapper classes which make the behavior more explicit (ByRatio and ByRatioNegSize).

    This allows for things like ByRatio{a} <= ByRatio{b}, instead of the earlier !(a >> b). It also supports usage inside std::min/std::max/std::less, and std::greater, so one can use:

    • std::max<ByRatioNegSize<FeeFrac>>(a, b) to get the highest-feerate FeeFrac, tie-breaking by smallest size.
    • std::ranges::sort(v, std::greater<ByRatioNegSize<FeeFrac>>{}); to sort a vector that way.

    Suggested in #34257 (review).

  2. sipa commented at 4:39 PM on February 25, 2026: member

    Not intended for 31.0.

  3. DrahtBot commented at 4:39 PM on February 25, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK sedited
    Concept ACK ismaelsadeeq

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34803 (mempool: asynchronous mempool fee rate diagram updates via validation interface by ismaelsadeeq)
    • #33966 (refactor: disentangle miner startup defaults from runtime options by Sjors)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. in src/test/fuzz/txgraph.cpp:436 in 38e70ff287
     432 | @@ -433,7 +433,7 @@ FUZZ_TARGET(txgraph)
     433 |          assert(num_tx == sim.GetTransactionCount());
     434 |          // Sort by feerate only, since violating topological constraints within same-feerate
     435 |          // chunks won't affect diagram comparisons.
     436 | -        std::sort(chunk_feerates.begin(), chunk_feerates.end(), std::greater{});
     437 | +        std::sort(chunk_feerates.begin(), chunk_feerates.end(), std::greater<ByRatioNegSize<FeeFrac>>{});
    


    andrewtoth commented at 5:37 PM on February 25, 2026:

    Since we're touching all these std::sort, we can also update them to C++20 ranges:

            std::ranges::sort(chunk_feerates, std::greater<ByRatioNegSize<FeeFrac>>{});
    

    sipa commented at 6:18 PM on February 25, 2026:

    Added an extra commit that uses std::ranges::sort and std::ranges::unique wherever possible in the cluster linearization related files (not only in lines touches by the previous commit).

  5. in src/test/feefrac_tests.cpp:86 in 64b81ff965
      96 |      // "empty" comparisons
      97 | -    BOOST_CHECK(!(p1 >> empty)); // << will always result in false
      98 | -    BOOST_CHECK(!(p1 << empty));
      99 | -    BOOST_CHECK(!(empty >> empty));
     100 | -    BOOST_CHECK(!(empty << empty));
     101 | +    BOOST_CHECK(!(ByRatioNegSize{p1} > ByRatioNegSize{empty})); // << will always result in false
    


    w0xlt commented at 10:45 PM on February 25, 2026:

    It is replacing BOOST_CHECK(!(p1 >> empty));.

        BOOST_CHECK(!(ByRatio{p1} > ByRatio{empty}));
    

    sipa commented at 1:38 PM on February 27, 2026:

    Fixed.

  6. in src/util/feefrac.h:15 in 64b81ff965
      14 | @@ -15,26 +15,6 @@
      15 |  /** Data structure storing a fee and size, ordered by increasing fee/size.
    


    w0xlt commented at 10:47 PM on February 25, 2026:

    nit: FeeFrac no longer has comparison operators.

    /** Data structure storing a fee and size.
    

    sipa commented at 1:38 PM on February 27, 2026:

    Done.

  7. in src/util/feefrac.cpp:45 in 64b81ff965


    w0xlt commented at 11:01 PM on February 25, 2026:

    It seems the code is implicitly converting std::strong_ordering to std::weak_ordering.

    -        std::weak_ordering cmp = std::weak_ordering::equivalent;
    +        std::strong_ordering cmp = std::strong_ordering::equivalent;
    

    sipa commented at 1:38 PM on February 27, 2026:

    Done, and switched to auto to avoid repeating the type name.

  8. feefrac: drop comparison and operator{<<,>>} for sorted wrappers
    Instead of having an unintuitive but total implicit sort order on
    FeeFrac (first increasing feerate, then decreasing size), and separate
    overloaded operator<< and operator>> for a weak ordering that only looks
    at feerate, replace these with explicit wrapper classes which make the
    behavior more explicit.
    
    This allows for things like ByRatio{a} <= ByRatio{b}, instead of the
    earlier !(a >> b). It also supports usage inside std::max and
    std::greater, so one can use:
    * std::max<ByRatioNegSize<FeeFrac>>(a, b)
    * std::sort(v.begin(), v.end(), std::greater<ByRatioNegSize<FeeFrac>>{})
    747da25360
  9. clusterlin: adopt STL ranges algorithms (refactor) 1aa78cdab6
  10. sipa force-pushed on Feb 27, 2026
  11. ajtowns commented at 11:04 AM on March 2, 2026: contributor

    Maybe demote this to draft until 31 is branched off?

  12. sipa marked this as a draft on Mar 2, 2026
  13. fanquake added this to the milestone 32.0 on Mar 2, 2026
  14. sipa marked this as ready for review on Mar 12, 2026
  15. sipa commented at 1:38 PM on March 12, 2026: member

    Marked ready for review with 31.x branched off.

  16. sedited approved
  17. sedited commented at 9:12 PM on March 23, 2026: contributor

    ACK 1aa78cdab6bc8ecd4448b1b75ee3181ee8f3f519

  18. sedited requested review from ismaelsadeeq on Mar 23, 2026
  19. ismaelsadeeq commented at 7:00 AM on March 24, 2026: member

    Concept ACK


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me