@@ -4970,9 +4970,36 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
49704970 }
49714971
49724972 #[cfg(splicing)]
4973- fn check_get_splice_locked<L: Deref>(&mut self, funding: &FundingScope, height: u32, logger: &L) -> Option<msgs::SpliceLocked>
4974- where L::Target: Logger
4973+ fn check_get_splice_locked<L: Deref>(
4974+ &mut self, pending_splice: &mut Option<PendingSplice>, funding: &mut FundingScope,
4975+ height: u32, logger: &L,
4976+ ) -> Option<msgs::SpliceLocked>
4977+ where
4978+ L::Target: Logger,
49754979 {
4980+ // TODO: Check minimum depth has been reached.
4981+
4982+ let confirmed_funding_txo = funding.get_funding_txo();
4983+ if let Some(pending_splice) = pending_splice {
4984+ if let Some(funding_txid) = pending_splice.confirmed_funding_txid {
4985+ // splice_lock already received
4986+ if Some(funding_txid) == confirmed_funding_txo.map(|txo| txo.txid) {
4987+ // - swap FundingScope
4988+ // - clear pending_splice
4989+ // - clear pending_funding
4990+ // - send splice_locked
4991+ } else {
4992+ // splice_txid does not match one in received splice_locked
4993+ }
4994+ } else {
4995+ pending_splice.confirmed_funding_txid = confirmed_funding_txo.map(|txo| txo.txid);
4996+ debug_assert!(pending_splice.confirmed_funding_txid.is_some());
4997+ // - send splice_locked
4998+ // - wait for splice_locked
4999+ }
5000+ } else {
5001+ debug_assert!(false);
5002+ }
49765003 None
49775004 }
49785005}
@@ -8388,13 +8415,7 @@ impl<SP: Deref> FundedChannel<SP> where
83888415 }
83898416 } else {
83908417 #[cfg(splicing)] {
8391- if let Some(pending_splice) = &mut self.pending_splice {
8392- pending_splice.confirmed_funding_txid = confirmed_funding_txo.map(|txo| txo.txid);
8393- debug_assert!(pending_splice.confirmed_funding_txid.is_some());
8394- } else {
8395- debug_assert!(false);
8396- }
8397- if let Some(splice_locked) = self.context.check_get_splice_locked(funding, height, logger) {
8418+ if let Some(splice_locked) = self.context.check_get_splice_locked(&mut self.pending_splice, funding, height, logger) {
83988419 log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
83998420 let announcement_sigs = self.context.get_announcement_sigs(funding, node_signer, chain_hash, user_config, height, logger);
84008421 return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), announcement_sigs));
@@ -8501,11 +8522,11 @@ impl<SP: Deref> FundedChannel<SP> where
85018522 .and_then(|pending_splice| pending_splice.confirmed_funding_txid)
85028523 {
85038524 if let Some((funding, _)) = self.pending_funding
8504- .iter ()
8525+ .iter_mut ()
85058526 .filter_map(|funding| funding.get_funding_txo().map(|txo| (funding, txo.txid)))
85068527 .find(|(_, funding_txid)| *funding_txid == confirmed_funding_txid)
85078528 {
8508- if let Some(splice_locked) = self.context.check_get_splice_locked(funding, height, logger) {
8529+ if let Some(splice_locked) = self.context.check_get_splice_locked(&mut self.pending_splice, funding, height, logger) {
85098530 let announcement_sigs = if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
85108531 self.context.get_announcement_sigs(funding, node_signer, chain_hash, user_config, height, logger)
85118532 } else {
0 commit comments