Repository navigation
wallet: Replace fee magic numbers with named constants - #33254
151henry151 wants to merge 1 commit into
Conversation
- Add constexpr CFeeRate constructors to support compile-time constants - Replace magic CFeeRate(0) values with descriptive named constants: * DEFAULT_FEERATE for default/unset fee rates * NO_FEE_DATA for fee estimation failures * FEERATE_DISABLED for disabled fee features - Remove resolved TODO comment in src/wallet/fees.cpp:44 (magic value of 0) - Update comments to be more descriptive This improves code readability and maintainability by eliminating magic numbers and centralizing fee rate constants. The use of named constants makes the code's intent clearer and reduces the risk of mistakes when comparing fee rates in different contexts. Additionally, constexpr constructors enable compile-time constant initialization, allowing these constants to be used in constexpr contexts and providing compile-time safety.
|
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/33254. ReviewsSee the guideline for information on the review process. |
| if (coin_control.fOverrideFeeRate) return feerate_needed; | ||
| } | ||
| else if (!coin_control.m_confirm_target && wallet.m_pay_tx_fee != CFeeRate(0)) { // 3. TODO: remove magic value of 0 for wallet member m_pay_tx_fee | ||
| else if (!coin_control.m_confirm_target && wallet.m_pay_tx_fee != DEFAULT_FEERATE) { // 3. Check if user has set a custom fee rate (different from default) |
There was a problem hiding this comment.
the todo refers to the value of m_pay_tx_fee, not to the hardcoded 0 here. Also, see https://github.com/bitcoin/bitcoin/pull/32138/files
| //! Default/unset fee rate (user hasn't set a custom fee) | ||
| constexpr CFeeRate DEFAULT_FEERATE = CFeeRate(0); | ||
| //! Fee rate indicating "no data available" for estimation | ||
| constexpr CFeeRate NO_FEE_DATA = CFeeRate(0); | ||
| //! Fee rate indicating "disabled" feature | ||
| constexpr CFeeRate FEERATE_DISABLED = CFeeRate(0); |
There was a problem hiding this comment.
this is just removing magic values in one place and adding them in another. what is the point?
There was a problem hiding this comment.
Thanks for the feedback, I must have misunderstood the TODO. I thought this would be an improvement for the reasons outlined in the pull request, and thought it would address the TODO item.
|
Thanks, but the value of purely LLM generated "vibe" pull requests is limited, because:
My recommendation for the future would be to create your first pull request fully by yourself. This will hopefully ensure that you understand the changes yourself and can reply to feedback. ( Generally, I think it is fine to use LLMs, if the author would have written the same code almost exactly the same way without the LLM, and also fully understands it, and also can claim copyright on it. But this is probably a meta discussion. ) |
Thanks for your feedback. In this case I did use an AI assistant to help me identify an approach to this TODO and thought that it had helped me understand the issue well enough to address it correctly, but going forward I will do more research to make sure I'm not wasting valuable reviewer time. The code changes were made by me manually and the description of those changes was carefully written and adjusted numerous times before being submitted, in the hopes of being an actually valuable contribution. I'll try harder next time! Thanks for your candid feedback. |
Summary
This PR addresses a TODO item in the wallet fee handling code by replacing magic numbers with descriptive named constants. It also adds
constexprconstructors toCFeeRateto support compile-time constants.Changes
constexprCFeeRate constructors to support compile-time constantsCFeeRate(0)values with descriptive named constants:DEFAULT_FEERATEfor default/unset fee ratesNO_FEE_DATAfor fee estimation failuresFEERATE_DISABLEDfor disabled fee featuressrc/wallet/fees.cpp:44(magic value of 0)Benefits
This improves code readability and maintainability by:
constexprconstructorsTesting
Note: Local development build only - not a full Guix reproducible build.
Related
Fixes TODO item in
src/wallet/fees.cpp:44