Skip to content

Commit 173b5b5

Browse files
committed
wallet: update fee rate units, use sat/vB for fee_rate error messages
and BTC/kvB for feeRate error messages.
1 parent 7f9835a commit 173b5b5

File tree

9 files changed

+22
-21
lines changed

9 files changed

+22
-21
lines changed

src/policy/feerate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ CAmount CFeeRate::GetFee(size_t nBytes_) const
3838
std::string CFeeRate::ToString(const FeeEstimateMode& fee_estimate_mode) const
3939
{
4040
switch (fee_estimate_mode) {
41-
case FeeEstimateMode::SAT_B: return strprintf("%d.%03d %s/B", nSatoshisPerK / 1000, nSatoshisPerK % 1000, CURRENCY_ATOM);
42-
default: return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
41+
case FeeEstimateMode::SAT_VB: return strprintf("%d.%03d %s/vB", nSatoshisPerK / 1000, nSatoshisPerK % 1000, CURRENCY_ATOM);
42+
default: return strprintf("%d.%08d %s/kvB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
4343
}
4444
}

src/policy/feerate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ enum class FeeEstimateMode {
1919
UNSET, //!< Use default settings based on other criteria
2020
ECONOMICAL, //!< Force estimateSmartFee to use non-conservative estimates
2121
CONSERVATIVE, //!< Force estimateSmartFee to use conservative estimates
22-
BTC_KB, //!< Use explicit BTC/kB fee given in coin control
23-
SAT_B, //!< Use explicit sat/B fee given in coin control
22+
BTC_KVB, //!< Use BTC/kvB fee rate unit
23+
SAT_VB, //!< Use sat/vB fee rate unit
2424
};
2525

2626
/**
@@ -65,7 +65,7 @@ class CFeeRate
6565
friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
6666
friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
6767
CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
68-
std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KB) const;
68+
std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
6969

7070
SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
7171
};

src/test/amount_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(BinaryOperatorTest)
9898
BOOST_CHECK(a <= a);
9999
BOOST_CHECK(b >= a);
100100
BOOST_CHECK(b >= b);
101-
// a should be 0.00000002 BTC/kB now
101+
// a should be 0.00000002 BTC/kvB now
102102
a += a;
103103
BOOST_CHECK(a == b);
104104
}
@@ -107,7 +107,9 @@ BOOST_AUTO_TEST_CASE(ToStringTest)
107107
{
108108
CFeeRate feeRate;
109109
feeRate = CFeeRate(1);
110-
BOOST_CHECK_EQUAL(feeRate.ToString(), "0.00000001 BTC/kB");
110+
BOOST_CHECK_EQUAL(feeRate.ToString(), "0.00000001 BTC/kvB");
111+
BOOST_CHECK_EQUAL(feeRate.ToString(FeeEstimateMode::BTC_KVB), "0.00000001 BTC/kvB");
112+
BOOST_CHECK_EQUAL(feeRate.ToString(FeeEstimateMode::SAT_VB), "0.001 sat/vB");
111113
}
112114

113115
BOOST_AUTO_TEST_SUITE_END()

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3136,7 +3136,7 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f
31363136
}
31373137
CFeeRate fee_rate(AmountFromValue(options["feeRate"]));
31383138
if (fee_rate <= CFeeRate(0)) {
3139-
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid feeRate %s (must be greater than 0)", fee_rate.ToString()));
3139+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid feeRate %s (must be greater than 0)", fee_rate.ToString(FeeEstimateMode::BTC_KVB)));
31403140
}
31413141
coinControl.m_feerate = fee_rate;
31423142
coinControl.fOverrideFeeRate = true;

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,7 @@ bool CWallet::CreateTransactionInternal(
28342834
// Do not, ever, assume that it's fine to change the fee rate if the user has explicitly
28352835
// provided one
28362836
if (coin_control.m_feerate && nFeeRateNeeded > *coin_control.m_feerate) {
2837-
error = strprintf(_("Fee rate (%s) is lower than the minimum fee rate setting (%s)"), coin_control.m_feerate->ToString(), nFeeRateNeeded.ToString());
2837+
error = strprintf(_("Fee rate (%s) is lower than the minimum fee rate setting (%s)"), coin_control.m_feerate->ToString(FeeEstimateMode::SAT_VB), nFeeRateNeeded.ToString(FeeEstimateMode::SAT_VB));
28382838
return false;
28392839
}
28402840

test/functional/rpc_fundrawtransaction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,9 @@ def test_option_feerate(self):
752752
node.fundrawtransaction, rawtx, {"estimate_mode": mode, "conf_target": n, "add_inputs": True})
753753

754754
self.log.info("Test invalid fee rate settings")
755-
assert_raises_rpc_error(-4, "Fee rate (0.00000000 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)",
755+
assert_raises_rpc_error(-4, "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
756756
node.fundrawtransaction, rawtx, {"fee_rate": 0, "add_inputs": True})
757-
assert_raises_rpc_error(-8, "Invalid feeRate 0.00000000 BTC/kB (must be greater than 0)",
757+
assert_raises_rpc_error(-8, "Invalid feeRate 0.00000000 BTC/kvB (must be greater than 0)",
758758
node.fundrawtransaction, rawtx, {"feeRate": 0, "add_inputs": True})
759759
for param, value in {("fee_rate", 100000), ("feeRate", 1.000)}:
760760
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)",
@@ -768,7 +768,7 @@ def test_option_feerate(self):
768768

769769
# Test setting explicit fee rate just below the minimum.
770770
self.log.info("- raises RPC error 'fee rate too low' if fee_rate of 0.99999999 sat/vB is passed")
771-
msg = "Fee rate (0.00000999 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)"
771+
msg = "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"
772772
assert_raises_rpc_error(-4, msg, node.fundrawtransaction, rawtx, {"fee_rate": 0.99999999, "add_inputs": True})
773773
# This feeRate test only passes if `coinControl.fOverrideFeeRate = true` in wallet/rpcwallet.cpp::FundTransaction is removed.
774774
# assert_raises_rpc_error(-4, msg, node.fundrawtransaction, rawtx, {"feeRate": 0.00000999, "add_inputs": True})

test/functional/rpc_psbt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ def run_test(self):
194194
assert_approx(res2["fee"], 0.055, 0.005)
195195

196196
self.log.info("Test invalid fee rate settings")
197-
assert_raises_rpc_error(-4, "Fee rate (0.00000000 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)",
197+
assert_raises_rpc_error(-4, "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
198198
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {"fee_rate": 0, "add_inputs": True})
199-
assert_raises_rpc_error(-8, "Invalid feeRate 0.00000000 BTC/kB (must be greater than 0)",
199+
assert_raises_rpc_error(-8, "Invalid feeRate 0.00000000 BTC/kvB (must be greater than 0)",
200200
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {"feeRate": 0, "add_inputs": True})
201201
for param, value in {("fee_rate", 100000), ("feeRate", 1)}:
202202
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)",
@@ -246,7 +246,7 @@ def run_test(self):
246246

247247
# Test setting explicit fee rate just below the minimum.
248248
self.log.info("- raises RPC error 'fee rate too low' if feerate_sat_vb of 0.99999999 is passed")
249-
assert_raises_rpc_error(-4, "Fee rate (0.00000999 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)",
249+
assert_raises_rpc_error(-4, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
250250
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {"fee_rate": 0.99999999, "add_inputs": True})
251251

252252
self.log.info("Test walletcreatefundedpsbt with too-high fee rate produces total fee well above -maxtxfee and raises RPC error")

test/functional/wallet_basic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ def run_test(self):
250250

251251
# Test setting explicit fee rate just below the minimum.
252252
self.log.info("Test sendmany raises 'fee rate too low' if fee_rate of 0.99999999 is passed")
253-
assert_raises_rpc_error(-6, "Fee rate (0.00000999 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)",
253+
assert_raises_rpc_error(-6, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
254254
self.nodes[2].sendmany, amounts={address: 10}, fee_rate=0.99999999)
255255

256256
self.log.info("Test sendmany raises if fee_rate of 0 or -1 is passed")
257-
assert_raises_rpc_error(-6, "Fee rate (0.00000000 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)",
257+
assert_raises_rpc_error(-6, "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
258258
self.nodes[2].sendmany, amounts={address: 10}, fee_rate=0)
259259
assert_raises_rpc_error(-3, OUT_OF_RANGE, self.nodes[2].sendmany, amounts={address: 10}, fee_rate=-1)
260260

@@ -421,11 +421,11 @@ def run_test(self):
421421

422422
# Test setting explicit fee rate just below the minimum.
423423
self.log.info("Test sendtoaddress raises 'fee rate too low' if fee_rate of 0.99999999 is passed")
424-
assert_raises_rpc_error(-6, "Fee rate (0.00000999 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)",
424+
assert_raises_rpc_error(-6, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
425425
self.nodes[2].sendtoaddress, address=address, amount=1, fee_rate=0.99999999)
426426

427427
self.log.info("Test sendtoaddress raises if fee_rate of 0 or -1 is passed")
428-
assert_raises_rpc_error(-6, "Fee rate (0.00000000 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)",
428+
assert_raises_rpc_error(-6, "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
429429
self.nodes[2].sendtoaddress, address=address, amount=10, fee_rate=0)
430430
assert_raises_rpc_error(-3, OUT_OF_RANGE, self.nodes[2].sendtoaddress, address=address, amount=1.0, fee_rate=-1)
431431

test/functional/wallet_send.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,10 @@ def run_test(self):
306306
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=v, estimate_mode=mode,
307307
expect_error=(-3, "Expected type number for conf_target, got {}".format(k)))
308308

309-
# TODO: The error message should use sat/vB units instead of BTC/kB.
310309
# Test setting explicit fee rate just below the minimum.
311310
self.log.info("Explicit fee rate raises RPC error 'fee rate too low' if fee_rate of 0.99999999 is passed")
312311
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=0.99999999,
313-
expect_error=(-4, "Fee rate (0.00000999 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)"))
312+
expect_error=(-4, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"))
314313

315314
# TODO: Return hex if fee rate is below -maxmempool
316315
# res = self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=0.1, estimate_mode="sat/b", add_to_wallet=False)

0 commit comments

Comments
 (0)