Skip to content

Commit 660c7ee

Browse files
committed
Drop AddSigned trait
.. now that we can, addressing a TODO.
1 parent 8426b3b commit 660c7ee

File tree

1 file changed

+8
-38
lines changed

1 file changed

+8
-38
lines changed

lightning/src/ln/channel.rs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,10 +2419,9 @@ impl FundingScope {
24192419
their_funding_contribution.to_sat(),
24202420
);
24212421

2422-
let post_value_to_self_msat = AddSigned::checked_add_signed(
2423-
prev_funding.value_to_self_msat,
2424-
our_funding_contribution.to_sat() * 1000,
2425-
);
2422+
let post_value_to_self_msat = prev_funding
2423+
.value_to_self_msat
2424+
.checked_add_signed(our_funding_contribution.to_sat() * 1000);
24262425
debug_assert!(post_value_to_self_msat.is_some());
24272426
let post_value_to_self_msat = post_value_to_self_msat.unwrap();
24282427

@@ -2488,8 +2487,7 @@ impl FundingScope {
24882487
pub(super) fn compute_post_splice_value(
24892488
&self, our_funding_contribution: i64, their_funding_contribution: i64,
24902489
) -> u64 {
2491-
AddSigned::saturating_add_signed(
2492-
self.get_value_satoshis(),
2490+
self.get_value_satoshis().saturating_add_signed(
24932491
our_funding_contribution.saturating_add(their_funding_contribution),
24942492
)
24952493
}
@@ -2523,30 +2521,6 @@ impl FundingScope {
25232521
}
25242522
}
25252523

2526-
// TODO: Remove once MSRV is at least 1.66
2527-
trait AddSigned {
2528-
fn checked_add_signed(self, rhs: i64) -> Option<u64>;
2529-
fn saturating_add_signed(self, rhs: i64) -> u64;
2530-
}
2531-
2532-
impl AddSigned for u64 {
2533-
fn checked_add_signed(self, rhs: i64) -> Option<u64> {
2534-
if rhs >= 0 {
2535-
self.checked_add(rhs as u64)
2536-
} else {
2537-
self.checked_sub(rhs.unsigned_abs())
2538-
}
2539-
}
2540-
2541-
fn saturating_add_signed(self, rhs: i64) -> u64 {
2542-
if rhs >= 0 {
2543-
self.saturating_add(rhs as u64)
2544-
} else {
2545-
self.saturating_sub(rhs.unsigned_abs())
2546-
}
2547-
}
2548-
}
2549-
25502524
/// Info about a pending splice
25512525
struct PendingSplice {
25522526
funding_negotiation: Option<FundingNegotiation>,
@@ -11629,10 +11603,8 @@ where
1162911603

1163011604
if our_funding_contribution != SignedAmount::ZERO {
1163111605
let post_splice_holder_balance = Amount::from_sat(
11632-
AddSigned::checked_add_signed(
11633-
holder_balance_remaining.to_sat(),
11634-
our_funding_contribution.to_sat(),
11635-
)
11606+
holder_balance_remaining.to_sat()
11607+
.checked_add_signed(our_funding_contribution.to_sat())
1163611608
.ok_or(format!(
1163711609
"Channel {} cannot be spliced out; our remaining balance {} does not cover our negative funding contribution {}",
1163811610
self.context.channel_id(),
@@ -11653,10 +11625,8 @@ where
1165311625

1165411626
if their_funding_contribution != SignedAmount::ZERO {
1165511627
let post_splice_counterparty_balance = Amount::from_sat(
11656-
AddSigned::checked_add_signed(
11657-
counterparty_balance_remaining.to_sat(),
11658-
their_funding_contribution.to_sat(),
11659-
)
11628+
counterparty_balance_remaining.to_sat()
11629+
.checked_add_signed(their_funding_contribution.to_sat())
1166011630
.ok_or(format!(
1166111631
"Channel {} cannot be spliced out; their remaining balance {} does not cover their negative funding contribution {}",
1166211632
self.context.channel_id(),

0 commit comments

Comments
 (0)