@@ -1179,7 +1179,10 @@ struct RouteGraphNode {
1179
1179
1180
1180
impl cmp:: Ord for RouteGraphNode {
1181
1181
fn cmp ( & self , other : & RouteGraphNode ) -> cmp:: Ordering {
1182
- other. score . cmp ( & self . score ) . then_with ( || other. node_counter . cmp ( & self . node_counter ) )
1182
+ other. score . cmp ( & self . score )
1183
+ . then_with ( || self . value_contribution_msat . cmp ( & other. value_contribution_msat ) )
1184
+ . then_with ( || other. path_length_to_node . cmp ( & self . path_length_to_node ) )
1185
+ . then_with ( || other. node_counter . cmp ( & self . node_counter ) )
1183
1186
}
1184
1187
}
1185
1188
@@ -1809,11 +1812,7 @@ struct PathBuildingHop<'a> {
1809
1812
/// The value will be actually deducted from the counterparty balance on the previous link.
1810
1813
hop_use_fee_msat : u64 ,
1811
1814
1812
- #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
1813
- // In tests, we apply further sanity checks on cases where we skip nodes we already processed
1814
- // to ensure it is specifically in cases where the fee has gone down because of a decrease in
1815
- // value_contribution_msat, which requires tracking it here. See comments below where it is
1816
- // used for more info.
1815
+ /// The quantity of funds we're willing to route over this channel
1817
1816
value_contribution_msat : u64 ,
1818
1817
}
1819
1818
@@ -1834,9 +1833,7 @@ impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
1834
1833
. 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 ) ) )
1835
1834
. field ( "path_penalty_msat" , & self . path_penalty_msat )
1836
1835
. field ( "path_htlc_minimum_msat" , & self . path_htlc_minimum_msat )
1837
- . field ( "cltv_expiry_delta" , & self . candidate . cltv_expiry_delta ( ) ) ;
1838
- #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
1839
- let debug_struct = debug_struct
1836
+ . field ( "cltv_expiry_delta" , & self . candidate . cltv_expiry_delta ( ) )
1840
1837
. field ( "value_contribution_msat" , & self . value_contribution_msat ) ;
1841
1838
debug_struct. finish ( )
1842
1839
}
@@ -2546,7 +2543,6 @@ where L::Target: Logger {
2546
2543
path_penalty_msat: u64 :: max_value( ) ,
2547
2544
was_processed: false ,
2548
2545
is_first_hop_target: false ,
2549
- #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
2550
2546
value_contribution_msat,
2551
2547
} ) ;
2552
2548
dist_entry. as_mut( ) . unwrap( )
@@ -2622,8 +2618,11 @@ where L::Target: Logger {
2622
2618
. saturating_add( old_entry. path_penalty_msat) ;
2623
2619
let new_cost = cmp:: max( total_fee_msat, path_htlc_minimum_msat)
2624
2620
. saturating_add( path_penalty_msat) ;
2621
+ let should_replace =
2622
+ new_cost < old_cost
2623
+ || ( new_cost == old_cost && old_entry. value_contribution_msat < value_contribution_msat) ;
2625
2624
2626
- if !old_entry. was_processed && new_cost < old_cost {
2625
+ if !old_entry. was_processed && should_replace {
2627
2626
let new_graph_node = RouteGraphNode {
2628
2627
node_id: src_node_id,
2629
2628
node_counter: src_node_counter,
@@ -2640,10 +2639,7 @@ where L::Target: Logger {
2640
2639
old_entry. fee_msat = 0 ; // This value will be later filled with hop_use_fee_msat of the following channel
2641
2640
old_entry. path_htlc_minimum_msat = path_htlc_minimum_msat;
2642
2641
old_entry. path_penalty_msat = path_penalty_msat;
2643
- #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
2644
- {
2645
- old_entry. value_contribution_msat = value_contribution_msat;
2646
- }
2642
+ old_entry. value_contribution_msat = value_contribution_msat;
2647
2643
hop_contribution_amt_msat = Some ( value_contribution_msat) ;
2648
2644
} else if old_entry. was_processed && new_cost < old_cost {
2649
2645
#[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
@@ -2814,7 +2810,6 @@ where L::Target: Logger {
2814
2810
path_penalty_msat : u64:: max_value ( ) ,
2815
2811
was_processed : false ,
2816
2812
is_first_hop_target : true ,
2817
- #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
2818
2813
value_contribution_msat : 0 ,
2819
2814
} ) ;
2820
2815
}
0 commit comments