@@ -1181,6 +1181,11 @@ pub struct PrivateHopCandidate<'a> {
1181
1181
/// A [`CandidateRouteHop::Blinded`] entry.
1182
1182
#[ derive( Clone , Debug ) ]
1183
1183
pub struct BlindedPathCandidate < ' a > {
1184
+ /// The node id of the introduction node, resolved from either the [`NetworkGraph`] or first
1185
+ /// hops.
1186
+ ///
1187
+ /// This is not exported to bindings users as lifetimes are not expressable in most languages.
1188
+ pub source_node_id : & ' a NodeId ,
1184
1189
/// Information about the blinded path including the fee, HTLC amount limits, and
1185
1190
/// cryptographic material required to build an HTLC through the given path.
1186
1191
///
@@ -1196,6 +1201,11 @@ pub struct BlindedPathCandidate<'a> {
1196
1201
/// A [`CandidateRouteHop::OneHopBlinded`] entry.
1197
1202
#[ derive( Clone , Debug ) ]
1198
1203
pub struct OneHopBlindedPathCandidate < ' a > {
1204
+ /// The node id of the introduction node, resolved from either the [`NetworkGraph`] or first
1205
+ /// hops.
1206
+ ///
1207
+ /// This is not exported to bindings users as lifetimes are not expressable in most languages.
1208
+ pub source_node_id : & ' a NodeId ,
1199
1209
/// Information about the blinded path including the fee, HTLC amount limits, and
1200
1210
/// cryptographic material required to build an HTLC terminating with the given path.
1201
1211
///
@@ -1409,8 +1419,8 @@ impl<'a> CandidateRouteHop<'a> {
1409
1419
CandidateRouteHop :: FirstHop ( hop) => * hop. payer_node_id ,
1410
1420
CandidateRouteHop :: PublicHop ( hop) => * hop. info . source ( ) ,
1411
1421
CandidateRouteHop :: PrivateHop ( hop) => hop. hint . src_node_id . into ( ) ,
1412
- CandidateRouteHop :: Blinded ( hop) => hop. hint . 1 . introduction_node_id . into ( ) ,
1413
- CandidateRouteHop :: OneHopBlinded ( hop) => hop. hint . 1 . introduction_node_id . into ( ) ,
1422
+ CandidateRouteHop :: Blinded ( hop) => * hop. source_node_id ,
1423
+ CandidateRouteHop :: OneHopBlinded ( hop) => * hop. source_node_id ,
1414
1424
}
1415
1425
}
1416
1426
/// Returns the target node id of this hop, if known.
@@ -2515,26 +2525,38 @@ where L::Target: Logger {
2515
2525
// earlier than general path finding, they will be somewhat prioritized, although currently
2516
2526
// it matters only if the fees are exactly the same.
2517
2527
for ( hint_idx, hint) in payment_params. payee . blinded_route_hints ( ) . iter ( ) . enumerate ( ) {
2518
- let intro_node_id = NodeId :: from_pubkey ( & hint. 1 . introduction_node_id ) ;
2519
- let have_intro_node_in_graph =
2520
- // Only add the hops in this route to our candidate set if either
2521
- // we have a direct channel to the first hop or the first hop is
2522
- // in the regular network graph.
2523
- first_hop_targets. get ( & intro_node_id) . is_some ( ) ||
2524
- network_nodes. get ( & intro_node_id) . is_some ( ) ;
2525
- if !have_intro_node_in_graph || our_node_id == intro_node_id { continue }
2528
+ // Only add the hops in this route to our candidate set if either
2529
+ // we have a direct channel to the first hop or the first hop is
2530
+ // in the regular network graph.
2531
+ let source_node_id = match hint. 1 . introduction_node_id ( network_graph) {
2532
+ Some ( node_id) => node_id,
2533
+ None => {
2534
+ let node_id = NodeId :: from_pubkey ( & hint. 1 . introduction_node_id ) ;
2535
+ match first_hop_targets. get_key_value ( & node_id) . map ( |( key, _) | key) {
2536
+ Some ( node_id) => node_id,
2537
+ None => continue ,
2538
+ }
2539
+ } ,
2540
+ } ;
2541
+ if our_node_id == * source_node_id { continue }
2526
2542
let candidate = if hint. 1 . blinded_hops . len ( ) == 1 {
2527
- CandidateRouteHop :: OneHopBlinded ( OneHopBlindedPathCandidate { hint, hint_idx } )
2528
- } else { CandidateRouteHop :: Blinded ( BlindedPathCandidate { hint, hint_idx } ) } ;
2543
+ CandidateRouteHop :: OneHopBlinded (
2544
+ OneHopBlindedPathCandidate { source_node_id, hint, hint_idx }
2545
+ )
2546
+ } else {
2547
+ CandidateRouteHop :: Blinded ( BlindedPathCandidate { source_node_id, hint, hint_idx } )
2548
+ } ;
2529
2549
let mut path_contribution_msat = path_value_msat;
2530
2550
if let Some ( hop_used_msat) = add_entry ! ( & candidate,
2531
2551
0 , path_contribution_msat, 0 , 0_u64 , 0 , 0 )
2532
2552
{
2533
2553
path_contribution_msat = hop_used_msat;
2534
2554
} else { continue }
2535
- if let Some ( first_channels) = first_hop_targets. get_mut ( & NodeId :: from_pubkey ( & hint. 1 . introduction_node_id ) ) {
2536
- sort_first_hop_channels ( first_channels, & used_liquidities, recommended_value_msat,
2537
- our_node_pubkey) ;
2555
+ if let Some ( first_channels) = first_hop_targets. get ( source_node_id) {
2556
+ let mut first_channels = first_channels. clone ( ) ;
2557
+ sort_first_hop_channels (
2558
+ & mut first_channels, & used_liquidities, recommended_value_msat, our_node_pubkey
2559
+ ) ;
2538
2560
for details in first_channels {
2539
2561
let first_hop_candidate = CandidateRouteHop :: FirstHop ( FirstHopCandidate {
2540
2562
details, payer_node_id : & our_node_id,
@@ -2630,9 +2652,11 @@ where L::Target: Logger {
2630
2652
. saturating_add ( 1 ) ;
2631
2653
2632
2654
// Searching for a direct channel between last checked hop and first_hop_targets
2633
- if let Some ( first_channels) = first_hop_targets. get_mut ( target) {
2634
- sort_first_hop_channels ( first_channels, & used_liquidities,
2635
- recommended_value_msat, our_node_pubkey) ;
2655
+ if let Some ( first_channels) = first_hop_targets. get ( target) {
2656
+ let mut first_channels = first_channels. clone ( ) ;
2657
+ sort_first_hop_channels (
2658
+ & mut first_channels, & used_liquidities, recommended_value_msat, our_node_pubkey
2659
+ ) ;
2636
2660
for details in first_channels {
2637
2661
let first_hop_candidate = CandidateRouteHop :: FirstHop ( FirstHopCandidate {
2638
2662
details, payer_node_id : & our_node_id,
@@ -2677,9 +2701,11 @@ where L::Target: Logger {
2677
2701
// Note that we *must* check if the last hop was added as `add_entry`
2678
2702
// always assumes that the third argument is a node to which we have a
2679
2703
// path.
2680
- if let Some ( first_channels) = first_hop_targets. get_mut ( & NodeId :: from_pubkey ( & hop. src_node_id ) ) {
2681
- sort_first_hop_channels ( first_channels, & used_liquidities,
2682
- recommended_value_msat, our_node_pubkey) ;
2704
+ if let Some ( first_channels) = first_hop_targets. get ( & NodeId :: from_pubkey ( & hop. src_node_id ) ) {
2705
+ let mut first_channels = first_channels. clone ( ) ;
2706
+ sort_first_hop_channels (
2707
+ & mut first_channels, & used_liquidities, recommended_value_msat, our_node_pubkey
2708
+ ) ;
2683
2709
for details in first_channels {
2684
2710
let first_hop_candidate = CandidateRouteHop :: FirstHop ( FirstHopCandidate {
2685
2711
details, payer_node_id : & our_node_id,
0 commit comments