@@ -976,41 +976,69 @@ where
976
976
977
977
enum ErrorHop {
978
978
RouteHop ( RouteHop ) ,
979
+ TrampolineHop ( TrampolineHop ) ,
979
980
}
980
981
981
982
impl ErrorHop {
982
983
fn fee_msat ( & self ) -> u64 {
983
984
match self {
984
985
ErrorHop :: RouteHop ( rh) => rh. fee_msat ,
986
+ ErrorHop :: TrampolineHop ( th) => th. fee_msat ,
985
987
}
986
988
}
987
989
988
990
fn pubkey ( & self ) -> & PublicKey {
989
991
match self {
990
992
ErrorHop :: RouteHop ( rh) => rh. node_pubkey ( ) ,
993
+ ErrorHop :: TrampolineHop ( th) => th. node_pubkey ( ) ,
991
994
}
992
995
}
993
996
994
997
fn short_channel_id ( & self ) -> Option < u64 > {
995
998
match self {
996
999
ErrorHop :: RouteHop ( rh) => Some ( rh. short_channel_id ) ,
1000
+ ErrorHop :: TrampolineHop ( _) => None ,
997
1001
}
998
1002
}
999
1003
}
1000
1004
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
+
1001
1011
let mut onion_keys = Vec :: with_capacity ( path. hops . len ( ) ) ;
1002
1012
construct_onion_keys_generic_callback (
1003
1013
secp_ctx,
1004
1014
& 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) ,
1007
1018
|shared_secret, _, _, route_hop_option : Option < & RouteHop > , _| {
1008
1019
onion_keys
1009
1020
. push ( ( route_hop_option. map ( |rh| ErrorHop :: RouteHop ( rh. clone ( ) ) ) , shared_secret) )
1010
1021
} ,
1011
1022
)
1012
1023
. expect ( "Route we used spontaneously grew invalid keys in the middle of it?" ) ;
1013
1024
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
+
1014
1042
let num_blinded_hops = path. blinded_tail . as_ref ( ) . map_or ( 0 , |bt| bt. hops . len ( ) ) ;
1015
1043
1016
1044
// Handle packed channel/node updates for passing back for the route handler
0 commit comments