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;
3768
-
assert!(value_to_self_msat >= 0);
3767
+
// TODO: When MSRV >= 1.66.0, use u64::checked_add_signed
3768
+
let mut value_to_self_msat = u64::try_from(funding.value_to_self_msat as i64 + value_to_self_msat_offset).unwrap();
3769
3769
// Note that in case they have several just-awaiting-last-RAA fulfills in-progress (ie
3770
3770
// AwaitingRemoteRevokeToRemove or AwaitingRemovedRemoteRevoke) we may have allowed them to
3771
-
// "violate" their reserve value by couting those against it. Thus, we have to convert
3772
-
// everything to i64 before subtracting as otherwise we can overflow.
3773
-
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;
3774
-
assert!(value_to_remote_msat >= 0);
3771
+
// "violate" their reserve value by couting those against it. Thus, we have to do checked subtraction
3772
+
// as otherwise we can overflow.
3773
+
let mut value_to_remote_msat = u64::checked_sub(funding.get_value_satoshis() * 1000, value_to_self_msat).unwrap();
0 commit comments