Skip to content

Commit 2f86872

Browse files
committed
Drop AddSigned trait
.. now that we can, addressing a TODO.
1 parent 87c554d commit 2f86872

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
@@ -2482,10 +2482,9 @@ impl FundingScope {
24822482
their_funding_contribution.to_sat(),
24832483
);
24842484

2485-
let post_value_to_self_msat = AddSigned::checked_add_signed(
2486-
prev_funding.value_to_self_msat,
2487-
our_funding_contribution.to_sat() * 1000,
2488-
);
2485+
let post_value_to_self_msat = prev_funding
2486+
.value_to_self_msat
2487+
.checked_add_signed(our_funding_contribution.to_sat() * 1000);
24892488
debug_assert!(post_value_to_self_msat.is_some());
24902489
let post_value_to_self_msat = post_value_to_self_msat.unwrap();
24912490

@@ -2551,8 +2550,7 @@ impl FundingScope {
25512550
pub(super) fn compute_post_splice_value(
25522551
&self, our_funding_contribution: i64, their_funding_contribution: i64,
25532552
) -> u64 {
2554-
AddSigned::saturating_add_signed(
2555-
self.get_value_satoshis(),
2553+
self.get_value_satoshis().saturating_add_signed(
25562554
our_funding_contribution.saturating_add(their_funding_contribution),
25572555
)
25582556
}
@@ -2586,30 +2584,6 @@ impl FundingScope {
25862584
}
25872585
}
25882586

2589-
// TODO: Remove once MSRV is at least 1.66
2590-
trait AddSigned {
2591-
fn checked_add_signed(self, rhs: i64) -> Option<u64>;
2592-
fn saturating_add_signed(self, rhs: i64) -> u64;
2593-
}
2594-
2595-
impl AddSigned for u64 {
2596-
fn checked_add_signed(self, rhs: i64) -> Option<u64> {
2597-
if rhs >= 0 {
2598-
self.checked_add(rhs as u64)
2599-
} else {
2600-
self.checked_sub(rhs.unsigned_abs())
2601-
}
2602-
}
2603-
2604-
fn saturating_add_signed(self, rhs: i64) -> u64 {
2605-
if rhs >= 0 {
2606-
self.saturating_add(rhs as u64)
2607-
} else {
2608-
self.saturating_sub(rhs.unsigned_abs())
2609-
}
2610-
}
2611-
}
2612-
26132587
/// Information about pending attempts at funding a channel. This includes funding currently under
26142588
/// negotiation and any negotiated attempts waiting enough on-chain confirmations. More than one
26152589
/// such attempt indicates use of RBF to increase the chances of confirmation.
@@ -12102,10 +12076,8 @@ where
1210212076

1210312077
if our_funding_contribution != SignedAmount::ZERO {
1210412078
let post_splice_holder_balance = Amount::from_sat(
12105-
AddSigned::checked_add_signed(
12106-
holder_balance_remaining.to_sat(),
12107-
our_funding_contribution.to_sat(),
12108-
)
12079+
holder_balance_remaining.to_sat()
12080+
.checked_add_signed(our_funding_contribution.to_sat())
1210912081
.ok_or(format!(
1211012082
"Channel {} cannot be spliced out; our remaining balance {} does not cover our negative funding contribution {}",
1211112083
self.context.channel_id(),
@@ -12126,10 +12098,8 @@ where
1212612098

1212712099
if their_funding_contribution != SignedAmount::ZERO {
1212812100
let post_splice_counterparty_balance = Amount::from_sat(
12129-
AddSigned::checked_add_signed(
12130-
counterparty_balance_remaining.to_sat(),
12131-
their_funding_contribution.to_sat(),
12132-
)
12101+
counterparty_balance_remaining.to_sat()
12102+
.checked_add_signed(their_funding_contribution.to_sat())
1213312103
.ok_or(format!(
1213412104
"Channel {} cannot be spliced out; their remaining balance {} does not cover their negative funding contribution {}",
1213512105
self.context.channel_id(),

0 commit comments

Comments
 (0)