Skip to content

Commit 494f6be

Browse files
Persistent monitor events for off-chain outbound fails
We are in the process of moving the resolution of off-chain HTLCs from the Channel to the ChannelMonitor, via MonitorEvents. This will simplify how we reconstruct/reconcile the ChannelManager's pending HTLC set on startup and avoid needing to persist pending HTLCs explicitly in the manager, as we can just replay pending monitor events to reconstruct the set instead. In a recent commit, we started generating persistent monitor events whenever an htlc is failed off-chain, but those events were no-ops at the time. In this commit, we make those monitor events the sole driver of off-chain outbound payment failure. When `persistent_monitor_events` is enabled, we will skip the existing failure path for these HTLCs and instead fail them when the monitor event is processed. Similar to what we do for claims, the monitor event will not be acked and will continue to be re-provided on startup until the resulting PaymentFailed event is processed by the user. Forward and on-chain failure paths are unchanged and will be migrated separately as part of the broader refactor.
1 parent 0958b78 commit 494f6be

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10553,6 +10553,13 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1055310553
self.forward_htlcs(htlc_forwards);
1055410554
self.finalize_claims(finalized_claimed_htlcs);
1055510555
for failure in failed_htlcs {
10556+
if self.persistent_monitor_events
10557+
&& matches!(failure.0, HTLCSource::OutboundRoute { .. })
10558+
{
10559+
// The MonitorEvent::HTLCEvent generated when the previous counterparty commitment
10560+
// is pruned will drive the failure instead.
10561+
continue;
10562+
}
1055610563
let failure_type = failure.0.failure_type(counterparty_node_id, channel_id);
1055710564
self.fail_htlc_backwards_internal(
1055810565
&failure.0,
@@ -13977,26 +13984,40 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1397713984
OutboundHTLCResolution::Failed { reason } => {
1397813985
let from_onchain =
1397913986
self.channel_is_closed(&channel_id, &counterparty_node_id);
13980-
if from_onchain {
13987+
let we_are_sender =
13988+
matches!(htlc_update.source, HTLCSource::OutboundRoute { .. });
13989+
if from_onchain | we_are_sender {
1398113990
log_trace!(logger, "Failing HTLC from our monitor");
1398213991
let failure_type = htlc_update
1398313992
.source
1398413993
.failure_type(counterparty_node_id, channel_id);
13985-
let completion_update = Some(EventCompletionAction::ReleasePaymentCompleteChannelMonitorUpdate(PaymentCompleteUpdate {
13986-
counterparty_node_id,
13987-
channel_funding_outpoint: funding_outpoint,
13988-
channel_id,
13989-
htlc_id: SentHTLCId::from_source(&htlc_update.source),
13990-
}));
13994+
13995+
let completion_update = if self.persistent_monitor_events
13996+
&& we_are_sender && !from_onchain
13997+
{
13998+
EventCompletionAction::AckMonitorEvent {
13999+
event_id: monitor_event_source,
14000+
}
14001+
} else {
14002+
EventCompletionAction::ReleasePaymentCompleteChannelMonitorUpdate(PaymentCompleteUpdate {
14003+
counterparty_node_id,
14004+
channel_funding_outpoint: funding_outpoint,
14005+
channel_id,
14006+
htlc_id: SentHTLCId::from_source(&htlc_update.source),
14007+
})
14008+
};
14009+
1399114010
self.fail_htlc_backwards_internal(
1399214011
&htlc_update.source,
1399314012
&htlc_update.payment_hash,
1399414013
&reason,
1399514014
failure_type,
13996-
completion_update,
14015+
Some(completion_update),
1399714016
);
1399814017
}
13999-
self.chain_monitor.ack_monitor_event(monitor_event_source);
14018+
if from_onchain | !we_are_sender {
14019+
self.chain_monitor.ack_monitor_event(monitor_event_source);
14020+
}
1400014021
},
1400114022
}
1400214023
},

0 commit comments

Comments
 (0)