What changed, and why it matters
This commit removes a small helper trait called AddSigned and replaces its use with equivalent built-in Rust methods (checked_add_signed and saturating_add_signed on u64). The behavior of the code is unchanged; it is a cleanup made possible by raising the minimum supported Rust version. There is no security issue here.
No security action needed. This is a routine refactoring/cleanup commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch deletes the custom AddSigned trait and its u64 implementation, which provided checked_add_signed and saturating_add_signed. These are now native methods on u64 as of Rust 1.66, so the project can use the standard library versions. All call sites are updated from AddSigned::checked_add_signed(a, b) to a.checked_add_signed(b), and from AddSigned::saturating_add_signed(a, b) to a.saturating_add_signed(b). The arithmetic semantics are identical.
Changed components
lightning/src/ln/channel.rsInspect captured patch +8 / −38
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 5c12a75..1e3c45a 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -2482,10 +2482,9 @@ impl FundingScope {
their_funding_contribution.to_sat(),
);
- let post_value_to_self_msat = AddSigned::checked_add_signed(
- prev_funding.value_to_self_msat,
- our_funding_contribution.to_sat() * 1000,
- );
+ let post_value_to_self_msat = prev_funding
+ .value_to_self_msat
+ .checked_add_signed(our_funding_contribution.to_sat() * 1000);
debug_assert!(post_value_to_self_msat.is_some());
let post_value_to_self_msat = post_value_to_self_msat.unwrap();
@@ -2551,8 +2550,7 @@ impl FundingScope {
pub(super) fn compute_post_splice_value(
&self, our_funding_contribution: i64, their_funding_contribution: i64,
) -> u64 {
- AddSigned::saturating_add_signed(
- self.get_value_satoshis(),
+ self.get_value_satoshis().saturating_add_signed(
our_funding_contribution.saturating_add(their_funding_contribution),
)
}
@@ -2586,30 +2584,6 @@ impl FundingScope {
}
}
-// TODO: Remove once MSRV is at least 1.66
-trait AddSigned {
- fn checked_add_signed(self, rhs: i64) -> Option<u64>;
- fn saturating_add_signed(self, rhs: i64) -> u64;
-}
-
-impl AddSigned for u64 {
- fn checked_add_signed(self, rhs: i64) -> Option<u64> {
- if rhs >= 0 {
- self.checked_add(rhs as u64)
- } else {
- self.checked_sub(rhs.unsigned_abs())
- }
- }
-
- fn saturating_add_signed(self, rhs: i64) -> u64 {
- if rhs >= 0 {
- self.saturating_add(rhs as u64)
- } else {
- self.saturating_sub(rhs.unsigned_abs())
- }
- }
-}
-
/// Information about pending attempts at funding a channel. This includes funding currently under
/// negotiation and any negotiated attempts waiting enough on-chain confirmations. More than one
/// such attempt indicates use of RBF to increase the chances of confirmation.
@@ -12102,10 +12076,8 @@ where
if our_funding_contribution != SignedAmount::ZERO {
let post_splice_holder_balance = Amount::from_sat(
- AddSigned::checked_add_signed(
- holder_balance_remaining.to_sat(),
- our_funding_contribution.to_sat(),
- )
+ holder_balance_remaining.to_sat()
+ .checked_add_signed(our_funding_contribution.to_sat())
.ok_or(format!(
"Channel {} cannot be spliced out; our remaining balance {} does not cover our negative funding contribution {}",
self.context.channel_id(),
@@ -12126,10 +12098,8 @@ where
if their_funding_contribution != SignedAmount::ZERO {
let post_splice_counterparty_balance = Amount::from_sat(
- AddSigned::checked_add_signed(
- counterparty_balance_remaining.to_sat(),
- their_funding_contribution.to_sat(),
- )
+ counterparty_balance_remaining.to_sat()
+ .checked_add_signed(their_funding_contribution.to_sat())
.ok_or(format!(
"Channel {} cannot be spliced out; their remaining balance {} does not cover their negative funding contribution {}",
self.context.channel_id(),
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.