@@ -493,12 +493,22 @@ 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 > ( ) ;
496
499
match & self . blinded_tail {
497
- Some ( _) => self . hops . iter ( ) . map ( |hop| hop. fee_msat ) . sum :: < u64 > ( ) ,
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
+ } ,
498
509
None => {
499
510
// Do not count last hop of each path since that's the full value of the payment
500
- self . hops . split_last ( ) . map_or ( 0 ,
501
- |( _, path_prefix) | path_prefix. iter ( ) . map ( |hop| hop. fee_msat ) . sum ( ) )
511
+ route_fee + trampoline_fee
502
512
}
503
513
}
504
514
}
@@ -507,15 +517,29 @@ impl Path {
507
517
pub fn final_value_msat ( & self ) -> u64 {
508
518
match & self . blinded_tail {
509
519
Some ( blinded_tail) => blinded_tail. final_value_msat ,
510
- None => self . hops . last ( ) . map_or ( 0 , |hop| hop. fee_msat )
520
+ None => {
521
+ if let Some ( last_trampoline) = self . trampoline_hops . last ( ) {
522
+ // Note that this scenario should never occur until as we don't support
523
+ // unblinded Trampoline payments
524
+ return last_trampoline. fee_msat ;
525
+ }
526
+ self . hops . last ( ) . map_or ( 0 , |hop| hop. fee_msat )
527
+ }
511
528
}
512
529
}
513
530
514
531
/// Gets the final hop's CLTV expiry delta.
515
532
pub fn final_cltv_expiry_delta ( & self ) -> Option < u32 > {
516
533
match & self . blinded_tail {
517
534
Some ( _) => None ,
518
- None => self . hops . last ( ) . map ( |hop| hop. cltv_expiry_delta )
535
+ None => {
536
+ if let Some ( last_trampoline) = self . trampoline_hops . last ( ) {
537
+ // Note that this scenario should never occur until as we don't support
538
+ // unblinded Trampoline payments
539
+ return Some ( last_trampoline. cltv_expiry_delta ) ;
540
+ }
541
+ self . hops . last ( ) . map ( |hop| hop. cltv_expiry_delta )
542
+ }
519
543
}
520
544
}
521
545
}
0 commit comments