diff options
author | Andrew Chow <achow101-github@achow101.com> | 2021-08-11 22:05:51 -0400 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2021-08-20 10:36:45 +0300 |
commit | e86b023606193ca044f9ce20c88958d693585734 (patch) | |
tree | 4c8897ba916820149594ab4245260ecd82c20ea6 /src | |
parent | ffc81e2048bc9d3887211174b58f798b981f8c64 (diff) | |
download | bitcoin-e86b023606193ca044f9ce20c88958d693585734.tar.xz |
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.
Github-Pull: bitcoin/bitcoin#22686
Rebased-From: d9262324e80da32725e21d4e0fbfee56f25490b1
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/spend.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 6a8df437ae..e403b69b49 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -778,6 +778,10 @@ bool CWallet::CreateTransactionInternal( fee_needed = coin_selection_params.m_effective_feerate.GetFee(nBytes); } + // The only time that fee_needed should be less than the amount available for fees (in change_and_fee - change_amount) is when + // we are subtracting the fee from the outputs. If this occurs at any other time, it is a bug. + assert(coin_selection_params.m_subtract_fee_outputs || fee_needed <= change_and_fee - change_amount); + // Update nFeeRet in case fee_needed changed due to dropping the change output if (fee_needed <= change_and_fee - change_amount) { nFeeRet = change_and_fee - change_amount; |