@@ -942,7 +942,7 @@ pub(crate) struct DecodedOnionFailure {
942
942
#[ inline]
943
943
pub ( super ) fn process_onion_failure < T : secp256k1:: Signing , L : Deref > (
944
944
secp_ctx : & Secp256k1 < T > , logger : & L , htlc_source : & HTLCSource ,
945
- mut encrypted_packet : OnionErrorPacket ,
945
+ mut encrypted_packet : OnionErrorPacket , secondary_session_priv : Option < SecretKey > ,
946
946
) -> DecodedOnionFailure
947
947
where
948
948
L :: Target : Logger ,
@@ -1004,8 +1004,10 @@ where
1004
1004
1005
1005
let outer_session_priv = path. has_trampoline_hops ( ) . then ( || {
1006
1006
// 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!" )
1007
+ secondary_session_priv. unwrap_or_else ( || {
1008
+ let session_priv_hash = Sha256 :: hash ( & session_priv. secret_bytes ( ) ) . to_byte_array ( ) ;
1009
+ SecretKey :: from_slice ( & session_priv_hash[ ..] ) . expect ( "You broke SHA-256!" )
1010
+ } )
1009
1011
} ) ;
1010
1012
1011
1013
let mut onion_keys = Vec :: with_capacity ( path. hops . len ( ) ) ;
@@ -1469,7 +1471,7 @@ impl HTLCFailReason {
1469
1471
{
1470
1472
match self . 0 {
1471
1473
HTLCFailReasonRepr :: LightningError { ref err } => {
1472
- process_onion_failure ( secp_ctx, logger, & htlc_source, err. clone ( ) )
1474
+ process_onion_failure ( secp_ctx, logger, & htlc_source, err. clone ( ) , None )
1473
1475
} ,
1474
1476
#[ allow( unused) ]
1475
1477
HTLCFailReasonRepr :: Reason { ref failure_code, ref data, .. } => {
@@ -2397,7 +2399,7 @@ mod tests {
2397
2399
2398
2400
// Assert that the original failure can be retrieved and that all hmacs check out.
2399
2401
let decrypted_failure =
2400
- process_onion_failure ( & ctx_full, & logger, & htlc_source, onion_error) ;
2402
+ process_onion_failure ( & ctx_full, & logger, & htlc_source, onion_error, None ) ;
2401
2403
2402
2404
assert_eq ! ( decrypted_failure. onion_error_code, Some ( 0x2002 ) ) ;
2403
2405
}
@@ -2487,7 +2489,8 @@ mod tests {
2487
2489
payment_id : PaymentId ( [ 1 ; 32 ] ) ,
2488
2490
} ;
2489
2491
2490
- let decrypted_failure = process_onion_failure ( & ctx_full, & logger, & htlc_source, packet) ;
2492
+ let decrypted_failure =
2493
+ process_onion_failure ( & ctx_full, & logger, & htlc_source, packet, None ) ;
2491
2494
2492
2495
decrypted_failure
2493
2496
}
0 commit comments