Skip to content

Commit ba331bc

Browse files
committed
Split-out receive case from process_pending_htlcs_forwards
We split up the huge `process_pending_htlcs_forwards` method and move the `receive` case of the processing code to a `process_receive_htlcs` helper.
1 parent f263042 commit ba331bc

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6674,31 +6674,12 @@ where
66746674
}
66756675
}
66766676

6677-
/// Processes HTLCs which are pending waiting on random forward delay.
6678-
///
6679-
/// Should only really ever be called in response to a PendingHTLCsForwardable event.
6680-
/// Will likely generate further events.
6681-
pub fn process_pending_htlc_forwards(&self) {
6682-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
6683-
6684-
self.process_pending_update_add_htlcs();
6685-
6686-
let mut new_events = VecDeque::new();
6687-
let mut failed_forwards = Vec::new();
6688-
let mut phantom_receives: Vec<PerSourcePendingForward> = Vec::new();
6689-
{
6690-
let mut forward_htlcs = new_hash_map();
6691-
mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
6692-
6693-
for (short_chan_id, mut pending_forwards) in forward_htlcs {
6694-
if short_chan_id != 0 {
6695-
self.process_forward_htlcs(
6696-
short_chan_id,
6697-
&mut pending_forwards,
6698-
&mut failed_forwards,
6699-
&mut phantom_receives,
6700-
);
6701-
} else {
6677+
#[rustfmt::skip]
6678+
fn process_receive_htlcs(
6679+
&self, pending_forwards: &mut Vec<HTLCForwardInfo>,
6680+
new_events: &mut VecDeque<(Event, Option<EventCompletionAction>)>,
6681+
failed_forwards: &mut Vec<FailedHTLCForward>,
6682+
) {
67026683
'next_forwardable_htlc: for forward_info in pending_forwards.drain(..) {
67036684
match forward_info {
67046685
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
@@ -7090,6 +7071,38 @@ where
70907071
},
70917072
}
70927073
}
7074+
}
7075+
7076+
/// Processes HTLCs which are pending waiting on random forward delay.
7077+
///
7078+
/// Should only really ever be called in response to a PendingHTLCsForwardable event.
7079+
/// Will likely generate further events.
7080+
pub fn process_pending_htlc_forwards(&self) {
7081+
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
7082+
7083+
self.process_pending_update_add_htlcs();
7084+
7085+
let mut new_events = VecDeque::new();
7086+
let mut failed_forwards = Vec::new();
7087+
let mut phantom_receives: Vec<PerSourcePendingForward> = Vec::new();
7088+
{
7089+
let mut forward_htlcs = new_hash_map();
7090+
mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
7091+
7092+
for (short_chan_id, mut pending_forwards) in forward_htlcs {
7093+
if short_chan_id != 0 {
7094+
self.process_forward_htlcs(
7095+
short_chan_id,
7096+
&mut pending_forwards,
7097+
&mut failed_forwards,
7098+
&mut phantom_receives,
7099+
);
7100+
} else {
7101+
self.process_receive_htlcs(
7102+
&mut pending_forwards,
7103+
&mut new_events,
7104+
&mut failed_forwards,
7105+
);
70937106
}
70947107
}
70957108
}

0 commit comments

Comments
 (0)