Skip to content

Commit 34f724c

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 0f87ee8 commit 34f724c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lightning/src/routing/router.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,8 @@ impl<'a> PaymentPath<'a> {
12651265
// Note that this function is not aware of the available_liquidity limit, and thus does not
12661266
// support increasing the value being transferred beyond what was selected during the initial
12671267
// routing passes.
1268-
fn update_value_and_recompute_fees(&mut self, value_msat: u64) {
1268+
fn update_value_and_recompute_fees(&mut self, value_msat: u64) -> u64 {
1269+
let mut extra_contribution_msat = 0;
12691270
let mut total_fee_paid_msat = 0 as u64;
12701271
for i in (0..self.hops.len()).rev() {
12711272
let last_hop = i == self.hops.len() - 1;
@@ -1297,6 +1298,12 @@ impl<'a> PaymentPath<'a> {
12971298
cur_hop_transferred_amount_msat += extra_fees_msat;
12981299
total_fee_paid_msat += extra_fees_msat;
12991300
cur_hop_fees_msat += extra_fees_msat;
1301+
1302+
// We remember and return the extra fees on the final hop to allow accounting for
1303+
// them in the path's value contribution.
1304+
if last_hop {
1305+
extra_contribution_msat = extra_fees_msat;
1306+
}
13001307
}
13011308

13021309
if last_hop {
@@ -1324,6 +1331,7 @@ impl<'a> PaymentPath<'a> {
13241331
}
13251332
}
13261333
}
1334+
extra_contribution_msat
13271335
}
13281336
}
13291337

@@ -2321,7 +2329,7 @@ where L::Target: Logger {
23212329
// underpaid htlc_minimum_msat with fees.
23222330
debug_assert_eq!(payment_path.get_value_msat(), value_contribution_msat);
23232331
value_contribution_msat = cmp::min(value_contribution_msat, final_value_msat);
2324-
payment_path.update_value_and_recompute_fees(value_contribution_msat);
2332+
value_contribution_msat += payment_path.update_value_and_recompute_fees(value_contribution_msat);
23252333

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

0 commit comments

Comments
 (0)