Skip to content

Commit 06a90fa

Browse files
committed
rpc: for sat/vB fee rates, limit ParseFixedPoint decimals to 3
1 parent 0742c78 commit 06a90fa

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ static void SetFeeEstimateMode(const CWallet& wallet, CCoinControl& cc, const Un
216216
if (!estimate_mode.isNull() && estimate_mode.get_str() != "unset") {
217217
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both estimate_mode and fee_rate");
218218
}
219-
cc.m_feerate = CFeeRate(AmountFromValue(fee_rate), COIN);
219+
// Fee rates in sat/vB cannot represent more than 3 significant digits.
220+
cc.m_feerate = CFeeRate{AmountFromValue(fee_rate, /* decimals */ 3)};
220221
if (override_min_fee) cc.fOverrideFeeRate = true;
221222
// Default RBF to true for explicit fee_rate, if unset.
222223
if (!cc.m_signal_bip125_rbf) cc.m_signal_bip125_rbf = true;

test/functional/rpc_fundrawtransaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ def test_option_feerate(self):
773773
assert_raises_rpc_error(-3, "Invalid amount", node.fundrawtransaction, rawtx, {param: invalid_value, "add_inputs": True})
774774

775775
self.log.info("Test min fee rate checks are bypassed with fundrawtxn, e.g. a fee_rate under 1 sat/vB is allowed")
776-
node.fundrawtransaction(rawtx, {"fee_rate": 0.99999999, "add_inputs": True})
776+
node.fundrawtransaction(rawtx, {"fee_rate": 0.999, "add_inputs": True})
777777
node.fundrawtransaction(rawtx, {"feeRate": 0.00000999, "add_inputs": True})
778778

779779
self.log.info("- raises RPC error if both feeRate and fee_rate are passed")

test/functional/rpc_psbt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def run_test(self):
195195
assert_approx(res2["fee"], 0.055, 0.005)
196196

197197
self.log.info("Test min fee rate checks with walletcreatefundedpsbt are bypassed, e.g. a fee_rate under 1 sat/vB is allowed")
198-
res3 = self.nodes[1].walletcreatefundedpsbt(inputs, outputs, 0, {"fee_rate": "0.99999999", "add_inputs": True})
198+
res3 = self.nodes[1].walletcreatefundedpsbt(inputs, outputs, 0, {"fee_rate": "0.999", "add_inputs": True})
199199
assert_approx(res3["fee"], 0.00000381, 0.0000001)
200200
res4 = self.nodes[1].walletcreatefundedpsbt(inputs, outputs, 0, {"feeRate": 0.00000999, "add_inputs": True})
201201
assert_approx(res4["fee"], 0.00000381, 0.0000001)

test/functional/wallet_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def run_test(self):
265265
# Test setting explicit fee rate just below the minimum.
266266
self.log.info("Test sendmany raises 'fee rate too low' if fee_rate of 0.99999999 is passed")
267267
assert_raises_rpc_error(-6, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
268-
self.nodes[2].sendmany, amounts={address: 10}, fee_rate=0.99999999)
268+
self.nodes[2].sendmany, amounts={address: 10}, fee_rate=0.999)
269269

270270
self.log.info("Test sendmany raises if an invalid fee_rate is passed")
271271
# Test fee_rate with zero values.
@@ -458,7 +458,7 @@ def run_test(self):
458458
# Test setting explicit fee rate just below the minimum.
459459
self.log.info("Test sendtoaddress raises 'fee rate too low' if fee_rate of 0.99999999 is passed")
460460
assert_raises_rpc_error(-6, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
461-
self.nodes[2].sendtoaddress, address=address, amount=1, fee_rate=0.99999999)
461+
self.nodes[2].sendtoaddress, address=address, amount=1, fee_rate=0.999)
462462

463463
self.log.info("Test sendtoaddress raises if an invalid fee_rate is passed")
464464
# Test fee_rate with zero values.

test/functional/wallet_send.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,11 @@ def run_test(self):
350350

351351
# Test setting explicit fee rate just below the minimum of 1 sat/vB.
352352
self.log.info("Explicit fee rate raises RPC error 'fee rate too low' if fee_rate of 0.99999999 is passed")
353-
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=0.99999999,
354-
expect_error=(-4, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"))
355-
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=0.99999999,
356-
expect_error=(-4, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"))
353+
msg = "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"
354+
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=0.999, expect_error=(-4, msg))
355+
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=0.999, expect_error=(-4, msg))
356+
357+
self.log.info("Explicit fee rate raises if invalid fee_rate is passed")
357358
# Test fee_rate with zero values.
358359
msg = "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"
359360
for zero_value in [0, 0.000, 0.00000000, "0", "0.000", "0.00000000"]:

0 commit comments

Comments
 (0)