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