Skip to content

Commit 2d93444

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 4e7c168 commit 2d93444

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
@@ -2096,6 +2096,31 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
20962096
self.update_time_counter += 1;
20972097
(monitor_update, dropped_outbound_htlcs, unbroadcasted_batch_funding_txid)
20982098
}
2099+
2100+
/// Only allowed after [`Self::channel_transaction_parameters`] is set.
2101+
fn get_funding_created_msg<L: Deref>(&mut self, logger: &L) -> Option<msgs::FundingCreated> where L::Target: Logger {
2102+
let counterparty_keys = self.build_remote_transaction_keys();
2103+
let counterparty_initial_commitment_tx = self.build_commitment_transaction(self.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
2104+
let signature = match &self.holder_signer {
2105+
// TODO (taproot|arik): move match into calling method for Taproot
2106+
ChannelSignerType::Ecdsa(ecdsa) => {
2107+
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
2108+
.map(|(sig, _)| sig).ok()?
2109+
}
2110+
};
2111+
2112+
self.signer_pending_funding = false;
2113+
Some(msgs::FundingCreated {
2114+
temporary_channel_id: self.temporary_channel_id.unwrap(),
2115+
funding_txid: self.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().txid,
2116+
funding_output_index: self.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().index,
2117+
signature,
2118+
#[cfg(taproot)]
2119+
partial_signature_with_nonce: None,
2120+
#[cfg(taproot)]
2121+
next_local_nonce: None,
2122+
})
2123+
}
20992124
}
21002125

21012126
// Internal utility functions for channels
@@ -3925,7 +3950,9 @@ impl<SP: Deref> Channel<SP> where
39253950
self.get_last_commitment_update_for_send(logger).ok()
39263951
} else { None };
39273952
let funding_signed = None;
3928-
let funding_created = None;
3953+
let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() {
3954+
self.context.get_funding_created_msg(logger)
3955+
} else { None };
39293956
SignerResumeUpdates {
39303957
commitment_update,
39313958
funding_signed,
@@ -5957,18 +5984,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
59575984
})
59585985
}
59595986

5960-
fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ()> where L::Target: Logger {
5961-
let counterparty_keys = self.context.build_remote_transaction_keys();
5962-
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
5963-
match &self.context.holder_signer {
5964-
// TODO (taproot|arik): move match into calling method for Taproot
5965-
ChannelSignerType::Ecdsa(ecdsa) => {
5966-
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5967-
.map(|(sig, _)| sig)
5968-
}
5969-
}
5970-
}
5971-
59725987
/// Updates channel state with knowledge of the funding transaction's txid/index, and generates
59735988
/// a funding_created message for the remote peer.
59745989
/// Panics if called at some time other than immediately after initial handshake, if called twice,
@@ -6011,21 +6026,10 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
60116026
self.context.funding_transaction = Some(funding_transaction);
60126027
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
60136028

6014-
let funding_created = if let Ok(signature) = self.get_funding_created_signature(logger) {
6015-
Some(msgs::FundingCreated {
6016-
temporary_channel_id,
6017-
funding_txid: funding_txo.txid,
6018-
funding_output_index: funding_txo.index,
6019-
signature,
6020-
#[cfg(taproot)]
6021-
partial_signature_with_nonce: None,
6022-
#[cfg(taproot)]
6023-
next_local_nonce: None,
6024-
})
6025-
} else {
6029+
let funding_created = self.context.get_funding_created_msg(logger);
6030+
if funding_created.is_none() {
60266031
self.context.signer_pending_funding = true;
6027-
None
6028-
};
6032+
}
60296033

60306034
let channel = Channel {
60316035
context: self.context,

0 commit comments

Comments
 (0)