@@ -9480,8 +9480,11 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
94809480 }
94819481 }
94829482
9483- #[rustfmt::skip]
9484- fn handle_monitor_update_completion_actions<I: IntoIterator<Item=MonitorUpdateCompletionAction>>(&self, actions: I) {
9483+ fn handle_monitor_update_completion_actions<
9484+ I: IntoIterator<Item = MonitorUpdateCompletionAction>,
9485+ >(
9486+ &self, actions: I,
9487+ ) {
94859488 debug_assert_ne!(self.pending_events.held_by_thread(), LockHeldState::HeldByThread);
94869489 debug_assert_ne!(self.claimable_payments.held_by_thread(), LockHeldState::HeldByThread);
94879490 debug_assert_ne!(self.per_peer_state.held_by_thread(), LockHeldState::HeldByThread);
@@ -9490,44 +9493,67 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
94909493
94919494 for action in actions.into_iter() {
94929495 match action {
9493- MonitorUpdateCompletionAction::PaymentClaimed { payment_hash, pending_mpp_claim } => {
9494- if let Some((counterparty_node_id, chan_id, claim_ptr)) = pending_mpp_claim {
9496+ MonitorUpdateCompletionAction::PaymentClaimed {
9497+ payment_hash,
9498+ pending_mpp_claim,
9499+ } => {
9500+ let (peer_id, chan_id) = pending_mpp_claim
9501+ .as_ref()
9502+ .map(|c| (Some(c.0), Some(c.1)))
9503+ .unwrap_or_default();
9504+ let logger =
9505+ WithContext::from(&self.logger, peer_id, chan_id, Some(payment_hash));
9506+ log_trace!(logger, "Handling PaymentClaimed monitor update completion action");
9507+
9508+ if let Some((cp_node_id, chan_id, claim_ptr)) = pending_mpp_claim {
94959509 let per_peer_state = self.per_peer_state.read().unwrap();
9496- per_peer_state.get(&counterparty_node_id ).map(|peer_state_mutex| {
9510+ per_peer_state.get(&cp_node_id ).map(|peer_state_mutex| {
94979511 let mut peer_state = peer_state_mutex.lock().unwrap();
9498- let blockers_entry = peer_state.actions_blocking_raa_monitor_updates.entry(chan_id);
9512+ let blockers_entry =
9513+ peer_state.actions_blocking_raa_monitor_updates.entry(chan_id);
94999514 if let btree_map::Entry::Occupied(mut blockers) = blockers_entry {
9500- blockers.get_mut().retain(|blocker|
9501- if let &RAAMonitorUpdateBlockingAction::ClaimedMPPPayment { pending_claim } = &blocker {
9502- if *pending_claim == claim_ptr {
9503- let mut pending_claim_state_lock = pending_claim.0.lock().unwrap();
9504- let pending_claim_state = &mut *pending_claim_state_lock;
9505- pending_claim_state.channels_without_preimage.retain(|(cp, cid)| {
9506- let this_claim =
9507- *cp == counterparty_node_id && *cid == chan_id;
9508- if this_claim {
9509- pending_claim_state.channels_with_preimage.push((*cp, *cid));
9510- false
9511- } else { true }
9512- });
9513- if pending_claim_state.channels_without_preimage.is_empty() {
9514- for (cp, cid) in pending_claim_state.channels_with_preimage.iter() {
9515- let freed_chan = (*cp, *cid, blocker.clone());
9516- freed_channels.push(freed_chan);
9517- }
9518- }
9519- !pending_claim_state.channels_without_preimage.is_empty()
9520- } else { true }
9521- } else { true }
9522- );
9515+ blockers.get_mut().retain(|blocker| {
9516+ let pending_claim = match &blocker {
9517+ RAAMonitorUpdateBlockingAction::ClaimedMPPPayment {
9518+ pending_claim,
9519+ } => pending_claim,
9520+ _ => return true,
9521+ };
9522+ if *pending_claim != claim_ptr {
9523+ return true;
9524+ }
9525+ let mut claim_state_lock = pending_claim.0.lock().unwrap();
9526+ let claim_state = &mut *claim_state_lock;
9527+ claim_state.channels_without_preimage.retain(|(cp, cid)| {
9528+ let this_claim = *cp == cp_node_id && *cid == chan_id;
9529+ if this_claim {
9530+ claim_state.channels_with_preimage.push((*cp, *cid));
9531+ false
9532+ } else {
9533+ true
9534+ }
9535+ });
9536+ if claim_state.channels_without_preimage.is_empty() {
9537+ for (cp, cid) in claim_state.channels_with_preimage.iter() {
9538+ let freed_chan = (*cp, *cid, blocker.clone());
9539+ freed_channels.push(freed_chan);
9540+ }
9541+ }
9542+ !claim_state.channels_without_preimage.is_empty()
9543+ });
95239544 if blockers.get().is_empty() {
95249545 blockers.remove();
95259546 }
95269547 }
95279548 });
95289549 }
95299550
9530- let payment = self.claimable_payments.lock().unwrap().pending_claiming_payments.remove(&payment_hash);
9551+ let payment = self
9552+ .claimable_payments
9553+ .lock()
9554+ .unwrap()
9555+ .pending_claiming_payments
9556+ .remove(&payment_hash);
95319557 if let Some(ClaimingPayment {
95329558 amount_msat,
95339559 payment_purpose: purpose,
@@ -9537,7 +9563,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95379563 onion_fields,
95389564 payment_id,
95399565 durable_preimage_channel,
9540- }) = payment {
9566+ }) = payment
9567+ {
95419568 let event = events::Event::PaymentClaimed {
95429569 payment_hash,
95439570 purpose,
@@ -9548,8 +9575,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95489575 onion_fields,
95499576 payment_id,
95509577 };
9551- let action = if let Some((outpoint, counterparty_node_id, channel_id))
9552- = durable_preimage_channel
9578+ let action = if let Some((outpoint, counterparty_node_id, channel_id)) =
9579+ durable_preimage_channel
95539580 {
95549581 Some(EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
95559582 channel_funding_outpoint: Some(outpoint),
@@ -9566,12 +9593,18 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95669593 // `payment_id` should suffice to ensure we never spuriously drop a second
95679594 // event for a duplicate payment.
95689595 if !pending_events.contains(&event_action) {
9596+ log_trace!(
9597+ logger,
9598+ "Queuing PaymentClaimed event with event completion action {:?}",
9599+ event_action.1
9600+ );
95699601 pending_events.push_back(event_action);
95709602 }
95719603 }
95729604 },
95739605 MonitorUpdateCompletionAction::EmitEventAndFreeOtherChannel {
9574- event, downstream_counterparty_and_funding_outpoint
9606+ event,
9607+ downstream_counterparty_and_funding_outpoint,
95759608 } => {
95769609 self.pending_events.lock().unwrap().push_back((event, None));
95779610 if let Some(unblocked) = downstream_counterparty_and_funding_outpoint {
@@ -9583,7 +9616,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95839616 }
95849617 },
95859618 MonitorUpdateCompletionAction::FreeOtherChannelImmediately {
9586- downstream_counterparty_node_id, downstream_channel_id, blocking_action,
9619+ downstream_counterparty_node_id,
9620+ downstream_channel_id,
9621+ blocking_action,
95879622 } => {
95889623 self.handle_monitor_update_release(
95899624 downstream_counterparty_node_id,
@@ -17145,17 +17180,18 @@ where
1714517180
1714617181 let logger = WithChannelMonitor::from(&args.logger, monitor, None);
1714717182 let channel_id = monitor.channel_id();
17148- log_info!(
17149- logger,
17150- "Queueing monitor update to ensure missing channel is force closed",
17151- );
1715217183 let monitor_update = ChannelMonitorUpdate {
1715317184 update_id: monitor.get_latest_update_id().saturating_add(1),
1715417185 updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed {
1715517186 should_broadcast: true,
1715617187 }],
1715717188 channel_id: Some(monitor.channel_id()),
1715817189 };
17190+ log_info!(
17191+ logger,
17192+ "Queueing monitor update {} to ensure missing channel is force closed",
17193+ monitor_update.update_id
17194+ );
1715917195 let funding_txo = monitor.get_funding_txo();
1716017196 let update = BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
1716117197 counterparty_node_id,
0 commit comments