You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove i64 casts in ChannelContext::build_commitment_transaction
Instead of converting operands to `i64` and checking if the subtractions
overflowed by checking if the `i64` is smaller than zero, we instead
choose to do checked and saturating subtractions on the original
unsigned integers.
let value_to_self_msat: i64 = (funding.value_to_self_msat - local_htlc_total_msat) as i64 + value_to_self_msat_offset;
3762
-
assert!(value_to_self_msat >= 0);
3763
-
// Note that in case they have several just-awaiting-last-RAA fulfills in-progress (ie
3764
-
// AwaitingRemoteRevokeToRemove or AwaitingRemovedRemoteRevoke) we may have allowed them to
3765
-
// "violate" their reserve value by couting those against it. Thus, we have to convert
3766
-
// everything to i64 before subtracting as otherwise we can overflow.
3767
-
let value_to_remote_msat: i64 = (funding.get_value_satoshis() * 1000) as i64 - (funding.value_to_self_msat as i64) - (remote_htlc_total_msat as i64) - value_to_self_msat_offset;
3768
-
assert!(value_to_remote_msat >= 0);
3761
+
// # Panics
3762
+
//
3763
+
// While we expect `value_to_self_msat_offset` to be negative in some cases, the value going
3764
+
// to each party MUST be 0 or positive, even if all HTLCs pending in the commitment clear by
3765
+
// failure.
3766
+
3767
+
// TODO: When MSRV >= 1.66.0, use u64::checked_add_signed
3768
+
let mut value_to_self_msat = (funding.value_to_self_msat as i64 + value_to_self_msat_offset).try_into().unwrap();
3769
+
let mut value_to_remote_msat = (funding.get_value_satoshis() * 1000).checked_sub(value_to_self_msat).unwrap();
0 commit comments