Skip to content

Commit 261843e

Browse files
committed
wallet/rpc: Use the default maxfeerate value as BTC/kB
1 parent 3a3d8b8 commit 261843e

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <node/coin.h>
1515
#include <node/psbt.h>
1616
#include <node/transaction.h>
17+
#include <policy/policy.h>
1718
#include <policy/rbf.h>
1819
#include <primitives/transaction.h>
1920
#include <psbt.h>
@@ -37,11 +38,11 @@
3738

3839
#include <univalue.h>
3940

40-
/** High fee for sendrawtransaction and testmempoolaccept.
41-
* By default, transaction with a fee higher than this will be rejected by the
42-
* RPCs. This can be overridden with the maxfeerate argument.
41+
/** High fee rate for sendrawtransaction and testmempoolaccept.
42+
* By default, transaction with a fee rate higher than this will be rejected by
43+
* the RPCs. This can be overridden with the maxfeerate argument.
4344
*/
44-
constexpr static CAmount DEFAULT_MAX_RAW_TX_FEE{COIN / 10};
45+
static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
4546

4647
static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
4748
{
@@ -771,7 +772,7 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
771772
"\nAlso see createrawtransaction and signrawtransactionwithkey calls.\n",
772773
{
773774
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"},
774-
{"maxfeerate", RPCArg::Type::AMOUNT, /* default */ FormatMoney(DEFAULT_MAX_RAW_TX_FEE),
775+
{"maxfeerate", RPCArg::Type::AMOUNT, /* default */ FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK()),
775776
"Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT +
776777
"/kB.\nSet to 0 to accept any fee rate.\n"},
777778
},
@@ -801,19 +802,17 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
801802
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
802803
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
803804

804-
CAmount max_raw_tx_fee = DEFAULT_MAX_RAW_TX_FEE;
805+
CFeeRate max_raw_tx_fee_rate = DEFAULT_MAX_RAW_TX_FEE_RATE;
805806
// TODO: temporary migration code for old clients. Remove in v0.20
806807
if (request.params[1].isBool()) {
807808
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.");
808809
} else if (!request.params[1].isNull()) {
809-
size_t weight = GetTransactionWeight(*tx);
810-
CFeeRate fr(AmountFromValue(request.params[1]));
811-
// the +3/4 part rounds the value up, and is the same formula used when
812-
// calculating the fee for a transaction
813-
// (see GetVirtualTransactionSize)
814-
max_raw_tx_fee = fr.GetFee((weight+3)/4);
810+
max_raw_tx_fee_rate = CFeeRate(AmountFromValue(request.params[1]));
815811
}
816812

813+
int64_t virtual_size = GetVirtualTransactionSize(*tx);
814+
CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
815+
817816
std::string err_string;
818817
AssertLockNotHeld(cs_main);
819818
const TransactionError err = BroadcastTransaction(tx, err_string, max_raw_tx_fee, /*relay*/ true, /*wait_callback*/ true);
@@ -837,7 +836,7 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
837836
{"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""},
838837
},
839838
},
840-
{"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"},
839+
{"maxfeerate", RPCArg::Type::AMOUNT, /* default */ FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK()), "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT + "/kB\n"},
841840
},
842841
RPCResult{
843842
"[ (array) The result of the mempool acceptance test for each raw transaction in the input array.\n"
@@ -877,19 +876,17 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
877876
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
878877
const uint256& tx_hash = tx->GetHash();
879878

880-
CAmount max_raw_tx_fee = DEFAULT_MAX_RAW_TX_FEE;
879+
CFeeRate max_raw_tx_fee_rate = DEFAULT_MAX_RAW_TX_FEE_RATE;
881880
// TODO: temporary migration code for old clients. Remove in v0.20
882881
if (request.params[1].isBool()) {
883882
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.");
884883
} else if (!request.params[1].isNull()) {
885-
size_t weight = GetTransactionWeight(*tx);
886-
CFeeRate fr(AmountFromValue(request.params[1]));
887-
// the +3/4 part rounds the value up, and is the same formula used when
888-
// calculating the fee for a transaction
889-
// (see GetVirtualTransactionSize)
890-
max_raw_tx_fee = fr.GetFee((weight+3)/4);
884+
max_raw_tx_fee_rate = CFeeRate(AmountFromValue(request.params[1]));
891885
}
892886

887+
int64_t virtual_size = GetVirtualTransactionSize(*tx);
888+
CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
889+
893890
UniValue result(UniValue::VARR);
894891
UniValue result_0(UniValue::VOBJ);
895892
result_0.pushKV("txid", tx_hash.GetHex());

test/functional/feature_segwit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def run_test(self):
240240
tx.vin.append(CTxIn(COutPoint(int(txid2, 16), 0), b""))
241241
tx.vout.append(CTxOut(int(49.95 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))) # Huge fee
242242
tx.calc_sha256()
243-
txid3 = self.nodes[0].sendrawtransaction(ToHex(tx))
243+
txid3 = self.nodes[0].sendrawtransaction(ToHex(tx), 0)
244244
assert tx.wit.is_null()
245245
assert txid3 in self.nodes[0].getrawmempool()
246246

test/functional/mempool_accept.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def run_test(self):
183183
self.check_mempool_result(
184184
result_expected=[{'txid': tx.rehash(), 'allowed': True}],
185185
rawtxs=[tx.serialize().hex()],
186+
maxfeerate=0,
186187
)
187188

188189
self.log.info('A transaction with no outputs')

test/functional/wallet_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def run_test(self):
433433
# Split into two chains
434434
rawtx = self.nodes[0].createrawtransaction([{"txid": singletxid, "vout": 0}], {chain_addrs[0]: node0_balance / 2 - Decimal('0.01'), chain_addrs[1]: node0_balance / 2 - Decimal('0.01')})
435435
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
436-
singletxid = self.nodes[0].sendrawtransaction(signedtx["hex"])
436+
singletxid = self.nodes[0].sendrawtransaction(signedtx["hex"], 0)
437437
self.nodes[0].generate(1)
438438

439439
# Make a long chain of unconfirmed payments without hitting mempool limit

0 commit comments

Comments
 (0)