Skip to content

Commit caf523c

Browse files
Store retry data in PendingOutboundPayment::Retryable
Used in upcoming commit(s) to automatically retry HTLCs in ChannelManager
1 parent 5de89b8 commit caf523c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ use crate::ln::onion_utils;
5454
use crate::ln::onion_utils::HTLCFailReason;
5555
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, MAX_VALUE_MSAT};
5656
#[cfg(test)]
57-
use crate::ln::outbound_payment::{self, Retry};
58-
use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment};
57+
use crate::ln::outbound_payment;
58+
use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, Retry};
5959
use crate::ln::wire::Encode;
6060
use crate::chain::keysinterface::{EntropySource, KeysInterface, KeysManager, NodeSigner, Recipient, Sign, SignerProvider};
6161
use crate::util::config::{UserConfig, ChannelConfig};
@@ -6939,6 +6939,8 @@ where
69396939
hash_map::Entry::Vacant(entry) => {
69406940
let path_fee = path.get_path_fees();
69416941
entry.insert(PendingOutboundPayment::Retryable {
6942+
retry_strategy: Retry::Attempts(0),
6943+
attempts: PaymentAttempts::new(),
69426944
session_privs: [session_priv_bytes].iter().map(|a| *a).collect(),
69436945
payment_hash: htlc.payment_hash,
69446946
payment_secret,

lightning/src/ln/outbound_payment.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub(crate) enum PendingOutboundPayment {
4141
session_privs: HashSet<[u8; 32]>,
4242
},
4343
Retryable {
44+
retry_strategy: Retry,
45+
attempts: PaymentAttempts,
4446
session_privs: HashSet<[u8; 32]>,
4547
payment_hash: PaymentHash,
4648
payment_secret: Option<PaymentSecret>,
@@ -74,6 +76,17 @@ pub(crate) enum PendingOutboundPayment {
7476
}
7577

7678
impl PendingOutboundPayment {
79+
fn increment_attempts(&self) {
80+
if let PendingOutboundPayment::Retryable { attempts, .. } = self {
81+
attempts.count.fetch_add(1, Ordering::AcqRel);
82+
}
83+
}
84+
fn is_retryable(&self) -> bool {
85+
if let PendingOutboundPayment::Retryable { retry_strategy, attempts, .. } = self {
86+
return retry_strategy.is_retryable_now(&attempts)
87+
}
88+
false
89+
}
7790
pub(super) fn is_fulfilled(&self) -> bool {
7891
match self {
7992
PendingOutboundPayment::Fulfilled { .. } => true,
@@ -517,6 +530,8 @@ impl OutboundPayments {
517530
hash_map::Entry::Occupied(_) => Err(PaymentSendFailure::DuplicatePayment),
518531
hash_map::Entry::Vacant(entry) => {
519532
let payment = entry.insert(PendingOutboundPayment::Retryable {
533+
retry_strategy,
534+
attempts: PaymentAttempts::new(),
520535
session_privs: HashSet::new(),
521536
pending_amt_msat: 0,
522537
pending_fee_msat: Some(0),
@@ -920,7 +935,9 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
920935
(0, session_privs, required),
921936
(1, pending_fee_msat, option),
922937
(2, payment_hash, required),
938+
(3, retry_strategy, (reset_on_reload, Retry::Attempts(0))),
923939
(4, payment_secret, option),
940+
(5, attempts, (reset_on_reload, PaymentAttempts::new())),
924941
(6, total_msat, required),
925942
(8, pending_amt_msat, required),
926943
(10, starting_block_height, required),

0 commit comments

Comments
 (0)