@@ -2367,7 +2367,7 @@ where L::Target: Logger {
2367
2367
. map_or( 0 , |used_liquidity_msat| {
2368
2368
available_value_contribution_msat = available_value_contribution_msat
2369
2369
. saturating_sub( * used_liquidity_msat) ;
2370
- * used_liquidity_msat
2370
+ ( * used_liquidity_msat)
2371
2371
} ) ;
2372
2372
2373
2373
// Verify the liquidity offered by this channel complies to the minimal contribution.
@@ -2809,6 +2809,7 @@ where L::Target: Logger {
2809
2809
introduction_node_id_cache. len( ) ,
2810
2810
"introduction_node_id_cache was built by iterating the blinded_route_hints, so they should be the same len"
2811
2811
) ;
2812
+ let mut value_contributions = Vec :: with_capacity ( payment_params. payee . blinded_route_hints ( ) . len ( ) ) ;
2812
2813
for ( hint_idx, hint) in payment_params. payee . blinded_route_hints ( ) . iter ( ) . enumerate ( ) {
2813
2814
// Only add the hops in this route to our candidate set if either
2814
2815
// we have a direct channel to the first hop or the first hop is
@@ -2823,29 +2824,39 @@ where L::Target: Logger {
2823
2824
} else {
2824
2825
CandidateRouteHop :: Blinded ( BlindedPathCandidate { source_node_counter, source_node_id, hint, hint_idx } )
2825
2826
} ;
2826
- let mut path_contribution_msat = path_value_msat;
2827
2827
if let Some ( hop_used_msat) = add_entry ! ( & candidate,
2828
- 0 , path_contribution_msat , 0 , 0_u64 , 0 , 0 )
2828
+ 0 , path_value_msat , 0 , 0_u64 , 0 , 0 )
2829
2829
{
2830
- path_contribution_msat = hop_used_msat;
2830
+ value_contributions . push ( ( hint_idx , hop_used_msat) ) ;
2831
2831
} else { continue }
2832
- if let Some ( ( first_channels, peer_node_counter) ) = first_hop_targets. get_mut ( source_node_id) {
2833
- sort_first_hop_channels (
2834
- first_channels, & used_liquidities, recommended_value_msat, our_node_pubkey
2835
- ) ;
2836
- for details in first_channels {
2837
- let first_hop_candidate = CandidateRouteHop :: FirstHop ( FirstHopCandidate {
2838
- details, payer_node_id : & our_node_id, payer_node_counter,
2839
- target_node_counter : * peer_node_counter,
2840
- } ) ;
2841
- let blinded_path_fee = match compute_fees ( path_contribution_msat, candidate. fees ( ) ) {
2842
- Some ( fee) => fee,
2843
- None => continue
2844
- } ;
2845
- let path_min = candidate. htlc_minimum_msat ( ) . saturating_add (
2846
- compute_fees_saturating ( candidate. htlc_minimum_msat ( ) , candidate. fees ( ) ) ) ;
2847
- add_entry ! ( & first_hop_candidate, blinded_path_fee, path_contribution_msat, path_min,
2848
- 0_u64 , candidate. cltv_expiry_delta( ) , 0 ) ;
2832
+ }
2833
+ for ( hint_idx, path_contribution_msat) in value_contributions {
2834
+ // Only add the hops in this route to our candidate set if either
2835
+ // we have a direct channel to the first hop or the first hop is
2836
+ // in the regular network graph.
2837
+ let source_node_opt = introduction_node_id_cache[ hint_idx] ;
2838
+ let ( source_node_id, source_node_counter) = if let Some ( v) = source_node_opt { v } else { continue } ;
2839
+ if our_node_id == * source_node_id { continue }
2840
+ if let Some ( hop_candidate) = dist[ source_node_counter as usize ] . as_ref ( ) {
2841
+ let candidate = hop_candidate. candidate . clone ( ) ;
2842
+ if let Some ( ( first_channels, peer_node_counter) ) = first_hop_targets. get_mut ( source_node_id) {
2843
+ sort_first_hop_channels (
2844
+ first_channels, & used_liquidities, recommended_value_msat, our_node_pubkey
2845
+ ) ;
2846
+ for details in first_channels {
2847
+ let first_hop_candidate = CandidateRouteHop :: FirstHop ( FirstHopCandidate {
2848
+ details, payer_node_id : & our_node_id, payer_node_counter,
2849
+ target_node_counter : * peer_node_counter,
2850
+ } ) ;
2851
+ let blinded_path_fee = match compute_fees ( path_contribution_msat, candidate. fees ( ) ) {
2852
+ Some ( fee) => fee,
2853
+ None => continue
2854
+ } ;
2855
+ let path_min = candidate. htlc_minimum_msat ( ) . saturating_add (
2856
+ compute_fees_saturating ( candidate. htlc_minimum_msat ( ) , candidate. fees ( ) ) ) ;
2857
+ add_entry ! ( & first_hop_candidate, blinded_path_fee, path_contribution_msat, path_min,
2858
+ 0_u64 , candidate. cltv_expiry_delta( ) , 0 ) ;
2859
+ }
2849
2860
}
2850
2861
}
2851
2862
}
@@ -3114,17 +3125,20 @@ where L::Target: Logger {
3114
3125
let mut prevented_redundant_path_selection = false ;
3115
3126
for ( hop, _) in payment_path. hops . iter ( ) {
3116
3127
let spent_on_hop_msat = value_contribution_msat + hop. next_hops_fee_msat ;
3128
+ println ! ( "SPENT: {} = VALUE {} + NEXT_FEE {}" , spent_on_hop_msat, value_contribution_msat, hop. next_hops_fee_msat) ;
3117
3129
let used_liquidity_msat = used_liquidities
3118
3130
. entry ( hop. candidate . id ( ) )
3119
3131
. and_modify ( |used_liquidity_msat| * used_liquidity_msat += spent_on_hop_msat)
3120
3132
. or_insert ( spent_on_hop_msat) ;
3121
3133
let hop_capacity = hop. candidate . effective_capacity ( ) ;
3134
+ println ! ( "CAP: {}, USED: {}" , spent_on_hop_msat, used_liquidity_msat) ;
3122
3135
let hop_max_msat = max_htlc_from_capacity ( hop_capacity, channel_saturation_pow_half) ;
3123
3136
if * used_liquidity_msat == hop_max_msat {
3124
3137
// If this path used all of this channel's available liquidity, we know
3125
3138
// this path will not be selected again in the next loop iteration.
3126
3139
prevented_redundant_path_selection = true ;
3127
3140
}
3141
+ println ! ( "USED: {}, hop_max_msat: {}" , used_liquidity_msat, hop_max_msat) ;
3128
3142
debug_assert ! ( * used_liquidity_msat <= hop_max_msat) ;
3129
3143
}
3130
3144
if !prevented_redundant_path_selection {
0 commit comments