@@ -976,40 +976,68 @@ where
976
976
977
977
enum ErrorHop < ' a > {
978
978
RouteHop ( & ' a RouteHop ) ,
979
+ TrampolineHop ( & ' a TrampolineHop ) ,
979
980
}
980
981
981
982
impl < ' a > ErrorHop < ' a > {
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. push ( ( route_hop_option. map ( |rh| ErrorHop :: RouteHop ( rh) ) , shared_secret) )
1009
1020
} ,
1010
1021
)
1011
1022
. expect ( "Route we used spontaneously grew invalid keys in the middle of it?" ) ;
1012
1023
1024
+ if path. has_trampoline_hops ( ) {
1025
+ construct_onion_keys_generic_callback (
1026
+ secp_ctx,
1027
+ // Trampoline hops are part of the blinded tail, so this can never panic
1028
+ & path. blinded_tail . as_ref ( ) . unwrap ( ) . trampoline_hops ,
1029
+ path. blinded_tail . as_ref ( ) ,
1030
+ session_priv,
1031
+ |shared_secret, _, _, trampoline_hop_option : Option < & TrampolineHop > , _| {
1032
+ onion_keys. push ( (
1033
+ trampoline_hop_option. map ( |th| ErrorHop :: TrampolineHop ( th) ) ,
1034
+ shared_secret,
1035
+ ) )
1036
+ } ,
1037
+ )
1038
+ . expect ( "Route we used spontaneously grew invalid keys in the middle of it?" ) ;
1039
+ }
1040
+
1013
1041
let num_blinded_hops = path. blinded_tail . as_ref ( ) . map_or ( 0 , |bt| bt. hops . len ( ) ) ;
1014
1042
1015
1043
// Handle packed channel/node updates for passing back for the route handler
0 commit comments