@@ -10824,9 +10824,19 @@ where
10824
10824
)));
10825
10825
}
10826
10826
10827
+ debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10828
+
10827
10829
if our_funding_contribution > SignedAmount::MAX_MONEY {
10828
10830
return Err(ChannelError::WarnAndDisconnect(format!(
10829
- "Channel {} cannot be spliced; our contribution exceeds total bitcoin supply: {}",
10831
+ "Channel {} cannot be spliced in; our {} contribution exceeds the total bitcoin supply",
10832
+ self.context.channel_id(),
10833
+ our_funding_contribution,
10834
+ )));
10835
+ }
10836
+
10837
+ if our_funding_contribution < -SignedAmount::MAX_MONEY {
10838
+ return Err(ChannelError::WarnAndDisconnect(format!(
10839
+ "Channel {} cannot be spliced out; our {} contribution exhausts the total bitcoin supply",
10830
10840
self.context.channel_id(),
10831
10841
our_funding_contribution,
10832
10842
)));
@@ -10835,22 +10845,38 @@ where
10835
10845
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
10836
10846
if their_funding_contribution > SignedAmount::MAX_MONEY {
10837
10847
return Err(ChannelError::WarnAndDisconnect(format!(
10838
- "Channel {} cannot be spliced; their contribution exceeds total bitcoin supply: {} ",
10848
+ "Channel {} cannot be spliced in ; their {} contribution exceeds the total bitcoin supply",
10839
10849
self.context.channel_id(),
10840
10850
their_funding_contribution,
10841
10851
)));
10842
10852
}
10843
10853
10844
- debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10845
- if their_funding_contribution < SignedAmount::ZERO {
10854
+ if their_funding_contribution < -SignedAmount::MAX_MONEY {
10846
10855
return Err(ChannelError::WarnAndDisconnect(format!(
10847
- "Splice-out not supported, only splice in, contribution is {} ({} + {}) ",
10848
- their_funding_contribution + our_funding_contribution ,
10856
+ "Channel {} cannot be spliced out; their {} contribution exhausts the total bitcoin supply ",
10857
+ self.context.channel_id() ,
10849
10858
their_funding_contribution,
10850
- our_funding_contribution,
10851
10859
)));
10852
10860
}
10853
10861
10862
+ let their_channel_balance = Amount::from_sat(self.funding.get_value_satoshis())
10863
+ - Amount::from_sat(self.funding.get_value_to_self_msat() / 1000);
10864
+ let post_channel_balance = AddSigned::checked_add_signed(
10865
+ their_channel_balance.to_sat(),
10866
+ their_funding_contribution.to_sat(),
10867
+ );
10868
+
10869
+ if post_channel_balance.is_none() {
10870
+ return Err(ChannelError::WarnAndDisconnect(format!(
10871
+ "Channel {} cannot be spliced out; their {} contribution exhausts their channel balance: {}",
10872
+ self.context.channel_id(),
10873
+ their_funding_contribution,
10874
+ their_channel_balance,
10875
+ )));
10876
+ }
10877
+
10878
+ // TODO(splicing): Check that channel balance does not go below the channel reserve
10879
+
10854
10880
let splice_funding = FundingScope::for_splice(
10855
10881
&self.funding,
10856
10882
&self.context,
0 commit comments