Skip to content

Commit 3803654

Browse files
committed
f reset retries to be per-send not per-path again
1 parent 06947cc commit 3803654

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,22 @@ impl PendingOutboundPayment {
8282
attempts.count += 1;
8383
}
8484
}
85-
fn auto_retries_remaining_now(&self) -> usize {
85+
fn is_auto_retryable_now(&self) -> bool {
8686
match self {
8787
PendingOutboundPayment::Retryable { retry_strategy: Some(strategy), attempts, .. } => {
88-
strategy.retries_remaining_now(&attempts)
88+
strategy.is_retryable_now(&attempts)
8989
},
90-
_ => 0,
90+
_ => false,
9191
}
9292
}
93-
fn is_retryable_now(&self, pending_paths: usize) -> bool {
93+
fn is_retryable_now(&self) -> bool {
9494
match self {
9595
PendingOutboundPayment::Retryable { retry_strategy: None, .. } => {
9696
// We're handling retries manually, we can always retry.
9797
true
9898
},
9999
PendingOutboundPayment::Retryable { retry_strategy: Some(strategy), attempts, .. } => {
100-
strategy.retries_remaining_now(&attempts) >= pending_paths
100+
strategy.is_retryable_now(&attempts)
101101
},
102102
_ => false,
103103
}
@@ -236,17 +236,17 @@ pub enum Retry {
236236
}
237237

238238
impl Retry {
239-
pub(crate) fn retries_remaining_now(&self, attempts: &PaymentAttempts) -> usize {
239+
pub(crate) fn is_retryable_now(&self, attempts: &PaymentAttempts) -> bool {
240240
match (self, attempts) {
241241
(Retry::Attempts(max_retry_count), PaymentAttempts { count, .. }) => {
242-
*max_retry_count - count
242+
max_retry_count > count
243243
},
244244
#[cfg(all(not(feature = "no-std"), not(test)))]
245245
(Retry::Timeout(max_duration), PaymentAttempts { first_attempted_at, .. }) =>
246-
if *max_duration >= std::time::Instant::now().duration_since(*first_attempted_at) { usize::max_value() } else { 0 },
246+
*max_duration >= std::time::Instant::now().duration_since(*first_attempted_at),
247247
#[cfg(all(not(feature = "no-std"), test))]
248248
(Retry::Timeout(max_duration), PaymentAttempts { first_attempted_at, .. }) =>
249-
if *max_duration >= SinceEpoch::now().duration_since(*first_attempted_at) { usize::max_value() } else { 0 },
249+
*max_duration >= SinceEpoch::now().duration_since(*first_attempted_at),
250250
}
251251
}
252252
}
@@ -473,15 +473,10 @@ impl OutboundPayments {
473473
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
474474
let mut retry_id_route_params = None;
475475
for (pmt_id, pmt) in outbounds.iter_mut() {
476-
let retries_remaining = pmt.auto_retries_remaining_now();
477-
if retries_remaining > 0 {
476+
if pmt.is_auto_retryable_now() {
478477
if let PendingOutboundPayment::Retryable { pending_amt_msat, total_msat, route_params: Some(params), .. } = pmt {
479478
if pending_amt_msat < total_msat {
480-
let mut params = params.clone();
481-
if params.payment_params.max_path_count as usize > retries_remaining {
482-
params.payment_params.max_path_count = retries_remaining as u8;
483-
}
484-
retry_id_route_params = Some((*pmt_id, params));
479+
retry_id_route_params = Some((*pmt_id, params.clone()));
485480
break
486481
}
487482
}
@@ -615,14 +610,14 @@ impl OutboundPayments {
615610
}));
616611
},
617612
};
618-
if !payment.is_retryable_now(route.paths.len()) {
613+
if !payment.is_retryable_now() {
619614
return Err(PaymentSendFailure::ParameterError(APIError::APIMisuseError {
620615
err: format!("Retries exhausted for payment id {}", log_bytes!(payment_id.0)),
621616
}))
622617
}
618+
payment.increment_attempts();
623619
for (path, session_priv_bytes) in route.paths.iter().zip(onion_session_privs.iter()) {
624620
assert!(payment.insert(*session_priv_bytes, path));
625-
payment.increment_attempts();
626621
}
627622
res
628623
},
@@ -979,7 +974,7 @@ impl OutboundPayments {
979974
log_trace!(logger, "Received failure of HTLC with payment_hash {} after payment completion", log_bytes!(payment_hash.0));
980975
return
981976
}
982-
let is_retryable_now = payment.get().auto_retries_remaining_now() > 0;
977+
let is_retryable_now = payment.get().is_auto_retryable_now();
983978
if let Some(scid) = short_channel_id {
984979
payment.get_mut().insert_previously_failed_scid(scid);
985980
}

lightning/src/ln/payment_tests.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ fn retry_multi_path_single_failed_payment() {
21342134
final_value_msat: 100_000_001, final_cltv_expiry_delta: TEST_FINAL_CLTV
21352135
}, Ok(route.clone()));
21362136

2137-
nodes[0].node.send_payment_with_retry(payment_hash, &Some(payment_secret), PaymentId(payment_hash.0), route_params, Retry::Attempts(2)).unwrap();
2137+
nodes[0].node.send_payment_with_retry(payment_hash, &Some(payment_secret), PaymentId(payment_hash.0), route_params, Retry::Attempts(1)).unwrap();
21382138
let htlc_msgs = nodes[0].node.get_and_clear_pending_msg_events();
21392139
assert_eq!(htlc_msgs.len(), 2);
21402140
check_added_monitors!(nodes[0], 2);
@@ -2195,7 +2195,7 @@ fn immediate_retry_on_failure() {
21952195
final_value_msat: amt_msat, final_cltv_expiry_delta: TEST_FINAL_CLTV
21962196
}, Ok(route.clone()));
21972197

2198-
nodes[0].node.send_payment_with_retry(payment_hash, &Some(payment_secret), PaymentId(payment_hash.0), route_params, Retry::Attempts(2)).unwrap();
2198+
nodes[0].node.send_payment_with_retry(payment_hash, &Some(payment_secret), PaymentId(payment_hash.0), route_params, Retry::Attempts(1)).unwrap();
21992199
let htlc_msgs = nodes[0].node.get_and_clear_pending_msg_events();
22002200
assert_eq!(htlc_msgs.len(), 2);
22012201
check_added_monitors!(nodes[0], 2);
@@ -2282,8 +2282,7 @@ fn no_extra_retries_on_back_to_back_fail() {
22822282
nodes[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
22832283
let mut second_payment_params = route_params.payment_params.clone();
22842284
second_payment_params.previously_failed_channels = vec![chan_2_scid, chan_2_scid];
2285-
// We'll only have one retry left at the end, so we'll hlepfully get a max_path_count of 1
2286-
second_payment_params.max_path_count = 1;
2285+
// On retry, we'll only return one path
22872286
route.paths.remove(1);
22882287
route.paths[0][1].fee_msat = amt_msat;
22892288
nodes[0].router.expect_find_route(RouteParameters {

0 commit comments

Comments
 (0)