Skip to content

Commit 1688a64

Browse files
fail_htlc: PaymentCompleteUpdate -> EventComplAction
Generalize fail_htlc's completion-action parameter from PaymentCompleteUpdate to EventCompletionAction so the upcoming persistent-monitor-events path can pass AckMonitorEvent.
1 parent b7358c4 commit 1688a64

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9377,7 +9377,7 @@ impl<
93779377
fn fail_htlc_backwards_internal(
93789378
&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason,
93799379
failure_type: HTLCHandlingFailureType,
9380-
mut from_monitor_update_completion: Option<PaymentCompleteUpdate>,
9380+
mut from_monitor_update_completion: Option<EventCompletionAction>,
93819381
) {
93829382
// Ensure that no peer state channel storage lock is held when calling this function.
93839383
// This ensures that future code doesn't introduce a lock-order requirement for
@@ -9431,16 +9431,14 @@ impl<
94319431
&mut from_monitor_update_completion,
94329432
&logger,
94339433
);
9434-
if let Some(update) = from_monitor_update_completion {
9434+
if let Some(action) = from_monitor_update_completion {
94359435
// If `fail_htlc` didn't `take` the post-event action, we should go ahead and
94369436
// complete it here as the failure was duplicative - we've already handled it.
94379437
// This can happen in rare cases where a MonitorUpdate is replayed after
94389438
// restart because a ChannelMonitor wasn't persisted after it was applied (even
94399439
// though the ChannelManager was).
94409440
// For such cases, we also check that there's no existing pending event to
94419441
// complete this action already, which we let finish instead.
9442-
let action =
9443-
EventCompletionAction::ReleasePaymentCompleteChannelMonitorUpdate(update);
94449442
let have_action = {
94459443
let pending_events = self.pending_events.lock().unwrap();
94469444
pending_events.iter().any(|(_, act)| act.as_ref() == Some(&action))
@@ -13978,12 +13976,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1397813976
let failure_type = htlc_update
1397913977
.source
1398013978
.failure_type(counterparty_node_id, channel_id);
13981-
let completion_update = Some(PaymentCompleteUpdate {
13979+
let completion_update = Some(EventCompletionAction::ReleasePaymentCompleteChannelMonitorUpdate(PaymentCompleteUpdate {
1398213980
counterparty_node_id,
1398313981
channel_funding_outpoint: funding_outpoint,
1398413982
channel_id,
1398513983
htlc_id: SentHTLCId::from_source(&htlc_update.source),
13986-
});
13984+
}));
1398713985
self.fail_htlc_backwards_internal(
1398813986
&htlc_update.source,
1398913987
&htlc_update.payment_hash,
@@ -20173,12 +20171,16 @@ impl<
2017320171
"Failing HTLC with payment hash {} as it was resolved on-chain.",
2017420172
payment_hash
2017520173
);
20176-
let completion_action = Some(PaymentCompleteUpdate {
20177-
counterparty_node_id: monitor.get_counterparty_node_id(),
20178-
channel_funding_outpoint: monitor.get_funding_txo(),
20179-
channel_id: monitor.channel_id(),
20180-
htlc_id: SentHTLCId::from_source(&htlc_source),
20181-
});
20174+
let completion_action = Some(
20175+
EventCompletionAction::ReleasePaymentCompleteChannelMonitorUpdate(
20176+
PaymentCompleteUpdate {
20177+
counterparty_node_id: monitor.get_counterparty_node_id(),
20178+
channel_funding_outpoint: monitor.get_funding_txo(),
20179+
channel_id: monitor.channel_id(),
20180+
htlc_id: SentHTLCId::from_source(&htlc_source),
20181+
},
20182+
),
20183+
);
2018220184

2018320185
failed_htlcs.push((
2018420186
htlc_source,

lightning/src/ln/outbound_payment.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use crate::blinded_path::{IntroductionNode, NodeIdLookUp};
1818
use crate::events::{self, PaidBolt12Invoice, PaymentFailureReason};
1919
use crate::ln::channel_state::ChannelDetails;
2020
use crate::ln::channelmanager::{
21-
EventCompletionAction, HTLCSource, OptionalBolt11PaymentParams, PaymentCompleteUpdate,
22-
PaymentId,
21+
EventCompletionAction, HTLCSource, OptionalBolt11PaymentParams, PaymentId,
2322
};
2423
use crate::ln::msgs::DecodeError;
2524
use crate::ln::onion_utils;
@@ -2426,7 +2425,7 @@ impl OutboundPayments {
24262425
path: &Path, session_priv: &SecretKey, payment_id: &PaymentId,
24272426
probing_cookie_secret: [u8; 32], secp_ctx: &Secp256k1<secp256k1::All>,
24282427
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
2429-
completion_action: &mut Option<PaymentCompleteUpdate>, logger: &WithContext<L>,
2428+
completion_action: &mut Option<EventCompletionAction>, logger: &WithContext<L>,
24302429
) {
24312430
#[cfg(any(test, feature = "_test_utils"))]
24322431
let DecodedOnionFailure {
@@ -2574,9 +2573,7 @@ impl OutboundPayments {
25742573
}
25752574
};
25762575
let mut pending_events = pending_events.lock().unwrap();
2577-
let completion_action = completion_action
2578-
.take()
2579-
.map(|act| EventCompletionAction::ReleasePaymentCompleteChannelMonitorUpdate(act));
2576+
let completion_action = completion_action.take();
25802577
if let Some(ev) = full_failure_ev {
25812578
pending_events.push_back((path_failure, None));
25822579
pending_events.push_back((ev, completion_action));

0 commit comments

Comments
 (0)