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