@@ -188,6 +188,37 @@ impl PendingOutboundPayment {
188
188
}
189
189
}
190
190
191
+ /// Strategies available to retry payment path failures.
192
+ #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
193
+ pub enum Retry {
194
+ /// Max number of attempts to retry payment.
195
+ ///
196
+ /// Note that this is the number of *path* failures, not full payment retries. For multi-path
197
+ /// payments, if this is less than the total number of paths, we will never even retry all of the
198
+ /// payment's paths.
199
+ Attempts ( usize ) ,
200
+ #[ cfg( not( feature = "no-std" ) ) ]
201
+ /// Time elapsed before abandoning retries for a payment.
202
+ Timeout ( core:: time:: Duration ) ,
203
+ }
204
+
205
+ impl Retry {
206
+ pub ( crate ) fn is_retryable_now ( & self , attempts : & PaymentAttempts ) -> bool {
207
+ match ( self , attempts) {
208
+ ( Retry :: Attempts ( max_retry_count) , PaymentAttempts { count, .. } ) => {
209
+ if * max_retry_count == 0 { return false }
210
+ * max_retry_count >= count. load ( Ordering :: Acquire )
211
+ } ,
212
+ #[ cfg( all( not( feature = "no-std" ) , not( test) ) ) ]
213
+ ( Retry :: Timeout ( max_duration) , PaymentAttempts { first_attempted_at, .. } ) =>
214
+ * max_duration >= std:: time:: Instant :: now ( ) . duration_since ( * first_attempted_at) ,
215
+ #[ cfg( all( not( feature = "no-std" ) , test) ) ]
216
+ ( Retry :: Timeout ( max_duration) , PaymentAttempts { first_attempted_at, .. } ) =>
217
+ * max_duration >= SinceEpoch :: now ( ) . duration_since ( * first_attempted_at) ,
218
+ }
219
+ }
220
+ }
221
+
191
222
pub ( crate ) type PaymentAttempts = PaymentAttemptsUsingTime < ConfiguredTime > ;
192
223
193
224
/// Storing minimal payment attempts information required for determining if a outbound payment can
0 commit comments