@@ -9627,12 +9627,11 @@ where
96279627 }
96289628 }
96299629
9630- #[cfg(splicing)]
9631- let mut confirmed_funding_index = None;
9632- #[cfg(splicing)]
9633- let mut funding_already_confirmed = false;
96349630 #[cfg(splicing)]
96359631 if let Some(pending_splice) = &mut self.pending_splice {
9632+ let mut confirmed_funding_index = None;
9633+ let mut funding_already_confirmed = false;
9634+
96369635 for (index, funding) in pending_splice.negotiated_candidates.iter_mut().enumerate() {
96379636 if self.context.check_for_funding_tx_confirmed(
96389637 funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
@@ -9647,51 +9646,40 @@ where
96479646 funding_already_confirmed = true;
96489647 }
96499648 }
9650- }
96519649
9652- #[cfg(splicing)]
9653- if let Some(confirmed_funding_index) = confirmed_funding_index {
9654- let pending_splice = match self.pending_splice.as_mut() {
9655- Some(pending_splice) => pending_splice,
9656- None => {
9657- // TODO: Move pending_funding into pending_splice
9658- debug_assert!(false);
9659- let err = "expected a pending splice".to_string();
9660- return Err(ClosureReason::ProcessingError { err });
9661- },
9662- };
9663-
9664- if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9665- &self.context,
9666- confirmed_funding_index,
9667- height,
9668- ) {
9669- for &(idx, tx) in txdata.iter() {
9670- if idx > index_in_block {
9671- let funding = pending_splice.negotiated_candidates.get(confirmed_funding_index).unwrap();
9672- self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9650+ if let Some(confirmed_funding_index) = confirmed_funding_index {
9651+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9652+ &self.context,
9653+ confirmed_funding_index,
9654+ height,
9655+ ) {
9656+ for &(idx, tx) in txdata.iter() {
9657+ if idx > index_in_block {
9658+ let funding = pending_splice.negotiated_candidates.get(confirmed_funding_index).unwrap();
9659+ self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9660+ }
96739661 }
9674- }
96759662
9676- log_info!(
9677- logger,
9678- "Sending splice_locked txid {} to our peer for channel {}",
9679- splice_locked.splice_txid,
9680- &self.context.channel_id,
9681- );
9663+ log_info!(
9664+ logger,
9665+ "Sending splice_locked txid {} to our peer for channel {}",
9666+ splice_locked.splice_txid,
9667+ &self.context.channel_id,
9668+ );
96829669
9683- let funding_promoted =
9684- self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9685- let funding_txo = funding_promoted.then(|| {
9686- self.funding
9687- .get_funding_txo()
9688- .expect("Splice FundingScope should always have a funding_txo")
9689- });
9690- let announcement_sigs = funding_promoted
9691- .then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
9692- .flatten();
9670+ let funding_promoted =
9671+ self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9672+ let funding_txo = funding_promoted.then(|| {
9673+ self.funding
9674+ .get_funding_txo()
9675+ .expect("Splice FundingScope should always have a funding_txo")
9676+ });
9677+ let announcement_sigs = funding_promoted
9678+ .then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
9679+ .flatten();
96939680
9694- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), announcement_sigs));
9681+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), announcement_sigs));
9682+ }
96959683 }
96969684 }
96979685
@@ -9803,72 +9791,63 @@ where
98039791 }
98049792
98059793 #[cfg(splicing)]
9806- let mut confirmed_funding_index = None;
9807- #[cfg(splicing)]
9808- for (index, funding) in self.pending_funding().iter().enumerate() {
9809- if funding.funding_tx_confirmation_height != 0 {
9810- if confirmed_funding_index.is_some() {
9811- let err_reason = "splice tx of another pending funding already confirmed";
9812- return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
9813- }
9794+ if let Some(pending_splice) = &mut self.pending_splice {
9795+ let mut confirmed_funding_index = None;
98149796
9815- confirmed_funding_index = Some(index);
9797+ for (index, funding) in pending_splice.negotiated_candidates.iter().enumerate() {
9798+ if funding.funding_tx_confirmation_height != 0 {
9799+ if confirmed_funding_index.is_some() {
9800+ let err_reason = "splice tx of another pending funding already confirmed";
9801+ return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
9802+ }
9803+
9804+ confirmed_funding_index = Some(index);
9805+ }
98169806 }
9817- }
98189807
9819- #[cfg(splicing)]
9820- if let Some(confirmed_funding_index) = confirmed_funding_index {
9821- let pending_splice = match self.pending_splice.as_mut() {
9822- Some(pending_splice) => pending_splice,
9823- None => {
9824- // TODO: Move pending_funding into pending_splice
9825- debug_assert!(false);
9826- let err = "expected a pending splice".to_string();
9827- return Err(ClosureReason::ProcessingError { err });
9828- },
9829- };
9830- let funding = pending_splice.negotiated_candidates.get_mut(confirmed_funding_index).unwrap();
9831-
9832- // Check if the splice funding transaction was unconfirmed
9833- if funding.get_funding_tx_confirmations(height) == 0 {
9834- funding.funding_tx_confirmation_height = 0;
9835- if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
9836- if Some(sent_funding_txid) == funding.get_funding_txid() {
9837- log_warn!(
9838- logger,
9839- "Unconfirming sent splice_locked txid {} for channel {}",
9840- sent_funding_txid,
9841- &self.context.channel_id,
9842- );
9843- pending_splice.sent_funding_txid = None;
9808+ if let Some(confirmed_funding_index) = confirmed_funding_index {
9809+ let funding = pending_splice.negotiated_candidates.get_mut(confirmed_funding_index).unwrap();
9810+
9811+ // Check if the splice funding transaction was unconfirmed
9812+ if funding.get_funding_tx_confirmations(height) == 0 {
9813+ funding.funding_tx_confirmation_height = 0;
9814+ if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
9815+ if Some(sent_funding_txid) == funding.get_funding_txid() {
9816+ log_warn!(
9817+ logger,
9818+ "Unconfirming sent splice_locked txid {} for channel {}",
9819+ sent_funding_txid,
9820+ &self.context.channel_id,
9821+ );
9822+ pending_splice.sent_funding_txid = None;
9823+ }
98449824 }
98459825 }
9846- }
98479826
9848- let pending_splice = self.pending_splice.as_mut().unwrap();
9849- if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9850- &self.context,
9851- confirmed_funding_index,
9852- height,
9853- ) {
9854- log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
9827+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9828+ &self.context,
9829+ confirmed_funding_index,
9830+ height,
9831+ ) {
9832+ log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
98559833
9856- let funding_promoted =
9857- self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9858- let funding_txo = funding_promoted.then(|| {
9859- self.funding
9860- .get_funding_txo()
9861- .expect("Splice FundingScope should always have a funding_txo")
9862- });
9863- let announcement_sigs = funding_promoted
9864- .then(|| chain_node_signer
9865- .and_then(|(chain_hash, node_signer, user_config)|
9866- self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
9834+ let funding_promoted =
9835+ self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9836+ let funding_txo = funding_promoted.then(|| {
9837+ self.funding
9838+ .get_funding_txo()
9839+ .expect("Splice FundingScope should always have a funding_txo")
9840+ });
9841+ let announcement_sigs = funding_promoted
9842+ .then(|| chain_node_signer
9843+ .and_then(|(chain_hash, node_signer, user_config)|
9844+ self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
9845+ )
98679846 )
9868- )
9869- .flatten();
9847+ .flatten();
98709848
9871- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), timed_out_htlcs, announcement_sigs));
9849+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), timed_out_htlcs, announcement_sigs));
9850+ }
98729851 }
98739852 }
98749853
0 commit comments