Skip to content

Commit 2c4872b

Browse files
TheBlueMattwaterson
authored andcommitted
Handle retrying sign_counterparty_commitment outb funding failures
If sign_counterparty_commitment fails (i.e. because the signer is temporarily disconnected), this really indicates that we should retry the message sending which required the signature later, rather than force-closing the channel (which probably won't even work if the signer is missing). This commit adds retrying of outbound funding_created signing failures, regenerating the `FundingCreated` message, attempting to re-sign, and sending it to our peers if we succeed.
1 parent b8db8cd commit 2c4872b

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

lightning/src/ln/channel.rs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,31 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
20252025
self.update_time_counter += 1;
20262026
(monitor_update, dropped_outbound_htlcs)
20272027
}
2028+
2029+
/// Only allowed after [`Self::channel_transaction_parameters`] is set.
2030+
fn get_funding_created_msg<L: Deref>(&mut self, logger: &L) -> Option<msgs::FundingCreated> where L::Target: Logger {
2031+
let counterparty_keys = self.build_remote_transaction_keys();
2032+
let counterparty_initial_commitment_tx = self.build_commitment_transaction(self.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
2033+
let signature = match &self.holder_signer {
2034+
// TODO (taproot|arik): move match into calling method for Taproot
2035+
ChannelSignerType::Ecdsa(ecdsa) => {
2036+
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
2037+
.map(|(sig, _)| sig).ok()?
2038+
}
2039+
};
2040+
2041+
self.signer_pending_funding = false;
2042+
Some(msgs::FundingCreated {
2043+
temporary_channel_id: self.temporary_channel_id.unwrap(),
2044+
funding_txid: self.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().txid,
2045+
funding_output_index: self.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().index,
2046+
signature,
2047+
#[cfg(taproot)]
2048+
partial_signature_with_nonce: None,
2049+
#[cfg(taproot)]
2050+
next_local_nonce: None,
2051+
})
2052+
}
20282053
}
20292054

20302055
// Internal utility functions for channels
@@ -3830,7 +3855,9 @@ impl<SP: Deref> Channel<SP> where
38303855
None
38313856
} else { None };
38323857
let funding_signed = None;
3833-
let funding_created = None;
3858+
let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() {
3859+
self.context.get_funding_created_msg(logger)
3860+
} else { None };
38343861
SignerResumeUpdates {
38353862
commitment_update,
38363863
funding_signed,
@@ -5853,18 +5880,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
58535880
})
58545881
}
58555882

5856-
fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ()> where L::Target: Logger {
5857-
let counterparty_keys = self.context.build_remote_transaction_keys();
5858-
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
5859-
match &self.context.holder_signer {
5860-
// TODO (taproot|arik): move match into calling method for Taproot
5861-
ChannelSignerType::Ecdsa(ecdsa) => {
5862-
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5863-
.map(|(sig, _)| sig)
5864-
}
5865-
}
5866-
}
5867-
58685883
/// Updates channel state with knowledge of the funding transaction's txid/index, and generates
58695884
/// a funding_created message for the remote peer.
58705885
/// Panics if called at some time other than immediately after initial handshake, if called twice,
@@ -5906,21 +5921,10 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
59065921

59075922
self.context.funding_transaction = Some(funding_transaction);
59085923

5909-
let funding_created = if let Ok(signature) = self.get_funding_created_signature(logger) {
5910-
Some(msgs::FundingCreated {
5911-
temporary_channel_id,
5912-
funding_txid: funding_txo.txid,
5913-
funding_output_index: funding_txo.index,
5914-
signature,
5915-
#[cfg(taproot)]
5916-
partial_signature_with_nonce: None,
5917-
#[cfg(taproot)]
5918-
next_local_nonce: None,
5919-
})
5920-
} else {
5924+
let funding_created = self.context.get_funding_created_msg(logger);
5925+
if funding_created.is_none() {
59215926
self.context.signer_pending_funding = true;
5922-
None
5923-
};
5927+
}
59245928

59255929
let channel = Channel {
59265930
context: self.context,

0 commit comments

Comments
 (0)