Skip to content

Commit 1652927

Browse files
On initial send retries, avoid previously failed scids
Previously, we would have tried the same failed channels over and over until retries are exhausted.
1 parent 41d0352 commit 1652927

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

lightning/src/ln/outbound_payment.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,8 @@ impl OutboundPayments {
731731

732732
fn handle_pay_route_err<R: Deref, NS: Deref, ES: Deref, IH, SP, L: Deref>(
733733
&self, err: PaymentSendFailure, payment_id: PaymentId, payment_hash: PaymentHash, route: Route,
734-
route_params: RouteParameters, router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: &IH,
735-
entropy_source: &ES, node_signer: &NS, best_block_height: u32, logger: &L,
734+
mut route_params: RouteParameters, router: &R, first_hops: Vec<ChannelDetails>,
735+
inflight_htlcs: &IH, entropy_source: &ES, node_signer: &NS, best_block_height: u32, logger: &L,
736736
pending_events: &Mutex<Vec<events::Event>>, send_payment_along_path: &SP,
737737
)
738738
where
@@ -746,11 +746,11 @@ impl OutboundPayments {
746746
{
747747
match err {
748748
PaymentSendFailure::AllFailedResendSafe(errs) => {
749-
push_payment_path_failed_evs(payment_id, payment_hash, route.paths, errs.into_iter().map(|e| Err(e)), pending_events);
749+
push_path_failed_evs_and_scids(payment_id, payment_hash, Some(&mut route_params), route.paths, errs.into_iter().map(|e| Err(e)), pending_events);
750750
self.retry_payment_internal(payment_id, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path);
751751
},
752752
PaymentSendFailure::PartialFailure { failed_paths_retry: Some(retry), results, .. } => {
753-
push_payment_path_failed_evs(payment_id, payment_hash, route.paths, results.into_iter(), pending_events);
753+
push_path_failed_evs_and_scids(payment_id, payment_hash, None, route.paths, results.into_iter(), pending_events);
754754
// Some paths were sent, even if we failed to send the full MPP value our recipient may
755755
// misbehave and claim the funds, at which point we have to consider the payment sent, so
756756
// return `Ok()` here, ignoring any retry errors.
@@ -762,7 +762,7 @@ impl OutboundPayments {
762762
// initial HTLC-Add messages yet.
763763
},
764764
PaymentSendFailure::PathParameterError(results) => {
765-
push_payment_path_failed_evs(payment_id, payment_hash, route.paths, results.into_iter(), pending_events);
765+
push_path_failed_evs_and_scids(payment_id, payment_hash, None, route.paths, results.into_iter(), pending_events);
766766
self.abandon_payment(payment_id, pending_events);
767767
},
768768
PaymentSendFailure::ParameterError(e) => {
@@ -1270,14 +1270,17 @@ impl OutboundPayments {
12701270
}
12711271
}
12721272

1273-
fn push_payment_path_failed_evs<I: Iterator<Item = Result<(), APIError>>>(
1274-
payment_id: PaymentId, payment_hash: PaymentHash, paths: Vec<Vec<RouteHop>>, path_results: I,
1275-
pending_events: &Mutex<Vec<events::Event>>
1273+
fn push_path_failed_evs_and_scids<I: Iterator<Item = Result<(), APIError>>>(
1274+
payment_id: PaymentId, payment_hash: PaymentHash, mut route_params: Option<&mut RouteParameters>,
1275+
paths: Vec<Vec<RouteHop>>, path_results: I, pending_events: &Mutex<Vec<events::Event>>
12761276
) {
12771277
let mut events = pending_events.lock().unwrap();
12781278
for (path, path_res) in paths.into_iter().zip(path_results) {
12791279
if path_res.is_err() {
12801280
let scid = path[0].short_channel_id;
1281+
if let Some(ref mut params) = route_params {
1282+
params.payment_params.previously_failed_channels.push(scid);
1283+
}
12811284
events.push(events::Event::PaymentPathFailed {
12821285
payment_id: Some(payment_id),
12831286
payment_hash,

lightning/src/ln/payment_tests.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2196,9 +2196,11 @@ fn immediate_retry_on_failure() {
21962196
route.paths[0][0].short_channel_id = chans[1].short_channel_id.unwrap();
21972197
route.paths[0][0].fee_msat = 50_000_000;
21982198
route.paths[1][0].fee_msat = 50_000_001;
2199+
let mut pay_params = route_params.payment_params.clone();
2200+
pay_params.previously_failed_channels.push(chans[0].short_channel_id.unwrap());
21992201
nodes[0].router.expect_find_route(RouteParameters {
2200-
payment_params: route_params.payment_params.clone(),
2201-
final_value_msat: amt_msat, final_cltv_expiry_delta: TEST_FINAL_CLTV
2202+
payment_params: pay_params, final_value_msat: amt_msat,
2203+
final_cltv_expiry_delta: TEST_FINAL_CLTV
22022204
}, Ok(route.clone()));
22032205

22042206
nodes[0].node.send_payment_with_retry(payment_hash, &Some(payment_secret), PaymentId(payment_hash.0), route_params, Retry::Attempts(1)).unwrap();

0 commit comments

Comments
 (0)