Skip to content

Commit fa2a4fd

Browse files
author
MarcoFalke
committed
rpc: Fixed signed integer overflow for large feerates
1 parent fade94d commit fa2a4fd

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/rpc/mempool.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ static RPCHelpMan sendrawtransaction()
8181

8282
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
8383

84-
const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
85-
DEFAULT_MAX_RAW_TX_FEE_RATE :
86-
CFeeRate(AmountFromValue(request.params[1]));
84+
const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>(1))};
8785

8886
int64_t virtual_size = GetVirtualTransactionSize(*tx);
8987
CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
@@ -162,9 +160,7 @@ static RPCHelpMan testmempoolaccept()
162160
"Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions.");
163161
}
164162

165-
const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
166-
DEFAULT_MAX_RAW_TX_FEE_RATE :
167-
CFeeRate(AmountFromValue(request.params[1]));
163+
const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>(1))};
168164

169165
std::vector<CTransactionRef> txns;
170166
txns.reserve(raw_transactions.size());

test/functional/mempool_accept.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,17 @@ def run_test(self):
9090
txid_in_block = self.wallet.sendrawtransaction(from_node=node, tx_hex=raw_tx_in_block)
9191
self.generate(node, 1)
9292
self.mempool_size = 0
93+
# Also check feerate. 1BTC/kvB fails
94+
assert_raises_rpc_error(-8, "Fee rates larger than or equal to 1BTC/kvB are not accepted", lambda: self.check_mempool_result(
95+
result_expected=None,
96+
rawtxs=[raw_tx_in_block],
97+
maxfeerate=1,
98+
))
99+
# ... 0.99 passes
93100
self.check_mempool_result(
94101
result_expected=[{'txid': txid_in_block, 'allowed': False, 'reject-reason': 'txn-already-known'}],
95102
rawtxs=[raw_tx_in_block],
103+
maxfeerate=0.99,
96104
)
97105

98106
self.log.info('A transaction not in the mempool')

0 commit comments

Comments
 (0)