Skip to content

Commit 5de2515

Browse files
Add MonitorUpdateCompletionAction::AckMonitorEvents
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 add a MonitorUpdateCompletionAction that will allow the ChannelManager to tell a monitor that an event is complete, upon completion of a particular ChannelMonitorUpdate. For example, this will be used when an HTLC is irrevocably failed backwards post-channel-close, to delete the corresponding MonitorEvent::HTLCEvent.
1 parent cfc185c commit 5de2515

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use crate::chain::chaininterface::{
4242
BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator,
4343
TransactionType,
4444
};
45+
use crate::chain::chainmonitor::MonitorEventSource;
4546
use crate::chain::channelmonitor::{
4647
ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, MonitorEvent,
4748
WithChannelMonitor, ANTI_REORG_DELAY, CLTV_CLAIM_BUFFER, HTLC_FAIL_BACK_BUFFER,
@@ -1492,6 +1493,9 @@ pub(crate) enum MonitorUpdateCompletionAction {
14921493
blocking_action: RAAMonitorUpdateBlockingAction,
14931494
downstream_channel_id: ChannelId,
14941495
},
1496+
/// Indicates that one or more [`MonitorEvent`]s should be acknowledged once the associated
1497+
/// [`ChannelMonitorUpdate`] has been durably persisted.
1498+
AckMonitorEvents { monitor_events_to_ack: Vec<MonitorEventSource> },
14951499
}
14961500

14971501
impl_writeable_tlv_based_enum_upgradable!(MonitorUpdateCompletionAction,
@@ -1513,6 +1517,9 @@ impl_writeable_tlv_based_enum_upgradable!(MonitorUpdateCompletionAction,
15131517
(0, event, upgradable_option),
15141518
(1, downstream_counterparty_and_funding_outpoint, upgradable_required),
15151519
},
1520+
(3, AckMonitorEvents) => {
1521+
(0, monitor_events_to_ack, required_vec),
1522+
},
15161523
);
15171524

15181525
/// Result of attempting to resume a channel after a monitor update completes while locks are held.
@@ -10252,6 +10259,11 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1025210259
Some(blocking_action),
1025310260
);
1025410261
},
10262+
MonitorUpdateCompletionAction::AckMonitorEvents { monitor_events_to_ack } => {
10263+
for source in monitor_events_to_ack {
10264+
self.chain_monitor.ack_monitor_event(source);
10265+
}
10266+
},
1025510267
}
1025610268
}
1025710269

0 commit comments

Comments
 (0)