@@ -10808,11 +10808,21 @@ where
1080810808 )));
1080910809 }
1081010810
10811+ debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10812+
1081110813 // TODO(splicing): Move this check once user-provided contributions are supported for
1081210814 // counterparty-initiated splices.
1081310815 if our_funding_contribution > SignedAmount::MAX_MONEY {
1081410816 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",
1081610826 self.context.channel_id(),
1081710827 our_funding_contribution,
1081810828 )));
@@ -10821,22 +10831,38 @@ where
1082110831 let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
1082210832 if their_funding_contribution > SignedAmount::MAX_MONEY {
1082310833 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",
1082510835 self.context.channel_id(),
1082610836 their_funding_contribution,
1082710837 )));
1082810838 }
1082910839
10830- debug_assert_eq!(our_funding_contribution, SignedAmount::ZERO);
10831- if their_funding_contribution < SignedAmount::ZERO {
10840+ if their_funding_contribution < -SignedAmount::MAX_MONEY {
1083210841 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() ,
1083510844 their_funding_contribution,
10836- our_funding_contribution,
1083710845 )));
1083810846 }
1083910847
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+
1084010866 let splice_funding = FundingScope::for_splice(
1084110867 &self.funding,
1084210868 &self.context,
0 commit comments