@@ -8459,6 +8459,24 @@ impl<SP: Deref> FundedChannel<SP> where
84598459 }
84608460 }
84618461
8462+ fn maybe_promote_splice_funding(
8463+ &mut self, splice_txid: Txid, confirmed_funding_index: usize,
8464+ ) -> bool {
8465+ debug_assert!(self.pending_splice.is_some());
8466+ debug_assert!(confirmed_funding_index < self.pending_funding.len());
8467+
8468+ let pending_splice = self.pending_splice.as_mut().unwrap();
8469+ pending_splice.sent_funding_txid = Some(splice_txid);
8470+
8471+ if pending_splice.sent_funding_txid == pending_splice.received_funding_txid {
8472+ let funding = self.pending_funding.get_mut(confirmed_funding_index).unwrap();
8473+ promote_splice_funding!(self, funding);
8474+ return true;
8475+ }
8476+
8477+ return false;
8478+ }
8479+
84628480 /// When a transaction is confirmed, we check whether it is or spends the funding transaction
84638481 /// In the first case, we store the confirmation height and calculating the short channel id.
84648482 /// In the second, we simply return an Err indicating we need to be force-closed now.
@@ -8532,18 +8550,12 @@ impl<SP: Deref> FundedChannel<SP> where
85328550
85338551 log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
85348552
8535- let pending_splice = self.pending_splice.as_mut().unwrap();
8536- pending_splice.sent_funding_txid = Some(splice_locked.splice_txid);
8537-
8538- if pending_splice.sent_funding_txid == pending_splice.received_funding_txid {
8539- let funding = self.pending_funding.get_mut(confirmed_funding_index).unwrap();
8540- promote_splice_funding!(self, funding);
8541-
8542- let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
8543- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), announcement_sigs));
8544- }
8553+ let announcement_sigs = self
8554+ .maybe_promote_splice_funding(splice_locked.splice_txid, confirmed_funding_index)
8555+ .then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
8556+ .flatten();
85458557
8546- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), None ));
8558+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), announcement_sigs ));
85478559 }
85488560 }
85498561
@@ -8678,22 +8690,16 @@ impl<SP: Deref> FundedChannel<SP> where
86788690 if let Some(splice_locked) = self.check_get_splice_locked(pending_splice, funding, height) {
86798691 log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
86808692
8681- let pending_splice = self.pending_splice.as_mut().unwrap();
8682- pending_splice.sent_funding_txid = Some(splice_locked.splice_txid);
8683-
8684- if pending_splice.sent_funding_txid == pending_splice.received_funding_txid {
8685- let funding = self.pending_funding.get_mut(confirmed_funding_index).unwrap();
8686- promote_splice_funding!(self, funding);
8687-
8688- let mut announcement_sigs = None;
8689- if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
8690- announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
8691- }
8692-
8693- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), timed_out_htlcs, announcement_sigs));
8694- }
8693+ let announcement_sigs = self
8694+ .maybe_promote_splice_funding(splice_locked.splice_txid, confirmed_funding_index)
8695+ .then(|| chain_node_signer
8696+ .and_then(|(chain_hash, node_signer, user_config)|
8697+ self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
8698+ )
8699+ )
8700+ .flatten();
86958701
8696- return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), timed_out_htlcs, None ));
8702+ return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), timed_out_htlcs, announcement_sigs ));
86978703 }
86988704 }
86998705
0 commit comments