@@ -9641,12 +9641,11 @@ where
96419641 }
96429642 }
96439643
9644- #[cfg(splicing)]
9645- let mut confirmed_funding_index = None;
9646- #[cfg(splicing)]
9647- let mut funding_already_confirmed = false;
96489644 #[cfg(splicing)]
96499645 if let Some(pending_splice) = &mut self.pending_splice {
9646+ let mut confirmed_funding_index = None;
9647+ let mut funding_already_confirmed = false;
9648+
96509649 for (index, funding) in pending_splice.negotiated_candidates.iter_mut().enumerate() {
96519650 if self.context.check_for_funding_tx_confirmed(
96529651 funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
@@ -9661,51 +9660,40 @@ where
96619660 funding_already_confirmed = true;
96629661 }
96639662 }
9664- }
9665-
9666- #[cfg(splicing)]
9667- if let Some(confirmed_funding_index) = confirmed_funding_index {
9668- let pending_splice = match self.pending_splice.as_mut() {
9669- Some(pending_splice) => pending_splice,
9670- None => {
9671- // TODO: Move pending_funding into pending_splice
9672- debug_assert!(false);
9673- let err = "expected a pending splice".to_string();
9674- return Err(ClosureReason::ProcessingError { err });
9675- },
9676- };
96779663
9678- if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9679- &self.context,
9680- confirmed_funding_index,
9681- height,
9682- ) {
9683- for &(idx, tx) in txdata.iter() {
9684- if idx > index_in_block {
9685- let funding = &pending_splice.negotiated_candidates[confirmed_funding_index];
9686- self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9664+ if let Some(confirmed_funding_index) = confirmed_funding_index {
9665+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9666+ &self.context,
9667+ confirmed_funding_index,
9668+ height,
9669+ ) {
9670+ for &(idx, tx) in txdata.iter() {
9671+ if idx > index_in_block {
9672+ let funding = &pending_splice.negotiated_candidates[confirmed_funding_index];
9673+ self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9674+ }
96879675 }
9688- }
96899676
9690- log_info!(
9691- logger,
9692- "Sending splice_locked txid {} to our peer for channel {}",
9693- splice_locked.splice_txid,
9694- &self.context.channel_id,
9695- );
9677+ log_info!(
9678+ logger,
9679+ "Sending splice_locked txid {} to our peer for channel {}",
9680+ splice_locked.splice_txid,
9681+ &self.context.channel_id,
9682+ );
96969683
9697- let funding_promoted =
9698- self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9699- let funding_txo = funding_promoted.then(|| {
9700- self.funding
9701- .get_funding_txo()
9702- .expect("Splice FundingScope should always have a funding_txo")
9703- });
9704- let announcement_sigs = funding_promoted
9705- .then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
9706- .flatten();
9684+ let funding_promoted =
9685+ self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9686+ let funding_txo = funding_promoted.then(|| {
9687+ self.funding
9688+ .get_funding_txo()
9689+ .expect("Splice FundingScope should always have a funding_txo")
9690+ });
9691+ let announcement_sigs = funding_promoted
9692+ .then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
9693+ .flatten();
97079694
9708- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), announcement_sigs));
9695+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), announcement_sigs));
9696+ }
97099697 }
97109698 }
97119699
@@ -9817,72 +9805,63 @@ where
98179805 }
98189806
98199807 #[cfg(splicing)]
9820- let mut confirmed_funding_index = None;
9821- #[cfg(splicing)]
9822- for (index, funding) in self.pending_funding().iter().enumerate() {
9823- if funding.funding_tx_confirmation_height != 0 {
9824- if confirmed_funding_index.is_some() {
9825- let err_reason = "splice tx of another pending funding already confirmed";
9826- return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
9827- }
9808+ if let Some(pending_splice) = &mut self.pending_splice {
9809+ let mut confirmed_funding_index = None;
98289810
9829- confirmed_funding_index = Some(index);
9830- }
9831- }
9811+ for (index, funding) in pending_splice.negotiated_candidates.iter().enumerate() {
9812+ if funding.funding_tx_confirmation_height != 0 {
9813+ if confirmed_funding_index.is_some() {
9814+ let err_reason = "splice tx of another pending funding already confirmed";
9815+ return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
9816+ }
98329817
9833- #[cfg(splicing)]
9834- if let Some(confirmed_funding_index) = confirmed_funding_index {
9835- let pending_splice = match self.pending_splice.as_mut() {
9836- Some(pending_splice) => pending_splice,
9837- None => {
9838- // TODO: Move pending_funding into pending_splice
9839- debug_assert!(false);
9840- let err = "expected a pending splice".to_string();
9841- return Err(ClosureReason::ProcessingError { err });
9842- },
9843- };
9844- let funding = &mut pending_splice.negotiated_candidates[confirmed_funding_index];
9818+ confirmed_funding_index = Some(index);
9819+ }
9820+ }
98459821
9846- // Check if the splice funding transaction was unconfirmed
9847- if funding.get_funding_tx_confirmations(height) == 0 {
9848- funding.funding_tx_confirmation_height = 0;
9849- if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
9850- if Some(sent_funding_txid) == funding.get_funding_txid() {
9851- log_warn!(
9852- logger,
9853- "Unconfirming sent splice_locked txid {} for channel {}",
9854- sent_funding_txid,
9855- &self.context.channel_id,
9856- );
9857- pending_splice.sent_funding_txid = None;
9822+ if let Some(confirmed_funding_index) = confirmed_funding_index {
9823+ let funding = &mut pending_splice.negotiated_candidates[confirmed_funding_index];
9824+
9825+ // Check if the splice funding transaction was unconfirmed
9826+ if funding.get_funding_tx_confirmations(height) == 0 {
9827+ funding.funding_tx_confirmation_height = 0;
9828+ if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
9829+ if Some(sent_funding_txid) == funding.get_funding_txid() {
9830+ log_warn!(
9831+ logger,
9832+ "Unconfirming sent splice_locked txid {} for channel {}",
9833+ sent_funding_txid,
9834+ &self.context.channel_id,
9835+ );
9836+ pending_splice.sent_funding_txid = None;
9837+ }
98589838 }
98599839 }
9860- }
98619840
9862- let pending_splice = self.pending_splice.as_mut().unwrap();
9863- if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9864- &self.context,
9865- confirmed_funding_index,
9866- height,
9867- ) {
9868- log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
9841+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9842+ &self.context,
9843+ confirmed_funding_index,
9844+ height,
9845+ ) {
9846+ log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
98699847
9870- let funding_promoted =
9871- self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9872- let funding_txo = funding_promoted.then(|| {
9873- self.funding
9874- .get_funding_txo()
9875- .expect("Splice FundingScope should always have a funding_txo")
9876- });
9877- let announcement_sigs = funding_promoted
9878- .then(|| chain_node_signer
9879- .and_then(|(chain_hash, node_signer, user_config)|
9880- self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
9848+ let funding_promoted =
9849+ self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9850+ let funding_txo = funding_promoted.then(|| {
9851+ self.funding
9852+ .get_funding_txo()
9853+ .expect("Splice FundingScope should always have a funding_txo")
9854+ });
9855+ let announcement_sigs = funding_promoted
9856+ .then(|| chain_node_signer
9857+ .and_then(|(chain_hash, node_signer, user_config)|
9858+ self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
9859+ )
98819860 )
9882- )
9883- .flatten();
9861+ .flatten();
98849862
9885- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), timed_out_htlcs, announcement_sigs));
9863+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), timed_out_htlcs, announcement_sigs));
9864+ }
98869865 }
98879866 }
98889867
0 commit comments