Skip to content

fees: wallet: remove block policy fee estimator internals from wallet - #34617

Closed
ismaelsadeeq wants to merge 2 commits into
bitcoin:masterfrom
ismaelsadeeq:02-2026-remove-estimatesmartfee-internals-from-wallet
Closed

ismaelsadeeq wants to merge 2 commits into
bitcoin:masterfrom
ismaelsadeeq:02-2026-remove-estimatesmartfee-internals-from-wallet

Conversation

@ismaelsadeeq

@ismaelsadeeq ismaelsadeeq commented Feb 18, 2026 •

Copy link
Copy Markdown
Member

Part of #34075

Motivation

The wallet currently depends on CBlockPolicyEstimator internals through FeeCalculation and the old FeeReason enum returned by estimateSmartFee.

That enum mixed two different concepts:

  • why the block policy estimator chose a specific estimate, such as the half-target, full-target, double-target, or conservative threshold;
  • why the wallet selected the fee rate it will use, such as fallback fee, mempool minimum fee, user-specified fee, or minimum required fee.

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:

    • Added a wallet-facing FeeReason enum in src/util/fees.h with FEE_RATE_ESTIMATOR, MEMPOOL_MIN, USER_SPECIFIED, FALLBACK, and REQUIRED.
    • Renamed the estimator reason enum to BlockPolicyEstimateReason and scoped it to estimator outputs: NONE, HALF_ESTIMATE, FULL_ESTIMATE, DOUBLE_ESTIMATE, and CONSERVATIVE.
  • Stop passing estimator internals through wallet fee selection:

    • Replaced the FeeCalculation* output parameter in wallet::GetMinimumFeeRate with a MinimumFeeRateResult struct containing the selected fee rate, wallet fee reason, and returned target.
    • Updated wallet, Qt, RPC, interface, and test/fuzz callers to use the wallet fee reason instead of FeeCalculation.
    • Updated CreatedTransactionResult to store the wallet FeeReason instead of a full FeeCalculation.
  • Keep wallet RPC fee_reason at wallet scope:

    • Verbose wallet RPC responses still use the existing fee_reason field name for compatibility.
    • The field now reports the wallet fee selection reason, not the block policy estimator's detailed threshold reason.
    • The help text for the affected wallet RPC responses was updated to describe this behavior.
  • Move estimator reason stringification into the estimator:

    • Moved StringForBlockPolicyEstimateReason out of src/common/messages.cpp and into src/policy/fees/block_policy_estimator.cpp.
    • Implemented it with a switch without a default case so missing enum cases can be caught by compiler warnings.
  • Move detailed estimator logging into estimateSmartFee:

    • CBlockPolicyEstimator::estimateSmartFee now always populates a local FeeCalculation, even when the caller does not pass one, so estimator debug logging remains available inside the estimator.
    • The detailed estimate debug log now lives in estimateSmartFee, where the estimator data originates.
    • Wallet transaction creation now logs only the selected fee, transaction size, and wallet fee reason.

@DrahtBot DrahtBot changed the title fees: wallet: remove block policy fee estimator internals from wallet fees: wallet: remove block policy fee estimator internals from wallet Feb 18, 2026
@DrahtBot

DrahtBot commented Feb 18, 2026 •

Copy link
Copy Markdown
Contributor

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34617.

Reviews

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

Type Reviewers
ACK musaHaruna
Stale ACK Eunovo

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:

  • #35675 (mining: add block template manager by ismaelsadeeq)
  • #34405 (wallet: skip APS when no partial spend exists by 8144225309)
  • #34075 (fees: Introduce Mempool Based Fee Estimation to reduce overestimation by ismaelsadeeq)
  • #30343 (wallet, logging: Replace WalletLogPrintf() with LogInfo() by ryanofsky)
  • #19461 (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
  • #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
  • #10102 (Multiprocess bitcoin by ryanofsky)

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.

Comment thread src/qt/sendcoinsdialog.cpp Resolved
Comment thread src/wallet/rpc/spend.cpp Resolved

@musaHaruna musaHaruna left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK on separating FeeSource from FeeReason

  1. Maintain complete backward compatibility by not changing the output to the fee source, i.e making it fee_reason but 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_reason field to fee_source in wallet RPCs (such as send, 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.

Comment thread src/wallet/interfaces.cpp Resolved
@DrahtBot DrahtBot mentioned this pull request Mar 4, 2026
@ismaelsadeeq
ismaelsadeeq force-pushed the 02-2026-remove-estimatesmartfee-internals-from-wallet branch 2 times, most recently from a2fb19d to 067fadb Compare March 5, 2026 11:21
@ismaelsadeeq

ismaelsadeeq commented Mar 5, 2026 •

Copy link
Copy Markdown
Member Author

Forced pushed from 991df9bd182679e1fb1632ea1688042030fd264f to f21af8784ac44045f1f3428746e20ac935cd7340 compare diff

Thanks for the review @Eunovo @musaHaruna

C.I failure seems unrelated, see #34731

@ismaelsadeeq
ismaelsadeeq force-pushed the 02-2026-remove-estimatesmartfee-internals-from-wallet branch from 067fadb to f21af87 Compare March 5, 2026 11:40
@Eunovo

Eunovo commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

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
Take a look and feel free to use.

@ismaelsadeeq
ismaelsadeeq force-pushed the 02-2026-remove-estimatesmartfee-internals-from-wallet branch from f21af87 to aa6198a Compare March 19, 2026 12:07
@ismaelsadeeq

Copy link
Copy Markdown
Member Author

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 Take a look and feel free to use.

Rebased, taken with a few modifications. Thanks for your review and suggestions @Eunovo

35cd7340..aa6198a6

@Eunovo Eunovo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ismaelsadeeq
ismaelsadeeq force-pushed the 02-2026-remove-estimatesmartfee-internals-from-wallet branch from 40dc149 to 51629d0 Compare May 26, 2026 10:15
@ismaelsadeeq

Copy link
Copy Markdown
Member Author

Rebased to fix merge conflict. 456785..5162

  • The C.I failure here is unrelated to the changes in this PR.

@ismaelsadeeq
ismaelsadeeq force-pushed the 02-2026-remove-estimatesmartfee-internals-from-wallet branch from 51629d0 to 9cb269b Compare June 17, 2026 13:19
@ismaelsadeeq
ismaelsadeeq force-pushed the 02-2026-remove-estimatesmartfee-internals-from-wallet branch from 9cb269b to e50e002 Compare June 29, 2026 23:24
@ismaelsadeeq

Copy link
Copy Markdown
Member Author

Forced pushed 9cb269b..e50e002e to match changes with parent PR.

I squash the commits to ditch the intermediate fix-me.

@musaHaruna musaHaruna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ismaelsadeeq and others added 2 commits July 14, 2026 09:33
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]>
@ismaelsadeeq
ismaelsadeeq force-pushed the 02-2026-remove-estimatesmartfee-internals-from-wallet branch from e50e002 to 3d0bac9 Compare July 14, 2026 13:12
@sedited
sedited requested a review from musaHaruna July 23, 2026 21:27

@musaHaruna musaHaruna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DrahtBot

Copy link
Copy Markdown
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@ismaelsadeeq

Copy link
Copy Markdown
Member Author

Fixed in #34075

@ismaelsadeeq
ismaelsadeeq deleted the 02-2026-remove-estimatesmartfee-internals-from-wallet branch August 21, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants