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