@@ -391,15 +391,22 @@ pub(super) fn build_first_hop_failure_packet(shared_secret: &[u8], failure_type:
391
391
encrypt_failure_packet ( shared_secret, & failure_packet. encode ( ) [ ..] )
392
392
}
393
393
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
+
394
404
/// Process failure we got back from upstream on a payment we sent (implying htlc_source is an
395
405
/// 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.
398
406
#[ inline]
399
407
pub ( super ) fn process_onion_failure < T : secp256k1:: Signing , L : Deref > (
400
408
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 {
403
410
let ( path, session_priv, first_hop_htlc_msat) =
404
411
if let & HTLCSource :: OutboundRoute { ref path, ref session_priv, ref first_hop_htlc_msat, .. } = htlc_source {
405
412
( path, session_priv, first_hop_htlc_msat)
@@ -629,11 +636,23 @@ where L::Target: Logger {
629
636
}
630
637
} ) . expect ( "Route that we sent via spontaneously grew invalid keys in the middle of it?" ) ;
631
638
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
+ }
633
646
} else {
634
647
// only not set either packet unparseable or hmac does not match with any
635
648
// 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
+ }
637
656
}
638
657
}
639
658
@@ -757,20 +776,28 @@ impl HTLCFailReason {
757
776
758
777
pub ( super ) fn decode_onion_failure < T : secp256k1:: Signing , L : Deref > (
759
778
& 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 {
762
780
match self . 0 {
763
781
HTLCFailReasonRepr :: LightningError { ref err } => {
764
782
process_onion_failure ( secp_ctx, logger, & htlc_source, err. data . clone ( ) )
765
783
} ,
784
+ #[ allow( unused) ]
766
785
HTLCFailReasonRepr :: Reason { ref failure_code, ref data, .. } => {
767
786
// we get a fail_malformed_htlc from the first hop
768
787
// TODO: We'd like to generate a NetworkUpdate for temporary
769
788
// failures here, but that would be insufficient as find_route
770
789
// generally ignores its view of our own channels as we provide them via
771
790
// ChannelDetails.
772
791
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
+ }
774
801
} else { unreachable ! ( ) ; }
775
802
}
776
803
}
0 commit comments