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