Skip to content

Commit 2e857bb

Browse files
committed
Merge #10942: Eliminate fee overpaying edge case when subtracting fee from recipients
49d903e Eliminate fee overpaying edge case when subtracting fee from recipients (Alex Morcos) Pull request description: I'm not sure if this is the cause of the issue in #10034 , but this was a known edge case. I just didn't realize how simple the fix is. Could use a couple more eyes to make sure nothing silly can go wrong here, but if we all agree it's this simple, we can add this as another 0.15 bug fix. Tree-SHA512: db1dd1e83363a3c231267b626d3a388893ee70ba1972056fe2c339c5c9e4fbfd30f7fe837c30cc7be884d454797fd4c619b9d631a8d5eeb55cdb07402a83acb3
2 parents 659c096 + 49d903e commit 2e857bb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,10 +2789,6 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
27892789
// selected to meet nFeeNeeded result in a transaction that
27902790
// requires less fee than the prior iteration.
27912791

2792-
// TODO: The case where nSubtractFeeFromAmount > 0 remains
2793-
// to be addressed because it requires returning the fee to
2794-
// the payees and not the change output.
2795-
27962792
// If we have no change and a big enough excess fee, then
27972793
// try to construct transaction again only without picking
27982794
// new inputs. We now know we only need the smaller fee
@@ -2819,6 +2815,8 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
28192815
else if (!pick_new_inputs) {
28202816
// This shouldn't happen, we should have had enough excess
28212817
// fee to pay for the new output and still meet nFeeNeeded
2818+
// Or we should have just subtracted fee from recipients and
2819+
// nFeeNeeded should not have changed
28222820
strFailReason = _("Transaction fee and change calculation failed");
28232821
return false;
28242822
}
@@ -2835,6 +2833,12 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
28352833
}
28362834
}
28372835

2836+
// If subtracting fee from recipients, we now know what fee we
2837+
// need to subtract, we have no reason to reselect inputs
2838+
if (nSubtractFeeFromAmount > 0) {
2839+
pick_new_inputs = false;
2840+
}
2841+
28382842
// Include more fee and try again.
28392843
nFeeRet = nFeeNeeded;
28402844
continue;

0 commit comments

Comments
 (0)