@@ -391,15 +391,22 @@ pub(super) fn build_first_hop_failure_packet(shared_secret: &[u8], failure_type:
391391	encrypt_failure_packet ( shared_secret,  & failure_packet. encode ( ) [ ..] ) 
392392} 
393393
394+ pub ( crate )  struct  DecodedOnionFailure  { 
395+ 	pub ( crate )  network_update :  Option < NetworkUpdate > , 
396+ 	pub ( crate )  short_channel_id :  Option < u64 > , 
397+ 	pub ( crate )  payment_retryable :  bool , 
398+ 	#[ cfg( test) ]  
399+ 	pub ( crate )  onion_error_code :  Option < u16 > , 
400+ 	#[ cfg( test) ]  
401+ 	pub ( crate )  onion_error_data :  Option < Vec < u8 > > , 
402+ } 
403+ 
394404/// Process failure we got back from upstream on a payment we sent (implying htlc_source is an 
395405/// OutboundRoute). 
396- /// Returns update, a boolean indicating that the payment itself failed, the short channel id of 
397- /// the responsible channel, and the error code. 
398406#[ inline]  
399407pub ( super )  fn  process_onion_failure < T :  secp256k1:: Signing ,  L :  Deref > ( 
400408	secp_ctx :  & Secp256k1 < T > ,  logger :  & L ,  htlc_source :  & HTLCSource ,  mut  packet_decrypted :  Vec < u8 > 
401- )  -> ( Option < NetworkUpdate > ,  Option < u64 > ,  bool ,  Option < u16 > ,  Option < Vec < u8 > > ) 
402- where  L :: Target :  Logger  { 
409+ )  -> DecodedOnionFailure  where  L :: Target :  Logger  { 
403410	let  ( path,  session_priv,  first_hop_htlc_msat)  =
404411	if  let  & HTLCSource :: OutboundRoute  {  ref  path,  ref  session_priv,  ref  first_hop_htlc_msat,  .. }  = htlc_source { 
405412		( path,  session_priv,  first_hop_htlc_msat) 
@@ -629,11 +636,23 @@ where L::Target: Logger {
629636		} 
630637	} ) . expect ( "Route that we sent via spontaneously grew invalid keys in the middle of it?" ) ; 
631638	if  let  Some ( ( channel_update,  short_channel_id,  payment_retryable) )  = res { 
632- 		( channel_update,  short_channel_id,  payment_retryable,  error_code_ret,  error_packet_ret) 
639+ 		DecodedOnionFailure  { 
640+ 			network_update :  channel_update,  short_channel_id,  payment_retryable, 
641+ 			#[ cfg( test) ]  
642+ 			onion_error_code :  error_code_ret, 
643+ 			#[ cfg( test) ]  
644+ 			onion_error_data :  error_packet_ret
645+ 		} 
633646	}  else  { 
634647		// only not set either packet unparseable or hmac does not match with any 
635648		// payment not retryable only when garbage is from the final node 
636- 		( None ,  None ,  !is_from_final_node,  None ,  None ) 
649+ 		DecodedOnionFailure  { 
650+ 			network_update :  None ,  short_channel_id :  None ,  payment_retryable :  !is_from_final_node, 
651+ 			#[ cfg( test) ]  
652+ 			onion_error_code :  None , 
653+ 			#[ cfg( test) ]  
654+ 			onion_error_data :  None 
655+ 		} 
637656	} 
638657} 
639658
@@ -757,20 +776,28 @@ impl HTLCFailReason {
757776
758777	pub ( super )  fn  decode_onion_failure < T :  secp256k1:: Signing ,  L :  Deref > ( 
759778		& self ,  secp_ctx :  & Secp256k1 < T > ,  logger :  & L ,  htlc_source :  & HTLCSource 
760- 	)  -> ( Option < NetworkUpdate > ,  Option < u64 > ,  bool ,  Option < u16 > ,  Option < Vec < u8 > > ) 
761- 	where  L :: Target :  Logger  { 
779+ 	)  -> DecodedOnionFailure  where  L :: Target :  Logger  { 
762780		match  self . 0  { 
763781			HTLCFailReasonRepr :: LightningError  {  ref  err }  => { 
764782				process_onion_failure ( secp_ctx,  logger,  & htlc_source,  err. data . clone ( ) ) 
765783			} , 
784+ 			#[ allow( unused) ]  
766785			HTLCFailReasonRepr :: Reason  {  ref  failure_code,  ref  data,  .. }  => { 
767786				// we get a fail_malformed_htlc from the first hop 
768787				// TODO: We'd like to generate a NetworkUpdate for temporary 
769788				// failures here, but that would be insufficient as find_route 
770789				// generally ignores its view of our own channels as we provide them via 
771790				// ChannelDetails. 
772791				if  let  & HTLCSource :: OutboundRoute  {  ref  path,  .. }  = htlc_source { 
773- 					( None ,  Some ( path. hops [ 0 ] . short_channel_id ) ,  true ,  Some ( * failure_code) ,  Some ( data. clone ( ) ) ) 
792+ 					DecodedOnionFailure  { 
793+ 						network_update :  None , 
794+ 						payment_retryable :  true , 
795+ 						short_channel_id :  Some ( path. hops [ 0 ] . short_channel_id ) , 
796+ 						#[ cfg( test) ]  
797+ 						onion_error_code :  Some ( * failure_code) , 
798+ 						#[ cfg( test) ]  
799+ 						onion_error_data :  Some ( data. clone ( ) ) , 
800+ 					} 
774801				}  else  {  unreachable ! ( ) ;  } 
775802			} 
776803		} 
0 commit comments