@@ -145,7 +145,6 @@ use crate::prelude::*;
145145use lightning:: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
146146use lightning:: ln:: channelmanager:: { ChannelDetails , PaymentId , PaymentSendFailure } ;
147147use lightning:: ln:: msgs:: LightningError ;
148- use lightning:: routing:: gossip:: NodeId ;
149148use lightning:: routing:: router:: { InFlightHtlcs , PaymentParameters , Route , RouteHop , RouteParameters , Router } ;
150149use lightning:: util:: errors:: APIError ;
151150use lightning:: util:: events:: { Event , EventHandler } ;
@@ -717,38 +716,15 @@ where
717716 /// This function should be called whenever we need information about currently used up liquidity
718717 /// across payments.
719718 fn create_inflight_map ( & self ) -> InFlightHtlcs {
720- let mut total_inflight_map: HashMap < ( u64 , bool ) , u64 > = HashMap :: new ( ) ;
721- // Make an attempt at finding existing payment information from `payment_cache`. If it
722- // does not exist, it probably is a fresh payment and we can just return an empty
723- // HashMap.
719+ let mut total_inflight_map = InFlightHtlcs :: new ( ) ;
720+ // Make an attempt at finding existing payment information from `payment_cache`.
724721 for payment_info in self . payment_cache . lock ( ) . unwrap ( ) . values ( ) {
725722 for path in & payment_info. paths {
726- if path. is_empty ( ) { break } ;
727- // total_inflight_map needs to be direction-sensitive when keeping track of the HTLC value
728- // that is held up. However, the `hops` array, which is a path returned by `find_route` in
729- // the router excludes the payer node. In the following lines, the payer's information is
730- // hardcoded with an inflight value of 0 so that we can correctly represent the first hop
731- // in our sliding window of two.
732- let our_node_id: PublicKey = self . payer . node_id ( ) ;
733- let reversed_hops_with_payer = path. iter ( ) . rev ( ) . skip ( 1 )
734- . map ( |hop| hop. pubkey )
735- . chain ( core:: iter:: once ( our_node_id) ) ;
736- let mut cumulative_msat = 0 ;
737-
738- // Taking the reversed vector from above, we zip it with just the reversed hops list to
739- // work "backwards" of the given path, since the last hop's `fee_msat` actually represents
740- // the total amount sent.
741- for ( next_hop, prev_hop) in path. iter ( ) . rev ( ) . zip ( reversed_hops_with_payer) {
742- cumulative_msat += next_hop. fee_msat ;
743- total_inflight_map
744- . entry ( ( next_hop. short_channel_id , NodeId :: from_pubkey ( & prev_hop) < NodeId :: from_pubkey ( & next_hop. pubkey ) ) )
745- . and_modify ( |used_liquidity_msat| * used_liquidity_msat += cumulative_msat)
746- . or_insert ( cumulative_msat) ;
747- }
723+ total_inflight_map. process_path ( path, self . payer . node_id ( ) ) ;
748724 }
749725 }
750726
751- InFlightHtlcs :: new ( total_inflight_map)
727+ total_inflight_map
752728 }
753729}
754730
0 commit comments