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