Skip to content

Commit be9dec6

Browse files
committed
Allow failing revoke_and_ack if commitment point is not available
1 parent e784104 commit be9dec6

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

lightning/src/ln/channel.rs

+44-19
Original file line numberDiff line numberDiff line change
@@ -5363,16 +5363,21 @@ impl<SP: Deref> Channel<SP> where
53635363
}
53645364

53655365
let mut raa = if self.context.monitor_pending_revoke_and_ack {
5366-
Some(self.get_last_revoke_and_ack())
5366+
self.get_last_revoke_and_ack(logger)
53675367
} else { None };
5368-
let commitment_update = if self.context.monitor_pending_commitment_signed {
5368+
let mut commitment_update = if self.context.monitor_pending_commitment_signed {
53695369
self.get_last_commitment_update_for_send(logger).ok()
53705370
} else { None };
53715371
if self.context.resend_order == RAACommitmentOrder::CommitmentFirst
53725372
&& self.context.signer_pending_commitment_update && raa.is_some() {
53735373
self.context.signer_pending_revoke_and_ack = true;
53745374
raa = None;
53755375
}
5376+
if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
5377+
&& self.context.signer_pending_revoke_and_ack {
5378+
self.context.signer_pending_commitment_update = true;
5379+
commitment_update = None;
5380+
}
53765381

53775382
if commitment_update.is_some() {
53785383
self.mark_awaiting_response();
@@ -5443,6 +5448,10 @@ impl<SP: Deref> Channel<SP> where
54435448
/// blocked.
54445449
#[cfg(async_signing)]
54455450
pub fn signer_maybe_unblocked<L: Deref>(&mut self, logger: &L) -> SignerResumeUpdates where L::Target: Logger {
5451+
if !self.context.holder_commitment_point.is_available() {
5452+
log_trace!(logger, "Attempting to update holder per-commitment point...");
5453+
self.context.holder_commitment_point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger);
5454+
}
54465455
let funding_signed = if self.context.signer_pending_funding && !self.context.is_outbound() {
54475456
self.context.get_funding_signed_msg(logger).1
54485457
} else { None };
@@ -5456,7 +5465,7 @@ impl<SP: Deref> Channel<SP> where
54565465
} else { None };
54575466
let mut revoke_and_ack = if self.context.signer_pending_revoke_and_ack {
54585467
log_trace!(logger, "Attempting to generate pending revoke and ack...");
5459-
Some(self.get_last_revoke_and_ack())
5468+
self.get_last_revoke_and_ack(logger)
54605469
} else { None };
54615470

54625471
if self.context.resend_order == RAACommitmentOrder::CommitmentFirst
@@ -5488,19 +5497,28 @@ impl<SP: Deref> Channel<SP> where
54885497
}
54895498
}
54905499

5491-
fn get_last_revoke_and_ack(&mut self) -> msgs::RevokeAndACK {
5492-
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
5493-
// TODO: handle non-available case when get_per_commitment_point becomes async
5494-
debug_assert!(self.context.holder_commitment_point.is_available());
5495-
let next_per_commitment_point = self.context.holder_commitment_point.current_point();
5500+
fn get_last_revoke_and_ack<L: Deref>(&mut self, logger: &L) -> Option<msgs::RevokeAndACK> where L::Target: Logger {
5501+
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER - 2);
54965502
let per_commitment_secret = self.context.holder_signer.as_ref().release_commitment_secret(self.context.holder_commitment_point.transaction_number() + 2);
5497-
self.context.signer_pending_revoke_and_ack = false;
5498-
msgs::RevokeAndACK {
5499-
channel_id: self.context.channel_id,
5500-
per_commitment_secret,
5501-
next_per_commitment_point,
5502-
#[cfg(taproot)]
5503-
next_local_nonce: None,
5503+
if let HolderCommitmentPoint::Available { transaction_number: _, current, next: _ } = self.context.holder_commitment_point {
5504+
self.context.signer_pending_revoke_and_ack = false;
5505+
Some(msgs::RevokeAndACK {
5506+
channel_id: self.context.channel_id,
5507+
per_commitment_secret,
5508+
next_per_commitment_point: current,
5509+
#[cfg(taproot)]
5510+
next_local_nonce: None,
5511+
})
5512+
} else {
5513+
#[cfg(not(async_signing))] {
5514+
panic!("Holder commitment point must be Available when generating revoke_and_ack");
5515+
}
5516+
#[cfg(async_signing)] {
5517+
log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment point is not available",
5518+
&self.context.channel_id(), self.context.holder_commitment_point.transaction_number());
5519+
self.context.signer_pending_revoke_and_ack = true;
5520+
None
5521+
}
55045522
}
55055523
}
55065524

@@ -5708,7 +5726,7 @@ impl<SP: Deref> Channel<SP> where
57085726
self.context.monitor_pending_revoke_and_ack = true;
57095727
None
57105728
} else {
5711-
Some(self.get_last_revoke_and_ack())
5729+
self.get_last_revoke_and_ack(logger)
57125730
}
57135731
} else {
57145732
debug_assert!(false, "All values should have been handled in the four cases above");
@@ -5735,7 +5753,7 @@ impl<SP: Deref> Channel<SP> where
57355753
} else { None };
57365754

57375755
if msg.next_local_commitment_number == next_counterparty_commitment_number {
5738-
if required_revoke.is_some() {
5756+
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
57395757
log_debug!(logger, "Reconnected channel {} with only lost outbound RAA", &self.context.channel_id());
57405758
} else {
57415759
log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
@@ -5748,7 +5766,7 @@ impl<SP: Deref> Channel<SP> where
57485766
order: self.context.resend_order.clone(),
57495767
})
57505768
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
5751-
if required_revoke.is_some() {
5769+
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
57525770
log_debug!(logger, "Reconnected channel {} with lost outbound RAA and lost remote commitment tx", &self.context.channel_id());
57535771
} else {
57545772
log_debug!(logger, "Reconnected channel {} with only lost remote commitment tx", &self.context.channel_id());
@@ -5762,7 +5780,14 @@ impl<SP: Deref> Channel<SP> where
57625780
order: self.context.resend_order.clone(),
57635781
})
57645782
} else {
5765-
let commitment_update = self.get_last_commitment_update_for_send(logger).ok();
5783+
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
5784+
&& self.context.signer_pending_revoke_and_ack {
5785+
log_trace!(logger, "Reconnected channel {} with lost outbound RAA and lost remote commitment tx, but unable to send due to resend order, waiting on signer for revoke and ack", &self.context.channel_id());
5786+
self.context.signer_pending_commitment_update = true;
5787+
None
5788+
} else {
5789+
self.get_last_commitment_update_for_send(logger).ok()
5790+
};
57665791
let raa = if self.context.resend_order == RAACommitmentOrder::CommitmentFirst
57675792
&& self.context.signer_pending_commitment_update && required_revoke.is_some() {
57685793
log_trace!(logger, "Reconnected channel {} with lost outbound RAA and lost remote commitment tx, but unable to send due to resend order, waiting on signer for commitment update", &self.context.channel_id());

0 commit comments

Comments
 (0)