Skip to content

Commit ceddf3c

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 8853627 commit ceddf3c

File tree

1 file changed

+39
-44
lines changed

1 file changed

+39
-44
lines changed

lightning/src/ln/channel.rs

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

3932-
match &self.holder_signer {
3932+
let signature = match &self.holder_signer {
39333933
// TODO (arik): move match into calling method for Taproot
3934-
ChannelSignerType::Ecdsa(ecdsa) => {
3935-
let funding_signed = ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx)
3936-
.map(|(signature, _)| msgs::FundingSigned {
3937-
channel_id: self.channel_id(),
3938-
signature,
3939-
#[cfg(taproot)]
3940-
partial_signature_with_nonce: None,
3941-
})
3942-
.ok();
3943-
3944-
if funding_signed.is_none() {
3945-
#[cfg(not(async_signing))] {
3946-
panic!("Failed to get signature for funding_signed");
3947-
}
3948-
#[cfg(async_signing)] {
3949-
log_trace!(logger, "Counterparty commitment signature not available for funding_signed message; setting signer_pending_funding");
3950-
self.signer_pending_funding = true;
3951-
}
3952-
} else if self.signer_pending_funding {
3953-
log_trace!(logger, "Counterparty commitment signature available for funding_signed message; clearing signer_pending_funding");
3954-
self.signer_pending_funding = false;
3955-
}
3956-
3957-
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
3958-
funding_signed
3959-
},
3934+
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_counterparty_commitment(
3935+
&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx
3936+
).ok(),
39603937
// TODO (taproot|arik)
39613938
#[cfg(taproot)]
39623939
_ => todo!()
3940+
};
3941+
3942+
if signature.is_some() && self.signer_pending_funding {
3943+
log_trace!(logger, "Counterparty commitment signature available for funding_signed message; clearing signer_pending_funding");
3944+
self.signer_pending_funding = false;
3945+
} else if signature.is_none() {
3946+
#[cfg(not(async_signing))] {
3947+
panic!("Failed to get signature for funding_signed");
3948+
}
3949+
#[cfg(async_signing)] {
3950+
log_trace!(logger, "Counterparty commitment signature not available for funding_signed message; setting signer_pending_funding");
3951+
self.signer_pending_funding = true;
3952+
}
39633953
}
3954+
3955+
let funding_signed = signature.map(|(signature, _)| msgs::FundingSigned {
3956+
channel_id: self.channel_id(),
3957+
signature,
3958+
#[cfg(taproot)]
3959+
partial_signature_with_nonce: None,
3960+
});
3961+
3962+
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
3963+
funding_signed
39643964
}
39653965

39663966
/// If we receive an error message when attempting to open a channel, it may only be a rejection
@@ -8314,19 +8314,27 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
83148314
// TODO (taproot|arik): move match into calling method for Taproot
83158315
ChannelSignerType::Ecdsa(ecdsa) => {
83168316
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.context.secp_ctx)
8317-
.map(|(sig, _)| sig).ok()?
8317+
.map(|(sig, _)| sig).ok()
83188318
},
83198319
// TODO (taproot|arik)
83208320
#[cfg(taproot)]
83218321
_ => todo!()
83228322
};
83238323

8324-
if self.context.signer_pending_funding {
8324+
if signature.is_some() && self.context.signer_pending_funding {
83258325
log_trace!(logger, "Counterparty commitment signature ready for funding_created message: clearing signer_pending_funding");
83268326
self.context.signer_pending_funding = false;
8327-
}
8327+
} else if signature.is_none() {
8328+
#[cfg(not(async_signing))] {
8329+
panic!("Failed to get signature for new funding creation");
8330+
}
8331+
#[cfg(async_signing)] {
8332+
log_trace!(logger, "funding_created awaiting signer; setting signer_pending_funding");
8333+
self.context.signer_pending_funding = true;
8334+
}
8335+
};
83288336

8329-
Some(msgs::FundingCreated {
8337+
signature.map(|signature| msgs::FundingCreated {
83308338
temporary_channel_id: self.context.temporary_channel_id.unwrap(),
83318339
funding_txid: self.context.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().txid,
83328340
funding_output_index: self.context.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().index,
@@ -8379,18 +8387,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
83798387
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
83808388

83818389
let funding_created = self.get_funding_created_msg(logger);
8382-
if funding_created.is_none() {
8383-
#[cfg(not(async_signing))] {
8384-
panic!("Failed to get signature for new funding creation");
8385-
}
8386-
#[cfg(async_signing)] {
8387-
if !self.context.signer_pending_funding {
8388-
log_trace!(logger, "funding_created awaiting signer; setting signer_pending_funding");
8389-
self.context.signer_pending_funding = true;
8390-
}
8391-
}
8392-
}
8393-
83948390
Ok(funding_created)
83958391
}
83968392

@@ -8546,7 +8542,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
85468542
};
85478543
let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() {
85488544
log_trace!(logger, "Attempting to generate pending funding created...");
8549-
self.context.signer_pending_funding = false;
85508545
self.get_funding_created_msg(logger)
85518546
} else { None };
85528547
(open_channel, funding_created)

0 commit comments

Comments
 (0)