mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-16 05:00:42 +02:00
wallet: Sanity check fee paid cannot be negative
We need to check that the fee is not negative even before it is finalized. The setting of fees for SFFO may adjust the fee to be "correct" and no longer negative, but erroneously reduce the amounts too far. So we need to check this condition before we do those adjustments.
This commit is contained in:
parent
c1a84f108e
commit
798430d127
@ -964,6 +964,11 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
|
||||
Assume(recipients_sum + change_amount == output_value);
|
||||
CAmount current_fee = result->GetSelectedValue() - output_value;
|
||||
|
||||
// Sanity check that the fee cannot be negative as that means we have more output value than input value
|
||||
if (current_fee < 0) {
|
||||
return util::Error{Untranslated(STR_INTERNAL_BUG("Fee paid < 0"))};
|
||||
}
|
||||
|
||||
// If there is a change output and we overpay the fees then increase the change to match the fee needed
|
||||
if (nChangePosInOut != -1 && fee_needed < current_fee) {
|
||||
auto& change = txNew.vout.at(nChangePosInOut);
|
||||
|
Loading…
Reference in New Issue
Block a user