Skip to content

Commit 20ebcd3

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 4282345 commit 20ebcd3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8196,6 +8196,7 @@ impl<
81968196
&&logger,
81978197
),
81988198
htlc_id,
8199+
monitor_event_source,
81998200
))
82008201
} else {
82018202
self.forwarding_channel_not_found(
@@ -8228,7 +8229,7 @@ impl<
82288229
monitor_event_source,
82298230
&&logger,
82308231
);
8231-
Some((res, htlc_id))
8232+
Some((res, htlc_id, monitor_event_source))
82328233
} else {
82338234
self.forwarding_channel_not_found(
82348235
core::iter::once(forward_info).chain(draining_pending_forwards),
@@ -8241,8 +8242,12 @@ impl<
82418242
}
82428243
},
82438244
};
8244-
if let Some((queue_fail_htlc_res, htlc_id)) = queue_fail_htlc_res {
8245+
if let Some((queue_fail_htlc_res, htlc_id, monitor_event_source)) = queue_fail_htlc_res
8246+
{
82458247
if let Err(e) = queue_fail_htlc_res {
8248+
if let Some(source) = monitor_event_source {
8249+
self.chain_monitor.ack_monitor_event(source);
8250+
}
82468251
if let ChannelError::Ignore(msg) = e {
82478252
if let Some(chan) = peer_state
82488253
.channel_by_id

0 commit comments

Comments
 (0)