Skip to content

Commit a84b056

Browse files
committed
Merge #12749: [wallet] feebumper: discard change outputs below discard rate
f526046 adapt bumpfee change discard test to be more strict and add note on p2sh discrep (Gregory Sanders) 5805d6f feebumper: discard change outputs below discard rate (Gregory Sanders) Pull request description: The "discard rate" is the concept we use to ensure the wallet isnt creating not so useful just-above-relay dust. Outside of bumpfee previous to this PR, and manually creating such an output, the wallet will never make change outputs of that size, preferring to send them to fees instead. "Worst case" for the user is that users pay a slightly higher feerate than they were expecting, which is already a possibility with relay dust. Tree-SHA512: dd69351810dc1709437602e7db1be46e4e905ccd8e16d03952de8b4c1fdbf9cb7e6c99968930896baf6b5c7cb005a03ec0506a2669d22e21e32982e60329606b
2 parents 8d651ae + f526046 commit a84b056

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/wallet/feebumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Result CreateTransaction(const CWallet* wallet, const uint256& txid, const CCoin
194194

195195
// If the output would become dust, discard it (converting the dust to fee)
196196
poutput->nValue -= nDelta;
197-
if (poutput->nValue <= GetDustThreshold(*poutput, ::dustRelayFee)) {
197+
if (poutput->nValue <= GetDustThreshold(*poutput, GetDiscardRate(::feeEstimator))) {
198198
LogPrint(BCLog::RPC, "Bumping fee and discarding dust output\n");
199199
new_fee += poutput->nValue;
200200
mtx.vout.erase(mtx.vout.begin() + nOutput);

test/functional/wallet_bumpfee.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ def test_dust_to_fee(rbf_node, dest_address):
179179
# the bumped tx sets fee=49,900, but it converts to 50,000
180180
rbfid = spend_one_input(rbf_node, dest_address)
181181
fulltx = rbf_node.getrawtransaction(rbfid, 1)
182-
bumped_tx = rbf_node.bumpfee(rbfid, {"totalFee": 49900})
182+
# (32-byte p2sh-pwpkh output size + 148 p2pkh spend estimate) * 10k(discard_rate) / 1000 = 1800
183+
# P2SH outputs are slightly "over-discarding" due to the IsDust calculation assuming it will
184+
# be spent as a P2PKH.
185+
bumped_tx = rbf_node.bumpfee(rbfid, {"totalFee": 50000-1800})
183186
full_bumped_tx = rbf_node.getrawtransaction(bumped_tx["txid"], 1)
184187
assert_equal(bumped_tx["fee"], Decimal("0.00050000"))
185188
assert_equal(len(fulltx["vout"]), 2)

0 commit comments

Comments
 (0)