Skip to content

Commit 656a15e

Browse files
author
MarcoFalke
committed
Merge #15620: rpc: Uncouple non-wallet rpcs from maxTxFee global
fa1ad20 doc: Add release notes for 15620 (MarcoFalke) fa96d76 rpc: Uncouple rpcs from maxTxFee global (MarcoFalke) fa965e0 rpc: Use IsValidNumArgs over hardcoded size checks (MarcoFalke) Pull request description: This makes the rpcs a bit more stateless by falling back to their own default max fee instead of the global maxTxFee. A follow up pull request will move `-maxtxfee` to the wallet. See also related discussions: * `-maxtxfee` should not be used by both node and wallet #15355 * [RFC] Long term plan for wallet command-line args #13044 ACKs for commit fa1ad2: jnewbery: utACK fa1ad20 Empact: utACK bitcoin/bitcoin@fa1ad20 jnewbery: utACK fa1ad20 promag: utACK fa1ad20. Tree-SHA512: c9cf0b54cd30ff3ab0d090b072cc38fcbb2840bc6ad9a9711995333bc927d2500aece6b5a60e061666eca5ed72b70aa318d21e51eb15ee0106b41f5b6e4e1adf
2 parents 848ec56 + fa1ad20 commit 656a15e

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

doc/release-notes-15620.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Updated RPCs
2+
------------
3+
4+
* The -maxtxfee setting no longer has any effect on non-wallet RPCs.
5+
6+
The `sendrawtransaction` and `testmempoolaccept` RPC methods previously
7+
accepted an `allowhighfees` parameter to fail the mempool acceptance in case
8+
the transaction's fee would exceed the value of the command line argument
9+
`-maxtxfee`. To uncouple the RPCs from the global option, they now have a
10+
hardcoded default for the maximum transaction fee, that can be changed for
11+
both RPCs on a per-call basis with the `maxfeerate` parameter. The
12+
`allowhighfees` boolean option has been removed and replaced by the
13+
`maxfeerate` numeric option.

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ void SetupServerArgs()
500500
gArgs.AddArg("-mocktime=<n>", "Replace actual time with <n> seconds since epoch (default: 0)", true, OptionsCategory::DEBUG_TEST);
501501
gArgs.AddArg("-maxsigcachesize=<n>", strprintf("Limit sum of signature cache and script execution cache sizes to <n> MiB (default: %u)", DEFAULT_MAX_SIG_CACHE_SIZE), true, OptionsCategory::DEBUG_TEST);
502502
gArgs.AddArg("-maxtipage=<n>", strprintf("Maximum tip age in seconds to consider node in initial block download (default: %u)", DEFAULT_MAX_TIP_AGE), true, OptionsCategory::DEBUG_TEST);
503-
gArgs.AddArg("-maxtxfee=<amt>", strprintf("Maximum total fees (in %s) to use in a single wallet transaction or raw transaction; setting this too low may abort large transactions (default: %s)",
503+
gArgs.AddArg("-maxtxfee=<amt>", strprintf("Maximum total fees (in %s) to use in a single wallet transaction; setting this too low may abort large transactions (default: %s)", // TODO move setting to wallet
504504
CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MAXFEE)), false, OptionsCategory::DEBUG_TEST);
505505
gArgs.AddArg("-printpriority", strprintf("Log transaction fee per kB when mining blocks (default: %u)", DEFAULT_PRINTPRIORITY), true, OptionsCategory::DEBUG_TEST);
506506
gArgs.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -daemon. To disable logging to file, set -nodebuglogfile)", false, OptionsCategory::DEBUG_TEST);

src/rpc/rawtransaction.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040

4141
#include <univalue.h>
4242

43+
/** High fee for sendrawtransaction and testmempoolaccept.
44+
* By default, transaction with a fee higher than this will be rejected by the
45+
* RPCs. This can be overriden with the maxfeerate argument.
46+
*/
47+
constexpr static CAmount DEFAULT_MAX_RAW_TX_FEE{COIN / 10};
4348

