Skip to content

Commit 0dd2745

Browse files
committed
Move setting signer flags to get_funding_created_msg
For all of our async signing logic in channel establishment v1, we set signer flags in the method where we create the raw lightning message object. To keep things consistent, this commit moves setting the signer flags to where we create funding_created, since this was being set elsewhere before. While we're doing this cleanup, this also slightly refactors our funding_signed method to move some code out of an indent, as well as removes a log to fix a nit from lightningdevkit#3152.
1 parent a217aba commit 0dd2745

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
@@ -3931,38 +3931,38 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
39313931
log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
39323932
&self.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
39333933

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

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

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

8333-
Some(msgs::FundingCreated {
8341+
signature.map(|signature| msgs::FundingCreated {
83348342
temporary_channel_id: self.context.temporary_channel_id.unwrap(),
83358343
funding_txid: self.context.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().txid,
83368344
funding_output_index: self.context.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().index,
@@ -8383,18 +8391,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
83838391
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
83848392

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

@@ -8552,7 +8548,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
85528548
} else { None };
85538549
let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() {
85548550
log_trace!(logger, "Attempting to generate pending funding created...");
8555-
self.context.signer_pending_funding = false;
85568551
self.get_funding_created_msg(logger)
85578552
} else { None };
85588553
(open_channel, funding_created)

0 commit comments

Comments
 (0)