File tree Expand file tree Collapse file tree 1 file changed +8
-17
lines changed Expand file tree Collapse file tree 1 file changed +8
-17
lines changed Original file line number Diff line number Diff line change @@ -493,23 +493,14 @@ pub struct Path {
493
493
impl Path {
494
494
/// Gets the fees for a given path, excluding any excess paid to the recipient.
495
495
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 ( )
513
504
}
514
505
}
515
506
You can’t perform that action at this time.
0 commit comments