@@ -145,7 +145,6 @@ use crate::prelude::*;
145
145
use lightning:: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
146
146
use lightning:: ln:: channelmanager:: { ChannelDetails , PaymentId , PaymentSendFailure } ;
147
147
use lightning:: ln:: msgs:: LightningError ;
148
- use lightning:: routing:: gossip:: NodeId ;
149
148
use lightning:: routing:: router:: { InFlightHtlcs , PaymentParameters , Route , RouteHop , RouteParameters , Router } ;
150
149
use lightning:: util:: errors:: APIError ;
151
150
use lightning:: util:: events:: { Event , EventHandler } ;
@@ -698,38 +697,15 @@ where
698
697
/// This function should be called whenever we need information about currently used up liquidity
699
698
/// across payments.
700
699
fn create_inflight_map ( & self ) -> InFlightHtlcs {
701
- let mut total_inflight_map: HashMap < ( u64 , bool ) , u64 > = HashMap :: new ( ) ;
702
- // Make an attempt at finding existing payment information from `payment_cache`. If it
703
- // does not exist, it probably is a fresh payment and we can just return an empty
704
- // HashMap.
700
+ let mut total_inflight_map = InFlightHtlcs :: new ( ) ;
701
+ // Make an attempt at finding existing payment information from `payment_cache`.
705
702
for payment_info in self . payment_cache . lock ( ) . unwrap ( ) . values ( ) {
706
703
for path in & payment_info. paths {
707
- if path. is_empty ( ) { break } ;
708
- // total_inflight_map needs to be direction-sensitive when keeping track of the HTLC value
709
- // that is held up. However, the `hops` array, which is a path returned by `find_route` in
710
- // the router excludes the payer node. In the following lines, the payer's information is
711
- // hardcoded with an inflight value of 0 so that we can correctly represent the first hop
712
- // in our sliding window of two.
713
- let our_node_id: PublicKey = self . payer . node_id ( ) ;
714
- let reversed_hops_with_payer = path. iter ( ) . rev ( ) . skip ( 1 )
715
- . map ( |hop| hop. pubkey )
716
- . chain ( core:: iter:: once ( our_node_id) ) ;
717
- let mut cumulative_msat = 0 ;
718
-
719
- // Taking the reversed vector from above, we zip it with just the reversed hops list to
720
- // work "backwards" of the given path, since the last hop's `fee_msat` actually represents
721
- // the total amount sent.
722
- for ( next_hop, prev_hop) in path. iter ( ) . rev ( ) . zip ( reversed_hops_with_payer) {
723
- cumulative_msat += next_hop. fee_msat ;
724
- total_inflight_map
725
- . entry ( ( next_hop. short_channel_id , NodeId :: from_pubkey ( & prev_hop) < NodeId :: from_pubkey ( & next_hop. pubkey ) ) )
726
- . and_modify ( |used_liquidity_msat| * used_liquidity_msat += cumulative_msat)
727
- . or_insert ( cumulative_msat) ;
728
- }
704
+ total_inflight_map. process_path ( path, self . payer . node_id ( ) ) ;
729
705
}
730
706
}
731
707
732
- InFlightHtlcs :: new ( total_inflight_map)
708
+ total_inflight_map
733
709
}
734
710
}
735
711
0 commit comments