@@ -10820,11 +10820,21 @@ where
1082010820 )));
1082110821 }
1082210822
10823+ debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10824+
1082310825 // TODO(splicing): Move this check once user-provided contributions are supported for
1082410826 // counterparty-initiated splices.
1082510827 if our_funding_contribution > SignedAmount::MAX_MONEY {
1082610828 return Err(ChannelError::WarnAndDisconnect(format!(
10827- "Channel {} cannot be spliced; our contribution exceeds total bitcoin supply: {}",
10829+ "Channel {} cannot be spliced in; our {} contribution exceeds the total bitcoin supply",
10830+ self.context.channel_id(),
10831+ our_funding_contribution,
10832+ )));
10833+ }
10834+
10835+ if our_funding_contribution < -SignedAmount::MAX_MONEY {
10836+ return Err(ChannelError::WarnAndDisconnect(format!(
10837+ "Channel {} cannot be spliced out; our {} contribution exhausts the total bitcoin supply",
1082810838 self.context.channel_id(),
1082910839 our_funding_contribution,
1083010840 )));
@@ -10833,22 +10843,38 @@ where
1083310843 let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
1083410844 if their_funding_contribution > SignedAmount::MAX_MONEY {
1083510845 return Err(ChannelError::WarnAndDisconnect(format!(
10836- "Channel {} cannot be spliced; their contribution exceeds total bitcoin supply: {} ",
10846+ "Channel {} cannot be spliced in ; their {} contribution exceeds the total bitcoin supply",
1083710847 self.context.channel_id(),
1083810848 their_funding_contribution,
1083910849 )));
1084010850 }
1084110851
10842- debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10843- if their_funding_contribution < SignedAmount::ZERO {
10852+ if their_funding_contribution < -SignedAmount::MAX_MONEY {
1084410853 return Err(ChannelError::WarnAndDisconnect(format!(
10845- "Splice-out not supported, only splice in, contribution is {} ({} + {}) ",
10846- their_funding_contribution + our_funding_contribution ,
10854+ "Channel {} cannot be spliced out; their {} contribution exhausts the total bitcoin supply ",
10855+ self.context.channel_id() ,
1084710856 their_funding_contribution,
10848- our_funding_contribution,
1084910857 )));
1085010858 }
1085110859
10860+ let their_channel_balance = Amount::from_sat(self.funding.get_value_satoshis())
10861+ - Amount::from_sat(self.funding.get_value_to_self_msat() / 1000);
10862+ let post_channel_balance = AddSigned::checked_add_signed(
10863+ their_channel_balance.to_sat(),
10864+ their_funding_contribution.to_sat(),
10865+ );
10866+
10867+ if post_channel_balance.is_none() {
10868+ return Err(ChannelError::WarnAndDisconnect(format!(
10869+ "Channel {} cannot be spliced out; their {} contribution exhausts their channel balance: {}",
10870+ self.context.channel_id(),
10871+ their_funding_contribution,
10872+ their_channel_balance,
10873+ )));
10874+ }
10875+
10876+ // TODO(splicing): Check that channel balance does not go below the channel reserve
10877+
1085210878 let splice_funding = FundingScope::for_splice(
1085310879 &self.funding,
1085410880 &self.context,
0 commit comments