Skip to content

Commit 107e6e1

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 8492847 commit 107e6e1

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,8 @@ impl OutboundPayments {
725725

726726
fn handle_pay_route_err<R: Deref, NS: Deref, ES: Deref, IH, SP, L: Deref>(
727727
&self, err: PaymentSendFailure, payment_id: PaymentId, payment_hash: PaymentHash, route: Route,
728-
route_params: RouteParameters, router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: &IH,
729-
entropy_source: &ES, node_signer: &NS, best_block_height: u32, logger: &L,
728+
mut route_params: RouteParameters, router: &R, first_hops: Vec<ChannelDetails>,
729+
inflight_htlcs: &IH, entropy_source: &ES, node_signer: &NS, best_block_height: u32, logger: &L,
730730
pending_events: &Mutex<Vec<events::Event>>, send_payment_along_path: &SP,
731731
)
732732
where
@@ -740,11 +740,11 @@ impl OutboundPayments {
740740
{
741741
match err {
742742
PaymentSendFailure::AllFailedResendSafe(errs) => {
743-
push_payment_path_failed_evs(payment_id, payment_hash, route.paths, errs.into_iter().map(|e| Err(e)), pending_events);
743+
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);
744744
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);
745745
},
746746
PaymentSendFailure::PartialFailure { failed_paths_retry: Some(retry), results, .. } => {
747-
push_payment_path_failed_evs(payment_id, payment_hash, route.paths, results.into_iter(), pending_events);
747+
push_path_failed_evs_and_scids(payment_id, payment_hash, None, route.paths, results.into_iter(), pending_events);
748748
// Some paths were sent, even if we failed to send the full MPP value our recipient may
749749
// misbehave and claim the funds, at which point we have to consider the payment sent, so
750750
// return `Ok()` here, ignoring any retry errors.
@@ -756,7 +756,7 @@ impl OutboundPayments {
756756
// initial HTLC-Add messages yet.
757757
},
758758
PaymentSendFailure::PathParameterError(results) => {
759-
push_payment_path_failed_evs(payment_id, payment_hash, route.paths, results.into_iter(), pending_events);
759+
push_path_failed_evs_and_scids(payment_id, payment_hash, None, route.paths, results.into_iter(), pending_events);
760760
self.abandon_payment(payment_id, pending_events);
761761
},
762762
PaymentSendFailure::ParameterError(e) => {
@@ -1261,14 +1261,17 @@ impl OutboundPayments {
12611261
}
12621262
}
12631263

1264-
fn push_payment_path_failed_evs<I: Iterator<Item = Result<(), APIError>>>(
1265-
payment_id: PaymentId, payment_hash: PaymentHash, paths: Vec<Vec<RouteHop>>, path_results: I,
1266-
pending_events: &Mutex<Vec<events::Event>>
1264+
fn push_path_failed_evs_and_scids<I: Iterator<Item = Result<(), APIError>>>(
1265+
payment_id: PaymentId, payment_hash: PaymentHash, mut route_params: Option<&mut RouteParameters>,
1266+
paths: Vec<Vec<RouteHop>>, path_results: I, pending_events: &Mutex<Vec<events::Event>>
12671267
) {
12681268
let mut events = pending_events.lock().unwrap();
12691269
for (path, path_res) in paths.into_iter().zip(path_results) {
12701270
if let Err(e) = path_res {
12711271
let scid = path[0].short_channel_id;
1272+
if let Some(ref mut params) = route_params {
1273+
params.payment_params.previously_failed_channels.push(scid);
1274+
}
12721275
events.push(events::Event::PaymentPathFailed {
12731276
payment_id: Some(payment_id),
12741277
payment_hash,

lightning/src/ln/payment_tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,9 +2199,11 @@ fn immediate_retry_on_failure() {
21992199
route.paths[0][0].short_channel_id = chans[1].short_channel_id.unwrap();
22002200
route.paths[0][0].fee_msat = 50_000_000;
22012201
route.paths[1][0].fee_msat = 50_000_001;
2202+
let mut pay_params = route_params.payment_params.clone();
2203+
pay_params.previously_failed_channels.push(chans[0].short_channel_id.unwrap());
22022204
nodes[0].router.expect_find_route(RouteParameters {
2203-
payment_params: route_params.payment_params.clone(),
2204-
final_value_msat: amt_msat, final_cltv_expiry_delta: TEST_FINAL_CLTV
2205+
payment_params: pay_params, final_value_msat: amt_msat,
2206+
final_cltv_expiry_delta: TEST_FINAL_CLTV
22052207
}, Ok(route.clone()));
22062208

22072209
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)