Skip to content

Commit 751581e

Browse files
f move push_payment_path_failed_evs and add debug asserts
1 parent 4d87461 commit 751581e

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,11 @@ impl OutboundPayments {
675675
{
676676
match err {
677677
PaymentSendFailure::AllFailedResendSafe(errs) => {
678-
push_payment_path_failed_evs(payment_id, payment_hash, route.paths, errs.into_iter().map(|e| Err(e)), pending_events);
678+
Self::push_payment_path_failed_evs(payment_id, payment_hash, route.paths, errs.into_iter().map(|e| Err(e)), pending_events);
679679
self.retry_payment_internal(payment_id, payment_hash, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path);
680680
},
681681
PaymentSendFailure::PartialFailure { failed_paths_retry: Some(retry), results, .. } => {
682-
push_payment_path_failed_evs(payment_id, payment_hash, route.paths, results.into_iter(), pending_events);
682+
Self::push_payment_path_failed_evs(payment_id, payment_hash, route.paths, results.into_iter(), pending_events);
683683
// Some paths were sent, even if we failed to send the full MPP value our recipient may
684684
// misbehave and claim the funds, at which point we have to consider the payment sent, so
685685
// return `Ok()` here, ignoring any retry errors.
@@ -691,14 +691,41 @@ impl OutboundPayments {
691691
// initial HTLC-Add messages yet.
692692
},
693693
PaymentSendFailure::PathParameterError(results) => {
694-
push_payment_path_failed_evs(payment_id, payment_hash, route.paths, results.into_iter(), pending_events);
694+
Self::push_payment_path_failed_evs(payment_id, payment_hash, route.paths, results.into_iter(), pending_events);
695695
self.abandon_payment(payment_id, pending_events);
696696
},
697697
PaymentSendFailure::ParameterError(e) => {
698698
log_error!(logger, "Failed to send to route due to parameter error: {:?}. Your router is buggy", e);
699699
self.abandon_payment(payment_id, pending_events);
700700
},
701-
PaymentSendFailure::DuplicatePayment => {}, // unreachable
701+
PaymentSendFailure::DuplicatePayment => debug_assert!(false), // unreachable
702+
}
703+
}
704+
705+
fn push_payment_path_failed_evs<I: ExactSizeIterator + Iterator<Item = Result<(), APIError>>>(
706+
payment_id: PaymentId, payment_hash: PaymentHash, paths: Vec<Vec<RouteHop>>, path_results: I,
707+
pending_events: &Mutex<Vec<events::Event>>
708+
) {
709+
let mut events = pending_events.lock().unwrap();
710+
debug_assert_eq!(paths.len(), path_results.len());
711+
for (path, path_res) in paths.into_iter().zip(path_results) {
712+
if path_res.is_err() {
713+
let scid = path[0].short_channel_id;
714+
events.push(events::Event::PaymentPathFailed {
715+
payment_id: Some(payment_id),
716+
payment_hash,
717+
payment_failed_permanently: false,
718+
network_update: None,
719+
all_paths_failed: false,
720+
path,
721+
short_channel_id: Some(scid),
722+
retry: None,
723+
#[cfg(test)]
724+
error_code: None,
725+
#[cfg(test)]
726+
error_data: None,
727+
});
728+
}
702729
}
703730
}
704731

@@ -1275,32 +1302,6 @@ impl OutboundPayments {
12751302
}
12761303
}
12771304

1278-
fn push_payment_path_failed_evs<I: Iterator<Item = Result<(), APIError>>>(
1279-
payment_id: PaymentId, payment_hash: PaymentHash, paths: Vec<Vec<RouteHop>>, path_results: I,
1280-
pending_events: &Mutex<Vec<events::Event>>
1281-
) {
1282-
let mut events = pending_events.lock().unwrap();
1283-
for (path, path_res) in paths.into_iter().zip(path_results) {
1284-
if path_res.is_err() {
1285-
let scid = path[0].short_channel_id;
1286-
events.push(events::Event::PaymentPathFailed {
1287-
payment_id: Some(payment_id),
1288-
payment_hash,
1289-
payment_failed_permanently: false,
1290-
network_update: None,
1291-
all_paths_failed: false,
1292-
path,
1293-
short_channel_id: Some(scid),
1294-
retry: None,
1295-
#[cfg(test)]
1296-
error_code: None,
1297-
#[cfg(test)]
1298-
error_data: None,
1299-
});
1300-
}
1301-
}
1302-
}
1303-
13041305
/// Returns whether a payment with the given [`PaymentHash`] and [`PaymentId`] is, in fact, a
13051306
/// payment probe.
13061307
pub(super) fn payment_is_probe(payment_hash: &PaymentHash, payment_id: &PaymentId,

0 commit comments

Comments
 (0)