X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Frouter.rs;h=9c5fe8e1f9bd3dab59033644591a4a59b49d173b;hb=b5e959460f1473022321c8b8868fb0f7da6906b5;hp=8b3a96eb42ed21c04fe915d6c9674ced3d3da46a;hpb=61cf75265ebff493af5a04550a5ff8b250f3b2f6;p=rust-lightning diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 8b3a96eb..9c5fe8e1 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -348,14 +348,23 @@ pub struct Route { impl Route { /// Returns the total amount of fees paid on this [`Route`]. /// - /// This doesn't include any extra payment made to the recipient, which can happen in excess of - /// the amount passed to [`find_route`]'s `route_params.final_value_msat`. + /// For objects serialized with LDK 0.0.117 and after, this includes any extra payment made to + /// the recipient, which can happen in excess of the amount passed to [`find_route`] via + /// [`RouteParameters::final_value_msat`], if we had to reach the [`htlc_minimum_msat`] limits. + /// + /// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message pub fn get_total_fees(&self) -> u64 { - self.paths.iter().map(|path| path.fee_msat()).sum() + let overpaid_value_msat = self.route_params.as_ref() + .map_or(0, |p| self.get_total_amount().saturating_sub(p.final_value_msat)); + overpaid_value_msat + self.paths.iter().map(|path| path.fee_msat()).sum::() } - /// Returns the total amount paid on this [`Route`], excluding the fees. Might be more than - /// requested if we had to reach htlc_minimum_msat. + /// Returns the total amount paid on this [`Route`], excluding the fees. + /// + /// Might be more than requested as part of the given [`RouteParameters::final_value_msat`] if + /// we had to reach the [`htlc_minimum_msat`] limits. + /// + /// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message pub fn get_total_amount(&self) -> u64 { self.paths.iter().map(|path| path.final_value_msat()).sum() }