@@ -658,10 +658,17 @@ pub enum Hints {
658
658
}
659
659
660
660
impl Hints {
661
- fn blinded_len ( & self ) -> usize {
661
+ fn blinded ( & self ) -> & [ ( BlindedPayInfo , BlindedPath ) ] {
662
662
match self {
663
- Self :: Blinded ( hints) => hints. len ( ) ,
664
- Self :: Clear ( _) => 0 ,
663
+ Self :: Blinded ( hints) => & hints[ ..] ,
664
+ Self :: Clear ( _) => & [ ]
665
+ }
666
+ }
667
+
668
+ fn clear ( & self ) -> & [ RouteHint ] {
669
+ match self {
670
+ Self :: Blinded ( _) => & [ ] ,
671
+ Self :: Clear ( hints) => & hints[ ..]
665
672
}
666
673
}
667
674
}
@@ -1249,27 +1256,27 @@ where L::Target: Logger {
1249
1256
}
1250
1257
}
1251
1258
1252
- // Marshall route hints
1253
- let mut route_hints = Vec :: with_capacity ( payment_params. route_hints . blinded_len ( ) ) ;
1254
- let route_hints_ref = match & payment_params. route_hints {
1255
- Hints :: Clear ( hints) => hints,
1256
- Hints :: Blinded ( blinded_hints) => {
1257
- for ( blinded_payinfo, blinded_path) in blinded_hints {
1258
- route_hints. push ( RouteHint ( vec ! [ RouteHintHop {
1259
- src_node_id: blinded_path. introduction_node_id,
1260
- short_channel_id: BLINDED_PATH_SCID ,
1261
- fees: RoutingFees {
1262
- base_msat: blinded_payinfo. fee_base_msat,
1263
- proportional_millionths: blinded_payinfo. fee_proportional_millionths,
1264
- } ,
1265
- cltv_expiry_delta: blinded_payinfo. cltv_expiry_delta,
1266
- htlc_minimum_msat: Some ( blinded_payinfo. htlc_minimum_msat) ,
1267
- htlc_maximum_msat: Some ( blinded_payinfo. htlc_maximum_msat) ,
1268
- } ] ) ) ;
1269
- }
1270
- & route_hints
1259
+ // Marshall blinded route hints
1260
+ let mut blinded_route_hints = Vec :: with_capacity ( payment_params. route_hints . blinded ( ) . len ( ) ) ;
1261
+ for ( blinded_payinfo, blinded_path) in payment_params. route_hints . blinded ( ) . iter ( ) {
1262
+ if blinded_path. blinded_hops . len ( ) == 1 {
1263
+ // If the introduction node is the destination, this hint is for a public node and we can just
1264
+ // use the public network graph
1265
+ blinded_route_hints = Vec :: new ( ) ;
1266
+ break
1271
1267
}
1272
- } ;
1268
+ blinded_route_hints. push ( RouteHintHop {
1269
+ src_node_id : blinded_path. introduction_node_id ,
1270
+ short_channel_id : BLINDED_PATH_SCID ,
1271
+ fees : RoutingFees {
1272
+ base_msat : blinded_payinfo. fee_base_msat ,
1273
+ proportional_millionths : blinded_payinfo. fee_proportional_millionths ,
1274
+ } ,
1275
+ cltv_expiry_delta : blinded_payinfo. cltv_expiry_delta ,
1276
+ htlc_minimum_msat : Some ( blinded_payinfo. htlc_minimum_msat ) ,
1277
+ htlc_maximum_msat : Some ( blinded_payinfo. htlc_maximum_msat ) ,
1278
+ } ) ;
1279
+ }
1273
1280
1274
1281
// The main heap containing all candidate next-hops sorted by their score (max(fee,
1275
1282
// htlc_minimum)). Ideally this would be a heap which allowed cheap score reduction instead of
@@ -1683,7 +1690,20 @@ where L::Target: Logger {
1683
1690
// If a caller provided us with last hops, add them to routing targets. Since this happens
1684
1691
// earlier than general path finding, they will be somewhat prioritized, although currently
1685
1692
// it matters only if the fees are exactly the same.
1686
- for route in route_hints_ref. iter ( ) . filter ( |route| !route. 0 . is_empty ( ) ) {
1693
+ for hint in blinded_route_hints. iter ( ) {
1694
+ let have_hop_src_in_graph =
1695
+ // Only add the hops in this route to our candidate set if either
1696
+ // we have a direct channel to the first hop or the first hop is
1697
+ // in the regular network graph.
1698
+ first_hop_targets. get ( & NodeId :: from_pubkey ( & hint. src_node_id ) ) . is_some ( ) ||
1699
+ network_nodes. get ( & NodeId :: from_pubkey ( & hint. src_node_id ) ) . is_some ( ) ;
1700
+ if have_hop_src_in_graph {
1701
+ add_entry ! ( CandidateRouteHop :: PrivateHop { hint } ,
1702
+ NodeId :: from_pubkey( & hint. src_node_id) ,
1703
+ NodeId :: from_pubkey( & payment_params. payee_pubkey) , 0 , path_value_msat, 0 , 0_u64 , 0 , 0 ) ;
1704
+ }
1705
+ }
1706
+ for route in payment_params. route_hints . clear ( ) . iter ( ) . filter ( |route| !route. 0 . is_empty ( ) ) {
1687
1707
let first_hop_in_route = & ( route. 0 ) [ 0 ] ;
1688
1708
let have_hop_src_in_graph =
1689
1709
// Only add the hops in this route to our candidate set if either
@@ -2102,15 +2122,12 @@ where L::Target: Logger {
2102
2122
for results_vec in selected_paths {
2103
2123
let mut hops = Vec :: new ( ) ;
2104
2124
for res in results_vec { hops. push ( res?) ; }
2105
- let mut blinded_tail = None ;
2106
- if let Hints :: Blinded ( hints) = & payment_params. route_hints {
2107
- blinded_tail = hints. iter ( )
2108
- . find ( |( _, p) | {
2109
- let intro_node_idx = if p. blinded_hops . len ( ) == 1 { hops. len ( ) - 1 } else { hops. len ( ) - 2 } ;
2110
- p. introduction_node_id == hops[ intro_node_idx] . pubkey
2111
- } )
2112
- . map ( |( _, p) | p. clone ( ) ) ;
2113
- }
2125
+ let blinded_tail = payment_params. route_hints . blinded ( ) . iter ( )
2126
+ . find ( |( _, p) | {
2127
+ let intro_node_idx = if p. blinded_hops . len ( ) == 1 { hops. len ( ) - 1 } else { hops. len ( ) - 2 } ;
2128
+ p. introduction_node_id == hops[ intro_node_idx] . pubkey
2129
+ } )
2130
+ . map ( |( _, p) | p. clone ( ) ) ;
2114
2131
paths. push ( Path { hops, blinded_tail } ) ;
2115
2132
}
2116
2133
let route = Route {
0 commit comments