Skip to content

Commit 37c40b2

Browse files
Store retry data in PendingOutboundPayment::Retryable
Used in upcoming commit(s) to automatically retry HTLCs in ChannelManager
1 parent 85e2097 commit 37c40b2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, MAX_VA
5454
pub use crate::ln::outbound_payment::PaymentSendFailure;
5555
#[cfg(test)]
5656
use crate::ln::outbound_payment;
57-
use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, Retry};
57+
use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, Retry};
5858
use crate::ln::wire::Encode;
5959
use crate::chain::keysinterface::{Sign, KeysInterface, KeysManager, Recipient};
6060
use crate::util::config::{UserConfig, ChannelConfig};
@@ -6933,6 +6933,8 @@ where
69336933
hash_map::Entry::Vacant(entry) => {
69346934
let path_fee = path.get_path_fees();
69356935
entry.insert(PendingOutboundPayment::Retryable {
6936+
retry_strategy: Retry::Attempts(0),
6937+
attempts: PaymentAttempts::new(),
69366938
session_privs: [session_priv_bytes].iter().map(|a| *a).collect(),
69376939
payment_hash: htlc.payment_hash,
69386940
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,
@@ -507,6 +520,8 @@ impl OutboundPayments {
507520
hash_map::Entry::Occupied(_) => Err(PaymentSendFailure::DuplicatePayment),
508521
hash_map::Entry::Vacant(entry) => {
509522
let payment = entry.insert(PendingOutboundPayment::Retryable {
523+
retry_strategy,
524+
attempts: PaymentAttempts::new(),
510525
session_privs: HashSet::new(),
511526
pending_amt_msat: 0,
512527
pending_fee_msat: Some(0),
@@ -906,7 +921,9 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
906921
(0, session_privs, required),
907922
(1, pending_fee_msat, option),
908923
(2, payment_hash, required),
924+
(3, retry_strategy, (reset_on_reload, Retry::Attempts(0))),
909925
(4, payment_secret, option),
926+
(5, attempts, (reset_on_reload, PaymentAttempts::new())),
910927
(6, total_msat, required),
911928
(8, pending_amt_msat, required),
912929
(10, starting_block_height, required),

0 commit comments

Comments
 (0)