Skip to content

Commit 798430d

Browse files
committed
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.
1 parent c1a84f1 commit 798430d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/wallet/spend.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,11 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
964964
Assume(recipients_sum + change_amount == output_value);
965965
CAmount current_fee = result->GetSelectedValue() - output_value;
966966

967+
// Sanity check that the fee cannot be negative as that means we have more output value than input value
968+
if (current_fee < 0) {
969+
return util::Error{Untranslated(STR_INTERNAL_BUG("Fee paid < 0"))};
970+
}
971+
967972
// If there is a change output and we overpay the fees then increase the change to match the fee needed
968973
if (nChangePosInOut != -1 && fee_needed < current_fee) {
969974
auto& change = txNew.vout.at(nChangePosInOut);

0 commit comments

Comments
 (0)