Part of #34075
Motivation
The wallet currently knows the block policy estimator’s internals from the response returned by estimateSmartFee.
estimateSmartFee logging, which is supposed to be inside the method, is done in the wallet.
Also, the source of a wallet transaction fee is saved in the CBlockPolicyEstimator::FeeReason enum. This shows that there is tight coupling between the wallet and CBlockPolicyEstimator, which results in code that is a bit messy to extend and even read.
In #34075 the wallet is going to use a response returned via a fee rate estimator manager which does not return all those internals, hence motivating this refactor.
This PR refactors the interface between the wallet and the fee estimator to improve encapsulation and separate two distinct concerns: the source of a fee rate (where it came from) and the estimator’s reason (why the algorithm chose it).
Key Changes
- Separate
FeeSourcefromFeeReason: Introduced a newFeeSourceenum insrc/util/fees.hto represent the high-level origin of a fee rate (e.g.,PAYTXFEE,FALLBACK,FEE_RATE_ESTIMATOR). The existingFeeReasonis now strictly scoped to internalCBlockPolicyEstimatordetails. - Encapsulate
estimateSmartFeeLogging: Moved the fee calculation logging logic intoCBlockPolicyEstimator. This removes the need for the wallet to manage aFeeCalculationobject just to facilitate logging, especially when the caller passesnullptr. - Refactor
GetMinimumFeeRate: Updatedwallet::GetMinimumFeeRateto return aMinimumFeeRateResultstruct. This avoids the use of output parameters and provides a cleaner interface for retrieving the fee rate, source, and target. - Move
StringForFeeReason: MovedStringForFeeReasontosrc/policy/fees/block_policy_estimator.cppto align with the location of theFeeReasonenum. The function was also refactored to use a switch statement without a default case to ensure compile-time coverage of all reasons. - RPC Breaking Change:
Renamed the
fee_reasonfield tofee_sourcein wallet RPCs (such assend,walletcreatefundedpsbt). This correctly identifies the origin of the fee rate rather than the estimator’s internal logic. - Additional Logging:
Added logging for transaction fee, size, and source in
CreateTransactionInternalto improve debugging of fee selection.