@@ -10819,11 +10819,21 @@ where
10819
10819
)));
10820
10820
}
10821
10821
10822
+ debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10823
+
10822
10824
// TODO(splicing): Move this check once user-provided contributions are supported for
10823
10825
// counterparty-initiated splices.
10824
10826
if our_funding_contribution > SignedAmount::MAX_MONEY {
10825
10827
return Err(ChannelError::WarnAndDisconnect(format!(
10826
- "Channel {} cannot be spliced; our contribution exceeds total bitcoin supply: {}",
10828
+ "Channel {} cannot be spliced in; our {} contribution exceeds the total bitcoin supply",
10829
+ self.context.channel_id(),
10830
+ our_funding_contribution,
10831
+ )));
10832
+ }
10833
+
10834
+ if our_funding_contribution < -SignedAmount::MAX_MONEY {
10835
+ return Err(ChannelError::WarnAndDisconnect(format!(
10836
+ "Channel {} cannot be spliced out; our {} contribution exhausts the total bitcoin supply",
10827
10837
self.context.channel_id(),
10828
10838
our_funding_contribution,
10829
10839
)));
@@ -10832,22 +10842,38 @@ where
10832
10842
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
10833
10843
if their_funding_contribution > SignedAmount::MAX_MONEY {
10834
10844
return Err(ChannelError::WarnAndDisconnect(format!(
10835
- "Channel {} cannot be spliced; their contribution exceeds total bitcoin supply: {} ",
10845
+ "Channel {} cannot be spliced in ; their {} contribution exceeds the total bitcoin supply",
10836
10846
self.context.channel_id(),
10837
10847
their_funding_contribution,
10838
10848
)));
10839
10849
}
10840
10850
10841
- debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10842
- if their_funding_contribution < SignedAmount::ZERO {
10851
+ if their_funding_contribution < -SignedAmount::MAX_MONEY {
10843
10852
return Err(ChannelError::WarnAndDisconnect(format!(
10844
- "Splice-out not supported, only splice in, contribution is {} ({} + {}) ",
10845
- their_funding_contribution + our_funding_contribution ,
10853
+ "Channel {} cannot be spliced out; their {} contribution exhausts the total bitcoin supply ",
10854
+ self.context.channel_id() ,
10846
10855
their_funding_contribution,
10847
- our_funding_contribution,
10848
10856
)));
10849
10857
}
10850
10858
10859
+ let their_channel_balance = Amount::from_sat(self.funding.get_value_satoshis())
10860
+ - Amount::from_sat(self.funding.get_value_to_self_msat() / 1000);
10861
+ let post_channel_balance = AddSigned::checked_add_signed(
10862
+ their_channel_balance.to_sat(),
10863
+ their_funding_contribution.to_sat(),
10864
+ );
10865
+
10866
+ if post_channel_balance.is_none() {
10867
+ return Err(ChannelError::WarnAndDisconnect(format!(
10868
+ "Channel {} cannot be spliced out; their {} contribution exhausts their channel balance: {}",
10869
+ self.context.channel_id(),
10870
+ their_funding_contribution,
10871
+ their_channel_balance,
10872
+ )));
10873
+ }
10874
+
10875
+ // TODO(splicing): Check that channel balance does not go below the channel reserve
10876
+
10851
10877
let splice_funding = FundingScope::for_splice(
10852
10878
&self.funding,
10853
10879
&self.context,
@@ -10981,10 +11007,34 @@ where
10981
11007
10982
11008
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
10983
11009
if their_funding_contribution > SignedAmount::MAX_MONEY {
10984
- return Err(ChannelError::Warn(format!(
10985
- "Channel {} cannot be spliced; their contribution exceeds total bitcoin supply: {}",
11010
+ return Err(ChannelError::WarnAndDisconnect(format!(
11011
+ "Channel {} cannot be spliced in; their {} contribution exceeds the total bitcoin supply",
11012
+ self.context.channel_id(),
11013
+ their_funding_contribution,
11014
+ )));
11015
+ }
11016
+
11017
+ if their_funding_contribution < -SignedAmount::MAX_MONEY {
11018
+ return Err(ChannelError::WarnAndDisconnect(format!(
11019
+ "Channel {} cannot be spliced out; their {} contribution exhausts the total bitcoin supply",
11020
+ self.context.channel_id(),
11021
+ their_funding_contribution,
11022
+ )));
11023
+ }
11024
+
11025
+ let their_channel_balance = Amount::from_sat(self.funding.get_value_satoshis())
11026
+ - Amount::from_sat(self.funding.get_value_to_self_msat() / 1000);
11027
+ let post_channel_balance = AddSigned::checked_add_signed(
11028
+ their_channel_balance.to_sat(),
11029
+ their_funding_contribution.to_sat(),
11030
+ );
11031
+
11032
+ if post_channel_balance.is_none() {
11033
+ return Err(ChannelError::WarnAndDisconnect(format!(
11034
+ "Channel {} cannot be spliced out; their {} contribution exhausts their channel balance: {}",
10986
11035
self.context.channel_id(),
10987
11036
their_funding_contribution,
11037
+ their_channel_balance,
10988
11038
)));
10989
11039
}
10990
11040
0 commit comments