@@ -5355,9 +5355,14 @@ where
53555355 }
53565356 }
53575357
5358+ fn fail_htlc_backwards_internal(&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason, destination: HTLCDestination) {
5359+ let push_forward_event = self.fail_htlc_backwards_internal_without_forward_event(source, payment_hash, onion_error, destination);
5360+ if push_forward_event { self.push_pending_forwards_ev(); }
5361+ }
5362+
53585363 /// Fails an HTLC backwards to the sender of it to us.
53595364 /// Note that we do not assume that channels corresponding to failed HTLCs are still available.
5360- fn fail_htlc_backwards_internal (&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason, destination: HTLCDestination) {
5365+ fn fail_htlc_backwards_internal_without_forward_event (&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason, destination: HTLCDestination) -> bool {
53615366 // Ensure that no peer state channel storage lock is held when calling this function.
53625367 // This ensures that future code doesn't introduce a lock-order requirement for
53635368 // `forward_htlcs` to be locked after the `per_peer_state` peer locks, which calling
@@ -5375,12 +5380,12 @@ where
53755380 // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
53765381 // from block_connected which may run during initialization prior to the chain_monitor
53775382 // being fully configured. See the docs for `ChannelManagerReadArgs` for more.
5383+ let mut push_forward_event;
53785384 match source {
53795385 HTLCSource::OutboundRoute { ref path, ref session_priv, ref payment_id, .. } => {
5380- if self.pending_outbound_payments.fail_htlc(source, payment_hash, onion_error, path,
5386+ push_forward_event = self.pending_outbound_payments.fail_htlc(source, payment_hash, onion_error, path,
53815387 session_priv, payment_id, self.probing_cookie_secret, &self.secp_ctx,
5382- &self.pending_events, &self.logger)
5383- { self.push_pending_forwards_ev(); }
5388+ &self.pending_events, &self.logger);
53845389 },
53855390 HTLCSource::PreviousHopData(HTLCPreviousHopData {
53865391 ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret,
@@ -5414,9 +5419,9 @@ where
54145419 }
54155420 };
54165421
5417- let mut push_forward_ev = self.decode_update_add_htlcs.lock().unwrap().is_empty();
5422+ push_forward_event = self.decode_update_add_htlcs.lock().unwrap().is_empty();
54185423 let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
5419- push_forward_ev &= forward_htlcs.is_empty();
5424+ push_forward_event &= forward_htlcs.is_empty();
54205425 match forward_htlcs.entry(*short_channel_id) {
54215426 hash_map::Entry::Occupied(mut entry) => {
54225427 entry.get_mut().push(failure);
@@ -5426,14 +5431,14 @@ where
54265431 }
54275432 }
54285433 mem::drop(forward_htlcs);
5429- if push_forward_ev { self.push_pending_forwards_ev(); }
54305434 let mut pending_events = self.pending_events.lock().unwrap();
54315435 pending_events.push_back((events::Event::HTLCHandlingFailed {
54325436 prev_channel_id: *channel_id,
54335437 failed_next_destination: destination,
54345438 }, None));
54355439 },
54365440 }
5441+ push_forward_event
54375442 }
54385443
54395444 /// Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
@@ -7018,8 +7023,14 @@ where
70187023
70197024 #[inline]
70207025 fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) {
7026+ let push_forward_event = self.forward_htlcs_without_forward_event(per_source_pending_forwards);
7027+ if push_forward_event { self.push_pending_forwards_ev() }
7028+ }
7029+
7030+ #[inline]
7031+ fn forward_htlcs_without_forward_event(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) -> bool {
7032+ let mut push_forward_event = false;
70217033 for &mut (prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_user_channel_id, ref mut pending_forwards) in per_source_pending_forwards {
7022- let mut push_forward_event = false;
70237034 let mut new_intercept_events = VecDeque::new();
70247035 let mut failed_intercept_forwards = Vec::new();
70257036 if !pending_forwards.is_empty() {
@@ -7081,9 +7092,7 @@ where
70817092 } else {
70827093 // We don't want to generate a PendingHTLCsForwardable event if only intercepted
70837094 // payments are being processed.
7084- if forward_htlcs_empty && decode_update_add_htlcs_empty {
7085- push_forward_event = true;
7086- }
7095+ push_forward_event |= forward_htlcs_empty && decode_update_add_htlcs_empty;
70877096 entry.insert(vec!(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
70887097 prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info })));
70897098 }
@@ -7093,15 +7102,15 @@ where
70937102 }
70947103
70957104 for (htlc_source, payment_hash, failure_reason, destination) in failed_intercept_forwards.drain(..) {
7096- self.fail_htlc_backwards_internal (&htlc_source, &payment_hash, &failure_reason, destination);
7105+ push_forward_event |= self.fail_htlc_backwards_internal_without_forward_event (&htlc_source, &payment_hash, &failure_reason, destination);
70977106 }
70987107
70997108 if !new_intercept_events.is_empty() {
71007109 let mut events = self.pending_events.lock().unwrap();
71017110 events.append(&mut new_intercept_events);
71027111 }
7103- if push_forward_event { self.push_pending_forwards_ev() }
71047112 }
7113+ push_forward_event
71057114 }
71067115
71077116 fn push_pending_forwards_ev(&self) {
0 commit comments