Skip to content

Commit 0ece3d6

Browse files
Ack monitor events if CommitmentSecret was blocked
If we stored a monitor event id with a pending inbound HTLC and that HTLC is about to be fully removed from the channel via revoke_and_ack, we should ack the monitor event corresponding to that id when the monitor update associated with the RAA is complete. We do this so the monitor event will keep being re-provided to us on startup until the HTLC is removed, to ensure the HTLC gets resolved even if we lose the holding cell.
1 parent f73aa93 commit 0ece3d6

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,10 +1480,18 @@ pub(crate) const CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY: u32 = 144;
14801480
#[derive(Debug)]
14811481
struct PendingChannelMonitorUpdate {
14821482
update: ChannelMonitorUpdate,
1483+
monitor_events_to_ack: Vec<MonitorEventSource>,
1484+
}
1485+
1486+
impl PendingChannelMonitorUpdate {
1487+
fn new(update: ChannelMonitorUpdate) -> Self {
1488+
Self { update, monitor_events_to_ack: Vec::new() }
1489+
}
14831490
}
14841491

14851492
impl_writeable_tlv_based!(PendingChannelMonitorUpdate, {
14861493
(0, update, required),
1494+
(1, monitor_events_to_ack, optional_vec),
14871495
});
14881496

14891497
/// A payment channel with a counterparty throughout its life-cycle, encapsulating negotiation and
@@ -7707,7 +7715,7 @@ where
77077715
let update = self.build_commitment_no_status_check(logger);
77087716
self.context
77097717
.blocked_monitor_updates
7710-
.push(PendingChannelMonitorUpdate { update });
7718+
.push(PendingChannelMonitorUpdate::new(update));
77117719
}
77127720
}
77137721

@@ -9250,9 +9258,10 @@ where
92509258
($htlcs_to_fail: expr) => {
92519259
let events_to_ack = core::mem::take(&mut monitor_events_to_ack);
92529260
if !release_monitor {
9253-
self.context
9254-
.blocked_monitor_updates
9255-
.push(PendingChannelMonitorUpdate { update: monitor_update });
9261+
self.context.blocked_monitor_updates.push(PendingChannelMonitorUpdate {
9262+
update: monitor_update,
9263+
monitor_events_to_ack: events_to_ack,
9264+
});
92569265
return Ok(($htlcs_to_fail, static_invoices, None));
92579266
} else {
92589267
return Ok((
@@ -11347,14 +11356,15 @@ where
1134711356

1134811357
/// Returns the next blocked monitor update, if one exists, and a bool which indicates a
1134911358
/// further blocked monitor update exists after the next.
11350-
pub fn unblock_next_blocked_monitor_update(&mut self) -> Option<(ChannelMonitorUpdate, bool)> {
11359+
pub fn unblock_next_blocked_monitor_update(
11360+
&mut self,
11361+
) -> Option<(ChannelMonitorUpdate, Vec<MonitorEventSource>, bool)> {
1135111362
if self.context.blocked_monitor_updates.is_empty() {
1135211363
return None;
1135311364
}
11354-
Some((
11355-
self.context.blocked_monitor_updates.remove(0).update,
11356-
!self.context.blocked_monitor_updates.is_empty(),
11357-
))
11365+
let PendingChannelMonitorUpdate { update, monitor_events_to_ack } =
11366+
self.context.blocked_monitor_updates.remove(0);
11367+
Some((update, monitor_events_to_ack, !self.context.blocked_monitor_updates.is_empty()))
1135811368
}
1135911369

1136011370
/// Pushes a new monitor update into our monitor update queue, returning it if it should be
@@ -11364,9 +11374,7 @@ where
1136411374
-> Option<ChannelMonitorUpdate> {
1136511375
let release_monitor = self.context.blocked_monitor_updates.is_empty();
1136611376
if !release_monitor {
11367-
self.context.blocked_monitor_updates.push(PendingChannelMonitorUpdate {
11368-
update,
11369-
});
11377+
self.context.blocked_monitor_updates.push(PendingChannelMonitorUpdate::new(update));
1137011378
None
1137111379
} else {
1137211380
Some(update)

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15372,9 +15372,18 @@ impl<
1537215372
channel_id) {
1537315373
if let Some(chan) = chan_entry.get_mut().as_funded_mut() {
1537415374
let channel_funding_outpoint = chan.funding_outpoint();
15375-
if let Some((monitor_update, further_update_exists)) = chan.unblock_next_blocked_monitor_update() {
15375+
if let Some((monitor_update, mon_events_to_ack, further_update_exists)) = chan.unblock_next_blocked_monitor_update() {
1537615376
log_debug!(logger, "Unlocking monitor updating and updating monitor",
1537715377
);
15378+
if !mon_events_to_ack.is_empty() {
15379+
peer_state
15380+
.monitor_update_blocked_actions
15381+
.entry(channel_id)
15382+
.or_default()
15383+
.push(MonitorUpdateCompletionAction::AckMonitorEvents {
15384+
event_ids: mon_events_to_ack,
15385+
});
15386+
}
1537815387
let post_update_data = self.handle_new_monitor_update(
1537915388
&mut peer_state.in_flight_monitor_updates,
1538015389
&mut peer_state.monitor_update_blocked_actions,

0 commit comments

Comments
 (0)