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