Skip to content

Commit cbb75e2

Browse files
Copy Retry from invoice module to outbound_payment module
Also configure it such that in std tests, it will use SinceEpoch instead of Instant so time can be manually advanced.
1 parent 948ebc6 commit cbb75e2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,36 @@ impl PendingOutboundPayment {
187187
}
188188
}
189189

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

192222
/// Storing minimal payment attempts information required for determining if a outbound payment can

0 commit comments

Comments
 (0)