Merge bitcoin/bitcoin#36432: wallet: show real fee_reason strings in help
What changed, and why it matters
This change only updates the help text shown by two wallet RPC commands (sendtoaddress and sendmany) so the list of possible fee reasons matches the actual strings returned by the software. It also adds a test to confirm that an explicit fee rate returns the string 'User Specified Fee'. There is no security issue here—just a documentation/help-text consistency fix.
No security action needed. This is a routine documentation/help-text improvement with added regression test.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors StringForFeeReason into a shared FeeReasonMap and a new FeeReasons helper, then uses FeeReasons to generate the RPC help text for the fee_reason field in sendtoaddress and sendmany. Previously the help text paraphrased the values and omitted ‘User Specified Fee’. A functional test is added to assert that fee_rate=5 yields ‘User Specified Fee’. No code behavior changes; only help strings and test coverage.
Changed components
src/common/messages.cppsrc/common/messages.hsrc/wallet/rpc/spend.cpptest/functional/wallet_basic.pyInspect captured patch +21 / −3
### src/common/messages.cpp
@@ -24,7 +24,7 @@ using node::TransactionError;
using util::Join;
namespace common {
-std::string StringForFeeReason(FeeReason reason)
+const std::map<FeeReason, std::string>& FeeReasonMap()
{
static const std::map<FeeReason, std::string> fee_reason_strings = {
{FeeReason::FEE_RATE_ESTIMATOR, "Fee Rate Estimator"},
@@ -33,13 +33,24 @@ std::string StringForFeeReason(FeeReason reason)
{FeeReason::FALLBACK, "Fallback fee"},
{FeeReason::REQUIRED, "Minimum Required Fee"},
};
+ return fee_reason_strings;
+}
+
+std::string StringForFeeReason(FeeReason reason)
+{
+ const auto& fee_reason_strings = FeeReasonMap();
auto reason_string = fee_reason_strings.find(reason);
if (reason_string == fee_reason_strings.end()) return "Unknown";
return reason_string->second;
}
+std::string FeeReasons(const std::string& delimiter)
+{
+ return Join(FeeReasonMap(), delimiter, [](const auto& reason) { return reason.second; });
+}
+
const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
{
static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
### src/common/messages.h
@@ -27,6 +27,7 @@ enum class PSBTError;
bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode& fee_estimate_mode);
std::string StringForFeeReason(FeeReason reason);
+std::string FeeReasons(const std::string& delimiter);
std::string FeeModes(const std::string& delimiter);
std::string FeeModeInfo(std::pair<std::string, FeeEstimateMode>& mode);
std::string FeeModesDetail(std::string default_info);
### src/wallet/rpc/spend.cpp
@@ -26,6 +26,7 @@
using common::FeeModeFromString;
using common::FeeModesDetail;
+using common::FeeReasons;
using common::InvalidEstimateModeErrorMessage;
using common::StringForFeeReason;
using common::TransactionErrorString;
@@ -272,7 +273,7 @@ RPCMethod sendtoaddress()
RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::STR_HEX, "txid", "The transaction id."},
- {RPCResult::Type::STR, "fee_reason", "The reason the wallet selected this fee rate (e.g. fee rate estimator, mempool minimum, fallback, or minimum required)."}
+ {RPCResult::Type::STR, "fee_reason", "The reason the wallet selected this fee rate (\"" + FeeReasons("\", \"") + "\")."}
},
},
},
@@ -382,7 +383,7 @@ RPCMethod sendmany()
{
{RPCResult::Type::STR_HEX, "txid", "The transaction id for the send. Only 1 transaction is created regardless of\n"
"the number of addresses."},
- {RPCResult::Type::STR, "fee_reason", "The reason the wallet selected this fee rate (e.g. fee rate estimator, mempool minimum, fallback, or minimum required)."}
+ {RPCResult::Type::STR, "fee_reason", "The reason the wallet selected this fee rate (\"" + FeeReasons("\", \"") + "\")."}
},
},
},
### test/functional/wallet_basic.py
@@ -590,6 +590,11 @@ def run_test(self):
assert_equal(txid_feeReason_one["fee_reason"], "Fallback fee")
txid_feeReason_two = self.nodes[2].sendmany(dummy='', amounts={address: 5}, verbose=True)
assert_equal(txid_feeReason_two["fee_reason"], "Fallback fee")
+ self.log.info("Test send* RPCs with an explicit fee_rate")
+ txid_feeReason_specified = self.nodes[2].sendtoaddress(address=address, amount=1, fee_rate=5, verbose=True)
+ assert_equal(txid_feeReason_specified["fee_reason"], "User Specified Fee")
+ txid_feeReason_specified_many = self.nodes[2].sendmany(dummy='', amounts={address: 1}, fee_rate=5, verbose=True)
+ assert_equal(txid_feeReason_specified_many["fee_reason"], "User Specified Fee")
self.log.info("Test send* RPCs with verbose=False")
txid_feeReason_three = self.nodes[2].sendtoaddress(address=address, amount=5, verbose=False)
assert_equal(self.nodes[2].gettransaction(txid_feeReason_three)['txid'], txid_feeReason_three)Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.