Add code comment to amount calculation

Its not immediately obvious that x - y cannot overflow. Add a code
comment to explain it.
This commit is contained in:
Tobin C. Harding 2025-05-29 05:08:34 +01:00
parent 8cf1dc39b5
commit 56516757ad
No known key found for this signature in database
GPG Key ID: 0AEF0A899E41F7DD
1 changed files with 2 additions and 0 deletions

View File

@ -784,6 +784,8 @@ pub fn effective_value(
let weight = input_weight_prediction.total_weight(); let weight = input_weight_prediction.total_weight();
let fee = fee_rate.to_fee(weight); let fee = fee_rate.to_fee(weight);
// Cannot overflow because after conversion to signed Amount::MIN - Amount::MAX
// still fits in SignedAmount::MAX (0 - MAX = -MAX).
(value.to_signed() - fee.to_signed()).expect("cannot overflow") (value.to_signed() - fee.to_signed()).expect("cannot overflow")
} }