@@ -943,6 +943,7 @@ fn decrypt_onion_error_packet(packet: &mut Vec<u8>, shared_secret: SharedSecret)
943943#[ inline]
944944pub ( super ) fn process_onion_failure < T : secp256k1:: Signing , L : Deref > (
945945 secp_ctx : & Secp256k1 < T > , logger : & L , htlc_source : & HTLCSource , mut encrypted_packet : Vec < u8 > ,
946+ secondary_session_priv : Option < SecretKey > ,
946947) -> DecodedOnionFailure
947948where
948949 L :: Target : Logger ,
@@ -1004,8 +1005,10 @@ where
10041005
10051006 let outer_session_priv = path. has_trampoline_hops ( ) . then ( || {
10061007 // if we have Trampoline hops, the outer onion session_priv is a hash of the inner one
1007- let session_priv_hash = Sha256 :: hash ( & session_priv. secret_bytes ( ) ) . to_byte_array ( ) ;
1008- SecretKey :: from_slice ( & session_priv_hash[ ..] ) . expect ( "You broke SHA-256!" )
1008+ secondary_session_priv. unwrap_or_else ( || {
1009+ let session_priv_hash = Sha256 :: hash ( & session_priv. secret_bytes ( ) ) . to_byte_array ( ) ;
1010+ SecretKey :: from_slice ( & session_priv_hash[ ..] ) . expect ( "You broke SHA-256!" )
1011+ } )
10091012 } ) ;
10101013
10111014 let mut onion_keys = Vec :: with_capacity ( path. hops . len ( ) ) ;
@@ -1465,7 +1468,7 @@ impl HTLCFailReason {
14651468 {
14661469 match self . 0 {
14671470 HTLCFailReasonRepr :: LightningError { ref err } => {
1468- process_onion_failure ( secp_ctx, logger, & htlc_source, err. data . clone ( ) )
1471+ process_onion_failure ( secp_ctx, logger, & htlc_source, err. data . clone ( ) , None )
14691472 } ,
14701473 #[ allow( unused) ]
14711474 HTLCFailReasonRepr :: Reason { ref failure_code, ref data, .. } => {
@@ -2405,7 +2408,7 @@ mod tests {
24052408
24062409 // Assert that the original failure can be retrieved and that all hmacs check out.
24072410 let decrypted_failure =
2408- process_onion_failure ( & ctx_full, & logger, & htlc_source, onion_packet_5. data ) ;
2411+ process_onion_failure ( & ctx_full, & logger, & htlc_source, onion_packet_5. data , None ) ;
24092412
24102413 assert_eq ! ( decrypted_failure. onion_error_code, Some ( 0x2002 ) ) ;
24112414 }
@@ -2491,7 +2494,7 @@ mod tests {
24912494 } ;
24922495
24932496 let decrypted_failure =
2494- process_onion_failure ( & ctx_full, & logger, & htlc_source, packet. into ( ) ) ;
2497+ process_onion_failure ( & ctx_full, & logger, & htlc_source, packet. into ( ) , None ) ;
24952498
24962499 decrypted_failure
24972500 }
0 commit comments