From 423a1b6b95856b102c7c76c0f6016f48d8427560 Mon Sep 17 00:00:00 2001 From: Alec Chen Date: Wed, 5 Jun 2024 22:52:53 -0500 Subject: [PATCH] Handle sending open_channel when signer is unblocked --- lightning/src/ln/channel.rs | 29 +++++++++++++++++++++++++---- lightning/src/ln/channelmanager.rs | 9 ++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 584e634a3b3..9287d546edd 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -7966,11 +7966,32 @@ impl OutboundV1Channel where SP::Target: SignerProvider { /// Indicates that the signer may have some signatures for us, so we should retry if we're /// blocked. #[cfg(async_signing)] - pub fn signer_maybe_unblocked(&mut self, logger: &L) -> Option where L::Target: Logger { - if self.context.signer_pending_funding && self.context.is_outbound() { - log_trace!(logger, "Signer unblocked a funding_created"); + pub fn signer_maybe_unblocked(&mut self, chain_hash: ChainHash, logger: &L) -> (Option, Option) + where L::Target: Logger + { + // If we were pending a commitment point, retry the signer and advance to an + // available state. + if self.unfunded_context.holder_commitment_point.is_none() { + self.unfunded_context.holder_commitment_point = HolderCommitmentPoint::new(&self.context.holder_signer, &self.context.secp_ctx); + } + if let Some(ref mut point) = self.unfunded_context.holder_commitment_point { + if !point.is_available() { + point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger); + } + } + let open_channel = match self.unfunded_context.holder_commitment_point { + Some(ref mut point) if point.is_available() && self.signer_pending_open_channel => { + log_trace!(logger, "Attempting to generate open_channel..."); + self.get_open_channel(chain_hash, logger) + } + _ => None + }; + let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() { + log_trace!(logger, "Attempting to generate pending funding created..."); + self.context.signer_pending_funding = false; self.get_funding_created_msg(logger) - } else { None } + } else { None }; + (open_channel, funding_created) } } diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 9337efc355a..4d595d811ac 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -8866,7 +8866,14 @@ where msgs.shutdown_result } ChannelPhase::UnfundedOutboundV1(chan) => { - if let Some(msg) = chan.signer_maybe_unblocked(&self.logger) { + let (open_channel, funding_created) = chan.signer_maybe_unblocked(self.chain_hash.clone(), &self.logger); + if let Some(msg) = open_channel { + pending_msg_events.push(events::MessageSendEvent::SendOpenChannel { + node_id, + msg, + }); + } + if let Some(msg) = funding_created { pending_msg_events.push(events::MessageSendEvent::SendFundingCreated { node_id, msg,