@@ -10811,11 +10811,21 @@ where
10811
10811
)));
10812
10812
}
10813
10813
10814
+ debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10815
+
10814
10816
// TODO(splicing): Move this check once user-provided contributions are supported for
10815
10817
// counterparty-initiated splices.
10816
10818
if our_funding_contribution > SignedAmount::MAX_MONEY {
10817
10819
return Err(ChannelError::WarnAndDisconnect(format!(
10818
- "Channel {} cannot be spliced; our contribution exceeds total bitcoin supply: {}",
10820
+ "Channel {} cannot be spliced in; our {} contribution exceeds the total bitcoin supply",
10821
+ self.context.channel_id(),
10822
+ our_funding_contribution,
10823
+ )));
10824
+ }
10825
+
10826
+ if our_funding_contribution < -SignedAmount::MAX_MONEY {
10827
+ return Err(ChannelError::WarnAndDisconnect(format!(
10828
+ "Channel {} cannot be spliced out; our {} contribution exhausts the total bitcoin supply",
10819
10829
self.context.channel_id(),
10820
10830
our_funding_contribution,
10821
10831
)));
@@ -10824,22 +10834,38 @@ where
10824
10834
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
10825
10835
if their_funding_contribution > SignedAmount::MAX_MONEY {
10826
10836
return Err(ChannelError::WarnAndDisconnect(format!(
10827
- "Channel {} cannot be spliced; their contribution exceeds total bitcoin supply: {} ",
10837
+ "Channel {} cannot be spliced in ; their {} contribution exceeds the total bitcoin supply",
10828
10838
self.context.channel_id(),
10829
10839
their_funding_contribution,
10830
10840
)));
10831
10841
}
10832
10842
10833
- debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10834
- if their_funding_contribution < SignedAmount::ZERO {
10843
+ if their_funding_contribution < -SignedAmount::MAX_MONEY {
10835
10844
return Err(ChannelError::WarnAndDisconnect(format!(
10836
- "Splice-out not supported, only splice in, contribution is {} ({} + {}) ",
10837
- their_funding_contribution + our_funding_contribution ,
10845
+ "Channel {} cannot be spliced out; their {} contribution exhausts the total bitcoin supply ",
10846
+ self.context.channel_id() ,
10838
10847
their_funding_contribution,
10839
- our_funding_contribution,
10840
10848
)));
10841
10849
}
10842
10850
10851
+ let their_channel_balance = Amount::from_sat(self.funding.get_value_satoshis())
10852
+ - Amount::from_sat(self.funding.get_value_to_self_msat() / 1000);
10853
+ let post_channel_balance = AddSigned::checked_add_signed(
10854
+ their_channel_balance.to_sat(),
10855
+ their_funding_contribution.to_sat(),
10856
+ );
10857
+
10858
+ if post_channel_balance.is_none() {
10859
+ return Err(ChannelError::WarnAndDisconnect(format!(
10860
+ "Channel {} cannot be spliced out; their {} contribution exhausts their channel balance: {}",
10861
+ self.context.channel_id(),
10862
+ their_funding_contribution,
10863
+ their_channel_balance,
10864
+ )));
10865
+ }
10866
+
10867
+ // TODO(splicing): Check that channel balance does not go below the channel reserve
10868
+
10843
10869
let splice_funding = FundingScope::for_splice(
10844
10870
&self.funding,
10845
10871
&self.context,
0 commit comments