Skip to content

Commit

Permalink
Handle sending open_channel when signer is unblocked
Browse files Browse the repository at this point in the history
  • Loading branch information
alecchendev committed Sep 16, 2024
1 parent c6d76c9 commit 423a1b6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
29 changes: 25 additions & 4 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7966,11 +7966,32 @@ impl<SP: Deref> OutboundV1Channel<SP> 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<L: Deref>(&mut self, logger: &L) -> Option<msgs::FundingCreated> 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<L: Deref>(&mut self, chain_hash: ChainHash, logger: &L) -> (Option<msgs::OpenChannel>, Option<msgs::FundingCreated>)
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)
}
}

Expand Down
9 changes: 8 additions & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 423a1b6

Please sign in to comment.