policy: Document rounding behavior of feerate fee getters #36741

Manually merged
maflcko merged 1 commit from 2611-doc-policy-feerate-fee-get into master 2026-11-05 21:50:43 +00:00 AGit
maflcko commented 2026-11-03 10:26:37 +00:00 (Migrated from github.com)

Now that the impl moved into the C++ file in 38ece2a9c8, it could make sense to document the rounding behavior in the header file doxygen comment.

Also, drop the "special case", which seems more confusing than helpful. (It is only a special case for negative feerates, which are mostly irrelevant and only possible with manual fee prioritization deltas)

Now that the impl moved into the C++ file in 38ece2a9c853ae3db9afb5215611c3e23e40461f, it could make sense to document the rounding behavior in the header file doxygen comment. Also, drop the "special case", which seems more confusing than helpful. (It is only a special case for negative feerates, which are mostly irrelevant and only possible with manual fee prioritization deltas)
DrahtBot commented 2026-11-03 10:26:51 +00:00 (Migrated from github.com)

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

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK polespinasa, pablomartin4btc, sedited

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35511 (RFC: consensus: Make CAmount a class by hodlinator)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36741 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36741.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36741#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [polespinasa](https://github.com/bitcoin/bitcoin/pull/36741#pullrequestreview-5789322557), [pablomartin4btc](https://github.com/bitcoin/bitcoin/pull/36741#issuecomment-6667180354), [sedited](https://github.com/bitcoin/bitcoin/pull/36741#pullrequestreview-5792589915) | 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: * [#35511](https://github.com/bitcoin/bitcoin/pull/35511) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35511.svg"></sub> (RFC: consensus: Make `CAmount` a class by hodlinator) 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-->
First-time contributor

🔵 Suggestion · Getter comments leave signed rounding directions implicit

The comments use correct ceiling/floor terminology, but spelling out the infinity directions would make the negative-feerate behavior clearer.

Location: src/policy/feerate.h:59 (head).

Review coverage was incomplete.


