@@ -5347,9 +5347,14 @@ where
5347
5347
}
5348
5348
}
5349
5349
5350
+ fn fail_htlc_backwards_internal(&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason, destination: HTLCDestination) {
5351
+ let push_forward_event = self.fail_htlc_backwards_internal_without_forward_event(source, payment_hash, onion_error, destination);
5352
+ if push_forward_event { self.push_pending_forwards_ev(); }
5353
+ }
5354
+
5350
5355
/// Fails an HTLC backwards to the sender of it to us.
5351
5356
/// Note that we do not assume that channels corresponding to failed HTLCs are still available.
5352
- fn fail_htlc_backwards_internal (&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason, destination: HTLCDestination) {
5357
+ fn fail_htlc_backwards_internal_without_forward_event (&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason, destination: HTLCDestination) -> bool {
5353
5358
// Ensure that no peer state channel storage lock is held when calling this function.
5354
5359
// This ensures that future code doesn't introduce a lock-order requirement for
5355
5360
// `forward_htlcs` to be locked after the `per_peer_state` peer locks, which calling
@@ -5367,12 +5372,12 @@ where
5367
5372
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
5368
5373
// from block_connected which may run during initialization prior to the chain_monitor
5369
5374
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
5375
+ let mut push_forward_event;
5370
5376
match source {
5371
5377
HTLCSource::OutboundRoute { ref path, ref session_priv, ref payment_id, .. } => {
5372
- if self.pending_outbound_payments.fail_htlc(source, payment_hash, onion_error, path,
5378
+ push_forward_event = self.pending_outbound_payments.fail_htlc(source, payment_hash, onion_error, path,
5373
5379
session_priv, payment_id, self.probing_cookie_secret, &self.secp_ctx,
5374
- &self.pending_events, &self.logger)
5375
- { self.push_pending_forwards_ev(); }
5380
+ &self.pending_events, &self.logger);
5376
5381
},
5377
5382
HTLCSource::PreviousHopData(HTLCPreviousHopData {
5378
5383
ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret,
@@ -5406,9 +5411,9 @@ where
5406
5411
}
5407
5412
};
5408
5413
5409
- let mut push_forward_ev = self.decode_update_add_htlcs.lock().unwrap().is_empty();
5414
+ push_forward_event = self.decode_update_add_htlcs.lock().unwrap().is_empty();
5410
5415
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
5411
- push_forward_ev &= forward_htlcs.is_empty();
5416
+ push_forward_event &= forward_htlcs.is_empty();
5412
5417
match forward_htlcs.entry(*short_channel_id) {
5413
5418
hash_map::Entry::Occupied(mut entry) => {
5414
5419
entry.get_mut().push(failure);
@@ -5418,14 +5423,14 @@ where
5418
5423
}
5419
5424
}
5420
5425
mem::drop(forward_htlcs);
5421
- if push_forward_ev { self.push_pending_forwards_ev(); }
5422
5426
let mut pending_events = self.pending_events.lock().unwrap();
5423
5427
pending_events.push_back((events::Event::HTLCHandlingFailed {
5424
5428
prev_channel_id: *channel_id,
5425
5429
failed_next_destination: destination,
5426
5430
}, None));
5427
5431
},
5428
5432
}
5433
+ push_forward_event
5429
5434
}
5430
5435
5431
5436
/// Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
@@ -6998,8 +7003,14 @@ where
6998
7003
6999
7004
#[inline]
7000
7005
fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) {
7006
+ let push_forward_event = self.forward_htlcs_without_forward_event(per_source_pending_forwards);
7007
+ if push_forward_event { self.push_pending_forwards_ev() }
7008
+ }
7009
+
7010
+ #[inline]
7011
+ fn forward_htlcs_without_forward_event(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) -> bool {
7012
+ let mut push_forward_event = false;
7001
7013
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 {
7002
- let mut push_forward_event = false;
7003
7014
let mut new_intercept_events = VecDeque::new();
7004
7015
let mut failed_intercept_forwards = Vec::new();
7005
7016
if !pending_forwards.is_empty() {
@@ -7061,9 +7072,7 @@ where
7061
7072
} else {
7062
7073
// We don't want to generate a PendingHTLCsForwardable event if only intercepted
7063
7074
// payments are being processed.
7064
- if forward_htlcs_empty && decode_update_add_htlcs_empty {
7065
- push_forward_event = true;
7066
- }
7075
+ push_forward_event |= forward_htlcs_empty && decode_update_add_htlcs_empty;
7067
7076
entry.insert(vec!(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
7068
7077
prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info })));
7069
7078
}
@@ -7073,15 +7082,15 @@ where
7073
7082
}
7074
7083
7075
7084
for (htlc_source, payment_hash, failure_reason, destination) in failed_intercept_forwards.drain(..) {
7076
- self.fail_htlc_backwards_internal (&htlc_source, &payment_hash, &failure_reason, destination);
7085
+ push_forward_event |= self.fail_htlc_backwards_internal_without_forward_event (&htlc_source, &payment_hash, &failure_reason, destination);
7077
7086
}
7078
7087
7079
7088
if !new_intercept_events.is_empty() {
7080
7089
let mut events = self.pending_events.lock().unwrap();
7081
7090
events.append(&mut new_intercept_events);
7082
7091
}
7083
- if push_forward_event { self.push_pending_forwards_ev() }
7084
7092
}
7093
+ push_forward_event
7085
7094
}
7086
7095
7087
7096
fn push_pending_forwards_ev(&self) {
0 commit comments