@@ -854,7 +854,7 @@ where L::Target: Logger {
854854 let short_channel_id = $candidate. short_channel_id( ) ;
855855 let available_liquidity_msat = bookkept_channels_liquidity_available_msat
856856 . entry( short_channel_id)
857- . or_insert_with( || $candidate. effective_capacity( ) . as_msat ( ) ) ;
857+ . or_insert_with( || $candidate. effective_capacity( ) ) ;
858858
859859 // It is tricky to substract $next_hops_fee_msat from available liquidity here.
860860 // It may be misleading because we might later choose to reduce the value transferred
@@ -863,7 +863,7 @@ where L::Target: Logger {
863863 // fees caused by one expensive channel, but then this channel could have been used
864864 // if the amount being transferred over this path is lower.
865865 // We do this for now, but this is a subject for removal.
866- if let Some ( available_value_contribution_msat ) = available_liquidity_msat. checked_sub( $next_hops_fee_msat) {
866+ if let Some ( available_value_contribution ) = available_liquidity_msat. checked_sub( $next_hops_fee_msat) {
867867
868868 // Routing Fragmentation Mitigation heuristic:
869869 //
@@ -886,6 +886,7 @@ where L::Target: Logger {
886886 final_value_msat
887887 } ;
888888 // Verify the liquidity offered by this channel complies to the minimal contribution.
889+ let available_value_contribution_msat = available_value_contribution. as_msat_without_bounds( ) ;
889890 let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
890891
891892 // Do not consider candidates that exceed the maximum total cltv expiry limit.
@@ -1220,9 +1221,8 @@ where L::Target: Logger {
12201221 short_channel_id : hop. short_channel_id ,
12211222 } )
12221223 . unwrap_or_else ( || CandidateRouteHop :: PrivateHop { hint : hop } ) ;
1223- let capacity_msat = candidate. effective_capacity ( ) . as_msat ( ) ;
12241224 aggregate_next_hops_path_penalty_msat = aggregate_next_hops_path_penalty_msat
1225- . checked_add ( scorer. channel_penalty_msat ( hop. short_channel_id , final_value_msat , capacity_msat , & source, & target) )
1225+ . checked_add ( scorer. channel_penalty_msat ( hop. short_channel_id , path_value_msat , candidate . effective_capacity ( ) , & source, & target) )
12261226 . unwrap_or_else ( || u64:: max_value ( ) ) ;
12271227
12281228 aggregate_next_hops_cltv_delta = aggregate_next_hops_cltv_delta
@@ -1382,12 +1382,13 @@ where L::Target: Logger {
13821382 let mut spent_on_hop_msat = value_contribution_msat;
13831383 let next_hops_fee_msat = payment_hop. next_hops_fee_msat ;
13841384 spent_on_hop_msat += next_hops_fee_msat;
1385- if spent_on_hop_msat == * channel_liquidity_available_msat {
1385+ if spent_on_hop_msat == channel_liquidity_available_msat. as_msat_without_bounds ( ) {
13861386 // If this path used all of this channel's available liquidity, we know
13871387 // this path will not be selected again in the next loop iteration.
13881388 prevented_redundant_path_selection = true ;
13891389 }
1390- * channel_liquidity_available_msat -= spent_on_hop_msat;
1390+ * channel_liquidity_available_msat = channel_liquidity_available_msat
1391+ . checked_sub ( spent_on_hop_msat) . unwrap_or ( EffectiveCapacity :: ExactLiquidity { liquidity_msat : 0 } ) ;
13911392 }
13921393 if !prevented_redundant_path_selection {
13931394 // If we weren't capped by hitting a liquidity limit on a channel in the path,
@@ -1396,7 +1397,7 @@ where L::Target: Logger {
13961397 let victim_scid = payment_path. hops [ ( payment_path. hops . len ( ) - 1 ) / 2 ] . 0 . candidate . short_channel_id ( ) ;
13971398 log_trace ! ( logger, "Disabling channel {} for future path building iterations to avoid duplicates." , victim_scid) ;
13981399 let victim_liquidity = bookkept_channels_liquidity_available_msat. get_mut ( & victim_scid) . unwrap ( ) ;
1399- * victim_liquidity = 0 ;
1400+ * victim_liquidity = EffectiveCapacity :: ExactLiquidity { liquidity_msat : 0 } ;
14001401 }
14011402
14021403 // Track the total amount all our collected paths allow to send so that we:
@@ -1664,7 +1665,7 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
16641665
16651666#[ cfg( test) ]
16661667mod tests {
1667- use routing:: network_graph:: { NetworkGraph , NetGraphMsgHandler , NodeId } ;
1668+ use routing:: network_graph:: { EffectiveCapacity , NetworkGraph , NetGraphMsgHandler , NodeId } ;
16681669 use routing:: router:: { get_route, add_random_cltv_offset, PaymentParameters , Route , RouteHint , RouteHintHop , RouteHop , RoutingFees , DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA } ;
16691670 use routing:: scoring:: Score ;
16701671 use chain:: transaction:: OutPoint ;
@@ -5001,7 +5002,7 @@ mod tests {
50015002 fn write < W : Writer > ( & self , _w : & mut W ) -> Result < ( ) , :: io:: Error > { unimplemented ! ( ) }
50025003 }
50035004 impl Score for BadChannelScorer {
5004- fn channel_penalty_msat ( & self , short_channel_id : u64 , _send_amt : u64 , _capacity_msat : u64 , _source : & NodeId , _target : & NodeId ) -> u64 {
5005+ fn channel_penalty_msat ( & self , short_channel_id : u64 , _send_amt : u64 , _capacity : EffectiveCapacity , _source : & NodeId , _target : & NodeId ) -> u64 {
50055006 if short_channel_id == self . short_channel_id { u64:: max_value ( ) } else { 0 }
50065007 }
50075008
@@ -5019,7 +5020,7 @@ mod tests {
50195020 }
50205021
50215022 impl Score for BadNodeScorer {
5022- fn channel_penalty_msat ( & self , _short_channel_id : u64 , _send_amt : u64 , _capacity_msat : u64 , _source : & NodeId , target : & NodeId ) -> u64 {
5023+ fn channel_penalty_msat ( & self , _short_channel_id : u64 , _send_amt : u64 , _capacity : EffectiveCapacity , _source : & NodeId , target : & NodeId ) -> u64 {
50235024 if * target == self . node_id { u64:: max_value ( ) } else { 0 }
50245025 }
50255026
0 commit comments