@@ -444,7 +444,14 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
444444	}  = htlc_source { 
445445		( path,  session_priv,  first_hop_htlc_msat) 
446446	}  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+ 		payment_failed_permanently :  bool , 
453+ 	} 
454+ 	let  mut  res:  Option < FailureLearnings >  = None ; 
448455	let  mut  htlc_msat = * first_hop_htlc_msat; 
449456	let  mut  error_code_ret = None ; 
450457	let  mut  error_packet_ret = None ; 
@@ -507,7 +514,9 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
507514					is_permanent :  true , 
508515				} ) ; 
509516				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,  payment_failed_permanently :  is_from_final_node
519+ 				} ) ; 
511520				return 
512521			} 
513522		} ; 
@@ -659,7 +668,10 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
659668			short_channel_id = Some ( route_hop. short_channel_id ) ; 
660669		} 
661670
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+ 			payment_failed_permanently :  error_code &  PERM  == PERM  && is_from_final_node
674+ 		} ) ; 
663675
664676		let  ( description,  title)  = errors:: get_onion_error_description ( error_code) ; 
665677		if  debug_field_size > 0  && err_packet. failuremsg . len ( )  >= 4  + debug_field_size { 
@@ -668,7 +680,9 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
668680			log_info ! ( logger,  "Onion Error[from {}: {}({:#x})] {}" ,  route_hop. pubkey,  title,  error_code,  description) ; 
669681		} 
670682	} ) . expect ( "Route that we sent via spontaneously grew invalid keys in the middle of it?" ) ; 
671- 	if  let  Some ( ( network_update,  short_channel_id,  payment_failed_permanently) )  = res { 
683+ 	if  let  Some ( FailureLearnings  { 
684+ 		network_update,  short_channel_id,  payment_failed_permanently
685+ 	} )  = res { 
672686		DecodedOnionFailure  { 
673687			network_update,  short_channel_id,  payment_retryable :  !payment_failed_permanently, 
674688			#[ cfg( test) ]  
0 commit comments