@@ -68,6 +68,8 @@ pub(crate) enum PendingOutboundPayment {
68
68
Abandoned {
69
69
session_privs : HashSet < [ u8 ; 32 ] > ,
70
70
payment_hash : PaymentHash ,
71
+ /// Will be `None` if the payment was serialized before 0.0.115.
72
+ reason : Option < PaymentFailureReason > ,
71
73
} ,
72
74
}
73
75
@@ -145,7 +147,7 @@ impl PendingOutboundPayment {
145
147
* self = PendingOutboundPayment :: Fulfilled { session_privs, payment_hash, timer_ticks_without_htlcs : 0 } ;
146
148
}
147
149
148
- fn mark_abandoned ( & mut self ) -> Result < ( ) , ( ) > {
150
+ fn mark_abandoned ( & mut self , reason : PaymentFailureReason ) -> Result < ( ) , ( ) > {
149
151
let mut session_privs = HashSet :: new ( ) ;
150
152
let our_payment_hash;
151
153
core:: mem:: swap ( & mut session_privs, match self {
@@ -158,7 +160,7 @@ impl PendingOutboundPayment {
158
160
session_privs
159
161
} ,
160
162
} ) ;
161
- * self = PendingOutboundPayment :: Abandoned { session_privs, payment_hash : our_payment_hash } ;
163
+ * self = PendingOutboundPayment :: Abandoned { session_privs, payment_hash : our_payment_hash, reason : Some ( reason ) } ;
162
164
Ok ( ( ) )
163
165
}
164
166
@@ -546,11 +548,12 @@ impl OutboundPayments {
546
548
outbounds. retain ( |pmt_id, pmt| {
547
549
let mut retain = true ;
548
550
if !pmt. is_auto_retryable_now ( ) && pmt. remaining_parts ( ) == 0 {
549
- if pmt. mark_abandoned ( ) . is_ok ( ) {
551
+ let reason = PaymentFailureReason :: RetriesExhausted ;
552
+ if pmt. mark_abandoned ( reason) . is_ok ( ) {
550
553
pending_events. lock ( ) . unwrap ( ) . push ( events:: Event :: PaymentFailed {
551
554
payment_id : * pmt_id,
552
555
payment_hash : pmt. payment_hash ( ) . expect ( "PendingOutboundPayments::Retryable always has a payment hash set" ) ,
553
- reason : Some ( events :: PaymentFailureReason :: RetriesExhausted ) ,
556
+ reason : Some ( reason ) ,
554
557
} ) ;
555
558
retain = false ;
556
559
}
@@ -663,7 +666,7 @@ impl OutboundPayments {
663
666
664
667
macro_rules! abandon_with_entry {
665
668
( $payment: expr, $reason: expr) => {
666
- if $payment. get_mut( ) . mark_abandoned( ) . is_ok( ) && $payment. get( ) . remaining_parts( ) == 0 {
669
+ if $payment. get_mut( ) . mark_abandoned( $reason ) . is_ok( ) && $payment. get( ) . remaining_parts( ) == 0 {
667
670
pending_events. lock( ) . unwrap( ) . push( events:: Event :: PaymentFailed {
668
671
payment_id,
669
672
payment_hash,
@@ -1169,7 +1172,12 @@ impl OutboundPayments {
1169
1172
}
1170
1173
1171
1174
if payment_is_probe || !is_retryable_now || !payment_retryable {
1172
- let _ = payment. get_mut ( ) . mark_abandoned ( ) ; // we'll only Err if it's a legacy payment
1175
+ let reason = if !payment_retryable {
1176
+ PaymentFailureReason :: RecipientRejected
1177
+ } else {
1178
+ PaymentFailureReason :: RetriesExhausted
1179
+ } ;
1180
+ let _ = payment. get_mut ( ) . mark_abandoned ( reason) ; // we'll only Err if it's a legacy payment
1173
1181
is_retryable_now = false ;
1174
1182
}
1175
1183
if payment. get ( ) . remaining_parts ( ) == 0 {
@@ -1244,7 +1252,7 @@ impl OutboundPayments {
1244
1252
) {
1245
1253
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1246
1254
if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( payment_id) {
1247
- if let Ok ( ( ) ) = payment. get_mut ( ) . mark_abandoned ( ) {
1255
+ if let Ok ( ( ) ) = payment. get_mut ( ) . mark_abandoned ( reason ) {
1248
1256
if payment. get ( ) . remaining_parts ( ) == 0 {
1249
1257
pending_events. lock ( ) . unwrap ( ) . push ( events:: Event :: PaymentFailed {
1250
1258
payment_id,
@@ -1311,6 +1319,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
1311
1319
} ,
1312
1320
( 3 , Abandoned ) => {
1313
1321
( 0 , session_privs, required) ,
1322
+ ( 1 , reason, option) ,
1314
1323
( 2 , payment_hash, required) ,
1315
1324
} ,
1316
1325
) ;
0 commit comments