Skip to content

Commit 45a941c

Browse files
Ack monitor event when inbound edge is closed
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 try to fail backwards and discover the inbound edge is closed. If that's the case, there's nothing for us to do as the HTLC will be resolved via timeout by the inbound edge counterparty.
1 parent e9cf62b commit 45a941c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7971,11 +7971,15 @@ impl<
79717971
continue;
79727972
}
79737973
},
7974-
HTLCForwardInfo::FailHTLC { .. } | HTLCForwardInfo::FailMalformedHTLC { .. } => {
7974+
HTLCForwardInfo::FailHTLC { monitor_event_source, .. }
7975+
| HTLCForwardInfo::FailMalformedHTLC { monitor_event_source, .. } => {
79757976
// Channel went away before we could fail it. This implies
79767977
// the channel is now on chain and our counterparty is
79777978
// trying to broadcast the HTLC-Timeout, but that's their
79787979
// problem, not ours.
7980+
if let Some(source) = monitor_event_source {
7981+
self.chain_monitor.ack_monitor_event(source);
7982+
}
79797983
},
79807984
}
79817985
}

0 commit comments

Comments
 (0)