@@ -3423,7 +3423,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
34233423 /// The channel value is an input as opposed to using from self, so that this can be used in case of splicing
34243424 /// to checks with new channel value (before being comitted to it).
34253425 #[cfg(any(dual_funding, splicing))]
3426- pub fn check_balance_meets_reserve_requirements(&self, channel_value: u64, balance: u64) -> Result<(), ChannelError> {
3426+ pub fn check_balance_meets_reserve_requirements(&self, balance: u64, channel_value: u64) -> Result<(), ChannelError> {
3427+ if balance == 0 {
3428+ return Ok(());
3429+ }
34273430 let holder_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
34283431 channel_value, self.holder_dust_limit_satoshis);
34293432 if balance < holder_selected_channel_reserve_satoshis {
@@ -7485,9 +7488,11 @@ impl<SP: Deref> Channel<SP> where
74857488
74867489 /// Handle splice_init
74877490 #[cfg(splicing)]
7488- pub fn splice_init(
7489- &mut self, their_funding_contribution_satoshis: i64, our_funding_contribution_satoshis: i64,
7490- ) -> Result<msgs::SpliceAck, ChannelError> {
7491+ pub fn splice_init(&mut self, msg: &msgs::SpliceInit) -> Result<msgs::SpliceAck, ChannelError> {
7492+ let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
7493+ // TODO(splicing): Currently not possible to contribute on the splicing-acceptor side
7494+ let our_funding_contribution_satoshis = 0i64;
7495+
74917496 // Check if a splice has been initiated already.
74927497 // Note: this could be handled more nicely, and support multiple outstanding splice's, the incoming splice_ack matters anyways.
74937498 if let Some(splice_info) = &self.context.pending_splice_pre {
@@ -7520,11 +7525,12 @@ impl<SP: Deref> Channel<SP> where
75207525 }
75217526
75227527 let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, their_funding_contribution_satoshis, our_funding_contribution_satoshis);
7523-
7528+ let post_balance = PendingSpliceInfoPre::add_checked(self.context.value_to_self_msat, our_funding_contribution_satoshis);
75247529 // Early check for reserve requirement, assuming maximum balance of full channel value
75257530 // This will also be checked later at tx_complete
7526- let _res = self.context.check_balance_meets_reserve_requirements(post_channel_value , post_channel_value)?;
7531+ let _res = self.context.check_balance_meets_reserve_requirements(post_balance , post_channel_value)?;
75277532
7533+ // TODO(splicing): Store msg.funding_pubkey
75287534 // TODO(splicing): Apply start of splice (splice_start)
75297535
75307536 let splice_ack_msg = self.context.get_splice_ack(our_funding_contribution_satoshis);
@@ -7534,22 +7540,24 @@ impl<SP: Deref> Channel<SP> where
75347540
75357541 /// Handle splice_ack
75367542 #[cfg(splicing)]
7537- pub fn splice_ack(
7538- &mut self, their_funding_contribution_satoshis: i64,
7539- ) -> Result<(), ChannelError> {
7543+ pub fn splice_ack(&mut self, msg: &msgs::SpliceAck) -> Result<(), ChannelError> {
7544+ let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
7545+
75407546 // check if splice is pending
75417547 let pending_splice = if let Some(pending_splice) = &self.context.pending_splice_pre {
75427548 pending_splice
75437549 } else {
75447550 return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
75457551 };
75467552
7547- let pre_channel_value = self.context.get_value_satoshis();
7548- let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, pending_splice.our_funding_contribution, their_funding_contribution_satoshis);
7553+ let our_funding_contribution = pending_splice.our_funding_contribution;
75497554
7555+ let pre_channel_value = self.context.get_value_satoshis();
7556+ let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution_satoshis);
7557+ let post_balance = PendingSpliceInfoPre::add_checked(self.context.value_to_self_msat, our_funding_contribution);
75507558 // Early check for reserve requirement, assuming maximum balance of full channel value
75517559 // This will also be checked later at tx_complete
7552- let _res = self.context.check_balance_meets_reserve_requirements(post_channel_value , post_channel_value)?;
7560+ let _res = self.context.check_balance_meets_reserve_requirements(post_balance , post_channel_value)?;
75537561 Ok(())
75547562 }
75557563
0 commit comments