Skip to content

Commit 58f985c

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 a2a1882 commit 58f985c

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
@@ -8316,19 +8316,27 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
83168316
// TODO (taproot|arik): move match into calling method for Taproot
83178317
ChannelSignerType::Ecdsa(ecdsa) => {
83188318
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.context.secp_ctx)
8319-
.map(|(sig, _)| sig).ok()?
8319+
.map(|(sig, _)| sig).ok()
83208320
},
83218321
// TODO (taproot|arik)
83228322
#[cfg(taproot)]
83238323
_ => todo!()
83248324
};
83258325

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

8331-
Some(msgs::FundingCreated {
8339+
signature.map(|signature| msgs::FundingCreated {
83328340
temporary_channel_id: self.context.temporary_channel_id.unwrap(),
83338341
funding_txid: self.context.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().txid,
83348342
funding_output_index: self.context.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().index,
@@ -8381,18 +8389,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
83818389
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
83828390

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

@@ -8548,7 +8544,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
85488544
};
85498545
let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() {
85508546
log_trace!(logger, "Attempting to generate pending funding created...");
8551-
self.context.signer_pending_funding = false;
85528547
self.get_funding_created_msg(logger)
85538548
} else { None };
85548549
(open_channel, funding_created)

0 commit comments

Comments
 (0)