@@ -10826,35 +10826,31 @@ where
10826
10826
)));
10827
10827
}
10828
10828
10829
+ debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10830
+
10829
10831
// TODO(splicing): Move this check once user-provided contributions are supported for
10830
10832
// counterparty-initiated splices.
10831
10833
if our_funding_contribution > SignedAmount::MAX_MONEY {
10832
10834
return Err(ChannelError::WarnAndDisconnect(format!(
10833
- "Channel {} cannot be spliced; our contribution exceeds total bitcoin supply: {} ",
10835
+ "Channel {} cannot be spliced in ; our {} contribution exceeds the total bitcoin supply",
10834
10836
self.context.channel_id(),
10835
10837
our_funding_contribution,
10836
10838
)));
10837
10839
}
10838
10840
10839
- let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
10840
- if their_funding_contribution > SignedAmount::MAX_MONEY {
10841
+ if our_funding_contribution < -SignedAmount::MAX_MONEY {
10841
10842
return Err(ChannelError::WarnAndDisconnect(format!(
10842
- "Channel {} cannot be spliced; their contribution exceeds total bitcoin supply: {} ",
10843
+ "Channel {} cannot be spliced out; our {} contribution exhausts the total bitcoin supply",
10843
10844
self.context.channel_id(),
10844
- their_funding_contribution,
10845
- )));
10846
- }
10847
-
10848
- debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10849
- if their_funding_contribution < SignedAmount::ZERO {
10850
- return Err(ChannelError::WarnAndDisconnect(format!(
10851
- "Splice-out not supported, only splice in, contribution is {} ({} + {})",
10852
- their_funding_contribution + our_funding_contribution,
10853
- their_funding_contribution,
10854
10845
our_funding_contribution,
10855
10846
)));
10856
10847
}
10857
10848
10849
+ let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
10850
+ self.validate_splice_contribution(their_funding_contribution)?;
10851
+
10852
+ // TODO(splicing): Check that channel balance does not go below the channel reserve
10853
+
10858
10854
let splice_funding = FundingScope::for_splice(
10859
10855
&self.funding,
10860
10856
&self.context,
@@ -10874,6 +10870,45 @@ where
10874
10870
Ok(splice_funding)
10875
10871
}
10876
10872
10873
+ #[cfg(splicing)]
10874
+ fn validate_splice_contribution(
10875
+ &self, their_funding_contribution: SignedAmount,
10876
+ ) -> Result<(), ChannelError> {
10877
+ if their_funding_contribution > SignedAmount::MAX_MONEY {
10878
+ return Err(ChannelError::WarnAndDisconnect(format!(
10879
+ "Channel {} cannot be spliced in; their {} contribution exceeds the total bitcoin supply",
10880
+ self.context.channel_id(),
10881
+ their_funding_contribution,
10882
+ )));
10883
+ }
10884
+
10885
+ if their_funding_contribution < -SignedAmount::MAX_MONEY {
10886
+ return Err(ChannelError::WarnAndDisconnect(format!(
10887
+ "Channel {} cannot be spliced out; their {} contribution exhausts the total bitcoin supply",
10888
+ self.context.channel_id(),
10889
+ their_funding_contribution,
10890
+ )));
10891
+ }
10892
+
10893
+ let their_channel_balance = Amount::from_sat(self.funding.get_value_satoshis())
10894
+ - Amount::from_sat(self.funding.get_value_to_self_msat() / 1000);
10895
+ let post_channel_balance = AddSigned::checked_add_signed(
10896
+ their_channel_balance.to_sat(),
10897
+ their_funding_contribution.to_sat(),
10898
+ );
10899
+
10900
+ if post_channel_balance.is_none() {
10901
+ return Err(ChannelError::WarnAndDisconnect(format!(
10902
+ "Channel {} cannot be spliced out; their {} contribution exhausts their channel balance: {}",
10903
+ self.context.channel_id(),
10904
+ their_funding_contribution,
10905
+ their_channel_balance,
10906
+ )));
10907
+ }
10908
+
10909
+ Ok(())
10910
+ }
10911
+
10877
10912
/// See also [`validate_splice_init`]
10878
10913
#[cfg(splicing)]
10879
10914
pub(crate) fn splice_init<ES: Deref, L: Deref>(
@@ -10987,13 +11022,7 @@ where
10987
11022
debug_assert!(our_funding_contribution <= SignedAmount::MAX_MONEY);
10988
11023
10989
11024
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
10990
- if their_funding_contribution > SignedAmount::MAX_MONEY {
10991
- return Err(ChannelError::Warn(format!(
10992
- "Channel {} cannot be spliced; their contribution exceeds total bitcoin supply: {}",
10993
- self.context.channel_id(),
10994
- their_funding_contribution,
10995
- )));
10996
- }
11025
+ self.validate_splice_contribution(their_funding_contribution)?;
10997
11026
10998
11027
let splice_funding = FundingScope::for_splice(
10999
11028
&self.funding,
@@ -11031,6 +11060,9 @@ where
11031
11060
let tx_msg_opt = interactive_tx_constructor.take_initiator_first_message();
11032
11061
11033
11062
debug_assert!(self.interactive_tx_signing_session.is_none());
11063
+
11064
+ let pending_splice =
11065
+ self.pending_splice.as_mut().expect("pending_splice should still be set");
11034
11066
pending_splice.funding_negotiation = Some(FundingNegotiation::ConstructingTransaction(
11035
11067
splice_funding,
11036
11068
interactive_tx_constructor,
0 commit comments