@@ -1038,7 +1038,7 @@ pub enum CandidateRouteHop<'a> {
1038
1038
/// Information about the private hop communicated via BOLT 11.
1039
1039
hint : & ' a RouteHintHop ,
1040
1040
/// Node id of the next hop in BOLT 11 route hint.
1041
- target_node_id : NodeId
1041
+ target_node_id : & ' a NodeId
1042
1042
} ,
1043
1043
/// A blinded path which starts with an introduction point and ultimately terminates with the
1044
1044
/// payee.
@@ -1249,7 +1249,7 @@ impl<'a> CandidateRouteHop<'a> {
1249
1249
match self {
1250
1250
CandidateRouteHop :: FirstHop { details, .. } => Some ( details. counterparty . node_id . into ( ) ) ,
1251
1251
CandidateRouteHop :: PublicHop { info, .. } => Some ( * info. target ( ) ) ,
1252
- CandidateRouteHop :: PrivateHop { target_node_id, .. } => Some ( * target_node_id) ,
1252
+ CandidateRouteHop :: PrivateHop { target_node_id, .. } => Some ( * * target_node_id) ,
1253
1253
CandidateRouteHop :: Blinded { .. } => None ,
1254
1254
CandidateRouteHop :: OneHopBlinded { .. } => None ,
1255
1255
}
@@ -1794,6 +1794,20 @@ where L::Target: Logger {
1794
1794
}
1795
1795
}
1796
1796
1797
+ let mut private_hop_key_cache = HashMap :: with_capacity (
1798
+ payment_params. payee . unblinded_route_hints ( ) . iter ( ) . map ( |path| path. 0 . len ( ) ) . sum ( )
1799
+ ) ;
1800
+
1801
+ // Because we store references to private hop node_ids in `dist`, below, we need them to exist
1802
+ // (as `NodeId`, not `PublicKey`) for the lifetime of `dist`. Thus, we calculate all the keys
1803
+ // we'll need here and simply fetch them when routing.
1804
+ private_hop_key_cache. insert ( maybe_dummy_payee_pk, NodeId :: from_pubkey ( & maybe_dummy_payee_pk) ) ;
1805
+ for route in payment_params. payee . unblinded_route_hints ( ) . iter ( ) {
1806
+ for hop in route. 0 . iter ( ) {
1807
+ private_hop_key_cache. insert ( hop. src_node_id , NodeId :: from_pubkey ( & hop. src_node_id ) ) ;
1808
+ }
1809
+ }
1810
+
1797
1811
// The main heap containing all candidate next-hops sorted by their score (max(fee,
1798
1812
// htlc_minimum)). Ideally this would be a heap which allowed cheap score reduction instead of
1799
1813
// adding duplicate entries when we find a better path to a given node.
@@ -2352,8 +2366,7 @@ where L::Target: Logger {
2352
2366
let mut aggregate_path_contribution_msat = path_value_msat;
2353
2367
2354
2368
for ( idx, ( hop, prev_hop_id) ) in hop_iter. zip ( prev_hop_iter) . enumerate ( ) {
2355
- let source = NodeId :: from_pubkey ( & hop. src_node_id ) ;
2356
- let target = NodeId :: from_pubkey ( & prev_hop_id) ;
2369
+ let target = private_hop_key_cache. get ( & prev_hop_id) . unwrap ( ) ;
2357
2370
2358
2371
if let Some ( first_channels) = first_hop_targets. get ( & target) {
2359
2372
if first_channels. iter ( ) . any ( |d| d. outbound_scid_alias == Some ( hop. short_channel_id ) ) {
0 commit comments