@@ -10793,9 +10793,10 @@ where
10793
10793
}
10794
10794
}
10795
10795
10796
- let mut confirmed_funding_index = None;
10797
- let mut funding_already_confirmed = false;
10798
10796
if let Some(pending_splice) = &mut self.pending_splice {
10797
+ let mut confirmed_funding_index = None;
10798
+ let mut funding_already_confirmed = false;
10799
+
10799
10800
for (index, funding) in pending_splice.negotiated_candidates.iter_mut().enumerate() {
10800
10801
if self.context.check_for_funding_tx_confirmed(
10801
10802
funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
@@ -10810,40 +10811,36 @@ where
10810
10811
funding_already_confirmed = true;
10811
10812
}
10812
10813
}
10813
- }
10814
10814
10815
- if let Some(confirmed_funding_index) = confirmed_funding_index {
10816
- let pending_splice = match self.pending_splice.as_mut() {
10817
- Some(pending_splice) => pending_splice,
10818
- None => {
10819
- // TODO: Move pending_funding into pending_splice
10820
- debug_assert!(false);
10821
- let err = "expected a pending splice".to_string();
10822
- return Err(ClosureReason::ProcessingError { err });
10823
- },
10824
- };
10815
+ if let Some(confirmed_funding_index) = confirmed_funding_index {
10816
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
10817
+ &self.context,
10818
+ confirmed_funding_index,
10819
+ height,
10820
+ ) {
10825
10821
10826
- if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, confirmed_funding_index, height) {
10827
- log_info!(
10828
- logger,
10829
- "Sending splice_locked txid {} to our peer for channel {}",
10830
- splice_locked.splice_txid,
10831
- &self.context.channel_id,
10832
- );
10833
-
10834
- let (funding_txo, monitor_update, announcement_sigs, discarded_funding) =
10835
- self.maybe_promote_splice_funding(
10836
- node_signer, chain_hash, user_config, height, logger,
10837
- ).map(|splice_promotion| (
10838
- Some(splice_promotion.funding_txo),
10839
- splice_promotion.monitor_update,
10840
- splice_promotion.announcement_sigs,
10841
- splice_promotion.discarded_funding,
10842
- )).unwrap_or((None, None, None, Vec::new()));
10822
+ log_info!(
10823
+ logger,
10824
+ "Sending splice_locked txid {} to our peer for channel {}",
10825
+ splice_locked.splice_txid,
10826
+ &self.context.channel_id,
10827
+ );
10843
10828
10844
- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), announcement_sigs));
10829
+ let (funding_txo, monitor_update, announcement_sigs, discarded_funding) =
10830
+ self.maybe_promote_splice_funding(
10831
+ node_signer, chain_hash, user_config, height, logger,
10832
+ ).map(|splice_promotion| (
10833
+ Some(splice_promotion.funding_txo),
10834
+ splice_promotion.monitor_update,
10835
+ splice_promotion.announcement_sigs,
10836
+ splice_promotion.discarded_funding,
10837
+ )).unwrap_or((None, None, None, Vec::new()));
10838
+
10839
+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), announcement_sigs));
10840
+ }
10845
10841
}
10846
10842
}
10843
+
10847
10844
}
10848
10845
10849
10846
Ok((None, None))
@@ -10946,70 +10943,62 @@ where
10946
10943
return Err(ClosureReason::FundingTimedOut);
10947
10944
}
10948
10945
10949
- let mut confirmed_funding_index = None;
10950
- for (index, funding) in self.pending_funding().iter().enumerate() {
10951
- if funding.funding_tx_confirmation_height != 0 {
10952
- if confirmed_funding_index.is_some() {
10953
- let err_reason = "splice tx of another pending funding already confirmed";
10954
- return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
10955
- }
10946
+ if let Some(pending_splice) = &mut self.pending_splice {
10947
+ let mut confirmed_funding_index = None;
10948
+
10949
+ for (index, funding) in pending_splice.negotiated_candidates.iter().enumerate() {
10950
+ if funding.funding_tx_confirmation_height != 0 {
10951
+ if confirmed_funding_index.is_some() {
10952
+ let err_reason = "splice tx of another pending funding already confirmed";
10953
+ return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
10954
+ }
10956
10955
10957
- confirmed_funding_index = Some(index);
10956
+ confirmed_funding_index = Some(index);
10957
+ }
10958
10958
}
10959
- }
10960
10959
10961
- if let Some(confirmed_funding_index) = confirmed_funding_index {
10962
- let pending_splice = match self.pending_splice.as_mut() {
10963
- Some(pending_splice) => pending_splice,
10964
- None => {
10965
- // TODO: Move pending_funding into pending_splice
10966
- debug_assert!(false);
10967
- let err = "expected a pending splice".to_string();
10968
- return Err(ClosureReason::ProcessingError { err });
10969
- },
10970
- };
10971
- let funding = &mut pending_splice.negotiated_candidates[confirmed_funding_index];
10972
-
10973
- // Check if the splice funding transaction was unconfirmed
10974
- if funding.get_funding_tx_confirmations(height) == 0 {
10975
- funding.funding_tx_confirmation_height = 0;
10976
- if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
10977
- if Some(sent_funding_txid) == funding.get_funding_txid() {
10978
- log_warn!(
10979
- logger,
10980
- "Unconfirming sent splice_locked txid {} for channel {}",
10981
- sent_funding_txid,
10982
- &self.context.channel_id,
10983
- );
10984
- pending_splice.sent_funding_txid = None;
10960
+ if let Some(confirmed_funding_index) = confirmed_funding_index {
10961
+ let funding = &mut pending_splice.negotiated_candidates[confirmed_funding_index];
10962
+
10963
+ // Check if the splice funding transaction was unconfirmed
10964
+ if funding.get_funding_tx_confirmations(height) == 0 {
10965
+ funding.funding_tx_confirmation_height = 0;
10966
+ if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
10967
+ if Some(sent_funding_txid) == funding.get_funding_txid() {
10968
+ log_warn!(
10969
+ logger,
10970
+ "Unconfirming sent splice_locked txid {} for channel {}",
10971
+ sent_funding_txid,
10972
+ &self.context.channel_id,
10973
+ );
10974
+ pending_splice.sent_funding_txid = None;
10975
+ }
10985
10976
}
10986
10977
}
10987
- }
10988
10978
10989
- let pending_splice = self.pending_splice.as_mut().unwrap();
10990
- if let Some(splice_locked) = pending_splice.check_get_splice_locked(
10991
- &self.context,
10992
- confirmed_funding_index,
10993
- height,
10994
- ) {
10995
- log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
10996
- debug_assert!(chain_node_signer.is_some());
10997
-
10998
- let (funding_txo, monitor_update, announcement_sigs, discarded_funding) = chain_node_signer
10999
- .and_then(|(chain_hash, node_signer, user_config)| {
11000
- // We can only promote on blocks connected, which is when we expect
11001
- // `chain_node_signer` to be `Some`.
11002
- self.maybe_promote_splice_funding(node_signer, chain_hash, user_config, height, logger)
11003
- })
11004
- .map(|splice_promotion| (
11005
- Some(splice_promotion.funding_txo),
11006
- splice_promotion.monitor_update,
11007
- splice_promotion.announcement_sigs,
11008
- splice_promotion.discarded_funding,
11009
- ))
11010
- .unwrap_or((None, None, None, Vec::new()));
10979
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
10980
+ &self.context,
10981
+ confirmed_funding_index,
10982
+ height,
10983
+ ) {
10984
+ log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
11011
10985
11012
- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), timed_out_htlcs, announcement_sigs));
10986
+ let (funding_txo, monitor_update, announcement_sigs, discarded_funding) = chain_node_signer
10987
+ .and_then(|(chain_hash, node_signer, user_config)| {
10988
+ // We can only promote on blocks connected, which is when we expect
10989
+ // `chain_node_signer` to be `Some`.
10990
+ self.maybe_promote_splice_funding(node_signer, chain_hash, user_config, height, logger)
10991
+ })
10992
+ .map(|splice_promotion| (
10993
+ Some(splice_promotion.funding_txo),
10994
+ splice_promotion.monitor_update,
10995
+ splice_promotion.announcement_sigs,
10996
+ splice_promotion.discarded_funding,
10997
+ ))
10998
+ .unwrap_or((None, None, None, Vec::new()));
10999
+
11000
+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), timed_out_htlcs, announcement_sigs));
11001
+ }
11013
11002
}
11014
11003
}
11015
11004
0 commit comments