@@ -1211,7 +1211,10 @@ struct RouteGraphNode {
1211
1211
1212
1212
impl cmp:: Ord for RouteGraphNode {
1213
1213
fn cmp ( & self , other : & RouteGraphNode ) -> cmp:: Ordering {
1214
- other. score . cmp ( & self . score ) . then_with ( || other. node_counter . cmp ( & self . node_counter ) )
1214
+ other. score . cmp ( & self . score )
1215
+ . then_with ( || self . value_contribution_msat . cmp ( & other. value_contribution_msat ) )
1216
+ . then_with ( || other. path_length_to_node . cmp ( & self . path_length_to_node ) )
1217
+ . then_with ( || other. node_counter . cmp ( & self . node_counter ) )
1215
1218
}
1216
1219
}
1217
1220
@@ -1841,11 +1844,7 @@ struct PathBuildingHop<'a> {
1841
1844
/// The value will be actually deducted from the counterparty balance on the previous link.
1842
1845
hop_use_fee_msat : u64 ,
1843
1846
1844
- #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
1845
- // In tests, we apply further sanity checks on cases where we skip nodes we already processed
1846
- // to ensure it is specifically in cases where the fee has gone down because of a decrease in
1847
- // value_contribution_msat, which requires tracking it here. See comments below where it is
1848
- // used for more info.
1847
+ /// The quantity of funds we're willing to route over this channel
1849
1848
value_contribution_msat : u64 ,
1850
1849
}
1851
1850
@@ -1866,9 +1865,7 @@ impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
1866
1865
. field ( "total_fee_msat - (next_hops_fee_msat + hop_use_fee_msat)" , & ( & self . total_fee_msat . saturating_sub ( self . next_hops_fee_msat ) . saturating_sub ( self . hop_use_fee_msat ) ) )
1867
1866
. field ( "path_penalty_msat" , & self . path_penalty_msat )
1868
1867
. field ( "path_htlc_minimum_msat" , & self . path_htlc_minimum_msat )
1869
- . field ( "cltv_expiry_delta" , & self . candidate . cltv_expiry_delta ( ) ) ;
1870
- #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
1871
- let debug_struct = debug_struct
1868
+ . field ( "cltv_expiry_delta" , & self . candidate . cltv_expiry_delta ( ) )
1872
1869
. field ( "value_contribution_msat" , & self . value_contribution_msat ) ;
1873
1870
debug_struct. finish ( )
1874
1871
}
@@ -2578,7 +2575,6 @@ where L::Target: Logger {
2578
2575
path_penalty_msat: u64 :: max_value( ) ,
2579
2576
was_processed: false ,
2580
2577
is_first_hop_target: false ,
2581
- #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
2582
2578
value_contribution_msat,
2583
2579
} ) ;
2584
2580
dist_entry. as_mut( ) . unwrap( )
@@ -2654,8 +2650,11 @@ where L::Target: Logger {
2654
2650
. saturating_add( old_entry. path_penalty_msat) ;
2655
2651
let new_cost = cmp:: max( total_fee_msat, path_htlc_minimum_msat)
2656
2652
. saturating_add( path_penalty_msat) ;
2653
+ let should_replace =
2654
+ new_cost < old_cost
2655
+ || ( new_cost == old_cost && old_entry. value_contribution_msat < value_contribution_msat) ;
2657
2656
2658
- if !old_entry. was_processed && new_cost < old_cost {
2657
+ if !old_entry. was_processed && should_replace {
2659
2658
let new_graph_node = RouteGraphNode {
2660
2659
node_id: src_node_id,
2661
2660
node_counter: src_node_counter,
@@ -2672,10 +2671,7 @@ where L::Target: Logger {
2672
2671
old_entry. fee_msat = 0 ; // This value will be later filled with hop_use_fee_msat of the following channel
2673
2672
old_entry. path_htlc_minimum_msat = path_htlc_minimum_msat;
2674
2673
old_entry. path_penalty_msat = path_penalty_msat;
2675
- #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
2676
- {
2677
- old_entry. value_contribution_msat = value_contribution_msat;
2678
- }
2674
+ old_entry. value_contribution_msat = value_contribution_msat;
2679
2675
hop_contribution_amt_msat = Some ( value_contribution_msat) ;
2680
2676
} else if old_entry. was_processed && new_cost < old_cost {
2681
2677
#[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
@@ -2846,7 +2842,6 @@ where L::Target: Logger {
2846
2842
path_penalty_msat : u64:: max_value ( ) ,
2847
2843
was_processed : false ,
2848
2844
is_first_hop_target : true ,
2849
- #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
2850
2845
value_contribution_msat : 0 ,
2851
2846
} ) ;
2852
2847
}
0 commit comments