Skip to content

Commit 61a9118

Browse files
committed
Move setting signer flags to get_funding_created_msg
This also slightly refactors get_funding_signed_msg to match the logic more similarly, as well as removes a log to fix a nit from lightningdevkit#3152.
1 parent 157618a commit 61a9118

File tree

1 file changed

+39
-46
lines changed

1 file changed

+39
-46
lines changed

lightning/src/ln/channel.rs

+39-46
Original file line numberDiff line numberDiff line change
@@ -3514,38 +3514,38 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35143514
log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
35153515
&self.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
35163516

3517-
match &self.holder_signer {
3517+
let signature = match &self.holder_signer {
35183518
// TODO (arik): move match into calling method for Taproot
3519-
ChannelSignerType::Ecdsa(ecdsa) => {
3520-
let funding_signed = ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx)
3521-
.map(|(signature, _)| msgs::FundingSigned {
3522-
channel_id: self.channel_id(),
3523-
signature,
3524-
#[cfg(taproot)]
3525-
partial_signature_with_nonce: None,
3526-
})
3527-
.ok();
3528-
3529-
if funding_signed.is_none() {
3530-
#[cfg(not(async_signing))] {
3531-
panic!("Failed to get signature for funding_signed");
3532-
}
3533-
#[cfg(async_signing)] {
3534-
log_trace!(logger, "Counterparty commitment signature not available for funding_signed message; setting signer_pending_funding");
3535-
self.signer_pending_funding = true;
3536-
}
3537-
} else if self.signer_pending_funding {
3538-
log_trace!(logger, "Counterparty commitment signature available for funding_signed message; clearing signer_pending_funding");
3539-
self.signer_pending_funding = false;
3540-
}
3541-
3542-
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
3543-
(counterparty_initial_commitment_tx, funding_signed)
3544-
},
3519+
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_counterparty_commitment(
3520+
&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx
3521+
).ok(),
35453522
// TODO (taproot|arik)
35463523
#[cfg(taproot)]
35473524
_ => todo!()
3525+
};
3526+
3527+
if signature.is_some() && self.signer_pending_funding {
3528+
log_trace!(logger, "Counterparty commitment signature available for funding_signed message; clearing signer_pending_funding");
3529+
self.signer_pending_funding = false;
3530+
} else if signature.is_none() {
3531+
#[cfg(not(async_signing))] {
3532+
panic!("Failed to get signature for funding_signed");
3533+
}
3534+
#[cfg(async_signing)] {
3535+
log_trace!(logger, "Counterparty commitment signature not available for funding_signed message; setting signer_pending_funding");
3536+
self.signer_pending_funding = true;
3537+
}
35483538
}
3539+
3540+
let funding_signed = signature.map(|(signature, _)| msgs::FundingSigned {
3541+
channel_id: self.channel_id(),
3542+
signature,
3543+
#[cfg(taproot)]
3544+
partial_signature_with_nonce: None,
3545+
});
3546+
3547+
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
3548+
(counterparty_initial_commitment_tx, funding_signed)
35493549
}
35503550

35513551
/// If we receive an error message when attempting to open a channel, it may only be a rejection
@@ -5543,8 +5543,6 @@ impl<SP: Deref> Channel<SP> where
55435543
// CS before we have any commitment point available. Blocking our
55445544
// RAA here is a convenient way to make sure that post-funding
55455545
// we're only ever waiting on one commitment point at a time.
5546-
log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment point is not available",
5547-
&self.context.channel_id(), self.context.holder_commitment_point.transaction_number());
55485546
self.context.signer_pending_revoke_and_ack = true;
55495547
None
55505548
}
@@ -7651,19 +7649,27 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
76517649
// TODO (taproot|arik): move match into calling method for Taproot
76527650
ChannelSignerType::Ecdsa(ecdsa) => {
76537651
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.context.secp_ctx)
7654-
.map(|(sig, _)| sig).ok()?
7652+
.map(|(sig, _)| sig).ok()
76557653
},
76567654
// TODO (taproot|arik)
76577655
#[cfg(taproot)]
76587656
_ => todo!()
76597657
};
76607658

7661-
if self.context.signer_pending_funding {
7659+
if signature.is_some() && self.context.signer_pending_funding {
76627660
log_trace!(logger, "Counterparty commitment signature ready for funding_created message: clearing signer_pending_funding");
76637661
self.context.signer_pending_funding = false;
7664-
}
7662+
} else if signature.is_none() {
7663+
#[cfg(not(async_signing))] {
7664+
panic!("Failed to get signature for new funding creation");
7665+
}
7666+
#[cfg(async_signing)] {
7667+
log_trace!(logger, "funding_created awaiting signer; setting signer_pending_funding");
7668+
self.context.signer_pending_funding = true;
7669+
}
7670+
};
76657671

7666-
Some(msgs::FundingCreated {
7672+
signature.map(|signature| msgs::FundingCreated {
76677673
temporary_channel_id: self.context.temporary_channel_id.unwrap(),
76687674
funding_txid: self.context.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().txid,
76697675
funding_output_index: self.context.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().index,
@@ -7719,18 +7725,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
77197725
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
77207726

77217727
let funding_created = self.get_funding_created_msg(logger);
7722-
if funding_created.is_none() {
7723-
#[cfg(not(async_signing))] {
7724-
panic!("Failed to get signature for new funding creation");
7725-
}
7726-
#[cfg(async_signing)] {
7727-
if !self.context.signer_pending_funding {
7728-
log_trace!(logger, "funding_created awaiting signer; setting signer_pending_funding");
7729-
self.context.signer_pending_funding = true;
7730-
}
7731-
}
7732-
}
7733-
77347728
Ok(funding_created)
77357729
}
77367730

@@ -7948,7 +7942,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
79487942
} else { None };
79497943
let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() {
79507944
log_trace!(logger, "Attempting to generate pending funding created...");
7951-
self.context.signer_pending_funding = false;
79527945
self.get_funding_created_msg(logger)
79537946
} else { None };
79547947
(open_channel, funding_created)

0 commit comments

Comments
 (0)