Skip to content

Commit 8f354ce

Browse files
Sjorspromag
authored andcommitted
0.18: [wallet] abort when attempting to fund a transaction above maxtxfee
FundTransaction calls GetMinimumFee which, when the fee rate is absurdly high, quietly reduced the fee to -maxtxfee. Becaue an absurdly high fee rate is usually the result of a fat finger, aborting seems safer behavior. Github-Pull: #16257 Rebased-From: 806b005
1 parent 00ffe5a commit 8f354ce

File tree

7 files changed

+22
-9
lines changed

7 files changed

+22
-9
lines changed

doc/release-notes-0.18.1-16257.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Wallet changes
2+
--------------
3+
When creating a transaction with a fee above `-maxtxfee` (default 0.1 BTC),
4+
the RPC commands `walletcreatefundedpsbt` and `fundrawtransaction` will now fail
5+
instead of rounding down the fee. Beware that the `feeRate` argument is specified
6+
in BTC per kilobyte, not satoshi per byte.

src/policy/fees.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ std::string StringForFeeReason(FeeReason reason) {
3838
{FeeReason::PAYTXFEE, "PayTxFee set"},
3939
{FeeReason::FALLBACK, "Fallback fee"},
4040
{FeeReason::REQUIRED, "Minimum Required Fee"},
41-
{FeeReason::MAXTXFEE, "MaxTxFee limit"}
4241
};
4342
auto reason_string = fee_reason_strings.find(reason);
4443

src/policy/fees.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ enum class FeeReason {
4343
PAYTXFEE,
4444
FALLBACK,
4545
REQUIRED,
46-
MAXTXFEE,
4746
};
4847

4948
std::string StringForFeeReason(FeeReason reason);

src/wallet/fees.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ CAmount GetRequiredFee(const CWallet& wallet, unsigned int nTxBytes)
2121

2222
CAmount GetMinimumFee(const CWallet& wallet, unsigned int nTxBytes, const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation* feeCalc)
2323
{
24-
CAmount fee_needed = GetMinimumFeeRate(wallet, coin_control, pool, estimator, feeCalc).GetFee(nTxBytes);
25-
// Always obey the maximum
26-
if (fee_needed > maxTxFee) {
27-
fee_needed = maxTxFee;
28-
if (feeCalc) feeCalc->reason = FeeReason::MAXTXFEE;
29-
}
30-
return fee_needed;
24+
return GetMinimumFeeRate(wallet, coin_control, pool, estimator, feeCalc).GetFee(nTxBytes);
3125
}
3226

3327
CFeeRate GetRequiredFeeRate(const CWallet& wallet)

src/wallet/wallet.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,11 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
26902690
}
26912691
}
26922692

2693+
if (nFeeRet > maxTxFee) {
2694+
strFailReason = _("Fee exceeds maximum configured by -maxtxfee");
2695+
return false;
2696+
}
2697+
26932698
return true;
26942699
}
26952700

test/functional/rpc_fundrawtransaction.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ def run_test(self):
662662
result = self.nodes[3].fundrawtransaction(rawtx) # uses min_relay_tx_fee (set by settxfee)
663663
result2 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 2*min_relay_tx_fee})
664664
result3 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 10*min_relay_tx_fee})
665+
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by -maxtxfee", self.nodes[3].fundrawtransaction, rawtx, {"feeRate": 1})
665666
result_fee_rate = result['fee'] * 1000 / count_bytes(result['hex'])
666667
assert_fee_amount(result2['fee'], count_bytes(result2['hex']), 2 * result_fee_rate)
667668
assert_fee_amount(result3['fee'], count_bytes(result3['hex']), 10 * result_fee_rate)

test/functional/rpc_psbt.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ def run_test(self):
128128
assert_equal(walletprocesspsbt_out['complete'], True)
129129
self.nodes[1].sendrawtransaction(self.nodes[1].finalizepsbt(walletprocesspsbt_out['psbt'])['hex'])
130130

131+
# feeRate of 0.1 BTC / KB produces a total fee slightly below -maxtxfee (~0.05280000):
132+
res = self.nodes[1].walletcreatefundedpsbt([{"txid":txid,"vout":p2wpkh_pos},{"txid":txid,"vout":p2sh_p2wpkh_pos},{"txid":txid,"vout":p2pkh_pos}], {self.nodes[1].getnewaddress():29.99}, 0, {"feeRate": 0.1})
133+
assert_greater_than(res["fee"], 0.05)
134+
assert_greater_than(0.06, res["fee"])
135+
136+
# feeRate of 10 BTC / KB produces a total fee well above -maxtxfee
137+
# previously this was silenty capped at -maxtxfee
138+
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by -maxtxfee", self.nodes[1].walletcreatefundedpsbt, [{"txid":txid,"vout":p2wpkh_pos},{"txid":txid,"vout":p2sh_p2wpkh_pos},{"txid":txid,"vout":p2pkh_pos}], {self.nodes[1].getnewaddress():29.99}, 0, {"feeRate": 10})
139+
131140
# partially sign multisig things with node 1
132141
psbtx = self.nodes[1].walletcreatefundedpsbt([{"txid":txid,"vout":p2wsh_pos},{"txid":txid,"vout":p2sh_pos},{"txid":txid,"vout":p2sh_p2wsh_pos}], {self.nodes[1].getnewaddress():29.99})['psbt']
133142
walletprocesspsbt_out = self.nodes[1].walletprocesspsbt(psbtx)

0 commit comments

Comments
 (0)