@@ -51,7 +51,7 @@ use crate::ln::msgs;
51
51
use crate :: ln:: onion_utils;
52
52
use crate :: ln:: onion_utils:: HTLCFailReason ;
53
53
use crate :: ln:: msgs:: { ChannelMessageHandler , DecodeError , LightningError , MAX_VALUE_MSAT } ;
54
- use crate :: ln:: payment_retry:: Retry ;
54
+ use crate :: ln:: payment_retry:: { PaymentAttempts , Retry } ;
55
55
use crate :: ln:: wire:: Encode ;
56
56
use crate :: chain:: keysinterface:: { Sign , KeysInterface , KeysManager , Recipient } ;
57
57
use crate :: util:: config:: { UserConfig , ChannelConfig } ;
@@ -488,6 +488,8 @@ pub(crate) enum PendingOutboundPayment {
488
488
session_privs : HashSet < [ u8 ; 32 ] > ,
489
489
} ,
490
490
Retryable {
491
+ retry_strategy : Retry ,
492
+ attempts : PaymentAttempts ,
491
493
session_privs : HashSet < [ u8 ; 32 ] > ,
492
494
payment_hash : PaymentHash ,
493
495
payment_secret : Option < PaymentSecret > ,
@@ -521,6 +523,17 @@ pub(crate) enum PendingOutboundPayment {
521
523
}
522
524
523
525
impl 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
+ }
524
537
fn is_fulfilled ( & self ) -> bool {
525
538
match self {
526
539
PendingOutboundPayment :: Fulfilled { .. } => true ,
@@ -2610,6 +2623,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, R: Deref, L: Deref> ChannelManager<
2610
2623
hash_map:: Entry :: Occupied ( _) => Err ( PaymentSendFailure :: DuplicatePayment ) ,
2611
2624
hash_map:: Entry :: Vacant ( entry) => {
2612
2625
let payment = entry. insert ( PendingOutboundPayment :: Retryable {
2626
+ retry_strategy,
2627
+ attempts : PaymentAttempts :: new ( ) ,
2613
2628
session_privs : HashSet :: new ( ) ,
2614
2629
pending_amt_msat : 0 ,
2615
2630
pending_fee_msat : Some ( 0 ) ,
@@ -6979,7 +6994,9 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
6979
6994
( 0 , session_privs, required) ,
6980
6995
( 1 , pending_fee_msat, option) ,
6981
6996
( 2 , payment_hash, required) ,
6997
+ ( 3 , retry_strategy, ( reset_on_reload, Retry :: Attempts ( 0 ) ) ) ,
6982
6998
( 4 , payment_secret, option) ,
6999
+ ( 5 , attempts, ( reset_on_reload, PaymentAttempts :: new( ) ) ) ,
6983
7000
( 6 , total_msat, required) ,
6984
7001
( 8 , pending_amt_msat, required) ,
6985
7002
( 10 , starting_block_height, required) ,
@@ -7546,6 +7563,8 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, R: Deref, L: Deref>
7546
7563
hash_map:: Entry :: Vacant ( entry) => {
7547
7564
let path_fee = path. get_path_fees ( ) ;
7548
7565
entry. insert ( PendingOutboundPayment :: Retryable {
7566
+ retry_strategy : Retry :: Attempts ( 0 ) ,
7567
+ attempts : PaymentAttempts :: new ( ) ,
7549
7568
session_privs : [ session_priv_bytes] . iter ( ) . map ( |a| * a) . collect ( ) ,
7550
7569
payment_hash : htlc. payment_hash ,
7551
7570
payment_secret,
0 commit comments