4449
static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
4550
{
@@ -1023,14 +1028,12 @@ static UniValue signrawtransactionwithkey(const JSONRPCRequest& request)
10231028

10241029
static UniValue sendrawtransaction(const JSONRPCRequest& request)
10251030
{
1026-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
1027-
throw std::runtime_error(
1028-
RPCHelpMan{"sendrawtransaction",
1031+
const RPCHelpMan help{"sendrawtransaction",
10291032
"\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n"
10301033
"\nAlso see createrawtransaction and signrawtransactionwithkey calls.\n",
10311034
{
10321035
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"},
1033-
{"maxfeerate", RPCArg::Type::AMOUNT, /* default */ FormatMoney(maxTxFee), "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT + "/kB\n"},
1036+
{"maxfeerate", RPCArg::Type::AMOUNT, /* default */ FormatMoney(DEFAULT_MAX_RAW_TX_FEE), "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT + "/kB\n"},
10341037
},
10351038
RPCResult{
10361039
"\"hex\" (string) The transaction hash in hex\n"
@@ -1045,7 +1048,11 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
10451048
"\nAs a JSON-RPC call\n"
10461049
+ HelpExampleRpc("sendrawtransaction", "\"signedhex\"")
10471050
},
1048-
}.ToString());
1051+
};
1052+
1053+
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
1054+
throw std::runtime_error(help.ToString());
1055+
}
10491056

10501057
RPCTypeCheck(request.params, {
10511058
UniValue::VSTR,
@@ -1058,7 +1065,7 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
10581065
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
10591066
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
10601067

1061-
CAmount max_raw_tx_fee = maxTxFee;
1068+
CAmount max_raw_tx_fee = DEFAULT_MAX_RAW_TX_FEE;
10621069
// TODO: temporary migration code for old clients. Remove in v0.20
10631070
if (request.params[1].isBool()) {
10641071
throw JSONRPCError(RPC_INVALID_PARAMETER, "Second argument must be numeric (maxfeerate) and no longer supports a boolean. To allow a transaction with high fees, set maxfeerate to 0.");
@@ -1085,9 +1092,7 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
10851092

10861093
static UniValue testmempoolaccept(const JSONRPCRequest& request)
10871094
{
1088-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
1089-
throw std::runtime_error(
1090-
RPCHelpMan{"testmempoolaccept",
1095+
const RPCHelpMan help{"testmempoolaccept",
10911096
"\nReturns result of mempool acceptance tests indicating if raw transaction (serialized, hex-encoded) would be accepted by mempool.\n"
10921097
"\nThis checks if the transaction violates the consensus or policy rules.\n"
10931098
"\nSee sendrawtransaction call.\n",
@@ -1098,7 +1103,7 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
10981103
{"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""},
10991104
},
11001105
},
1101-
{"maxfeerate", RPCArg::Type::AMOUNT, /* default */ FormatMoney(maxTxFee), "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT + "/kB\n"},
1106+
{"maxfeerate", RPCArg::Type::AMOUNT, /* default */ FormatMoney(DEFAULT_MAX_RAW_TX_FEE), "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT + "/kB\n"},
11021107
},
11031108
RPCResult{
11041109
"[ (array) The result of the mempool acceptance test for each raw transaction in the input array.\n"
@@ -1120,7 +1125,10 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
11201125
"\nAs a JSON-RPC call\n"
11211126
+ HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]")
11221127
},
1123-
}.ToString());
1128+
};
1129+
1130+
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
1131+
throw std::runtime_error(help.ToString());
11241132
}
11251133

11261134
RPCTypeCheck(request.params, {
@@ -1139,7 +1147,7 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
11391147
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
11401148
const uint256& tx_hash = tx->GetHash();
11411149

1142-
CAmount max_raw_tx_fee = maxTxFee;
1150+
CAmount max_raw_tx_fee = DEFAULT_MAX_RAW_TX_FEE;
11431151
// TODO: temporary migration code for old clients. Remove in v0.20
11441152
if (request.params[1].isBool()) {
11451153
throw JSONRPCError(RPC_INVALID_PARAMETER, "Second argument must be numeric (maxfeerate) and no longer supports a boolean. To allow a transaction with high fees, set maxfeerate to 0.");

0 commit comments

Comments
 (0)