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