Skip to content

Commit efa348e

Browse files
Store retry data in PendingOutboundPayment::Retryable
Used in upcoming commit(s) to automatically retry HTLCs in ChannelManager
1 parent 3a29e4b commit efa348e

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
@@ -53,7 +53,7 @@ use crate::ln::onion_utils::HTLCFailReason;
5353
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, MAX_VALUE_MSAT};
5454
#[cfg(test)]
5555
use crate::ln::outbound_payment;
56-
use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, Retry};
56+
use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, Retry};
5757
use crate::ln::wire::Encode;
5858
use crate::chain::keysinterface::{EntropySource, KeysInterface, KeysManager, NodeSigner, Recipient, Sign, SignerProvider};
5959
use crate::util::config::{UserConfig, ChannelConfig};
@@ -6926,6 +6926,8 @@ where
69266926
hash_map::Entry::Vacant(entry) => {
69276927
let path_fee = path.get_path_fees();
69286928
entry.insert(PendingOutboundPayment::Retryable {
6929+
retry_strategy: Retry::Attempts(0),
6930+
attempts: PaymentAttempts::new(),
69296931
session_privs: [session_priv_bytes].iter().map(|a| *a).collect(),
69306932
payment_hash: htlc.payment_hash,
69316933
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,
@@ -509,6 +522,8 @@ impl OutboundPayments {
509522
hash_map::Entry::Occupied(_) => Err(PaymentSendFailure::DuplicatePayment),
510523
hash_map::Entry::Vacant(entry) => {
511524
let payment = entry.insert(PendingOutboundPayment::Retryable {
525+
retry_strategy,
526+
attempts: PaymentAttempts::new(),
512527
session_privs: HashSet::new(),
513528
pending_amt_msat: 0,
514529
pending_fee_msat: Some(0),
@@ -910,7 +925,9 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
910925
(0, session_privs, required),
911926
(1, pending_fee_msat, option),
912927
(2, payment_hash, required),
928+
(3, retry_strategy, (reset_on_reload, Retry::Attempts(0))),
913929
(4, payment_secret, option),
930+
(5, attempts, (reset_on_reload, PaymentAttempts::new())),
914931
(6, total_msat, required),
915932
(8, pending_amt_msat, required),
916933
(10, starting_block_height, required),

0 commit comments

Comments
 (0)