@@ -396,15 +396,22 @@ pub(super) fn build_first_hop_failure_packet(shared_secret: &[u8], failure_type:
396
396
encrypt_failure_packet ( shared_secret, & failure_packet. encode ( ) [ ..] )
397
397
}
398
398
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
+
399
409
/// Process failure we got back from upstream on a payment we sent (implying htlc_source is an
400
410
/// 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.
403
411
#[ inline]
404
412
pub ( super ) fn process_onion_failure < T : secp256k1:: Signing , L : Deref > (
405
413
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 {
408
415
let ( path, session_priv, first_hop_htlc_msat) = if let & HTLCSource :: OutboundRoute {
409
416
ref path, ref session_priv, ref first_hop_htlc_msat, ..
410
417
} = htlc_source {
@@ -634,12 +641,24 @@ where L::Target: Logger {
634
641
log_info ! ( logger, "Onion Error[from {}: {}({:#x})] {}" , route_hop. pubkey, title, error_code, description) ;
635
642
}
636
643
} ) . expect ( "Route that we sent via spontaneously grew invalid keys in the middle of it?" ) ;
637
- 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)
644
+ if let Some ( ( network_update, short_channel_id, payment_retryable) ) = res {
645
+ DecodedOnionFailure {
646
+ network_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
+ }
639
652
} else {
640
653
// only not set either packet unparseable or hmac does not match with any
641
654
// 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
+ }
643
662
}
644
663
}
645
664
@@ -763,20 +782,28 @@ impl HTLCFailReason {
763
782
764
783
pub ( super ) fn decode_onion_failure < T : secp256k1:: Signing , L : Deref > (
765
784
& 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 {
768
786
match self . 0 {
769
787
HTLCFailReasonRepr :: LightningError { ref err } => {
770
788
process_onion_failure ( secp_ctx, logger, & htlc_source, err. data . clone ( ) )
771
789
} ,
790
+ #[ allow( unused) ]
772
791
HTLCFailReasonRepr :: Reason { ref failure_code, ref data, .. } => {
773
792
// we get a fail_malformed_htlc from the first hop
774
793
// TODO: We'd like to generate a NetworkUpdate for temporary
775
794
// failures here, but that would be insufficient as find_route
776
795
// generally ignores its view of our own channels as we provide them via
777
796
// ChannelDetails.
778
797
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
+ }
780
807
} else { unreachable ! ( ) ; }
781
808
}
782
809
}
0 commit comments