@@ -949,11 +949,11 @@ enum CandidateRouteHop<'a> {
949
949
}
950
950
951
951
impl < ' a > CandidateRouteHop < ' a > {
952
- fn short_channel_id ( & self ) -> u64 {
952
+ fn short_channel_id ( & self ) -> Option < u64 > {
953
953
match self {
954
- CandidateRouteHop :: FirstHop { details } => details. get_outbound_payment_scid ( ) . unwrap ( ) ,
955
- CandidateRouteHop :: PublicHop { short_channel_id, .. } => * short_channel_id,
956
- CandidateRouteHop :: PrivateHop { hint } => hint. short_channel_id ,
954
+ CandidateRouteHop :: FirstHop { details } => Some ( details. get_outbound_payment_scid ( ) . unwrap ( ) ) ,
955
+ CandidateRouteHop :: PublicHop { short_channel_id, .. } => Some ( * short_channel_id) ,
956
+ CandidateRouteHop :: PrivateHop { hint } => Some ( hint. short_channel_id ) ,
957
957
}
958
958
}
959
959
@@ -1005,7 +1005,9 @@ impl<'a> CandidateRouteHop<'a> {
1005
1005
}
1006
1006
}
1007
1007
fn id ( & self , channel_direction : bool /* src_node_id < target_node_id */ ) -> CandidateHopId {
1008
- CandidateHopId :: Clear ( ( self . short_channel_id ( ) , channel_direction) )
1008
+ match self {
1009
+ _ => CandidateHopId :: Clear ( ( self . short_channel_id ( ) . unwrap ( ) , channel_direction) ) ,
1010
+ }
1009
1011
}
1010
1012
}
1011
1013
@@ -1256,6 +1258,18 @@ impl fmt::Display for LoggedPayeePubkey {
1256
1258
}
1257
1259
}
1258
1260
1261
+ struct LoggedCandidateHop < ' a > ( & ' a CandidateRouteHop < ' a > ) ;
1262
+ impl < ' a > fmt:: Display for LoggedCandidateHop < ' a > {
1263
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1264
+ match self . 0 {
1265
+ _ => {
1266
+ "SCID " . fmt ( f) ?;
1267
+ self . 0 . short_channel_id ( ) . unwrap ( ) . fmt ( f)
1268
+ } ,
1269
+ }
1270
+ }
1271
+ }
1272
+
1259
1273
#[ inline]
1260
1274
fn sort_first_hop_channels (
1261
1275
channels : & mut Vec < & ChannelDetails > , used_liquidities : & HashMap < CandidateHopId , u64 > ,
@@ -1560,7 +1574,7 @@ where L::Target: Logger {
1560
1574
// - for regular channels at channel announcement (TODO)
1561
1575
// - for first and last hops early in get_route
1562
1576
if $src_node_id != $dest_node_id {
1563
- let short_channel_id = $candidate. short_channel_id( ) ;
1577
+ let scid_opt = $candidate. short_channel_id( ) ;
1564
1578
let effective_capacity = $candidate. effective_capacity( ) ;
1565
1579
let htlc_maximum_msat = max_htlc_from_capacity( effective_capacity, channel_saturation_pow_half) ;
1566
1580
@@ -1615,8 +1629,8 @@ where L::Target: Logger {
1615
1629
( amount_to_transfer_over_msat < $next_hops_path_htlc_minimum_msat &&
1616
1630
recommended_value_msat > $next_hops_path_htlc_minimum_msat) ) ;
1617
1631
1618
- let payment_failed_on_this_channel =
1619
- payment_params. previously_failed_channels. contains( & short_channel_id ) ;
1632
+ let payment_failed_on_this_channel = scid_opt . map_or ( false ,
1633
+ |scid| payment_params. previously_failed_channels. contains( & scid ) ) ;
1620
1634
1621
1635
// If HTLC minimum is larger than the amount we're going to transfer, we shouldn't
1622
1636
// bother considering this channel. If retrying with recommended_value_msat may
@@ -1685,9 +1699,9 @@ where L::Target: Logger {
1685
1699
inflight_htlc_msat: used_liquidity_msat,
1686
1700
effective_capacity,
1687
1701
} ;
1688
- let channel_penalty_msat = scorer . channel_penalty_msat (
1689
- short_channel_id , & $src_node_id, & $dest_node_id, channel_usage , score_params
1690
- ) ;
1702
+ let channel_penalty_msat = scid_opt . map_or ( 0 ,
1703
+ |scid| scorer . channel_penalty_msat ( scid , & $src_node_id, & $dest_node_id,
1704
+ channel_usage , score_params ) ) ;
1691
1705
let path_penalty_msat = $next_hops_path_penalty_msat
1692
1706
. saturating_add( channel_penalty_msat) ;
1693
1707
let new_graph_node = RouteGraphNode {
@@ -1857,8 +1871,8 @@ where L::Target: Logger {
1857
1871
let candidate = CandidateRouteHop :: FirstHop { details } ;
1858
1872
let added = add_entry ! ( candidate, our_node_id, payee, 0 , path_value_msat,
1859
1873
0 , 0u64 , 0 , 0 ) . is_some ( ) ;
1860
- log_trace ! ( logger, "{} direct route to payee via SCID {}" ,
1861
- if added { "Added" } else { "Skipped" } , candidate . short_channel_id ( ) ) ;
1874
+ log_trace ! ( logger, "{} direct route to payee via {}" ,
1875
+ if added { "Added" } else { "Skipped" } , LoggedCandidateHop ( & candidate ) ) ;
1862
1876
}
1863
1877
} ) ) ;
1864
1878
@@ -2039,10 +2053,12 @@ where L::Target: Logger {
2039
2053
let mut features_set = false ;
2040
2054
if let Some ( first_channels) = first_hop_targets. get ( & ordered_hops. last ( ) . unwrap ( ) . 0 . node_id ) {
2041
2055
for details in first_channels {
2042
- if details. get_outbound_payment_scid ( ) . unwrap ( ) == ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . short_channel_id ( ) {
2043
- ordered_hops. last_mut ( ) . unwrap ( ) . 1 = details. counterparty . features . to_context ( ) ;
2044
- features_set = true ;
2045
- break ;
2056
+ if let Some ( scid) = ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . short_channel_id ( ) {
2057
+ if details. get_outbound_payment_scid ( ) . unwrap ( ) == scid {
2058
+ ordered_hops. last_mut ( ) . unwrap ( ) . 1 = details. counterparty . features . to_context ( ) ;
2059
+ features_set = true ;
2060
+ break ;
2061
+ }
2046
2062
}
2047
2063
}
2048
2064
}
@@ -2128,11 +2144,12 @@ where L::Target: Logger {
2128
2144
// If we weren't capped by hitting a liquidity limit on a channel in the path,
2129
2145
// we'll probably end up picking the same path again on the next iteration.
2130
2146
// Decrease the available liquidity of a hop in the middle of the path.
2131
- let victim_scid = payment_path. hops [ ( payment_path. hops . len ( ) ) / 2 ] . 0 . candidate . short_channel_id ( ) ;
2147
+ let victim_candidate = & payment_path. hops [ ( payment_path. hops . len ( ) ) / 2 ] . 0 . candidate ;
2132
2148
let exhausted = u64:: max_value ( ) ;
2133
- log_trace ! ( logger, "Disabling channel {} for future path building iterations to avoid duplicates." , victim_scid) ;
2134
- * used_liquidities. entry ( CandidateHopId :: Clear ( ( victim_scid, false ) ) ) . or_default ( ) = exhausted;
2135
- * used_liquidities. entry ( CandidateHopId :: Clear ( ( victim_scid, true ) ) ) . or_default ( ) = exhausted;
2149
+ log_trace ! ( logger, "Disabling route candidate {} for future path building iterations to
2150
+ avoid duplicates." , LoggedCandidateHop ( victim_candidate) ) ;
2151
+ * used_liquidities. entry ( victim_candidate. id ( false ) ) . or_default ( ) = exhausted;
2152
+ * used_liquidities. entry ( victim_candidate. id ( true ) ) . or_default ( ) = exhausted;
2136
2153
}
2137
2154
2138
2155
// Track the total amount all our collected paths allow to send so that we know
@@ -2262,9 +2279,9 @@ where L::Target: Logger {
2262
2279
selected_route. sort_unstable_by_key ( |path| {
2263
2280
let mut key = [ 0u64 ; MAX_PATH_LENGTH_ESTIMATE as usize ] ;
2264
2281
debug_assert ! ( path. hops. len( ) <= key. len( ) ) ;
2265
- for ( scid, key) in path. hops . iter ( ) . map ( |h| h. 0 . candidate . short_channel_id ( ) ) . zip ( key . iter_mut ( ) ) {
2266
- * key = scid ;
2267
- }
2282
+ for ( scid, key) in path. hops . iter ( ) . filter ( |h| h. 0 . candidate . short_channel_id ( ) . is_some ( ) )
2283
+ . map ( |h| h . 0 . candidate . short_channel_id ( ) . unwrap ( ) ) . zip ( key . iter_mut ( ) )
2284
+ { * key = scid ; }
2268
2285
key
2269
2286
} ) ;
2270
2287
for idx in 0 ..( selected_route. len ( ) - 1 ) {
@@ -2279,15 +2296,16 @@ where L::Target: Logger {
2279
2296
2280
2297
let mut selected_paths = Vec :: < Vec < Result < RouteHop , LightningError > > > :: new ( ) ;
2281
2298
for payment_path in selected_route {
2282
- let mut path = payment_path. hops . iter ( ) . map ( |( payment_hop, node_features) | {
2283
- Ok ( RouteHop {
2284
- pubkey : PublicKey :: from_slice ( payment_hop. node_id . as_slice ( ) ) . map_err ( |_| LightningError { err : format ! ( "Public key {:?} is invalid" , & payment_hop. node_id) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ?,
2285
- node_features : node_features. clone ( ) ,
2286
- short_channel_id : payment_hop. candidate . short_channel_id ( ) ,
2287
- channel_features : payment_hop. candidate . features ( ) ,
2288
- fee_msat : payment_hop. fee_msat ,
2289
- cltv_expiry_delta : payment_hop. candidate . cltv_expiry_delta ( ) ,
2290
- } )
2299
+ let mut path = payment_path. hops . iter ( ) . filter ( |( h, _) | h. candidate . short_channel_id ( ) . is_some ( ) )
2300
+ . map ( |( payment_hop, node_features) | {
2301
+ Ok ( RouteHop {
2302
+ pubkey : PublicKey :: from_slice ( payment_hop. node_id . as_slice ( ) ) . map_err ( |_| LightningError { err : format ! ( "Public key {:?} is invalid" , & payment_hop. node_id) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ?,
2303
+ node_features : node_features. clone ( ) ,
2304
+ short_channel_id : payment_hop. candidate . short_channel_id ( ) . unwrap ( ) ,
2305
+ channel_features : payment_hop. candidate . features ( ) ,
2306
+ fee_msat : payment_hop. fee_msat ,
2307
+ cltv_expiry_delta : payment_hop. candidate . cltv_expiry_delta ( ) ,
2308
+ } )
2291
2309
} ) . collect :: < Vec < _ > > ( ) ;
2292
2310
// Propagate the cltv_expiry_delta one hop backwards since the delta from the current hop is
2293
2311
// applicable for the previous hop.
0 commit comments