@@ -938,11 +938,11 @@ enum CandidateRouteHop<'a> {
938
938
}
939
939
940
940
impl < ' a > CandidateRouteHop < ' a > {
941
- fn short_channel_id ( & self ) -> u64 {
941
+ fn short_channel_id ( & self ) -> Option < u64 > {
942
942
match self {
943
- CandidateRouteHop :: FirstHop { details } => details. get_outbound_payment_scid ( ) . unwrap ( ) ,
944
- CandidateRouteHop :: PublicHop { short_channel_id, .. } => * short_channel_id,
945
- CandidateRouteHop :: PrivateHop { hint } => hint. short_channel_id ,
943
+ CandidateRouteHop :: FirstHop { details } => Some ( details. get_outbound_payment_scid ( ) . unwrap ( ) ) ,
944
+ CandidateRouteHop :: PublicHop { short_channel_id, .. } => Some ( * short_channel_id) ,
945
+ CandidateRouteHop :: PrivateHop { hint } => Some ( hint. short_channel_id ) ,
946
946
}
947
947
}
948
948
@@ -994,7 +994,9 @@ impl<'a> CandidateRouteHop<'a> {
994
994
}
995
995
}
996
996
fn id ( & self , channel_direction : bool /* src_node_id < target_node_id */ ) -> CandidateHopId {
997
- CandidateHopId :: Clear ( ( self . short_channel_id ( ) , channel_direction) )
997
+ match self {
998
+ _ => CandidateHopId :: Clear ( ( self . short_channel_id ( ) . unwrap ( ) , channel_direction) ) ,
999
+ }
998
1000
}
999
1001
}
1000
1002
@@ -1245,6 +1247,18 @@ impl fmt::Display for LoggedPayeePubkey {
1245
1247
}
1246
1248
}
1247
1249
1250
+ struct LoggedCandidateHop < ' a > ( & ' a CandidateRouteHop < ' a > ) ;
1251
+ impl < ' a > fmt:: Display for LoggedCandidateHop < ' a > {
1252
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1253
+ match self . 0 {
1254
+ _ => {
1255
+ "SCID " . fmt ( f) ?;
1256
+ self . 0 . short_channel_id ( ) . unwrap ( ) . fmt ( f)
1257
+ } ,
1258
+ }
1259
+ }
1260
+ }
1261
+
1248
1262
#[ inline]
1249
1263
fn sort_first_hop_channels (
1250
1264
channels : & mut Vec < & ChannelDetails > , used_liquidities : & HashMap < CandidateHopId , u64 > ,
@@ -1549,7 +1563,7 @@ where L::Target: Logger {
1549
1563
// - for regular channels at channel announcement (TODO)
1550
1564
// - for first and last hops early in get_route
1551
1565
if $src_node_id != $dest_node_id {
1552
- let short_channel_id = $candidate. short_channel_id( ) ;
1566
+ let scid_opt = $candidate. short_channel_id( ) ;
1553
1567
let effective_capacity = $candidate. effective_capacity( ) ;
1554
1568
let htlc_maximum_msat = max_htlc_from_capacity( effective_capacity, channel_saturation_pow_half) ;
1555
1569
@@ -1604,8 +1618,8 @@ where L::Target: Logger {
1604
1618
( amount_to_transfer_over_msat < $next_hops_path_htlc_minimum_msat &&
1605
1619
recommended_value_msat > $next_hops_path_htlc_minimum_msat) ) ;
1606
1620
1607
- let payment_failed_on_this_channel =
1608
- payment_params. previously_failed_channels. contains( & short_channel_id ) ;
1621
+ let payment_failed_on_this_channel = scid_opt . map_or ( false ,
1622
+ |scid| payment_params. previously_failed_channels. contains( & scid ) ) ;
1609
1623
1610
1624
// If HTLC minimum is larger than the amount we're going to transfer, we shouldn't
1611
1625
// bother considering this channel. If retrying with recommended_value_msat may
@@ -1674,9 +1688,9 @@ where L::Target: Logger {
1674
1688
inflight_htlc_msat: used_liquidity_msat,
1675
1689
effective_capacity,
1676
1690
} ;
1677
- let channel_penalty_msat = scorer . channel_penalty_msat (
1678
- short_channel_id , & $src_node_id, & $dest_node_id, channel_usage , score_params
1679
- ) ;
1691
+ let channel_penalty_msat = scid_opt . map_or ( 0 ,
1692
+ |scid| scorer . channel_penalty_msat ( scid , & $src_node_id, & $dest_node_id,
1693
+ channel_usage , score_params ) ) ;
1680
1694
let path_penalty_msat = $next_hops_path_penalty_msat
1681
1695
. saturating_add( channel_penalty_msat) ;
1682
1696
let new_graph_node = RouteGraphNode {
@@ -1846,8 +1860,8 @@ where L::Target: Logger {
1846
1860
let candidate = CandidateRouteHop :: FirstHop { details } ;
1847
1861
let added = add_entry ! ( candidate, our_node_id, payee, 0 , path_value_msat,
1848
1862
0 , 0u64 , 0 , 0 ) . is_some ( ) ;
1849
- log_trace ! ( logger, "{} direct route to payee via SCID {}" ,
1850
- if added { "Added" } else { "Skipped" } , candidate . short_channel_id ( ) ) ;
1863
+ log_trace ! ( logger, "{} direct route to payee via {}" ,
1864
+ if added { "Added" } else { "Skipped" } , LoggedCandidateHop ( & candidate ) ) ;
1851
1865
}
1852
1866
} ) ) ;
1853
1867
@@ -2028,10 +2042,12 @@ where L::Target: Logger {
2028
2042
let mut features_set = false ;
2029
2043
if let Some ( first_channels) = first_hop_targets. get ( & ordered_hops. last ( ) . unwrap ( ) . 0 . node_id ) {
2030
2044
for details in first_channels {
2031
- if details. get_outbound_payment_scid ( ) . unwrap ( ) == ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . short_channel_id ( ) {
2032
- ordered_hops. last_mut ( ) . unwrap ( ) . 1 = details. counterparty . features . to_context ( ) ;
2033
- features_set = true ;
2034
- break ;
2045
+ if let Some ( scid) = ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . short_channel_id ( ) {
2046
+ if details. get_outbound_payment_scid ( ) . unwrap ( ) == scid {
2047
+ ordered_hops. last_mut ( ) . unwrap ( ) . 1 = details. counterparty . features . to_context ( ) ;
2048
+ features_set = true ;
2049
+ break ;
2050
+ }
2035
2051
}
2036
2052
}
2037
2053
}
@@ -2117,11 +2133,12 @@ where L::Target: Logger {
2117
2133
// If we weren't capped by hitting a liquidity limit on a channel in the path,
2118
2134
// we'll probably end up picking the same path again on the next iteration.
2119
2135
// Decrease the available liquidity of a hop in the middle of the path.
2120
- let victim_scid = payment_path. hops [ ( payment_path. hops . len ( ) ) / 2 ] . 0 . candidate . short_channel_id ( ) ;
2136
+ let victim_candidate = & payment_path. hops [ ( payment_path. hops . len ( ) ) / 2 ] . 0 . candidate ;
2121
2137
let exhausted = u64:: max_value ( ) ;
2122
- log_trace ! ( logger, "Disabling channel {} for future path building iterations to avoid duplicates." , victim_scid) ;
2123
- * used_liquidities. entry ( CandidateHopId :: Clear ( ( victim_scid, false ) ) ) . or_default ( ) = exhausted;
2124
- * used_liquidities. entry ( CandidateHopId :: Clear ( ( victim_scid, true ) ) ) . or_default ( ) = exhausted;
2138
+ log_trace ! ( logger, "Disabling route candidate {} for future path building iterations to
2139
+ avoid duplicates." , LoggedCandidateHop ( victim_candidate) ) ;
2140
+ * used_liquidities. entry ( victim_candidate. id ( false ) ) . or_default ( ) = exhausted;
2141
+ * used_liquidities. entry ( victim_candidate. id ( true ) ) . or_default ( ) = exhausted;
2125
2142
}
2126
2143
2127
2144
// Track the total amount all our collected paths allow to send so that we know
@@ -2251,9 +2268,9 @@ where L::Target: Logger {
2251
2268
selected_route. sort_unstable_by_key ( |path| {
2252
2269
let mut key = [ 0u64 ; MAX_PATH_LENGTH_ESTIMATE as usize ] ;
2253
2270
debug_assert ! ( path. hops. len( ) <= key. len( ) ) ;
2254
- for ( scid, key) in path. hops . iter ( ) . map ( |h| h. 0 . candidate . short_channel_id ( ) ) . zip ( key . iter_mut ( ) ) {
2255
- * key = scid ;
2256
- }
2271
+ for ( scid, key) in path. hops . iter ( ) . filter ( |h| h. 0 . candidate . short_channel_id ( ) . is_some ( ) )
2272
+ . map ( |h| h . 0 . candidate . short_channel_id ( ) . unwrap ( ) ) . zip ( key . iter_mut ( ) )
2273
+ { * key = scid ; }
2257
2274
key
2258
2275
} ) ;
2259
2276
for idx in 0 ..( selected_route. len ( ) - 1 ) {
@@ -2268,15 +2285,16 @@ where L::Target: Logger {
2268
2285
2269
2286
let mut selected_paths = Vec :: < Vec < Result < RouteHop , LightningError > > > :: new ( ) ;
2270
2287
for payment_path in selected_route {
2271
- let mut path = payment_path. hops . iter ( ) . map ( |( payment_hop, node_features) | {
2272
- Ok ( RouteHop {
2273
- 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 ) } ) ?,
2274
- node_features : node_features. clone ( ) ,
2275
- short_channel_id : payment_hop. candidate . short_channel_id ( ) ,
2276
- channel_features : payment_hop. candidate . features ( ) ,
2277
- fee_msat : payment_hop. fee_msat ,
2278
- cltv_expiry_delta : payment_hop. candidate . cltv_expiry_delta ( ) ,
2279
- } )
2288
+ let mut path = payment_path. hops . iter ( ) . filter ( |( h, _) | h. candidate . short_channel_id ( ) . is_some ( ) )
2289
+ . map ( |( payment_hop, node_features) | {
2290
+ Ok ( RouteHop {
2291
+ 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 ) } ) ?,
2292
+ node_features : node_features. clone ( ) ,
2293
+ short_channel_id : payment_hop. candidate . short_channel_id ( ) . unwrap ( ) ,
2294
+ channel_features : payment_hop. candidate . features ( ) ,
2295
+ fee_msat : payment_hop. fee_msat ,
2296
+ cltv_expiry_delta : payment_hop. candidate . cltv_expiry_delta ( ) ,
2297
+ } )
2280
2298
} ) . collect :: < Vec < _ > > ( ) ;
2281
2299
// Propagate the cltv_expiry_delta one hop backwards since the delta from the current hop is
2282
2300
// applicable for the previous hop.
0 commit comments