From: Valentine Wallace Date: Sun, 18 Dec 2022 23:22:56 +0000 (-0500) Subject: Store retry data in PendingOutboundPayment::Retryable X-Git-Tag: v0.0.114-beta~43^2~8 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=c0a22f717432cbf7f0c0cf60f3a247588617b7ae;p=rust-lightning Store retry data in PendingOutboundPayment::Retryable Used in upcoming commit(s) to automatically retry HTLCs in ChannelManager --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index ba54827d9..b18ddaeba 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -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, diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index e230002a0..a4211ea34 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -40,6 +40,9 @@ pub(crate) enum PendingOutboundPayment { session_privs: HashSet<[u8; 32]>, }, Retryable { + retry_strategy: Retry, + attempts: PaymentAttempts, + route_params: Option, session_privs: HashSet<[u8; 32]>, payment_hash: PaymentHash, payment_secret: Option, @@ -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), },