Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251auto cross_a = T::Mul(a.m_feefrac.fee, b.m_feefrac.size);252auto cross_b = T::Mul(b.m_feefrac.fee, a.m_feefrac.size);253return cross_a > cross_b;254}255friend bool operator<=(const ByRatio& a, const ByRatio& b) noexcept256{257auto cross_a = T::Mul(a.m_feefrac.fee, b.m_feefrac.size);258auto cross_b = T::Mul(b.m_feefrac.fee, a.m_feefrac.size);259return cross_a <= cross_b;260}261friend bool operator>=(const ByRatio& a, const ByRatio& b) noexcept262{263auto cross_a = T::Mul(a.m_feefrac.fee, b.m_feefrac.size);264auto cross_b = T::Mul(b.m_feefrac.fee, a.m_feefrac.size);265return cross_a >= cross_b;266}267};269/** Wrapper around FeeFrac & derived types, which adds a total ordering which first sorts by feerate270* and then by reversed size (i.e., larger sizes come first).271*272* This is not included inside FeeFrac itself, because it is not the most natural behavior, so it273* is better to make code using it invoke this explicitly.274*275* The empty FeeFrac (fee and size both 0) sorts last. So for example, the following FeeFracs are276* in sorted order:277*278* - fee=0 size=1 (feerate 0)279* - fee=1 size=2 (feerate 0.5)280* - fee=2 size=3 (feerate 0.667...)281* - fee=2 size=2 (feerate 1)282* - fee=1 size=1 (feerate 1)283* - fee=3 size=2 (feerate 1.5)284* - fee=2 size=1 (feerate 2)285* - fee=0 size=0 (undefined feerate)286*/287template<std::derived_from<FeeFrac> T>288class ByRatioNegSize289{290const T& m_feefrac;292public:293constexpr ByRatioNegSize(const T& feefrac) noexcept : m_feefrac{feefrac} {}295friend bool operator==(const ByRatioNegSize& a, const ByRatioNegSize& b) noexcept296{297return a.m_feefrac == b.m_feefrac;298}300friend std::strong_ordering operator<=>(const ByRatioNegSize& a, const ByRatioNegSize& b) noexcept301{302auto cross_a = T::Mul(a.m_feefrac.fee, b.m_feefrac.size);303auto cross_b = T::Mul(b.m_feefrac.fee, a.m_feefrac.size);304auto cmp = cross_a <=> cross_b;305if (cmp != 0) return cmp;306return b.m_feefrac.size <=> a.m_feefrac.size;307}309// Support conversion back to underlying FeeFrac, which allows using std::max().310operator const T&() const noexcept { return m_feefrac; }311};313#endif // BITCOIN_UTIL_FEEFRAC_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.