Skip to content

Commit ebae20c

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 7ccafd1 commit ebae20c

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
@@ -2084,6 +2084,31 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
20842084
self.update_time_counter += 1;
20852085
(monitor_update, dropped_outbound_htlcs, unbroadcasted_batch_funding_txid)
20862086
}
2087+
2088+
/// Only allowed after [`Self::channel_transaction_parameters`] is set.
2089+
fn get_funding_created_msg<L: Deref>(&mut self, logger: &L) -> Option<msgs::FundingCreated> where L::Target: Logger {
2090+
let counterparty_keys = self.build_remote_transaction_keys();
2091+
let counterparty_initial_commitment_tx = self.build_commitment_transaction(self.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
2092+
let signature = match &self.holder_signer {
2093+
// TODO (taproot|arik): move match into calling method for Taproot
2094+
ChannelSignerType::Ecdsa(ecdsa) => {
2095+
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
2096+
.map(|(sig, _)| sig).ok()?
2097+
}
2098+
};
2099+
2100+
self.signer_pending_funding = false;
2101+
Some(msgs::FundingCreated {
2102+
temporary_channel_id: self.temporary_channel_id.unwrap(),
2103+
funding_txid: self.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().txid,
2104+
funding_output_index: self.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().index,
2105+
signature,
2106+
#[cfg(taproot)]
2107+
partial_signature_with_nonce: None,
2108+
#[cfg(taproot)]
2109+
next_local_nonce: None,
2110+
})
2111+
}
20872112
}
20882113

20892114
// Internal utility functions for channels
@@ -3909,7 +3934,9 @@ impl<SP: Deref> Channel<SP> where
39093934
None
39103935
} else { None };
39113936
let funding_signed = None;
3912-
let funding_created = None;
3937+
let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() {
3938+
self.context.get_funding_created_msg(logger)
3939+
} else { None };
39133940
SignerResumeUpdates {
39143941
commitment_update,
39153942
funding_signed,
@@ -5939,18 +5966,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
59395966
})
59405967
}
59415968

5942-
fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ()> where L::Target: Logger {
5943-
let counterparty_keys = self.context.build_remote_transaction_keys();
5944-
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
5945-
match &self.context.holder_signer {
5946-
// TODO (taproot|arik): move match into calling method for Taproot
5947-
ChannelSignerType::Ecdsa(ecdsa) => {
5948-
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5949-
.map(|(sig, _)| sig)
5950-
}
5951-
}
5952-
}
5953-
59545969
/// Updates channel state with knowledge of the funding transaction's txid/index, and generates
59555970
/// a funding_created message for the remote peer.
59565971
/// Panics if called at some time other than immediately after initial handshake, if called twice,
@@ -5993,21 +6008,10 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
59936008
self.context.funding_transaction = Some(funding_transaction);
59946009
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
59956010

5996-
let funding_created = if let Ok(signature) = self.get_funding_created_signature(logger) {
5997-
Some(msgs::FundingCreated {
5998-
temporary_channel_id,
5999-
funding_txid: funding_txo.txid,
6000-
funding_output_index: funding_txo.index,
6001-
signature,
6002-
#[cfg(taproot)]
6003-
partial_signature_with_nonce: None,
6004-
#[cfg(taproot)]
6005-
next_local_nonce: None,
6006-
})
6007-
} else {
6011+
let funding_created = self.context.get_funding_created_msg(logger);
6012+
if funding_created.is_none() {
60086013
self.context.signer_pending_funding = true;
6009-
None
6010-
};
6014+
}
60116015

60126016
let channel = Channel {
60136017
context: self.context,

0 commit comments

Comments
 (0)