Skip to content

Commit 4bd4c7d

Browse files
committed
Account for extra fees in value contribution
When overpaying to meet `htlc_minimum_msat`, we update the path value and recompute fees accordingly. However, so far we didn't account for the extra paid fees in `value_contribution_msat`, which leads to it being slightly off, potentially having us hit a debug assertion when later checking the route's total value matches `already_collected_value_msat`. Here, we therefore add the extra fees to `value_contribution_msat`.
1 parent daf79f5 commit 4bd4c7d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lightning/src/routing/router.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,8 @@ impl<'a> PaymentPath<'a> {
12341234
// Note that this function is not aware of the available_liquidity limit, and thus does not
12351235
// support increasing the value being transferred beyond what was selected during the initial
12361236
// routing passes.
1237-
fn update_value_and_recompute_fees(&mut self, value_msat: u64) {
1237+
fn update_value_and_recompute_fees(&mut self, value_msat: u64) -> u64 {
1238+
let mut extra_contribution_msat = 0;
12381239
let mut total_fee_paid_msat = 0 as u64;
12391240
for i in (0..self.hops.len()).rev() {
12401241
let last_hop = i == self.hops.len() - 1;
@@ -1266,6 +1267,7 @@ impl<'a> PaymentPath<'a> {
12661267
cur_hop_transferred_amount_msat += extra_fees_msat;
12671268
total_fee_paid_msat += extra_fees_msat;
12681269
cur_hop_fees_msat += extra_fees_msat;
1270+
extra_contribution_msat += extra_fees_msat;
12691271
}
12701272

12711273
if last_hop {
@@ -1293,6 +1295,7 @@ impl<'a> PaymentPath<'a> {
12931295
}
12941296
}
12951297
}
1298+
extra_contribution_msat
12961299
}
12971300
}
12981301

@@ -2280,7 +2283,7 @@ where L::Target: Logger {
22802283
// underpaid htlc_minimum_msat with fees.
22812284
debug_assert_eq!(payment_path.get_value_msat(), value_contribution_msat);
22822285
value_contribution_msat = cmp::min(value_contribution_msat, final_value_msat);
2283-
payment_path.update_value_and_recompute_fees(value_contribution_msat);
2286+
value_contribution_msat += payment_path.update_value_and_recompute_fees(value_contribution_msat);
22842287

22852288
// Since a path allows to transfer as much value as
22862289
// the smallest channel it has ("bottleneck"), we should recompute

0 commit comments

Comments
 (0)