Skip to content

Commit dcea175

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 1688a64 commit dcea175

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
@@ -10547,6 +10547,13 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1054710547
self.forward_htlcs(htlc_forwards);
1054810548
self.finalize_claims(finalized_claimed_htlcs);
1054910549
for failure in failed_htlcs {
10550+
if self.persistent_monitor_events
10551+
&& matches!(failure.0, HTLCSource::OutboundRoute { .. })
10552+
{
10553+
// The MonitorEvent::HTLCEvent generated when the previous counterparty commitment
10554+
// is pruned will drive the failure instead.
10555+
continue;
10556+
}
1055010557
let failure_type = failure.0.failure_type(counterparty_node_id, channel_id);
1055110558
self.fail_htlc_backwards_internal(
1055210559
&failure.0,
@@ -13971,26 +13978,40 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1397113978
OutboundHTLCResolution::Failed { reason } => {
1397213979
let from_onchain =
1397313980
self.channel_is_closed(&channel_id, &counterparty_node_id);
13974-
if from_onchain {
13981+
let we_are_sender =
13982+
matches!(htlc_update.source, HTLCSource::OutboundRoute { .. });
13983+
if from_onchain | we_are_sender {
1397513984
log_trace!(logger, "Failing HTLC from our monitor");
1397613985
let failure_type = htlc_update
1397713986
.source
1397813987
.failure_type(counterparty_node_id, channel_id);
13979-
let completion_update = Some(EventCompletionAction::ReleasePaymentCompleteChannelMonitorUpdate(PaymentCompleteUpdate {
13980-
counterparty_node_id,
13981-
channel_funding_outpoint: funding_outpoint,
13982-
channel_id,
13983-
htlc_id: SentHTLCId::from_source(&htlc_update.source),
13984-
}));
13988+
13989+
let completion_update = if self.persistent_monitor_events
13990+
&& we_are_sender && !from_onchain
13991+
{
13992+
EventCompletionAction::AckMonitorEvent {
13993+
event_id: monitor_event_source,
13994+
}
13995+
} else {
13996+
EventCompletionAction::ReleasePaymentCompleteChannelMonitorUpdate(PaymentCompleteUpdate {
13997+
counterparty_node_id,
13998+
channel_funding_outpoint: funding_outpoint,
13999+
channel_id,
14000+
htlc_id: SentHTLCId::from_source(&htlc_update.source),
14001+
})
14002+
};
14003+
1398514004
self.fail_htlc_backwards_internal(
1398614005
&htlc_update.source,
1398714006
&htlc_update.payment_hash,
1398814007
&reason,
1398914008
failure_type,
13990-
completion_update,
14009+
Some(completion_update),
1399114010
);
1399214011
}
13993-
self.chain_monitor.ack_monitor_event(monitor_event_source);
14012+
if from_onchain | !we_are_sender {
14013+
self.chain_monitor.ack_monitor_event(monitor_event_source);
14014+
}
1399414015
},
1399514016
}
1399614017
},

0 commit comments

Comments
 (0)