@@ -51,7 +51,7 @@ use crate::ln::msgs;
5151use crate :: ln:: onion_utils;
5252use crate :: ln:: onion_utils:: HTLCFailReason ;
5353use crate :: ln:: msgs:: { ChannelMessageHandler , DecodeError , LightningError , MAX_VALUE_MSAT } ;
54- use crate :: ln:: payment_retry:: Retry ;
54+ use crate :: ln:: payment_retry:: { PaymentAttempts , Retry } ;
5555use crate :: ln:: wire:: Encode ;
5656use crate :: chain:: keysinterface:: { Sign , KeysInterface , KeysManager , Recipient } ;
5757use crate :: util:: config:: { UserConfig , ChannelConfig } ;
@@ -488,6 +488,8 @@ pub(crate) enum PendingOutboundPayment {
488488 session_privs : HashSet < [ u8 ; 32 ] > ,
489489 } ,
490490 Retryable {
491+ retry_strategy : Retry ,
492+ attempts : PaymentAttempts ,
491493 session_privs : HashSet < [ u8 ; 32 ] > ,
492494 payment_hash : PaymentHash ,
493495 payment_secret : Option < PaymentSecret > ,
@@ -521,6 +523,17 @@ pub(crate) enum PendingOutboundPayment {
521523}
522524
523525impl PendingOutboundPayment {
526+ fn increment_attempts ( & self ) {
527+ if let PendingOutboundPayment :: Retryable { attempts, .. } = self {
528+ attempts. count . fetch_add ( 1 , Ordering :: AcqRel ) ;
529+ }
530+ }
531+ fn is_retryable ( & self ) -> bool {
532+ if let PendingOutboundPayment :: Retryable { retry_strategy, attempts, .. } = self {
533+ return retry_strategy. is_retryable_now ( & attempts)
534+ }
535+ false
536+ }
524537 fn is_fulfilled ( & self ) -> bool {
525538 match self {
526539 PendingOutboundPayment :: Fulfilled { .. } => true ,
@@ -2610,6 +2623,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, R: Deref, L: Deref> ChannelManager<
26102623 hash_map:: Entry :: Occupied ( _) => Err ( PaymentSendFailure :: DuplicatePayment ) ,
26112624 hash_map:: Entry :: Vacant ( entry) => {
26122625 let payment = entry. insert ( PendingOutboundPayment :: Retryable {
2626+ retry_strategy,
2627+ attempts : PaymentAttempts :: new ( ) ,
26132628 session_privs : HashSet :: new ( ) ,
26142629 pending_amt_msat : 0 ,
26152630 pending_fee_msat : Some ( 0 ) ,
@@ -6979,7 +6994,9 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
69796994 ( 0 , session_privs, required) ,
69806995 ( 1 , pending_fee_msat, option) ,
69816996 ( 2 , payment_hash, required) ,
6997+ ( 3 , retry_strategy, ( reset_on_reload, Retry :: Attempts ( 0 ) ) ) ,
69826998 ( 4 , payment_secret, option) ,
6999+ ( 5 , attempts, ( reset_on_reload, PaymentAttempts :: new( ) ) ) ,
69837000 ( 6 , total_msat, required) ,
69847001 ( 8 , pending_amt_msat, required) ,
69857002 ( 10 , starting_block_height, required) ,
@@ -7546,6 +7563,8 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, R: Deref, L: Deref>
75467563 hash_map:: Entry :: Vacant ( entry) => {
75477564 let path_fee = path. get_path_fees ( ) ;
75487565 entry. insert ( PendingOutboundPayment :: Retryable {
7566+ retry_strategy : Retry :: Attempts ( 0 ) ,
7567+ attempts : PaymentAttempts :: new ( ) ,
75497568 session_privs : [ session_priv_bytes] . iter ( ) . map ( |a| * a) . collect ( ) ,
75507569 payment_hash : htlc. payment_hash ,
75517570 payment_secret,
0 commit comments