@@ -30,9 +30,9 @@ use crate::ln::msgs::LightningError;
30
30
use crate :: ln:: script:: ShutdownScript ;
31
31
use crate :: offers:: invoice:: UnsignedBolt12Invoice ;
32
32
use crate :: offers:: invoice_request:: UnsignedInvoiceRequest ;
33
- use crate :: routing:: gossip:: { EffectiveCapacity , NetworkGraph , NodeId } ;
33
+ use crate :: routing:: gossip:: { EffectiveCapacity , NetworkGraph , NodeId , RoutingFees } ;
34
34
use 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 } ;
36
36
use crate :: routing:: scoring:: { ChannelUsage , ScoreUpdate , ScoreLookUp } ;
37
37
use crate :: sync:: RwLock ;
38
38
use crate :: util:: config:: UserConfig ;
@@ -129,6 +129,7 @@ impl<'a> Router for TestRouter<'a> {
129
129
let scorer = ScorerAccountingForInFlightHtlcs :: new ( scorer, & inflight_htlcs) ;
130
130
for path in & route. paths {
131
131
let mut aggregate_msat = 0u64 ;
132
+ let mut prev_hop_node = payer;
132
133
for ( idx, hop) in path. hops . iter ( ) . rev ( ) . enumerate ( ) {
133
134
aggregate_msat += hop. fee_msat ;
134
135
let usage = ChannelUsage {
@@ -137,39 +138,44 @@ impl<'a> Router for TestRouter<'a> {
137
138
effective_capacity : EffectiveCapacity :: Unknown ,
138
139
} ;
139
140
140
- // Since the path is reversed, the last element in our iteration is the first
141
- // hop.
142
141
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
+ }
149
152
}
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 ,
155
160
} ;
156
161
scorer. channel_penalty_msat ( & candidate, usage, & ( ) ) ;
157
162
} 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,
169
166
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,
170
175
} ;
171
176
scorer. channel_penalty_msat ( & candidate, usage, & ( ) ) ;
172
177
}
178
+ prev_hop_node = & hop. pubkey ;
173
179
}
174
180
}
175
181
}
0 commit comments