@@ -10623,12 +10623,11 @@ where
10623
10623
}
10624
10624
}
10625
10625
10626
- #[cfg(splicing)]
10627
- let mut confirmed_funding_index = None;
10628
- #[cfg(splicing)]
10629
- let mut funding_already_confirmed = false;
10630
10626
#[cfg(splicing)]
10631
10627
if let Some(pending_splice) = &mut self.pending_splice {
10628
+ let mut confirmed_funding_index = None;
10629
+ let mut funding_already_confirmed = false;
10630
+
10632
10631
for (index, funding) in pending_splice.negotiated_candidates.iter_mut().enumerate() {
10633
10632
if self.context.check_for_funding_tx_confirmed(
10634
10633
funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
@@ -10643,41 +10642,36 @@ where
10643
10642
funding_already_confirmed = true;
10644
10643
}
10645
10644
}
10646
- }
10647
-
10648
- #[cfg(splicing)]
10649
- if let Some(confirmed_funding_index) = confirmed_funding_index {
10650
- let pending_splice = match self.pending_splice.as_mut() {
10651
- Some(pending_splice) => pending_splice,
10652
- None => {
10653
- // TODO: Move pending_funding into pending_splice
10654
- debug_assert!(false);
10655
- let err = "expected a pending splice".to_string();
10656
- return Err(ClosureReason::ProcessingError { err });
10657
- },
10658
- };
10659
10645
10660
- if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, confirmed_funding_index, height) {
10661
- log_info!(
10662
- logger,
10663
- "Sending splice_locked txid {} to our peer for channel {}",
10664
- splice_locked.splice_txid,
10665
- &self.context.channel_id,
10666
- );
10646
+ if let Some(confirmed_funding_index) = confirmed_funding_index {
10647
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
10648
+ &self.context,
10649
+ confirmed_funding_index,
10650
+ height,
10651
+ ) {
10667
10652
10668
- let (funding_txo, monitor_update, announcement_sigs, discarded_funding) =
10669
- self.maybe_promote_splice_funding(
10670
- node_signer, chain_hash, user_config, height, logger,
10671
- ).map(|splice_promotion| (
10672
- Some(splice_promotion.funding_txo),
10673
- splice_promotion.monitor_update,
10674
- splice_promotion.announcement_sigs,
10675
- splice_promotion.discarded_funding,
10676
- )).unwrap_or((None, None, None, Vec::new()));
10653
+ log_info!(
10654
+ logger,
10655
+ "Sending splice_locked txid {} to our peer for channel {}",
10656
+ splice_locked.splice_txid,
10657
+ &self.context.channel_id,
10658
+ );
10677
10659
10678
- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), announcement_sigs));
10660
+ let (funding_txo, monitor_update, announcement_sigs, discarded_funding) =
10661
+ self.maybe_promote_splice_funding(
10662
+ node_signer, chain_hash, user_config, height, logger,
10663
+ ).map(|splice_promotion| (
10664
+ Some(splice_promotion.funding_txo),
10665
+ splice_promotion.monitor_update,
10666
+ splice_promotion.announcement_sigs,
10667
+ splice_promotion.discarded_funding,
10668
+ )).unwrap_or((None, None, None, Vec::new()));
10669
+
10670
+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), announcement_sigs));
10671
+ }
10679
10672
}
10680
10673
}
10674
+
10681
10675
}
10682
10676
10683
10677
Ok((None, None))
@@ -10781,72 +10775,62 @@ where
10781
10775
}
10782
10776
10783
10777
#[cfg(splicing)]
10784
- let mut confirmed_funding_index = None;
10785
- #[cfg(splicing)]
10786
- for (index, funding) in self.pending_funding().iter().enumerate() {
10787
- if funding.funding_tx_confirmation_height != 0 {
10788
- if confirmed_funding_index.is_some() {
10789
- let err_reason = "splice tx of another pending funding already confirmed";
10790
- return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
10791
- }
10778
+ if let Some(pending_splice) = &mut self.pending_splice {
10779
+ let mut confirmed_funding_index = None;
10792
10780
10793
- confirmed_funding_index = Some(index);
10781
+ for (index, funding) in pending_splice.negotiated_candidates.iter().enumerate() {
10782
+ if funding.funding_tx_confirmation_height != 0 {
10783
+ if confirmed_funding_index.is_some() {
10784
+ let err_reason = "splice tx of another pending funding already confirmed";
10785
+ return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
10786
+ }
10787
+
10788
+ confirmed_funding_index = Some(index);
10789
+ }
10794
10790
}
10795
- }
10796
10791
10797
- #[cfg(splicing)]
10798
- if let Some(confirmed_funding_index) = confirmed_funding_index {
10799
- let pending_splice = match self.pending_splice.as_mut() {
10800
- Some(pending_splice) => pending_splice,
10801
- None => {
10802
- // TODO: Move pending_funding into pending_splice
10803
- debug_assert!(false);
10804
- let err = "expected a pending splice".to_string();
10805
- return Err(ClosureReason::ProcessingError { err });
10806
- },
10807
- };
10808
- let funding = &mut pending_splice.negotiated_candidates[confirmed_funding_index];
10809
-
10810
- // Check if the splice funding transaction was unconfirmed
10811
- if funding.get_funding_tx_confirmations(height) == 0 {
10812
- funding.funding_tx_confirmation_height = 0;
10813
- if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
10814
- if Some(sent_funding_txid) == funding.get_funding_txid() {
10815
- log_warn!(
10816
- logger,
10817
- "Unconfirming sent splice_locked txid {} for channel {}",
10818
- sent_funding_txid,
10819
- &self.context.channel_id,
10820
- );
10821
- pending_splice.sent_funding_txid = None;
10792
+ if let Some(confirmed_funding_index) = confirmed_funding_index {
10793
+ let funding = &mut pending_splice.negotiated_candidates[confirmed_funding_index];
10794
+
10795
+ // Check if the splice funding transaction was unconfirmed
10796
+ if funding.get_funding_tx_confirmations(height) == 0 {
10797
+ funding.funding_tx_confirmation_height = 0;
10798
+ if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
10799
+ if Some(sent_funding_txid) == funding.get_funding_txid() {
10800
+ log_warn!(
10801
+ logger,
10802
+ "Unconfirming sent splice_locked txid {} for channel {}",
10803
+ sent_funding_txid,
10804
+ &self.context.channel_id,
10805
+ );
10806
+ pending_splice.sent_funding_txid = None;
10807
+ }
10822
10808
}
10823
10809
}
10824
- }
10825
10810
10826
- let pending_splice = self.pending_splice.as_mut().unwrap();
10827
- if let Some(splice_locked) = pending_splice.check_get_splice_locked(
10828
- &self.context,
10829
- confirmed_funding_index,
10830
- height,
10831
- ) {
10832
- log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
10833
- debug_assert!(chain_node_signer.is_some());
10834
-
10835
- let (funding_txo, monitor_update, announcement_sigs, discarded_funding) = chain_node_signer
10836
- .and_then(|(chain_hash, node_signer, user_config)| {
10837
- // We can only promote on blocks connected, which is when we expect
10838
- // `chain_node_signer` to be `Some`.
10839
- self.maybe_promote_splice_funding(node_signer, chain_hash, user_config, height, logger)
10840
- })
10841
- .map(|splice_promotion| (
10842
- Some(splice_promotion.funding_txo),
10843
- splice_promotion.monitor_update,
10844
- splice_promotion.announcement_sigs,
10845
- splice_promotion.discarded_funding,
10846
- ))
10847
- .unwrap_or((None, None, None, Vec::new()));
10811
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
10812
+ &self.context,
10813
+ confirmed_funding_index,
10814
+ height,
10815
+ ) {
10816
+ log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
10817
+
10818
+ let (funding_txo, monitor_update, announcement_sigs, discarded_funding) = chain_node_signer
10819
+ .and_then(|(chain_hash, node_signer, user_config)| {
10820
+ // We can only promote on blocks connected, which is when we expect
10821
+ // `chain_node_signer` to be `Some`.
10822
+ self.maybe_promote_splice_funding(node_signer, chain_hash, user_config, height, logger)
10823
+ })
10824
+ .map(|splice_promotion| (
10825
+ Some(splice_promotion.funding_txo),
10826
+ splice_promotion.monitor_update,
10827
+ splice_promotion.announcement_sigs,
10828
+ splice_promotion.discarded_funding,
10829
+ ))
10830
+ .unwrap_or((None, None, None, Vec::new()));
10848
10831
10849
- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), timed_out_htlcs, announcement_sigs));
10832
+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), timed_out_htlcs, announcement_sigs));
10833
+ }
10850
10834
}
10851
10835
}
10852
10836
0 commit comments