Skip to content

Commit 8972f05

Browse files
Ack all monitor events besides HTLCUpdate
Currently, the resolution of HTLCs (and decisions on when HTLCs can be forwarded) is the responsibility of Channel objects (a part of ChannelManager) until the channel is closed, and then the ChannelMonitor thereafter. This leads to some complexity around race conditions for HTLCs right around channel closure. Additionally, there is lots of complexity reconstructing the state of all HTLCs in the ChannelManager deserialization/loading logic. Instead, we want to do all resolution in ChannelMonitors (in response to ChannelMonitorUpdates) and pass them back to ChannelManager in the form of MonitorEvents (similar to how HTLCs are resolved after channels are closed). In order to have reliable resolution, we'll need to keep MonitorEvents around in the ChannelMonitor until the ChannelManager has finished processing them. This will simplify things - on restart instead of examining the set of HTLCs in monitors we can simply replay all the pending MonitorEvents. Here we take care of the monitor events that are trivial to ACK, since all except HTLCEvents can be ACK'd immediately after the event is handled and don't need to be re-processed on startup.
1 parent 5de2515 commit 8972f05

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13267,7 +13267,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1326713267
for (funding_outpoint, channel_id, mut monitor_events, counterparty_node_id) in
1326813268
pending_monitor_events.drain(..)
1326913269
{
13270-
for (_event_id, monitor_event) in monitor_events.drain(..) {
13270+
for (event_id, monitor_event) in monitor_events.drain(..) {
13271+
let monitor_event_source = MonitorEventSource { event_id, channel_id };
1327113272
match monitor_event {
1327213273
MonitorEvent::HTLCEvent(htlc_update) => {
1327313274
let logger = WithContext::from(
@@ -13350,6 +13351,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1335013351
failed_channels.push((Err(e), counterparty_node_id));
1335113352
}
1335213353
}
13354+
// Channel close monitor events do not need to be replayed on startup because we
13355+
// already check the monitors to see if the channel is closed.
13356+
self.chain_monitor.ack_monitor_event(monitor_event_source);
1335313357
},
1335413358
MonitorEvent::CommitmentTxConfirmed(_) => {
1335513359
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -13371,13 +13375,17 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1337113375
failed_channels.push((Err(e), counterparty_node_id));
1337213376
}
1337313377
}
13378+
// Channel close monitor events do not need to be replayed on startup because we
13379+
// already check the monitors to see if the channel is closed.
13380+
self.chain_monitor.ack_monitor_event(monitor_event_source);
1337413381
},
1337513382
MonitorEvent::Completed { channel_id, monitor_update_id, .. } => {
1337613383
self.channel_monitor_updated(
1337713384
&channel_id,
1337813385
Some(monitor_update_id),
1337913386
&counterparty_node_id,
1338013387
);
13388+
self.chain_monitor.ack_monitor_event(monitor_event_source);
1338113389
},
1338213390
}
1338313391
}

0 commit comments

Comments
 (0)