@@ -6317,6 +6317,74 @@ where
6317
6317
}
6318
6318
}
6319
6319
6320
+ /// Processes HTLCs which are pending waiting on random forward delay.
6321
+ ///
6322
+ /// Should only really ever be called in response to a PendingHTLCsForwardable event.
6323
+ /// Will likely generate further events.
6324
+ pub fn process_pending_htlc_forwards(&self) {
6325
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
6326
+
6327
+ self.process_pending_update_add_htlcs();
6328
+
6329
+ let mut new_events = VecDeque::new();
6330
+ let mut failed_forwards = Vec::new();
6331
+ let mut phantom_receives: Vec<PerSourcePendingForward> = Vec::new();
6332
+ let mut forward_htlcs = new_hash_map();
6333
+ mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
6334
+
6335
+ for (short_chan_id, mut pending_forwards) in forward_htlcs {
6336
+ if short_chan_id != 0 {
6337
+ self.process_forward_htlcs(
6338
+ short_chan_id,
6339
+ &mut pending_forwards,
6340
+ &mut failed_forwards,
6341
+ &mut phantom_receives,
6342
+ );
6343
+ } else {
6344
+ self.process_receive_htlcs(
6345
+ &mut pending_forwards,
6346
+ &mut new_events,
6347
+ &mut failed_forwards,
6348
+ );
6349
+ }
6350
+ }
6351
+
6352
+ let best_block_height = self.best_block.read().unwrap().height;
6353
+ self.pending_outbound_payments.check_retry_payments(
6354
+ &self.router,
6355
+ || self.list_usable_channels(),
6356
+ || self.compute_inflight_htlcs(),
6357
+ &self.entropy_source,
6358
+ &self.node_signer,
6359
+ best_block_height,
6360
+ &self.pending_events,
6361
+ &self.logger,
6362
+ |args| self.send_payment_along_path(args),
6363
+ );
6364
+
6365
+ for (htlc_source, payment_hash, failure_reason, destination) in failed_forwards.drain(..) {
6366
+ self.fail_htlc_backwards_internal(
6367
+ &htlc_source,
6368
+ &payment_hash,
6369
+ &failure_reason,
6370
+ destination,
6371
+ );
6372
+ }
6373
+ self.forward_htlcs(&mut phantom_receives);
6374
+
6375
+ // Freeing the holding cell here is relatively redundant - in practice we'll do it when we
6376
+ // next get a `get_and_clear_pending_msg_events` call, but some tests rely on it, and it's
6377
+ // nice to do the work now if we can rather than while we're trying to get messages in the
6378
+ // network stack.
6379
+ self.check_free_holding_cells();
6380
+
6381
+ if new_events.is_empty() {
6382
+ return;
6383
+ }
6384
+ let mut events = self.pending_events.lock().unwrap();
6385
+ events.append(&mut new_events);
6386
+ }
6387
+
6320
6388
fn process_forward_htlcs(
6321
6389
&self, short_chan_id: u64, pending_forwards: &mut Vec<HTLCForwardInfo>,
6322
6390
failed_forwards: &mut Vec<FailedHTLCForward>,
@@ -7063,74 +7131,6 @@ where
7063
7131
}
7064
7132
}
7065
7133
7066
- /// Processes HTLCs which are pending waiting on random forward delay.
7067
- ///
7068
- /// Should only really ever be called in response to a PendingHTLCsForwardable event.
7069
- /// Will likely generate further events.
7070
- pub fn process_pending_htlc_forwards(&self) {
7071
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
7072
-
7073
- self.process_pending_update_add_htlcs();
7074
-
7075
- let mut new_events = VecDeque::new();
7076
- let mut failed_forwards = Vec::new();
7077
- let mut phantom_receives: Vec<PerSourcePendingForward> = Vec::new();
7078
- let mut forward_htlcs = new_hash_map();
7079
- mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
7080
-
7081
- for (short_chan_id, mut pending_forwards) in forward_htlcs {
7082
- if short_chan_id != 0 {
7083
- self.process_forward_htlcs(
7084
- short_chan_id,
7085
- &mut pending_forwards,
7086
- &mut failed_forwards,
7087
- &mut phantom_receives,
7088
- );
7089
- } else {
7090
- self.process_receive_htlcs(
7091
- &mut pending_forwards,
7092
- &mut new_events,
7093
- &mut failed_forwards,
7094
- );
7095
- }
7096
- }
7097
-
7098
- let best_block_height = self.best_block.read().unwrap().height;
7099
- self.pending_outbound_payments.check_retry_payments(
7100
- &self.router,
7101
- || self.list_usable_channels(),
7102
- || self.compute_inflight_htlcs(),
7103
- &self.entropy_source,
7104
- &self.node_signer,
7105
- best_block_height,
7106
- &self.pending_events,
7107
- &self.logger,
7108
- |args| self.send_payment_along_path(args),
7109
- );
7110
-
7111
- for (htlc_source, payment_hash, failure_reason, destination) in failed_forwards.drain(..) {
7112
- self.fail_htlc_backwards_internal(
7113
- &htlc_source,
7114
- &payment_hash,
7115
- &failure_reason,
7116
- destination,
7117
- );
7118
- }
7119
- self.forward_htlcs(&mut phantom_receives);
7120
-
7121
- // Freeing the holding cell here is relatively redundant - in practice we'll do it when we
7122
- // next get a `get_and_clear_pending_msg_events` call, but some tests rely on it, and it's
7123
- // nice to do the work now if we can rather than while we're trying to get messages in the
7124
- // network stack.
7125
- self.check_free_holding_cells();
7126
-
7127
- if new_events.is_empty() {
7128
- return;
7129
- }
7130
- let mut events = self.pending_events.lock().unwrap();
7131
- events.append(&mut new_events);
7132
- }
7133
-
7134
7134
/// Free the background events, generally called from [`PersistenceNotifierGuard`] constructors.
7135
7135
///
7136
7136
/// Expects the caller to have a total_consistency_lock read lock.
0 commit comments