@@ -30,9 +30,9 @@ use crate::ln::msgs::LightningError;
3030use  crate :: ln:: script:: ShutdownScript ; 
3131use  crate :: offers:: invoice:: UnsignedBolt12Invoice ; 
3232use  crate :: offers:: invoice_request:: UnsignedInvoiceRequest ; 
33- use  crate :: routing:: gossip:: { EffectiveCapacity ,  NetworkGraph ,  NodeId } ; 
33+ use  crate :: routing:: gossip:: { EffectiveCapacity ,  NetworkGraph ,  NodeId ,   RoutingFees } ; 
3434use  crate :: routing:: utxo:: { UtxoLookup ,  UtxoLookupError ,  UtxoResult } ; 
35- use  crate :: routing:: router:: { find_route,  InFlightHtlcs ,  Path ,  Route ,  RouteParameters ,  Router ,  ScorerAccountingForInFlightHtlcs } ; 
35+ use  crate :: routing:: router:: { find_route,  InFlightHtlcs ,  Path ,  Route ,  RouteParameters ,  RouteHintHop ,   Router ,  ScorerAccountingForInFlightHtlcs } ; 
3636use  crate :: routing:: scoring:: { ChannelUsage ,  ScoreUpdate ,  ScoreLookUp } ; 
3737use  crate :: sync:: RwLock ; 
3838use  crate :: util:: config:: UserConfig ; 
@@ -129,6 +129,7 @@ impl<'a> Router for TestRouter<'a> {
129129				let  scorer = ScorerAccountingForInFlightHtlcs :: new ( scorer,  & inflight_htlcs) ; 
130130				for  path in  & route. paths  { 
131131					let  mut  aggregate_msat = 0u64 ; 
132+ 					let  mut  prev_hop_node = payer; 
132133					for  ( idx,  hop)  in  path. hops . iter ( ) . rev ( ) . enumerate ( )  { 
133134						aggregate_msat += hop. fee_msat ; 
134135						let  usage = ChannelUsage  { 
@@ -137,39 +138,44 @@ impl<'a> Router for TestRouter<'a> {
137138							effective_capacity :  EffectiveCapacity :: Unknown , 
138139						} ; 
139140
140- 						// Since the path is reversed, the last element in our iteration is the first 
141- 						// hop. 
142141						if  idx == path. hops . len ( )  - 1  { 
143- 							let  first_hops = match  first_hops { 
144- 								Some ( hops)  => hops, 
145- 								None  => continue , 
146- 							} ; 
147- 							if  first_hops. len ( )  == 0  { 
148- 								continue ; 
142+ 							if  let  Some ( first_hops)  = first_hops { 
143+ 								if  let  Some ( idx)  = first_hops. iter ( ) . position ( |h| h. get_outbound_payment_scid ( )  == Some ( hop. short_channel_id ) )  { 
144+ 									let  node_id = NodeId :: from_pubkey ( payer) ; 
145+ 									let  candidate = CandidateRouteHop :: FirstHop  { 
146+ 										details :  first_hops[ idx] , 
147+ 										payer_node_id :  & node_id, 
148+ 									} ; 
149+ 									scorer. channel_penalty_msat ( & candidate,  usage,  & ( ) ) ; 
150+ 									continue ; 
151+ 								} 
149152							} 
150- 							let  idx = if  first_hops. len ( )  > 1  {  route. paths . iter ( ) . position ( |p| p == path) . unwrap_or ( 0 )  }  else  {  0  } ; 
151- 							let  node_id = NodeId :: from_pubkey ( payer) ; 
152- 							let  candidate = CandidateRouteHop :: FirstHop  { 
153- 								details :  first_hops[ idx] , 
154- 								payer_node_id :  & node_id, 
153+ 						} 
154+ 						let  network_graph = self . network_graph . read_only ( ) ; 
155+ 						if  let  Some ( channel)  = network_graph. channel ( hop. short_channel_id )  { 
156+ 							let  ( directed,  _)  = channel. as_directed_to ( & NodeId :: from_pubkey ( & hop. pubkey ) ) . unwrap ( ) ; 
157+ 							let  candidate = CandidateRouteHop :: PublicHop  { 
158+ 								info :  directed, 
159+ 								short_channel_id :  hop. short_channel_id , 
155160							} ; 
156161							scorer. channel_penalty_msat ( & candidate,  usage,  & ( ) ) ; 
157162						}  else  { 
158- 							let  network_graph = self . network_graph . read_only ( ) ; 
159- 							let  channel = match  network_graph. channel ( hop. short_channel_id )  { 
160- 								Some ( channel)  => channel, 
161- 								None  => continue , 
162- 							} ; 
163- 							let  channel = match  channel. as_directed_to ( & NodeId :: from_pubkey ( & hop. pubkey ) )  { 
164- 								Some ( channel)  => channel, 
165- 								None  => panic ! ( "Channel directed to {} was not found" ,  hop. pubkey) , 
166- 							} ; 
167- 							let  candidate = CandidateRouteHop :: PublicHop  { 
168- 								info :  channel. 0 , 
163+ 							let  target_node_id = NodeId :: from_pubkey ( & hop. pubkey ) ; 
164+ 							let  route_hint = RouteHintHop  { 
165+ 								src_node_id :  * prev_hop_node, 
169166								short_channel_id :  hop. short_channel_id , 
167+ 								fees :  RoutingFees  {  base_msat :  0 ,  proportional_millionths :  0  } , 
168+ 								cltv_expiry_delta :  0 , 
169+ 								htlc_minimum_msat :  None , 
170+ 								htlc_maximum_msat :  None , 
171+ 							} ; 
172+ 							let  candidate = CandidateRouteHop :: PrivateHop  { 
173+ 								hint :  & route_hint, 
174+ 								target_node_id :  target_node_id, 
170175							} ; 
171176							scorer. channel_penalty_msat ( & candidate,  usage,  & ( ) ) ; 
172177						} 
178+ 						prev_hop_node = & hop. pubkey ; 
173179					} 
174180				} 
175181			} 
0 commit comments