Skip to content

Commit 12c810d

Browse files
committed
f: simplify arithmetic
1 parent 6e768b7 commit 12c810d

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

lightning/src/routing/router.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -493,23 +493,14 @@ pub struct Path {
493493
impl Path {
494494
/// Gets the fees for a given path, excluding any excess paid to the recipient.
495495
pub fn fee_msat(&self) -> u64 {
496-
let route_fee = self.hops.split_last()
497-
.map_or(0, |(_, path_prefix)| path_prefix.iter().map(|hop| hop.fee_msat).sum());
498-
let trampoline_fee = self.trampoline_hops.iter().map(|hop| hop.fee_msat).sum::<u64>();
499-
match &self.blinded_tail {
500-
Some(_) => {
501-
if self.trampoline_hops.is_empty() {
502-
route_fee + trampoline_fee + self.hops.last().map_or(0, |hop| hop.fee_msat)
503-
} else {
504-
// exclude last RouteHop because its value is the outgoing amount to the
505-
// Trampoline entry point
506-
route_fee + trampoline_fee
507-
}
508-
},
509-
None => {
510-
// Do not count last hop of each path since that's the full value of the payment
511-
route_fee + trampoline_fee
512-
}
496+
let unblinded_hop_fee_iterator = self.hops.iter().rev().map(|hop| hop.fee_msat)
497+
.chain(self.trampoline_hops.iter().map(|hop| hop.fee_msat));
498+
499+
if self.blinded_tail.is_none() || !self.trampoline_hops.is_empty() {
500+
// If we don't have a blinded tail or if we have Trampoline hops, we skip the last RouteHop's fee
501+
unblinded_hop_fee_iterator.skip(1).sum()
502+
} else {
503+
unblinded_hop_fee_iterator.sum()
513504
}
514505
}
515506

0 commit comments

Comments
 (0)