Skip to content

Commit ad31b3e

Browse files
committed
Allow failing revoke_and_ack if commitment point is not available
1 parent e7b66f1 commit ad31b3e

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

lightning/src/ln/channel.rs

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5350,16 +5350,21 @@ impl<SP: Deref> Channel<SP> where
53505350
}
53515351

53525352
let mut raa = if self.context.monitor_pending_revoke_and_ack {
5353-
Some(self.get_last_revoke_and_ack())
5353+
self.get_last_revoke_and_ack(logger)
53545354
} else { None };
5355-
let commitment_update = if self.context.monitor_pending_commitment_signed {
5355+
let mut commitment_update = if self.context.monitor_pending_commitment_signed {
53565356
self.get_last_commitment_update_for_send(logger).ok()
53575357
} else { None };
53585358
if self.context.resend_order == RAACommitmentOrder::CommitmentFirst
53595359
&& self.context.signer_pending_commitment_update && raa.is_some() {
53605360
self.context.signer_pending_revoke_and_ack = true;
53615361
raa = None;
53625362
}
5363+
if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
5364+
&& self.context.signer_pending_revoke_and_ack {
5365+
self.context.signer_pending_commitment_update = true;
5366+
commitment_update = None;
5367+
}
53635368

53645369
if commitment_update.is_some() {
53655370
self.mark_awaiting_response();
@@ -5430,6 +5435,10 @@ impl<SP: Deref> Channel<SP> where
54305435
/// blocked.
54315436
#[cfg(async_signing)]
54325437
pub fn signer_maybe_unblocked<L: Deref>(&mut self, logger: &L) -> SignerResumeUpdates where L::Target: Logger {
5438+
if !self.context.holder_commitment_point.is_available() {
5439+
log_trace!(logger, "Attempting to update holder per-commitment point...");
5440+
self.context.holder_commitment_point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger);
5441+
}
54335442
let funding_signed = if self.context.signer_pending_funding && !self.context.is_outbound() {
54345443
log_trace!(logger, "Attempting to generate pending funding signed...");
54355444
self.context.signer_pending_funding = false;
@@ -5447,7 +5456,7 @@ impl<SP: Deref> Channel<SP> where
54475456
let mut revoke_and_ack = if self.context.signer_pending_revoke_and_ack {
54485457
log_trace!(logger, "Attempting to generate pending revoke and ack...");
54495458
self.context.signer_pending_revoke_and_ack = false;
5450-
Some(self.get_last_revoke_and_ack())
5459+
self.get_last_revoke_and_ack(logger)
54515460
} else { None };
54525461

54535462
if self.context.resend_order == RAACommitmentOrder::CommitmentFirst
@@ -5478,18 +5487,27 @@ impl<SP: Deref> Channel<SP> where
54785487
}
54795488
}
54805489

5481-
fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
5482-
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
5483-
// TODO: handle non-available case when get_per_commitment_point becomes async
5484-
debug_assert!(self.context.holder_commitment_point.is_available());
5485-
let next_per_commitment_point = self.context.holder_commitment_point.current_point();
5490+
fn get_last_revoke_and_ack<L: Deref>(&mut self, logger: &L) -> Option<msgs::RevokeAndACK> where L::Target: Logger {
5491+
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER - 2);
54865492
let per_commitment_secret = self.context.holder_signer.as_ref().release_commitment_secret(self.context.holder_commitment_point.transaction_number() + 2);
5487-
msgs::RevokeAndACK {
5488-
channel_id: self.context.channel_id,
5489-
per_commitment_secret,
5490-
next_per_commitment_point,
5491-
#[cfg(taproot)]
5492-
next_local_nonce: None,
5493+
if let HolderCommitmentPoint::Available { transaction_number: _, current, next: _ } = self.context.holder_commitment_point {
5494+
Some(msgs::RevokeAndACK {
5495+
channel_id: self.context.channel_id,
5496+
per_commitment_secret,
5497+
next_per_commitment_point: current,
5498+
#[cfg(taproot)]
5499+
next_local_nonce: None,
5500+
})
5501+
} else {
5502+
#[cfg(not(async_signing))] {
5503+
panic!("Holder commitment point must be Available when generating revoke_and_ack");
5504+
}
5505+
#[cfg(async_signing)] {
5506+
log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment point is not available",
5507+
&self.context.channel_id(), self.context.holder_commitment_point.transaction_number());
5508+
self.context.signer_pending_revoke_and_ack = true;
5509+
None
5510+
}
54935511
}
54945512
}
54955513

@@ -5691,7 +5709,7 @@ impl<SP: Deref> Channel<SP> where
56915709
self.context.monitor_pending_revoke_and_ack = true;
56925710
None
56935711
} else {
5694-
Some(self.get_last_revoke_and_ack())
5712+
self.get_last_revoke_and_ack(logger)
56955713
}
56965714
} else {
56975715
debug_assert!(false, "All values should have been handled in the four cases above");
@@ -5718,7 +5736,7 @@ impl<SP: Deref> Channel<SP> where
57185736
} else { None };
57195737

57205738
if msg.next_local_commitment_number == next_counterparty_commitment_number {
5721-
if required_revoke.is_some() {
5739+
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
57225740
log_debug!(logger, "Reconnected channel {} with only lost outbound RAA", &self.context.channel_id());
57235741
} else {
57245742
log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
@@ -5731,7 +5749,7 @@ impl<SP: Deref> Channel<SP> where
57315749
order: self.context.resend_order.clone(),
57325750
})
57335751
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
5734-
if required_revoke.is_some() {
5752+
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
57355753
log_debug!(logger, "Reconnected channel {} with lost outbound RAA and lost remote commitment tx", &self.context.channel_id());
57365754
} else {
57375755
log_debug!(logger, "Reconnected channel {} with only lost remote commitment tx", &self.context.channel_id());
@@ -5745,7 +5763,14 @@ impl<SP: Deref> Channel<SP> where
57455763
order: self.context.resend_order.clone(),
57465764
})
57475765
} else {
5748-
let commitment_update = self.get_last_commitment_update_for_send(logger).ok();
5766+
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
5767+
&& self.context.signer_pending_revoke_and_ack {
5768+
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());
5769+
self.context.signer_pending_commitment_update = true;
5770+
None
5771+
} else {
5772+
self.get_last_commitment_update_for_send(logger).ok()
5773+
};
57495774
let raa = if self.context.resend_order == RAACommitmentOrder::CommitmentFirst
57505775
&& self.context.signer_pending_commitment_update && required_revoke.is_some() {
57515776
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)