Store retry data in PendingOutboundPayment::Retryable
authorValentine Wallace <vwallace@protonmail.com>
Sun, 18 Dec 2022 23:22:56 +0000 (18:22 -0500)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 25 Jan 2023 19:44:03 +0000 (14:44 -0500)
Used in upcoming commit(s) to automatically retry HTLCs in ChannelManager

lightning/src/ln/channelmanager.rs
lightning/src/ln/outbound_payment.rs

index ba54827d9a756bfbb073c1952a8194a3df5a0df9..b18ddaeba6bc4d2a3b882f8993162418c9929913 100644 (file)
@@ -53,7 +53,7 @@ use crate::ln::onion_utils::HTLCFailReason;
 use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, MAX_VALUE_MSAT};
 #[cfg(test)]
 use crate::ln::outbound_payment;
-use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, Retry};
+use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, Retry};
 use crate::ln::wire::Encode;
 use crate::chain::keysinterface::{EntropySource, KeysManager, NodeSigner, Recipient, Sign, SignerProvider};
 use crate::util::config::{UserConfig, ChannelConfig};
@@ -7278,6 +7278,9 @@ where
                                                                hash_map::Entry::Vacant(entry) => {
                                                                        let path_fee = path.get_path_fees();
                                                                        entry.insert(PendingOutboundPayment::Retryable {
+                                                                               retry_strategy: Retry::Attempts(0),
+                                                                               attempts: PaymentAttempts::new(),
+                                                                               route_params: None,
                                                                                session_privs: [session_priv_bytes].iter().map(|a| *a).collect(),
                                                                                payment_hash: htlc.payment_hash,
                                                                                payment_secret,
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),
        },