Skip to content

Commit d4878f4

Browse files
f matt different math
1 parent 9ba2ba8 commit d4878f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ pub(super) fn compute_payinfo(
174174
.and_then(|f| f.checked_add(1_000_000 - 1))
175175
.map(|f| f / 1_000_000)
176176
.ok_or(())?;
177-
// (((curr_prop_mil + next_prop_mil) * 1_000_000 + curr_prop_mil * next_prop_mil) + 1_000_000 - 1) / 1_000_000
178-
curr_prop_mil = curr_prop_mil.checked_add(next_prop_mil)
179-
.and_then(|f| f.checked_mul(1_000_000))
180-
.and_then(|f| curr_prop_mil.checked_mul(next_prop_mil).and_then(|prop_mil| prop_mil.checked_add(f)))
177+
// ceil(((curr_prop_mil + 1_000_000) * (next_prop_mil + 1_000_000)) / 1_000_000) - 1_000_000
178+
curr_prop_mil = curr_prop_mil.checked_add(1_000_000)
179+
.and_then(|f1| next_prop_mil.checked_add(1_000_000).and_then(|f2| f2.checked_mul(f1)))
181180
.and_then(|f| f.checked_add(1_000_000 - 1))
182181
.map(|f| f / 1_000_000)
182+
.and_then(|f| f.checked_sub(1_000_000))
183183
.ok_or(())?;
184184

185185
cltv_expiry_delta = cltv_expiry_delta.checked_add(tlvs.payment_relay.cltv_expiry_delta).ok_or(())?;

0 commit comments

Comments
 (0)