Skip to content

Commit f3ad743

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 84a7762 commit f3ad743

File tree

1 file changed

+37
-44
lines changed

1 file changed

+37
-44
lines changed

lightning/src/ln/channel.rs

+37-44
Original file line numberDiff line numberDiff line change
@@ -3931,38 +3931,36 @@ 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+
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
3935+
let signature = match &self.holder_signer {
39353936
// 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-
},
3937+
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_counterparty_commitment(
3938+
&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx
3939+
).ok(),
39623940
// TODO (taproot|arik)
39633941
#[cfg(taproot)]
39643942
_ => todo!()
3943+
};
3944+
3945+
if signature.is_some() && self.signer_pending_funding {
3946+
log_trace!(logger, "Counterparty commitment signature available for funding_signed message; clearing signer_pending_funding");
3947+
self.signer_pending_funding = false;
3948+
} else if signature.is_none() {
3949+
#[cfg(not(async_signing))] {
3950+
panic!("Failed to get signature for funding_signed");
3951+
}
3952+
#[cfg(async_signing)] {
3953+
log_trace!(logger, "Counterparty commitment signature not available for funding_signed message; setting signer_pending_funding");
3954+
self.signer_pending_funding = true;
3955+
}
39653956
}
3957+
3958+
signature.map(|(signature, _)| msgs::FundingSigned {
3959+
channel_id: self.channel_id(),
3960+
signature,
3961+
#[cfg(taproot)]
3962+
partial_signature_with_nonce: None,
3963+
})
39663964
}
39673965

39683966
/// If we receive an error message when attempting to open a channel, it may only be a rejection
@@ -8318,19 +8316,27 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
83188316
// TODO (taproot|arik): move match into calling method for Taproot
83198317
ChannelSignerType::Ecdsa(ecdsa) => {
83208318
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.context.secp_ctx)
8321-
.map(|(sig, _)| sig).ok()?
8319+
.map(|(sig, _)| sig).ok()
83228320
},
83238321
// TODO (taproot|arik)
83248322
#[cfg(taproot)]
83258323
_ => todo!()
83268324
};
83278325

8328-
if self.context.signer_pending_funding {
8326+
if signature.is_some() && self.context.signer_pending_funding {
83298327
log_trace!(logger, "Counterparty commitment signature ready for funding_created message: clearing signer_pending_funding");
83308328
self.context.signer_pending_funding = false;
8331-
}
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+
};
83328338

8333-
Some(msgs::FundingCreated {
8339+
signature.map(|signature| msgs::FundingCreated {
83348340
temporary_channel_id: self.context.temporary_channel_id.unwrap(),
83358341
funding_txid: self.context.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().txid,
83368342
funding_output_index: self.context.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().index,
@@ -8383,18 +8389,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
83838389
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
83848390

83858391
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-
83988392
Ok(funding_created)
83998393
}
84008394

@@ -8552,7 +8546,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
85528546
} else { None };
85538547
let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() {
85548548
log_trace!(logger, "Attempting to generate pending funding created...");
8555-
self.context.signer_pending_funding = false;
85568549
self.get_funding_created_msg(logger)
85578550
} else { None };
85588551
(open_channel, funding_created)

0 commit comments

Comments
 (0)