@@ -5283,15 +5283,6 @@ where
5283
5283
/// Fails an HTLC backwards to the sender of it to us.
5284
5284
/// Note that we do not assume that channels corresponding to failed HTLCs are still available.
5285
5285
fn fail_htlc_backwards_internal(&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason, destination: HTLCDestination) {
5286
- // Ensure that no peer state channel storage lock is held when calling this function.
5287
- // This ensures that future code doesn't introduce a lock-order requirement for
5288
- // `forward_htlcs` to be locked after the `per_peer_state` peer locks, which calling
5289
- // this function with any `per_peer_state` peer lock acquired would.
5290
- #[cfg(debug_assertions)]
5291
- for (_, peer) in self.per_peer_state.read().unwrap().iter() {
5292
- debug_assert_ne!(peer.held_by_thread(), LockHeldState::HeldByThread);
5293
- }
5294
-
5295
5286
//TODO: There is a timing attack here where if a node fails an HTLC back to us they can
5296
5287
//identify whether we sent it or not based on the (I presume) very different runtime
5297
5288
//between the branches here. We should make this async and move it into the forward HTLCs
@@ -5339,28 +5330,41 @@ where
5339
5330
}
5340
5331
};
5341
5332
5342
- let mut push_forward_ev = false;
5343
- let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
5344
- if forward_htlcs.is_empty() {
5345
- push_forward_ev = true;
5346
- }
5347
- match forward_htlcs.entry(*short_channel_id) {
5348
- hash_map::Entry::Occupied(mut entry) => {
5349
- entry.get_mut().push(failure);
5350
- },
5351
- hash_map::Entry::Vacant(entry) => {
5352
- entry.insert(vec!(failure));
5353
- }
5354
- }
5355
- mem::drop(forward_htlcs);
5356
- if push_forward_ev { self.push_pending_forwards_ev(); }
5357
- let mut pending_events = self.pending_events.lock().unwrap();
5358
- pending_events.push_back((events::Event::HTLCHandlingFailed {
5359
- prev_channel_id: outpoint.to_channel_id(),
5360
- failed_next_destination: destination,
5361
- }, None));
5333
+ self.push_htlc_failure(*short_channel_id, outpoint.to_channel_id(), failure, destination);
5334
+ }
5335
+ }
5336
+ }
5337
+
5338
+ fn push_htlc_failure(&self, short_channel_id: u64, channel_id: ChannelId, failure: HTLCForwardInfo, destination: HTLCDestination) {
5339
+ // Ensure that no peer state channel storage lock is held when calling this function.
5340
+ // This ensures that future code doesn't introduce a lock-order requirement for
5341
+ // `forward_htlcs` to be locked after the `per_peer_state` peer locks, which calling
5342
+ // this function with any `per_peer_state` peer lock acquired would.
5343
+ #[cfg(debug_assertions)]
5344
+ for (_, peer) in self.per_peer_state.read().unwrap().iter() {
5345
+ debug_assert_ne!(peer.held_by_thread(), LockHeldState::HeldByThread);
5346
+ }
5347
+
5348
+ let mut push_forward_ev = false;
5349
+ let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
5350
+ if forward_htlcs.is_empty() {
5351
+ push_forward_ev = true;
5352
+ }
5353
+ match forward_htlcs.entry(short_channel_id) {
5354
+ hash_map::Entry::Occupied(mut entry) => {
5355
+ entry.get_mut().push(failure);
5362
5356
},
5357
+ hash_map::Entry::Vacant(entry) => {
5358
+ entry.insert(vec!(failure));
5359
+ }
5363
5360
}
5361
+ mem::drop(forward_htlcs);
5362
+ if push_forward_ev { self.push_pending_forwards_ev(); }
5363
+ let mut pending_events = self.pending_events.lock().unwrap();
5364
+ pending_events.push_back((events::Event::HTLCHandlingFailed {
5365
+ prev_channel_id: channel_id,
5366
+ failed_next_destination: destination,
5367
+ }, None));
5364
5368
}
5365
5369
5366
5370
/// Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
0 commit comments