Store retry data in PendingOutboundPayment::Retryable
[rust-lightning] / lightning / src / ln / outbound_payment.rs
index e230002a04ed7c00fea2785cc6564726bb565c8d..a4211ea34d6912d7283a09105258c14a143f32b1 100644 (file)
@@ -40,6 +40,9 @@ pub(crate) enum PendingOutboundPayment {
                session_privs: HashSet<[u8; 32]>,
        },
        Retryable {
+               retry_strategy: Retry,
+               attempts: PaymentAttempts,
+               route_params: Option<RouteParameters>,
                session_privs: HashSet<[u8; 32]>,
                payment_hash: PaymentHash,
                payment_secret: Option<PaymentSecret>,
@@ -73,6 +76,17 @@ pub(crate) enum PendingOutboundPayment {
 }
 
 impl PendingOutboundPayment {
+       fn increment_attempts(&mut self) {
+               if let PendingOutboundPayment::Retryable { attempts, .. } = self {
+                       attempts.count += 1;
+               }
+       }
+       fn is_retryable_now(&self) -> bool {
+               if let PendingOutboundPayment::Retryable { retry_strategy, attempts, .. } = self {
+                       return retry_strategy.is_retryable_now(&attempts)
+               }
+               false
+       }
        pub(super) fn is_fulfilled(&self) -> bool {
                match self {
                        PendingOutboundPayment::Fulfilled { .. } => true,
@@ -508,6 +522,9 @@ impl OutboundPayments {
                        hash_map::Entry::Occupied(_) => Err(PaymentSendFailure::DuplicatePayment),
                        hash_map::Entry::Vacant(entry) => {
                                let payment = entry.insert(PendingOutboundPayment::Retryable {
+                                       retry_strategy,
+                                       attempts: PaymentAttempts::new(),
+                                       route_params,
                                        session_privs: HashSet::new(),
                                        pending_amt_msat: 0,
                                        pending_fee_msat: Some(0),
@@ -911,8 +928,11 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
                (0, session_privs, required),
                (1, pending_fee_msat, option),
                (2, payment_hash, required),
+               (not_written, retry_strategy, (static_value, Retry::Attempts(0))),
                (4, payment_secret, option),
+               (not_written, attempts, (static_value, PaymentAttempts::new())),
                (6, total_msat, required),
+               (not_written, route_params, (static_value, None)),
                (8, pending_amt_msat, required),
                (10, starting_block_height, required),
        },