@@ -976,41 +976,69 @@ where
976976
977977 enum ErrorHop {
978978 RouteHop ( RouteHop ) ,
979+ TrampolineHop ( TrampolineHop ) ,
979980 }
980981
981982 impl ErrorHop {
982983 fn fee_msat ( & self ) -> u64 {
983984 match self {
984985 ErrorHop :: RouteHop ( rh) => rh. fee_msat ,
986+ ErrorHop :: TrampolineHop ( th) => th. fee_msat ,
985987 }
986988 }
987989
988990 fn pubkey ( & self ) -> & PublicKey {
989991 match self {
990992 ErrorHop :: RouteHop ( rh) => rh. node_pubkey ( ) ,
993+ ErrorHop :: TrampolineHop ( th) => th. node_pubkey ( ) ,
991994 }
992995 }
993996
994997 fn short_channel_id ( & self ) -> Option < u64 > {
995998 match self {
996999 ErrorHop :: RouteHop ( rh) => Some ( rh. short_channel_id ) ,
1000+ ErrorHop :: TrampolineHop ( _) => None ,
9971001 }
9981002 }
9991003 }
10001004
1005+ let outer_session_priv = path. has_trampoline_hops ( ) . then ( || {
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!" )
1009+ } ) ;
1010+
10011011 let mut onion_keys = Vec :: with_capacity ( path. hops . len ( ) ) ;
10021012 construct_onion_keys_generic_callback (
10031013 secp_ctx,
10041014 & path. hops ,
1005- path. blinded_tail . as_ref ( ) ,
1006- session_priv,
1015+ // if we have Trampoline hops, the blinded hops are part of the inner Trampoline onion
1016+ if path. has_trampoline_hops ( ) { None } else { path. blinded_tail . as_ref ( ) } ,
1017+ outer_session_priv. as_ref ( ) . unwrap_or ( session_priv) ,
10071018 |shared_secret, _, _, route_hop_option : Option < & RouteHop > , _| {
10081019 onion_keys
10091020 . push ( ( route_hop_option. map ( |rh| ErrorHop :: RouteHop ( rh. clone ( ) ) ) , shared_secret) )
10101021 } ,
10111022 )
10121023 . expect ( "Route we used spontaneously grew invalid keys in the middle of it?" ) ;
10131024
1025+ if path. has_trampoline_hops ( ) {
1026+ construct_onion_keys_generic_callback (
1027+ secp_ctx,
1028+ // Trampoline hops are part of the blinded tail, so this can never panic
1029+ & path. blinded_tail . as_ref ( ) . unwrap ( ) . trampoline_hops ,
1030+ path. blinded_tail . as_ref ( ) ,
1031+ session_priv,
1032+ |shared_secret, _, _, trampoline_hop_option : Option < & TrampolineHop > , _| {
1033+ onion_keys. push ( (
1034+ trampoline_hop_option. map ( |th| ErrorHop :: TrampolineHop ( th. clone ( ) ) ) ,
1035+ shared_secret,
1036+ ) )
1037+ } ,
1038+ )
1039+ . expect ( "Route we used spontaneously grew invalid keys in the middle of it?" ) ;
1040+ }
1041+
10141042 let num_blinded_hops = path. blinded_tail . as_ref ( ) . map_or ( 0 , |bt| bt. hops . len ( ) ) ;
10151043
10161044 // Handle packed channel/node updates for passing back for the route handler
0 commit comments