Skip to content

Commit ab29653

Browse files
committed
Breaking out if channel capacity reaches max value of u64.
1 parent cf0fd51 commit ab29653

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lightning/src/routing/router.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -907,10 +907,14 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
907907
fees: hop.fees,
908908
};
909909

910-
let reqd_channel_cap = Some(final_value_msat.checked_add(match idx {
910+
// let reqd_channel_cap = Some(final_value_msat.checked_add(match idx {
911+
// 0 => 999,
912+
// _ => aggregate_next_hops_fee_msat.checked_add(999).unwrap_or(u64::max_value())
913+
// }).unwrap_or(u64::max_value()) / 1000); // converting from msat
914+
let reqd_channel_cap = if let Some (val) = final_value_msat.checked_add(match idx {
911915
0 => 999,
912916
_ => aggregate_next_hops_fee_msat.checked_add(999).unwrap_or(u64::max_value())
913-
}).unwrap_or(u64::max_value()) / 1000); // converting from msat
917+
}) { Some( val / 1000 ) } else { break; }; // converting from msat or breaking if max ~ infinity
914918

915919

916920
// We assume that the recipient only included route hints for routes which had
@@ -944,8 +948,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
944948

945949
let hop_htlc_minimum_msat_inc = compute_fees(hop_htlc_minimum_msat, hop.fees).unwrap_or(u64::max_value());
946950
let hops_path_htlc_minimum = aggregate_next_hops_path_htlc_minimum_msat
947-
.checked_add(hop_htlc_minimum_msat_inc)
948-
.map_or(None, |inc| inc.checked_add(aggregate_next_hops_path_htlc_minimum_msat));
951+
.checked_add(hop_htlc_minimum_msat_inc);
949952
aggregate_next_hops_path_htlc_minimum_msat = if let Some(val) = hops_path_htlc_minimum { cmp::max(hop_htlc_minimum_msat, val) } else { break; };
950953

951954
if idx == route.0.len() - 1 {

0 commit comments

Comments
 (0)