Skip to content

Commit 2a93da1

Browse files
Ack monitor events when failing-to-fail-backwards
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 build on recent commits by ACK'ing monitor events for forward failures if we go to fail on the inbound edge and get an error when queueing the backwards failure. If we get an error in this case it means the failure is duplicate or the channel is closed, and in either case it's fine to mark the event as resolved.
1 parent 8c95410 commit 2a93da1

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8224,6 +8224,7 @@ impl<
82248224
&&logger,
82258225
),
82268226
htlc_id,
8227+
monitor_event_source,
82278228
))
82288229
} else {
82298230
self.forwarding_channel_not_found(
@@ -8256,7 +8257,7 @@ impl<
82568257
monitor_event_source,
82578258
&&logger,
82588259
);
8259-
Some((res, htlc_id))
8260+
Some((res, htlc_id, monitor_event_source))
82608261
} else {
82618262
self.forwarding_channel_not_found(
82628263
core::iter::once(forward_info).chain(draining_pending_forwards),
@@ -8269,8 +8270,12 @@ impl<
82698270
}
82708271
},
82718272
};
8272-
if let Some((queue_fail_htlc_res, htlc_id)) = queue_fail_htlc_res {
8273+
if let Some((queue_fail_htlc_res, htlc_id, monitor_event_source)) = queue_fail_htlc_res
8274+
{
82738275
if let Err(e) = queue_fail_htlc_res {
8276+
if let Some(source) = monitor_event_source {
8277+
self.chain_monitor.ack_monitor_event(source);
8278+
}
82748279
if let ChannelError::Ignore(msg) = e {
82758280
if let Some(chan) = peer_state
82768281
.channel_by_id

0 commit comments

Comments
 (0)