3 suggestions
Optional improvements
[suggestion] · Rounding comments leave the negative-feerate case implicit
GetFee and GetFeePerK use correct rounding terminology, but spelling out the infinity directions would clarify their behavior for negative feerates.
Location: src/policy/feerate.h:59 (head).
Details and suggested fix
For negative rates, rounding the signed result differs from rounding its magnitude. CFeeRate(-123).GetFee(8) now returns 0, while CFeeRate(-1, 3).GetFeePerK() returns -334 rather than truncating to -333. Describe GetFee as rounding towards positive infinity and GetFeePerK as rounding towards negative infinity, matching the detailed FeeFrac::EvaluateFee contract. This would distinguish ceiling and floor from away-from-zero and towards-zero readings.
[suggestion] · GetFeePerK tests do not distinguish floor from ceiling
The amount_tests assertions would not detect replacing GetFeePerK's documented floor rounding with GetFee(1000)'s ceiling rounding.
Location: src/policy/feerate.h:64 (head).
Details and suggested fix
In amount_tests, the direct GetFeePerK assertions only check zero-size rates, and the maximum-size call checks no result. Fractional-rate comparisons use ratio operators, while the ToString and addition assertions use rates integral in sat/kvB. Add getter assertions for CFeeRate(CAmount{1}, 1001) and CFeeRate(CAmount{-1}, 1001): their GetFeePerK() results should be 0 and -1, while their GetFee(1000) results should be 1 and 0. These positive-size fixtures preserve the exact fractions and bypass the empty-rate return. They would distinguish floor, ceiling, and truncation for the existing behavior this PR now documents.
[suggestion] · The fuzz comparison still tolerates GetFee adjustments
Within its existing guards, feefrac_mul_div can now require exact ceiling equality, but its unchanged tolerance still allows CFeeRate-specific fee adjustments to go unnoticed.
Location: src/policy/feerate.cpp:32 (base).
Details and suggested fix
The positive div preserves the exact fraction and avoids the empty-rate return, while mul32 >= 0 satisfies the size requirement. The existing magnitude guards keep ceiling evaluation representable for either round_down setting. GetFee now delegates without adjustment, so replace the gap checks in the unchanged src/test/fuzz/feefrac.cpp with assert((feerate_fee == FeeFrac{mul64, div}.EvaluateFeeUp(mul32)));. For mul32=8, mul64=-123, div=1000, restoring the removed override would still satisfy the current tolerance. This optional follow-up checks CFeeRate's delegation rather than independently testing FeeFrac arithmetic; amount_tests already catches that literal restoration at one point.