Skip to content

Commit 6082b57

Browse files
committed
Include overpaid value in Route::get_total_fees
1 parent 61cf752 commit 6082b57

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lightning/src/routing/router.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,15 @@ pub struct Route {
348348
impl Route {
349349
/// Returns the total amount of fees paid on this [`Route`].
350350
///
351-
/// This doesn't include any extra payment made to the recipient, which can happen in excess of
352-
/// the amount passed to [`find_route`]'s `route_params.final_value_msat`.
351+
/// For objects serialized with LDK 0.0.117 and after, this includes any extra payment made to
352+
/// the recipient, which can happen in excess of the amount passed to [`find_route`] via
353+
/// [`RouteParameters::final_value_msat`], if we had to reach the [`htlc_minimum_msat`] limits.
354+
///
355+
/// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
353356
pub fn get_total_fees(&self) -> u64 {
354-
self.paths.iter().map(|path| path.fee_msat()).sum()
357+
let overpaid_value_msat = self.route_params.as_ref()
358+
.map_or(0, |p| self.get_total_amount().saturating_sub(p.final_value_msat));
359+
overpaid_value_msat + self.paths.iter().map(|path| path.fee_msat()).sum::<u64>()
355360
}
356361

357362
/// Returns the total amount paid on this [`Route`], excluding the fees. Might be more than

0 commit comments

Comments
 (0)