Skip to content

Commit d926232

Browse files
committed
wallet: Assert that enough was selected to cover the fees
When the fee is not subtracted from the outputs, the amount that has been reserved for the fee (change_and_fee - change_amount) must be enough to cover the fee that is needed. It would be a bug to not do so, so use an assert to make this obvious if such a situation were to occur.
1 parent 2de222c commit d926232

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/wallet/spend.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,10 @@ bool CWallet::CreateTransactionInternal(
778778
fee_needed = coin_selection_params.m_effective_feerate.GetFee(nBytes);
779779
}
780780

781+
// The only time that fee_needed should be less than the amount available for fees (in change_and_fee - change_amount) is when
782+
// we are subtracting the fee from the outputs. If this occurs at any other time, it is a bug.
783+
assert(coin_selection_params.m_subtract_fee_outputs || fee_needed <= change_and_fee - change_amount);
784+
781785
// Update nFeeRet in case fee_needed changed due to dropping the change output
782786
if (fee_needed <= change_and_fee - change_amount) {
783787
nFeeRet = change_and_fee - change_amount;

0 commit comments

Comments
 (0)