Repository navigation
fees: wallet: remove block policy fee estimator internals from wallet - #34617
ismaelsadeeq wants to merge 2 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34617. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. |
a9c1bc2 to
991df9b
Compare
There was a problem hiding this comment.
Concept ACK on separating FeeSource from FeeReason
- Maintain complete backward compatibility by not changing the output to the fee source, i.e making it
fee_reasonbut changing and reducing the outputs to only the fee source, marking it as deprecated for removal.
I think option 2 makes sense IMO, if the goal is to avoid breaking changes while giving users who rely on this field time to migrate. During the transition period, the field can remain named fee_reason, while clearly informing users that its output now represents the fee source (i.e., where the fee rate came from) rather than the estimator’s internal reasoning.
I think this approach helps correct the misnomer by removing outputs that should not be exposed, while still maintaining backward compatibility. It also avoids leaking internal estimator details, since estimateSmartFee now logs its internal reasoning directly in this PR, and the wallet no longer handles or exposes those internals. As a result, the estimator logic remains properly encapsulated.
Renamed the
fee_reasonfield tofee_sourcein wallet RPCs (such assend,walletcreatefundedpsbt).
Not sure if sendand walletcreatefundedpsbt are the correct RPCs being affected. Unless am missing something, because fee_source appears in SendMoney() which is only used by sendtoaddress and sendmany.
This seems consistent with the comment in the function:
// This function is only used by sendtoaddress and sendmany.
So it looks like the RPCs affected might actually be sendtoaddress and sendmany.
a2fb19d to
067fadb
Compare
|
Forced pushed from 991df9bd182679e1fb1632ea1688042030fd264f to f21af8784ac44045f1f3428746e20ac935cd7340 compare diff Thanks for the review @Eunovo @musaHaruna
C.I failure seems unrelated, see #34731 |
067fadb to
f21af87
Compare
|
Concept ACK I think it's a bit weird that some intermediate commits add some new function parameters that get removed in later commits. I took a stab at rearranging the commits to see if I could eliminate that; I came up with this https://github.com/Eunovo/bitcoin/tree/2026-03-remove-estimatesmartfee-internals-from-wallet |
f21af87 to
aa6198a
Compare
Rebased, taken with a few modifications. Thanks for your review and suggestions @Eunovo |
Eunovo
left a comment
There was a problem hiding this comment.
ACK aa6198a
I wasn't sure about replacing fee_reason with fee_source, but I'm comfortable with deprecating it instead. It may be possible to keep fee_reason as is and just deprecate it, while adding a new fee_source key to the response, but I'm not sure it's worth it, since the fee_source information should be enough for the user.
40dc149 to
51629d0
Compare
|
Rebased to fix merge conflict. 456785..5162
|
51629d0 to
9cb269b
Compare
9cb269b to
e50e002
Compare
|
Forced pushed 9cb269b..e50e002e to match changes with parent PR. I squash the commits to ditch the intermediate fix-me. |
musaHaruna
left a comment
There was a problem hiding this comment.
Approach ACK
Reviewed at cc64dde.
I like the new approach on keeping the fee_reason RPC field name for compatibility while changing its semantics to report the wallet's fee selection reason rather than the block policy estimator's internal threshold reason. I also like updating the RPC help text to reflect the new behavior.
Nit:
In commit message:
The block policy estimator's FeeReason enum mixed two unrelated concerns:
could be
The block policy estimator's FeeReason enum mixed two unrelated concepts:
to match the wording used in the PR description.
Suggestion (non-blocking):
For the updated RPC help text:
{RPCResult::Type::STR, "fee_reason", "The reason the wallet selected this fee rate (e.g. fee rate estimator, mempool minimum, fallback, or minimum required). It no longer exposes the block policy estimator's detailed threshold internals."}I wonder if the second sentence could simply be omitted. The first sentence already clearly describes what fee_reason represents, and I think it's an improvement over the previous "The transaction fee reason" description.
Alternatively, if users are expected to obtain the estimator's detailed threshold reason elsewhere, perhaps the documentation could point them toward estimatesmartfee instead. Although, after this change, those detailed estimator reasons seem primarily intended for internal/debug logging:
LogDebug(BCLog::ESTIMATEFEE,
"... Reason:\"%s\" ...",
StringForBlockPolicyEstimateReason(feeCalc->reason), ...);So this is more of a documentation suggestion than a request for change—feel free to ignore if you think the explicit clarification is valuable.
The block policy estimator's FeeReason enum mixed two unrelated concerns: the threshold that produced an estimateSmartFee output (NONE, HALF_ESTIMATE, ...) and the reason the wallet ended up selecting a fee rate (FALLBACK, MEMPOOL_MIN, REQUIRED). Split them so each layer owns the reasons it actually uses: - Add a wallet-facing FeeReason enum (util/fees.h) with the main reasons the wallet selects a fee rate for: FEE_RATE_ESTIMATOR, MEMPOOL_MIN, USER_SPECIFIED, FALLBACK, REQUIRED, plus a StringForFeeReason helper. - Rename the estimator's enum to BlockPolicyEstimateReason and narrow it to the reasons the estimator produces: NONE, HALF_ESTIMATE, FULL_ESTIMATE, DOUBLE_ESTIMATE, CONSERVATIVE. - Migrate the wallet (and the QT/RPC/interfaces callers) off FeeCalculation and onto the new FeeReason, returned via MinimumFeeRateResult. The rest of the wallet no longer needs access to FeeCalculation internals. The two enums no longer share any values: BlockPolicyEstimateReason is internal to the estimator, FeeReason is the wallet's public fee reason. The detailed log in CreateTransactionInternal has been deleted and replaced with a simple log without estimateSmartFee internals because it does not belong in that scope. The detailed log will be added to estimateSmartFee method in the next commit.
Now that the wallet reports its own FeeReason, StringForBlockPolicyEstimateReason is only used internally by the block policy estimator. Move it from common/messages into the block policy fee rate estimator, written as a switch so the compiler warns on unhandled cases. Also add the detailed FeeCalculation debug log to estimateSmartFee, where the FeeCalculation data originates, and always populate feeCalc locally so the log is available even when the caller does not pass one. Co-authored-by: Novo <[email protected]>
e50e002 to
3d0bac9
Compare
musaHaruna
left a comment
There was a problem hiding this comment.
Code Review ACK 3d0bac9
Seeing that this PR is a part of #34075, I'm not sure which one will be merged first. However, in case this PR lands first, I think it's still worth updating the following:
For the updated RPC help text:
{RPCResult::Type::STR, "fee_reason", "The reason the wallet selected this fee rate (e.g. fee rate estimator, mempool minimum, fallback, or minimum required). It no longer exposes the block policy estimator's detailed threshold internals."}I wonder if the second sentence could simply be omitted. The first sentence already clearly describes what fee_reason represents, and I think it's an improvement over the previous "The transaction fee reason" description.
I mention this because the same point was raised again here during the review of #34075 by another reviewer.
|
🐙 This pull request conflicts with the target branch and needs rebase. |
|
Fixed in #34075 |
Part of #34075
Motivation
The wallet currently depends on
CBlockPolicyEstimatorinternals throughFeeCalculationand the oldFeeReasonenum returned byestimateSmartFee.That enum mixed two different concepts:
This coupling makes wallet fee selection harder to reason about and exposes estimator-specific details through wallet code and wallet RPC output. This PR separates those concerns so the estimator owns its internal estimate reasons and the wallet reports only wallet-level fee selection reasons.
Key Changes
Split wallet and estimator fee reasons:
FeeReasonenum insrc/util/fees.hwithFEE_RATE_ESTIMATOR,MEMPOOL_MIN,USER_SPECIFIED,FALLBACK, andREQUIRED.BlockPolicyEstimateReasonand scoped it to estimator outputs:NONE,HALF_ESTIMATE,FULL_ESTIMATE,DOUBLE_ESTIMATE, andCONSERVATIVE.Stop passing estimator internals through wallet fee selection:
FeeCalculation*output parameter inwallet::GetMinimumFeeRatewith aMinimumFeeRateResultstruct containing the selected fee rate, wallet fee reason, and returned target.FeeCalculation.CreatedTransactionResultto store the walletFeeReasoninstead of a fullFeeCalculation.Keep wallet RPC
fee_reasonat wallet scope:fee_reasonfield name for compatibility.Move estimator reason stringification into the estimator:
StringForBlockPolicyEstimateReasonout ofsrc/common/messages.cppand intosrc/policy/fees/block_policy_estimator.cpp.switchwithout adefaultcase so missing enum cases can be caught by compiler warnings.Move detailed estimator logging into
estimateSmartFee:CBlockPolicyEstimator::estimateSmartFeenow always populates a localFeeCalculation, even when the caller does not pass one, so estimator debug logging remains available inside the estimator.estimateSmartFee, where the estimator data originates.