@@ -5355,9 +5355,14 @@ where
5355
5355
}
5356
5356
}
5357
5357
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
+
5358
5363
/// Fails an HTLC backwards to the sender of it to us.
5359
5364
/// 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 {
5361
5366
// Ensure that no peer state channel storage lock is held when calling this function.
5362
5367
// This ensures that future code doesn't introduce a lock-order requirement for
5363
5368
// `forward_htlcs` to be locked after the `per_peer_state` peer locks, which calling
@@ -5375,12 +5380,12 @@ where
5375
5380
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
5376
5381
// from block_connected which may run during initialization prior to the chain_monitor
5377
5382
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
5383
+ let mut push_forward_event;
5378
5384
match source {
5379
5385
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,
5381
5387
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);
5384
5389
},
5385
5390
HTLCSource::PreviousHopData(HTLCPreviousHopData {
5386
5391
ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret,
@@ -5414,9 +5419,9 @@ where
5414
5419
}
5415
5420
};
5416
5421
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();
5418
5423
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();
5420
5425
match forward_htlcs.entry(*short_channel_id) {
5421
5426
hash_map::Entry::Occupied(mut entry) => {
5422
5427
entry.get_mut().push(failure);
@@ -5426,14 +5431,14 @@ where
5426
5431
}
5427
5432
}
5428
5433
mem::drop(forward_htlcs);
5429
- if push_forward_ev { self.push_pending_forwards_ev(); }
5430
5434
let mut pending_events = self.pending_events.lock().unwrap();
5431
5435
pending_events.push_back((events::Event::HTLCHandlingFailed {
5432
5436
prev_channel_id: *channel_id,
5433
5437
failed_next_destination: destination,
5434
5438
}, None));
5435
5439
},
5436
5440
}
5441
+ push_forward_event
5437
5442
}
5438
5443
5439
5444
/// Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
@@ -7016,8 +7021,14 @@ where
7016
7021
7017
7022
#[inline]
7018
7023
fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) {
7024
+ let push_forward_event = self.forward_htlcs_without_forward_event(per_source_pending_forwards);
7025
+ if push_forward_event { self.push_pending_forwards_ev() }
7026
+ }
7027
+
7028
+ #[inline]
7029
+ fn forward_htlcs_without_forward_event(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) -> bool {
7030
+ let mut push_forward_event = false;
7019
7031
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 {
7020
- let mut push_forward_event = false;
7021
7032
let mut new_intercept_events = VecDeque::new();
7022
7033
let mut failed_intercept_forwards = Vec::new();
7023
7034
if !pending_forwards.is_empty() {
@@ -7079,9 +7090,7 @@ where
7079
7090
} else {
7080
7091
// We don't want to generate a PendingHTLCsForwardable event if only intercepted
7081
7092
// payments are being processed.
7082
- if forward_htlcs_empty && decode_update_add_htlcs_empty {
7083
- push_forward_event = true;
7084
- }
7093
+ push_forward_event |= forward_htlcs_empty && decode_update_add_htlcs_empty;
7085
7094
entry.insert(vec!(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
7086
7095
prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info })));
7087
7096
}
@@ -7091,15 +7100,15 @@ where
7091
7100
}
7092
7101
7093
7102
for (htlc_source, payment_hash, failure_reason, destination) in failed_intercept_forwards.drain(..) {
7094
- self.fail_htlc_backwards_internal (&htlc_source, &payment_hash, &failure_reason, destination);
7103
+ push_forward_event |= self.fail_htlc_backwards_internal_without_forward_event (&htlc_source, &payment_hash, &failure_reason, destination);
7095
7104
}
7096
7105
7097
7106
if !new_intercept_events.is_empty() {
7098
7107
let mut events = self.pending_events.lock().unwrap();
7099
7108
events.append(&mut new_intercept_events);
7100
7109
}
7101
- if push_forward_event { self.push_pending_forwards_ev() }
7102
7110
}
7111
+ push_forward_event
7103
7112
}
7104
7113
7105
7114
fn push_pending_forwards_ev(&self) {
0 commit comments