@@ -444,7 +444,14 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
444
444
} = htlc_source {
445
445
( path, session_priv, first_hop_htlc_msat)
446
446
} else { unreachable ! ( ) } ;
447
- let mut res = None ;
447
+
448
+ // Learnings from the HTLC failure to inform future payment retries and scoring.
449
+ struct FailureLearnings {
450
+ network_update : Option < NetworkUpdate > ,
451
+ short_channel_id : Option < u64 > ,
452
+ recipient_rejected : bool ,
453
+ }
454
+ let mut res: Option < FailureLearnings > = None ;
448
455
let mut htlc_msat = * first_hop_htlc_msat;
449
456
let mut error_code_ret = None ;
450
457
let mut error_packet_ret = None ;
@@ -507,7 +514,9 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
507
514
is_permanent : true ,
508
515
} ) ;
509
516
let short_channel_id = Some ( route_hop. short_channel_id ) ;
510
- res = Some ( ( network_update, short_channel_id, is_from_final_node) ) ;
517
+ res = Some ( FailureLearnings {
518
+ network_update, short_channel_id, recipient_rejected : is_from_final_node
519
+ } ) ;
511
520
return
512
521
}
513
522
} ;
@@ -659,7 +668,10 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
659
668
short_channel_id = Some ( route_hop. short_channel_id ) ;
660
669
}
661
670
662
- res = Some ( ( network_update, short_channel_id, error_code & PERM == PERM && is_from_final_node) ) ;
671
+ res = Some ( FailureLearnings {
672
+ network_update, short_channel_id,
673
+ recipient_rejected : error_code & PERM == PERM && is_from_final_node
674
+ } ) ;
663
675
664
676
let ( description, title) = errors:: get_onion_error_description ( error_code) ;
665
677
if debug_field_size > 0 && err_packet. failuremsg . len ( ) >= 4 + debug_field_size {
@@ -668,7 +680,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
668
680
log_info ! ( logger, "Onion Error[from {}: {}({:#x})] {}" , route_hop. pubkey, title, error_code, description) ;
669
681
}
670
682
} ) . expect ( "Route that we sent via spontaneously grew invalid keys in the middle of it?" ) ;
671
- if let Some ( ( network_update, short_channel_id, recipient_rejected) ) = res {
683
+ if let Some ( FailureLearnings { network_update, short_channel_id, recipient_rejected } ) = res {
672
684
DecodedOnionFailure {
673
685
network_update, short_channel_id, payment_retryable : !recipient_rejected,
674
686
#[ cfg( test) ]
0 commit comments