Skip to content

Commit cbc5aaa

Browse files
committed
f clarify that / 0 cant happen
1 parent 9b9dbcc commit cbc5aaa

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lightning/src/routing/router.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,10 +2126,12 @@ impl<'a> PaymentPath<'a> {
21262126
/// can/will send over the path. This is also the heap score during our Dijkstra's walk.
21272127
fn get_cost_per_msat(&self) -> u128 {
21282128
let fee_cost = self.get_cost_msat();
2129-
if fee_cost == u64::MAX {
2129+
let value_msat = self.get_value_msat();
2130+
debug_assert!(value_msat > 0, "Paths should always send more than 0 msat");
2131+
if fee_cost == u64::MAX || value_msat == 0 {
21302132
u64::MAX.into()
21312133
} else {
2132-
((fee_cost as u128) << 64) / self.get_value_msat() as u128
2134+
((fee_cost as u128) << 64) / value_msat as u128
21332135
}
21342136
}
21352137

@@ -2800,8 +2802,6 @@ where L::Target: Logger {
28002802
*used_liquidity_msat
28012803
});
28022804

2803-
// Verify the liquidity offered by this channel complies to the minimal contribution.
2804-
let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
28052805
// Do not consider candidate hops that would exceed the maximum path length.
28062806
let path_length_to_node = $next_hops_path_length
28072807
+ if $candidate.blinded_hint_idx().is_some() { 0 } else { 1 };
@@ -2813,6 +2813,8 @@ where L::Target: Logger {
28132813
let exceeds_cltv_delta_limit = hop_total_cltv_delta > max_total_cltv_expiry_delta as u32;
28142814

28152815
let value_contribution_msat = cmp::min(available_value_contribution_msat, $next_hops_value_contribution);
2816+
// Verify the liquidity offered by this channel complies to the minimal contribution.
2817+
let contributes_sufficient_value = value_contribution_msat >= minimal_value_contribution_msat;
28162818
// Includes paying fees for the use of the following channels.
28172819
let amount_to_transfer_over_msat: u64 = match value_contribution_msat.checked_add($next_hops_fee_msat) {
28182820
Some(result) => result,
@@ -3020,6 +3022,8 @@ where L::Target: Logger {
30203022
u128::MAX
30213023
};
30223024
let new_cost = if new_fee_cost != u64::MAX {
3025+
// value_contribution_msat is always >= 1, checked above via
3026+
// `contributes_sufficient_value`.
30233027
((new_fee_cost as u128) << 64) / value_contribution_msat as u128
30243028
} else {
30253029
u128::MAX

0 commit comments

Comments
 (0)