@@ -396,15 +396,22 @@ pub(super) fn build_first_hop_failure_packet(shared_secret: &[u8], failure_type:
396396	encrypt_failure_packet ( shared_secret,  & failure_packet. encode ( ) [ ..] ) 
397397} 
398398
399+ pub ( crate )  struct  DecodedOnionFailure  { 
400+ 	pub ( crate )  network_update :  Option < NetworkUpdate > , 
401+ 	pub ( crate )  short_channel_id :  Option < u64 > , 
402+ 	pub ( crate )  payment_retryable :  bool , 
403+ 	#[ cfg( test) ]  
404+ 	pub ( crate )  onion_error_code :  Option < u16 > , 
405+ 	#[ cfg( test) ]  
406+ 	pub ( crate )  onion_error_data :  Option < Vec < u8 > > , 
407+ } 
408+ 
399409/// Process failure we got back from upstream on a payment we sent (implying htlc_source is an 
400410/// OutboundRoute). 
401- /// Returns update, a boolean indicating that the payment itself failed, the short channel id of 
402- /// the responsible channel, and the error code. 
403411#[ inline]  
404412pub ( super )  fn  process_onion_failure < T :  secp256k1:: Signing ,  L :  Deref > ( 
405413	secp_ctx :  & Secp256k1 < T > ,  logger :  & L ,  htlc_source :  & HTLCSource ,  mut  packet_decrypted :  Vec < u8 > 
406- )  -> ( Option < NetworkUpdate > ,  Option < u64 > ,  bool ,  Option < u16 > ,  Option < Vec < u8 > > ) 
407- where  L :: Target :  Logger  { 
414+ )  -> DecodedOnionFailure  where  L :: Target :  Logger  { 
408415	let  ( path,  session_priv,  first_hop_htlc_msat)  = if  let  & HTLCSource :: OutboundRoute  { 
409416		ref  path,  ref  session_priv,  ref  first_hop_htlc_msat,  ..
410417	}  = htlc_source { 
@@ -635,11 +642,23 @@ where L::Target: Logger {
635642		} 
636643	} ) . expect ( "Route that we sent via spontaneously grew invalid keys in the middle of it?" ) ; 
637644	if  let  Some ( ( channel_update,  short_channel_id,  payment_retryable) )  = res { 
638- 		( channel_update,  short_channel_id,  payment_retryable,  error_code_ret,  error_packet_ret) 
645+ 		DecodedOnionFailure  { 
646+ 			network_update :  channel_update,  short_channel_id,  payment_retryable, 
647+ 			#[ cfg( test) ]  
648+ 			onion_error_code :  error_code_ret, 
649+ 			#[ cfg( test) ]  
650+ 			onion_error_data :  error_packet_ret
651+ 		} 
639652	}  else  { 
640653		// only not set either packet unparseable or hmac does not match with any 
641654		// payment not retryable only when garbage is from the final node 
642- 		( None ,  None ,  !is_from_final_node,  None ,  None ) 
655+ 		DecodedOnionFailure  { 
656+ 			network_update :  None ,  short_channel_id :  None ,  payment_retryable :  !is_from_final_node, 
657+ 			#[ cfg( test) ]  
658+ 			onion_error_code :  None , 
659+ 			#[ cfg( test) ]  
660+ 			onion_error_data :  None 
661+ 		} 
643662	} 
644663} 
645664
@@ -763,20 +782,28 @@ impl HTLCFailReason {
763782
764783	pub ( super )  fn  decode_onion_failure < T :  secp256k1:: Signing ,  L :  Deref > ( 
765784		& self ,  secp_ctx :  & Secp256k1 < T > ,  logger :  & L ,  htlc_source :  & HTLCSource 
766- 	)  -> ( Option < NetworkUpdate > ,  Option < u64 > ,  bool ,  Option < u16 > ,  Option < Vec < u8 > > ) 
767- 	where  L :: Target :  Logger  { 
785+ 	)  -> DecodedOnionFailure  where  L :: Target :  Logger  { 
768786		match  self . 0  { 
769787			HTLCFailReasonRepr :: LightningError  {  ref  err }  => { 
770788				process_onion_failure ( secp_ctx,  logger,  & htlc_source,  err. data . clone ( ) ) 
771789			} , 
790+ 			#[ allow( unused) ]  
772791			HTLCFailReasonRepr :: Reason  {  ref  failure_code,  ref  data,  .. }  => { 
773792				// we get a fail_malformed_htlc from the first hop 
774793				// TODO: We'd like to generate a NetworkUpdate for temporary 
775794				// failures here, but that would be insufficient as find_route 
776795				// generally ignores its view of our own channels as we provide them via 
777796				// ChannelDetails. 
778797				if  let  & HTLCSource :: OutboundRoute  {  ref  path,  .. }  = htlc_source { 
779- 					( None ,  Some ( path. hops [ 0 ] . short_channel_id ) ,  true ,  Some ( * failure_code) ,  Some ( data. clone ( ) ) ) 
798+ 					DecodedOnionFailure  { 
799+ 						network_update :  None , 
800+ 						payment_retryable :  true , 
801+ 						short_channel_id :  Some ( path. hops [ 0 ] . short_channel_id ) , 
802+ 						#[ cfg( test) ]  
803+ 						onion_error_code :  Some ( * failure_code) , 
804+ 						#[ cfg( test) ]  
805+ 						onion_error_data :  Some ( data. clone ( ) ) , 
806+ 					} 
780807				}  else  {  unreachable ! ( ) ;  } 
781808			} 
782809		} 
0 commit comments