Skip to content

Commit 400ad00

Browse files
committed
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 97ffbeb commit 400ad00

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
@@ -1996,6 +1996,31 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19961996
self.update_time_counter += 1;
19971997
(monitor_update, dropped_outbound_htlcs)
19981998
}
1999+
2000+
/// Only allowed after [`Self::channel_transaction_parameters`] is set.
2001+
fn get_funding_created_msg<L: Deref>(&mut self, logger: &L) -> Option<msgs::FundingCreated> where L::Target: Logger {
2002+
let counterparty_keys = self.build_remote_transaction_keys();
2003+
let counterparty_initial_commitment_tx = self.build_commitment_transaction(self.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
2004+
let signature = match &self.holder_signer {
2005+
// TODO (taproot|arik): move match into calling method for Taproot
2006+
ChannelSignerType::Ecdsa(ecdsa) => {
2007+
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
2008+
.map(|(sig, _)| sig).ok()?
2009+
}
2010+
};
2011+
2012+
self.signer_pending_funding = false;
2013+
Some(msgs::FundingCreated {
2014+
temporary_channel_id: self.temporary_channel_id.unwrap(),
2015+
funding_txid: self.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().txid,
2016+
funding_output_index: self.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().index,
2017+
signature,
2018+
#[cfg(taproot)]
2019+
partial_signature_with_nonce: None,
2020+
#[cfg(taproot)]
2021+
next_local_nonce: None,
2022+
})
2023+
}
19992024
}
20002025

20012026
// Internal utility functions for channels
@@ -3806,7 +3831,9 @@ impl<SP: Deref> Channel<SP> where
38063831
None
38073832
} else { None };
38083833
let funding_signed = None;
3809-
let funding_created = None;
3834+
let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() {
3835+
self.context.get_funding_created_msg(logger)
3836+
} else { None };
38103837
SignerResumeUpdates {
38113838
commitment_update,
38123839
funding_signed,
@@ -5829,18 +5856,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
58295856
})
58305857
}
58315858

5832-
fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ()> where L::Target: Logger {
5833-
let counterparty_keys = self.context.build_remote_transaction_keys();
5834-
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
5835-
match &self.context.holder_signer {
5836-
// TODO (taproot|arik): move match into calling method for Taproot
5837-
ChannelSignerType::Ecdsa(ecdsa) => {
5838-
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5839-
.map(|(sig, _)| sig)
5840-
}
5841-
}
5842-
}
5843-
58445859
/// Updates channel state with knowledge of the funding transaction's txid/index, and generates
58455860
/// a funding_created message for the remote peer.
58465861
/// Panics if called at some time other than immediately after initial handshake, if called twice,
@@ -5882,21 +5897,10 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
58825897

58835898
self.context.funding_transaction = Some(funding_transaction);
58845899

5885-
let funding_created = if let Ok(signature) = self.get_funding_created_signature(logger) {
5886-
Some(msgs::FundingCreated {
5887-
temporary_channel_id,
5888-
funding_txid: funding_txo.txid,
5889-
funding_output_index: funding_txo.index,
5890-
signature,
5891-
#[cfg(taproot)]
5892-
partial_signature_with_nonce: None,
5893-
#[cfg(taproot)]
5894-
next_local_nonce: None,
5895-
})
5896-
} else {
5900+
let funding_created = self.context.get_funding_created_msg(logger);
5901+
if funding_created.is_none() {
58975902
self.context.signer_pending_funding = true;
5898-
None
5899-
};
5903+
}
59005904

59015905
let channel = Channel {
59025906
context: self.context,

0 commit comments

Comments
 (0)