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