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