Skip to content

Commit 49d903e

Browse files
committed
Eliminate fee overpaying edge case when subtracting fee from recipients
1 parent 0b11a07 commit 49d903e

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
@@ -2774,10 +2774,6 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
27742774
// selected to meet nFeeNeeded result in a transaction that
27752775
// requires less fee than the prior iteration.
27762776

2777-
// TODO: The case where nSubtractFeeFromAmount > 0 remains
2778-
// to be addressed because it requires returning the fee to
2779-
// the payees and not the change output.
2780-
27812777
// If we have no change and a big enough excess fee, then
27822778
// try to construct transaction again only without picking
27832779
// new inputs. We now know we only need the smaller fee
@@ -2804,6 +2800,8 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
28042800
else if (!pick_new_inputs) {
28052801
// This shouldn't happen, we should have had enough excess
28062802
// fee to pay for the new output and still meet nFeeNeeded
2803+
// Or we should have just subtracted fee from recipients and
2804+
// nFeeNeeded should not have changed
28072805
strFailReason = _("Transaction fee and change calculation failed");
28082806
return false;
28092807
}
@@ -2820,6 +2818,12 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
28202818
}
28212819
}
28222820

2821+
// If subtracting fee from recipients, we now know what fee we
2822+
// need to subtract, we have no reason to reselect inputs
2823+
if (nSubtractFeeFromAmount > 0) {
2824+
pick_new_inputs = false;
2825+
}
2826+
28232827
// Include more fee and try again.
28242828
nFeeRet = nFeeNeeded;
28252829
continue;

0 commit comments

Comments
 (0)