@@ -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
@@ -7018,8 +7023,14 @@ where
7018
7023
7019
7024
#[inline]
7020
7025
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;
7021
7033
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;
7023
7034
let mut new_intercept_events = VecDeque::new();
7024
7035
let mut failed_intercept_forwards = Vec::new();
7025
7036
if !pending_forwards.is_empty() {
@@ -7081,9 +7092,7 @@ where
7081
7092
} else {
7082
7093
// We don't want to generate a PendingHTLCsForwardable event if only intercepted
7083
7094
// 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;
7087
7096
entry.insert(vec!(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
7088
7097
prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_htlc_id, prev_user_channel_id, forward_info })));
7089
7098
}
@@ -7093,15 +7102,15 @@ where
7093
7102
}
7094
7103
7095
7104
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);
7097
7106
}
7098
7107
7099
7108
if !new_intercept_events.is_empty() {
7100
7109
let mut events = self.pending_events.lock().unwrap();
7101
7110
events.append(&mut new_intercept_events);
7102
7111
}
7103
- if push_forward_event { self.push_pending_forwards_ev() }
7104
7112
}
7113
+ push_forward_event
7105
7114
}
7106
7115
7107
7116
fn push_pending_forwards_ev(&self) {
0 commit comments