Reviewed: fa3d4f099282 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4d44b6ffa09c54db24f8f0ab27ae388beae06a733efcae741ca64db76bb1c938:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:0fe899d0ede0bd23be27e3af989087a318bceb29 --> <!-- ralph-head:fa3d4f099282a79099e59427180dffce4012a2b6 --> <!-- ralph-case:1f372818aaf5460ff677ab3e7a0012fc36b9cb0959f2503d337b27dd60fe662f --> **🔵 Suggestion · Getter comments leave signed rounding directions implicit** The comments use correct ceiling/floor terminology, but spelling out the infinity directions would make the negative-feerate behavior clearer. Location: [`src/policy/feerate.h:59`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/fa3d4f099282a79099e59427180dffce4012a2b6/src/policy/feerate.h#L59>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`fa3d4f099282`](<https://git.fish.foo/bitcoin/bitcoin/commit/fa3d4f099282a79099e59427180dffce4012a2b6>) · [Full review report](<https://review.fish.foo/traces/36741-fa3d4f099282a79099e59427180dffce4012a2b6-2248-4.html>) · [Previous reports](<https://review.fish.foo/traces/36741/>) [permalink](<https://review.fish.foo/traces/36741-fa3d4f099282a79099e59427180dffce4012a2b6-2248-4.html>)
maflcko commented 2026-11-03 17:50:40 +00:00 (Migrated from github.com)

(made the feefrac fuzz test stricter, thx Ralph review)

(made the feefrac fuzz test stricter, thx Ralph review)
pablomartin4btc (Migrated from github.com) reviewed 2026-11-05 15:21:54 +00:00
pablomartin4btc (Migrated from github.com) left a comment

cr ACK fa9aab2a29

Left one nit and a test suggestion (built and ran amount_tests locally with it).

cr ACK fa9aab2a29405852698e097d5615da6a3e997259 Left one nit and a test suggestion (built and ran `amount_tests` locally with it).
pablomartin4btc (Migrated from github.com) commented 2026-11-05 15:04:59 +00:00

nit: now that the special case is gone, the temporary isn't needed (and this matches GetFeePerK above):

    return CAmount(m_feerate.EvaluateFeeUp(virtual_bytes));
nit: now that the special case is gone, the temporary isn't needed (and this matches `GetFeePerK` above): ```suggestion return CAmount(m_feerate.EvaluateFeeUp(virtual_bytes)); ```
pablomartin4btc (Migrated from github.com) commented 2026-11-05 15:20:30 +00:00

The new "(Rounds down)" doc on GetFeePerK isn't covered by a test with a fractional rate (all existing ones are exact per kvB). Maybe we can add something like the following (which also pins the 1-sat gap between the two getters):


    // GetFeePerK rounds down for fractional rates
    BOOST_CHECK_EQUAL(CFeeRate(1, 3).GetFeePerK(), CAmount{333});
    BOOST_CHECK_EQUAL(CFeeRate(-1, 3).GetFeePerK(), CAmount{-334});
    // GetFee rounds up, so it can differ from GetFeePerK at 1000 vB
    BOOST_CHECK_EQUAL(CFeeRate(1, 3).GetFee(1000), CAmount{334});
    BOOST_CHECK_EQUAL(CFeeRate(-1, 3).GetFee(1000), CAmount{-333});

The new "(Rounds down)" doc on `GetFeePerK` isn't covered by a test with a fractional rate (all existing ones are exact per kvB). Maybe we can add something like the following (which also pins the 1-sat gap between the two getters): ```suggestion // GetFeePerK rounds down for fractional rates BOOST_CHECK_EQUAL(CFeeRate(1, 3).GetFeePerK(), CAmount{333}); BOOST_CHECK_EQUAL(CFeeRate(-1, 3).GetFeePerK(), CAmount{-334}); // GetFee rounds up, so it can differ from GetFeePerK at 1000 vB BOOST_CHECK_EQUAL(CFeeRate(1, 3).GetFee(1000), CAmount{334}); BOOST_CHECK_EQUAL(CFeeRate(-1, 3).GetFee(1000), CAmount{-333}); ```
maflcko (Migrated from github.com) reviewed 2026-11-05 15:55:57 +00:00
maflcko (Migrated from github.com) commented 2026-11-05 15:55:57 +00:00

thx, done

thx, done
polespinasa (Migrated from github.com) reviewed 2026-11-05 17:51:56 +00:00
polespinasa (Migrated from github.com) left a comment

ACK fa3d4f0992

The documentation change is clean :)

Tried to see why we were returning -1 before and I couldn't fine any specific reason for it. Seems good to remove the exception.

ACK fa3d4f099282a79099e59427180dffce4012a2b6 The documentation change is clean :) Tried to see why we were returning -1 before and I couldn't fine any specific reason for it. Seems good to remove the exception.
polespinasa (Migrated from github.com) commented 2026-11-05 17:39:53 +00:00

I guess this is worth to be mentioned in the commit message, just in case in the future someone checks this commits without context.

I guess this is worth to be mentioned in the commit message, just in case in the future someone checks this commits without context.
maflcko (Migrated from github.com) reviewed 2026-11-05 18:10:38 +00:00
maflcko (Migrated from github.com) commented 2026-11-05 18:10:38 +00:00

It is the function immediately above, so I think I'll leave as-is for now :)

It is the function immediately above, so I think I'll leave as-is for now :)
pablomartin4btc commented 2026-11-05 19:26:02 +00:00 (Migrated from github.com)

re-ACK fa3d4f0992

re-ACK fa3d4f099282a79099e59427180dffce4012a2b6
sedited (Migrated from github.com) approved these changes 2026-11-05 21:45:35 +00:00
sedited (Migrated from github.com) left a comment
ACK fa3d4f099282a79099e59427180dffce4012a2b6
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36741
No description provided.