@@ -82,22 +82,22 @@ impl PendingOutboundPayment {
82
82
attempts. count += 1 ;
83
83
}
84
84
}
85
- fn auto_retries_remaining_now ( & self ) -> usize {
85
+ fn is_auto_retryable_now ( & self ) -> bool {
86
86
match self {
87
87
PendingOutboundPayment :: Retryable { retry_strategy : Some ( strategy) , attempts, .. } => {
88
- strategy. retries_remaining_now ( & attempts)
88
+ strategy. is_retryable_now ( & attempts)
89
89
} ,
90
- _ => 0 ,
90
+ _ => false ,
91
91
}
92
92
}
93
- fn is_retryable_now ( & self , pending_paths : usize ) -> bool {
93
+ fn is_retryable_now ( & self ) -> bool {
94
94
match self {
95
95
PendingOutboundPayment :: Retryable { retry_strategy : None , .. } => {
96
96
// We're handling retries manually, we can always retry.
97
97
true
98
98
} ,
99
99
PendingOutboundPayment :: Retryable { retry_strategy : Some ( strategy) , attempts, .. } => {
100
- strategy. retries_remaining_now ( & attempts) >= pending_paths
100
+ strategy. is_retryable_now ( & attempts)
101
101
} ,
102
102
_ => false ,
103
103
}
@@ -236,17 +236,17 @@ pub enum Retry {
236
236
}
237
237
238
238
impl Retry {
239
- pub ( crate ) fn retries_remaining_now ( & self , attempts : & PaymentAttempts ) -> usize {
239
+ pub ( crate ) fn is_retryable_now ( & self , attempts : & PaymentAttempts ) -> bool {
240
240
match ( self , attempts) {
241
241
( Retry :: Attempts ( max_retry_count) , PaymentAttempts { count, .. } ) => {
242
- * max_retry_count - count
242
+ max_retry_count > count
243
243
} ,
244
244
#[ cfg( all( not( feature = "no-std" ) , not( test) ) ) ]
245
245
( 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) ,
247
247
#[ cfg( all( not( feature = "no-std" ) , test) ) ]
248
248
( 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) ,
250
250
}
251
251
}
252
252
}
@@ -473,15 +473,10 @@ impl OutboundPayments {
473
473
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
474
474
let mut retry_id_route_params = None ;
475
475
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 ( ) {
478
477
if let PendingOutboundPayment :: Retryable { pending_amt_msat, total_msat, route_params : Some ( params) , .. } = pmt {
479
478
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 ( ) ) ) ;
485
480
break
486
481
}
487
482
}
@@ -615,14 +610,14 @@ impl OutboundPayments {
615
610
} ) ) ;
616
611
} ,
617
612
} ;
618
- if !payment. is_retryable_now ( route . paths . len ( ) ) {
613
+ if !payment. is_retryable_now ( ) {
619
614
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
620
615
err : format ! ( "Retries exhausted for payment id {}" , log_bytes!( payment_id. 0 ) ) ,
621
616
} ) )
622
617
}
618
+ payment. increment_attempts ( ) ;
623
619
for ( path, session_priv_bytes) in route. paths . iter ( ) . zip ( onion_session_privs. iter ( ) ) {
624
620
assert ! ( payment. insert( * session_priv_bytes, path) ) ;
625
- payment. increment_attempts ( ) ;
626
621
}
627
622
res
628
623
} ,
@@ -979,7 +974,7 @@ impl OutboundPayments {
979
974
log_trace ! ( logger, "Received failure of HTLC with payment_hash {} after payment completion" , log_bytes!( payment_hash. 0 ) ) ;
980
975
return
981
976
}
982
- let is_retryable_now = payment. get ( ) . auto_retries_remaining_now ( ) > 0 ;
977
+ let is_retryable_now = payment. get ( ) . is_auto_retryable_now ( ) ;
983
978
if let Some ( scid) = short_channel_id {
984
979
payment. get_mut ( ) . insert_previously_failed_scid ( scid) ;
985
980
}
0 commit comments