@@ -1113,13 +1113,16 @@ where L::Target: Logger {
11131113 fees : hop. fees ,
11141114 } ;
11151115
1116- let reqd_channel_cap = if let Some ( val) = final_value_msat
1117- . checked_mul ( ROUTE_CAPACITY_PROVISION_FACTOR ) . unwrap_or ( u64:: max_value ( ) )
1118- . checked_add ( match idx {
1119- 0 => 999 ,
1120- _ => aggregate_next_hops_fee_msat. checked_add ( 999 ) . unwrap_or ( u64:: max_value ( ) )
1121- } )
1122- { Some ( val / 1000 ) } else { break ; } ; // converting from msat or breaking if max ~ infinity
1116+ // We want a value of final_value_msat * ROUTE_CAPACITY_PROVISION_FACTOR but we
1117+ // need it to increment at each hop by the fee charged at later hops. Further,
1118+ // we need to ensure we round up when we divide to get satoshis.
1119+ let channel_cap_msat = final_value_msat
1120+ . checked_mul ( ROUTE_CAPACITY_PROVISION_FACTOR ) . map ( |v| v. checked_add ( aggregate_next_hops_fee_msat) )
1121+ . flatten ( ) . unwrap_or ( u64:: max_value ( ) ) ;
1122+ let channel_cap_sat = match channel_cap_msat. checked_add ( 999 ) {
1123+ None => break , // We overflowed above, just ignore this route hint
1124+ Some ( val) => Some ( val / 1000 ) ,
1125+ } ;
11231126
11241127 let src_node_id = NodeId :: from_pubkey ( & hop. src_node_id ) ;
11251128 let dest_node_id = NodeId :: from_pubkey ( & prev_hop_id) ;
@@ -1131,7 +1134,7 @@ where L::Target: Logger {
11311134 // sufficient value to route `final_value_msat`. Note that in the case of "0-value"
11321135 // invoices where the invoice does not specify value this may not be the case, but
11331136 // better to include the hints than not.
1134- if !add_entry ! ( hop. short_channel_id, src_node_id, dest_node_id, directional_info, reqd_channel_cap , & empty_channel_features, aggregate_next_hops_fee_msat, path_value_msat, aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat) {
1137+ if !add_entry ! ( hop. short_channel_id, src_node_id, dest_node_id, directional_info, channel_cap_sat , & empty_channel_features, aggregate_next_hops_fee_msat, path_value_msat, aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat) {
11351138 // If this hop was not used then there is no use checking the preceding hops
11361139 // in the RouteHint. We can break by just searching for a direct channel between
11371140 // last checked hop and first_hop_targets
0 commit comments