@@ -15,7 +15,7 @@ use bitcoin::secp256k1::{self, Secp256k1, SecretKey};
15
15
16
16
use crate :: chain:: keysinterface:: { EntropySource , NodeSigner , Recipient } ;
17
17
use crate :: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
18
- use crate :: ln:: channelmanager:: { HTLCSource , IDEMPOTENCY_TIMEOUT_TICKS , PaymentId } ;
18
+ use crate :: ln:: channelmanager:: { HTLCSource , IDEMPOTENCY_TIMEOUT_TICKS , MIN_HTLC_RELAY_HOLDING_CELL_MILLIS , PaymentId } ;
19
19
use crate :: ln:: msgs:: DecodeError ;
20
20
use crate :: ln:: onion_utils:: HTLCFailReason ;
21
21
use crate :: routing:: router:: { PaymentParameters , Route , RouteHop , RouteParameters , RoutePath } ;
@@ -29,6 +29,7 @@ use crate::util::time::tests::SinceEpoch;
29
29
use core:: cmp;
30
30
use core:: fmt:: { self , Display , Formatter } ;
31
31
use core:: ops:: Deref ;
32
+ use core:: time:: Duration ;
32
33
33
34
use crate :: prelude:: * ;
34
35
use crate :: sync:: Mutex ;
@@ -87,6 +88,11 @@ impl PendingOutboundPayment {
87
88
}
88
89
false
89
90
}
91
+ pub fn insert_previously_failed_scid ( & mut self , scid : u64 ) {
92
+ if let PendingOutboundPayment :: Retryable { route_params : Some ( params) , .. } = self {
93
+ params. payment_params . previously_failed_channels . push ( scid) ;
94
+ }
95
+ }
90
96
pub ( super ) fn is_fulfilled ( & self ) -> bool {
91
97
match self {
92
98
PendingOutboundPayment :: Fulfilled { .. } => true ,
@@ -793,7 +799,8 @@ impl OutboundPayments {
793
799
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
794
800
let mut all_paths_failed = false ;
795
801
let mut full_failure_ev = None ;
796
- if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( * payment_id) {
802
+ let mut pending_retry_ev = None ;
803
+ let attempts_remaining = if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( * payment_id) {
797
804
if !payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path) ) {
798
805
log_trace ! ( logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
799
806
return
@@ -802,6 +809,10 @@ impl OutboundPayments {
802
809
log_trace ! ( logger, "Received failure of HTLC with payment_hash {} after payment completion" , log_bytes!( payment_hash. 0 ) ) ;
803
810
return
804
811
}
812
+ let is_retryable_now = payment. get ( ) . is_retryable_now ( ) ;
813
+ if let Some ( scid) = short_channel_id {
814
+ payment. get_mut ( ) . insert_previously_failed_scid ( scid) ;
815
+ }
805
816
if payment. get ( ) . remaining_parts ( ) == 0 {
806
817
all_paths_failed = true ;
807
818
if payment. get ( ) . abandoned ( ) {
@@ -812,10 +823,11 @@ impl OutboundPayments {
812
823
payment. remove ( ) ;
813
824
}
814
825
}
826
+ is_retryable_now
815
827
} else {
816
828
log_trace ! ( logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
817
829
return
818
- }
830
+ } ;
819
831
core:: mem:: drop ( outbounds) ;
820
832
let mut retry = if let Some ( payment_params_data) = payment_params {
821
833
let path_last_hop = path. last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
@@ -850,6 +862,12 @@ impl OutboundPayments {
850
862
if let Some ( scid) = short_channel_id {
851
863
retry. as_mut ( ) . map ( |r| r. payment_params . previously_failed_channels . push ( scid) ) ;
852
864
}
865
+ if payment_retryable && attempts_remaining && retry. is_some ( ) {
866
+ debug_assert ! ( full_failure_ev. is_none( ) ) ;
867
+ pending_retry_ev = Some ( events:: Event :: PendingHTLCsForwardable {
868
+ time_forwardable : Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ,
869
+ } ) ;
870
+ }
853
871
events:: Event :: PaymentPathFailed {
854
872
payment_id : Some ( * payment_id) ,
855
873
payment_hash : payment_hash. clone ( ) ,
@@ -869,6 +887,7 @@ impl OutboundPayments {
869
887
let mut pending_events = pending_events. lock ( ) . unwrap ( ) ;
870
888
pending_events. push ( path_failure) ;
871
889
if let Some ( ev) = full_failure_ev { pending_events. push ( ev) ; }
890
+ if let Some ( ev) = pending_retry_ev { pending_events. push ( ev) ; }
872
891
}
873
892
874
893
pub ( super ) fn abandon_payment ( & self , payment_id : PaymentId ) -> Option < events:: Event > {
0 commit comments