@@ -10820,11 +10820,21 @@ where
10820
10820
)));
10821
10821
}
10822
10822
10823
+ debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10824
+
10823
10825
// TODO(splicing): Move this check once user-provided contributions are supported for
10824
10826
// counterparty-initiated splices.
10825
10827
if our_funding_contribution > SignedAmount::MAX_MONEY {
10826
10828
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",
10828
10838
self.context.channel_id(),
10829
10839
our_funding_contribution,
10830
10840
)));
@@ -10833,22 +10843,38 @@ where
10833
10843
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
10834
10844
if their_funding_contribution > SignedAmount::MAX_MONEY {
10835
10845
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",
10837
10847
self.context.channel_id(),
10838
10848
their_funding_contribution,
10839
10849
)));
10840
10850
}
10841
10851
10842
- debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10843
- if their_funding_contribution < SignedAmount::ZERO {
10852
+ if their_funding_contribution < -SignedAmount::MAX_MONEY {
10844
10853
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() ,
10847
10856
their_funding_contribution,
10848
- our_funding_contribution,
10849
10857
)));
10850
10858
}
10851
10859
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
+
10852
10878
let splice_funding = FundingScope::for_splice(
10853
10879
&self.funding,
10854
10880
&self.context,
0 commit comments