@@ -134,18 +134,27 @@ impl<'a, SP: Sized, Sc: ScoreLookUp<ScoreParams = SP>, S: Deref<Target = Sc>> Wr
134
134
135
135
impl < ' a , SP : Sized , Sc : ' a + ScoreLookUp < ScoreParams = SP > , S : Deref < Target = Sc > > ScoreLookUp for ScorerAccountingForInFlightHtlcs < ' a , SP , Sc , S > {
136
136
type ScoreParams = Sc :: ScoreParams ;
137
- fn channel_penalty_msat ( & self , short_channel_id : u64 , source : & NodeId , target : & NodeId , usage : ChannelUsage , score_params : & Self :: ScoreParams ) -> u64 {
137
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , usage : ChannelUsage , score_params : & Self :: ScoreParams ) -> u64 {
138
+ let target = match candidate. target ( ) {
139
+ Some ( target) => target,
140
+ None => return 0 ,
141
+ } ;
142
+ let short_channel_id = match candidate. short_channel_id ( ) {
143
+ Some ( short_channel_id) => short_channel_id,
144
+ None => return 0 ,
145
+ } ;
146
+ let source = candidate. source ( ) ;
138
147
if let Some ( used_liquidity) = self . inflight_htlcs . used_liquidity_msat (
139
- source, target, short_channel_id
148
+ & source, & target, short_channel_id
140
149
) {
141
150
let usage = ChannelUsage {
142
151
inflight_htlc_msat : usage. inflight_htlc_msat + used_liquidity,
143
152
..usage
144
153
} ;
145
154
146
- self . scorer . channel_penalty_msat ( short_channel_id , source , target , usage, score_params)
155
+ self . scorer . channel_penalty_msat ( candidate , usage, score_params)
147
156
} else {
148
- self . scorer . channel_penalty_msat ( short_channel_id , source , target , usage, score_params)
157
+ self . scorer . channel_penalty_msat ( candidate , usage, score_params)
149
158
}
150
159
}
151
160
}
@@ -1903,7 +1912,7 @@ where L::Target: Logger {
1903
1912
effective_capacity,
1904
1913
} ;
1905
1914
let channel_penalty_msat = scid_opt. map_or( 0 ,
1906
- |scid| scorer. channel_penalty_msat( scid , & $src_node_id , & $dest_node_id ,
1915
+ |scid| scorer. channel_penalty_msat( $candidate ,
1907
1916
channel_usage, score_params) ) ;
1908
1917
let path_penalty_msat = $next_hops_path_penalty_msat
1909
1918
. saturating_add( channel_penalty_msat) ;
@@ -2017,7 +2026,7 @@ where L::Target: Logger {
2017
2026
if let Some ( first_channels) = first_hop_targets. get( & $node_id) {
2018
2027
for details in first_channels {
2019
2028
let candidate = CandidateRouteHop :: FirstHop { details, node_id: our_node_id } ;
2020
- add_entry!( candidate, our_node_id, $node_id, $fee_to_target_msat,
2029
+ add_entry!( & candidate, our_node_id, $node_id, $fee_to_target_msat,
2021
2030
$next_hops_value_contribution,
2022
2031
$next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat,
2023
2032
$next_hops_cltv_delta, $next_hops_path_length) ;
@@ -2041,7 +2050,7 @@ where L::Target: Logger {
2041
2050
info: directed_channel,
2042
2051
short_channel_id: * chan_id,
2043
2052
} ;
2044
- add_entry!( candidate, * source, $node_id,
2053
+ add_entry!( & candidate, * source, $node_id,
2045
2054
$fee_to_target_msat,
2046
2055
$next_hops_value_contribution,
2047
2056
$next_hops_path_htlc_minimum_msat,
@@ -2072,7 +2081,7 @@ where L::Target: Logger {
2072
2081
payee_node_id_opt. map ( |payee| first_hop_targets. get ( & payee) . map ( |first_channels| {
2073
2082
for details in first_channels {
2074
2083
let candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
2075
- let added = add_entry ! ( candidate, our_node_id, payee, 0 , path_value_msat,
2084
+ let added = add_entry ! ( & candidate, our_node_id, payee, 0 , path_value_msat,
2076
2085
0 , 0u64 , 0 , 0 ) . is_some ( ) ;
2077
2086
log_trace ! ( logger, "{} direct route to payee via {}" ,
2078
2087
if added { "Added" } else { "Skipped" } , LoggedCandidateHop ( & candidate) ) ;
@@ -2109,7 +2118,7 @@ where L::Target: Logger {
2109
2118
CandidateRouteHop :: OneHopBlinded { hint, hint_idx }
2110
2119
} else { CandidateRouteHop :: Blinded { hint, hint_idx } } ;
2111
2120
let mut path_contribution_msat = path_value_msat;
2112
- if let Some ( hop_used_msat) = add_entry ! ( candidate, intro_node_id, maybe_dummy_payee_node_id,
2121
+ if let Some ( hop_used_msat) = add_entry ! ( & candidate, intro_node_id, maybe_dummy_payee_node_id,
2113
2122
0 , path_contribution_msat, 0 , 0_u64 , 0 , 0 )
2114
2123
{
2115
2124
path_contribution_msat = hop_used_msat;
@@ -2123,7 +2132,7 @@ where L::Target: Logger {
2123
2132
Some ( fee) => fee,
2124
2133
None => continue
2125
2134
} ;
2126
- add_entry ! ( first_hop_candidate, our_node_id, intro_node_id, blinded_path_fee,
2135
+ add_entry ! ( & first_hop_candidate, our_node_id, intro_node_id, blinded_path_fee,
2127
2136
path_contribution_msat, candidate. htlc_minimum_msat( ) , 0_u64 ,
2128
2137
candidate. cltv_expiry_delta( ) ,
2129
2138
candidate. blinded_path( ) . map_or( 1 , |bp| bp. blinded_hops. len( ) as u8 ) ) ;
@@ -2166,7 +2175,7 @@ where L::Target: Logger {
2166
2175
} )
2167
2176
. unwrap_or_else ( || CandidateRouteHop :: PrivateHop { hint : hop, target_node_id : target } ) ;
2168
2177
2169
- if let Some ( hop_used_msat) = add_entry ! ( candidate, source, target,
2178
+ if let Some ( hop_used_msat) = add_entry ! ( & candidate, source, target,
2170
2179
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2171
2180
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
2172
2181
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length)
@@ -2188,7 +2197,7 @@ where L::Target: Logger {
2188
2197
effective_capacity : candidate. effective_capacity ( ) ,
2189
2198
} ;
2190
2199
let channel_penalty_msat = scorer. channel_penalty_msat (
2191
- hop . short_channel_id , & source , & target , channel_usage, score_params
2200
+ & candidate , channel_usage, score_params
2192
2201
) ;
2193
2202
aggregate_next_hops_path_penalty_msat = aggregate_next_hops_path_penalty_msat
2194
2203
. saturating_add ( channel_penalty_msat) ;
@@ -2205,7 +2214,7 @@ where L::Target: Logger {
2205
2214
recommended_value_msat, our_node_pubkey) ;
2206
2215
for details in first_channels {
2207
2216
let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id} ;
2208
- add_entry ! ( first_hop_candidate, our_node_id, NodeId :: from_pubkey( & prev_hop_id) ,
2217
+ add_entry ! ( & first_hop_candidate, our_node_id, NodeId :: from_pubkey( & prev_hop_id) ,
2209
2218
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2210
2219
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
2211
2220
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length) ;
@@ -2246,7 +2255,7 @@ where L::Target: Logger {
2246
2255
recommended_value_msat, our_node_pubkey) ;
2247
2256
for details in first_channels {
2248
2257
let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id} ;
2249
- add_entry ! ( first_hop_candidate, our_node_id,
2258
+ add_entry ! ( & first_hop_candidate, our_node_id,
2250
2259
NodeId :: from_pubkey( & hop. src_node_id) ,
2251
2260
aggregate_next_hops_fee_msat,
2252
2261
aggregate_path_contribution_msat,
@@ -2723,13 +2732,18 @@ fn build_route_from_hops_internal<L: Deref>(
2723
2732
2724
2733
impl ScoreLookUp for HopScorer {
2725
2734
type ScoreParams = ( ) ;
2726
- fn channel_penalty_msat ( & self , _short_channel_id : u64 , source : & NodeId , target : & NodeId ,
2735
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop ,
2727
2736
_usage : ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64
2728
2737
{
2738
+ let target = match candidate. target ( ) {
2739
+ Some ( target) => target,
2740
+ None => return 0 ,
2741
+ } ;
2742
+ let source = candidate. source ( ) ;
2729
2743
let mut cur_id = self . our_node_id ;
2730
2744
for i in 0 ..self . hop_ids . len ( ) {
2731
2745
if let Some ( next_id) = self . hop_ids [ i] {
2732
- if cur_id == * source && next_id == * target {
2746
+ if cur_id == source && next_id == target {
2733
2747
return 0 ;
2734
2748
}
2735
2749
cur_id = next_id;
@@ -2805,6 +2819,8 @@ mod tests {
2805
2819
2806
2820
use core:: convert:: TryInto ;
2807
2821
2822
+ use super :: CandidateRouteHop ;
2823
+
2808
2824
fn get_channel_details ( short_channel_id : Option < u64 > , node_id : PublicKey ,
2809
2825
features : InitFeatures , outbound_capacity_msat : u64 ) -> channelmanager:: ChannelDetails {
2810
2826
channelmanager:: ChannelDetails {
@@ -2900,7 +2916,7 @@ mod tests {
2900
2916
Arc :: clone ( & logger) , & scorer, & ( ) , & random_seed_bytes) {
2901
2917
assert_eq ! ( err, "First hop cannot have our_node_pubkey as a destination." ) ;
2902
2918
} else { panic ! ( ) ; }
2903
-
2919
+
2904
2920
let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
2905
2921
Arc :: clone ( & logger) , & scorer, & ( ) , & random_seed_bytes) . unwrap ( ) ;
2906
2922
assert_eq ! ( route. paths[ 0 ] . hops. len( ) , 2 ) ;
@@ -5981,7 +5997,11 @@ mod tests {
5981
5997
}
5982
5998
impl ScoreLookUp for BadChannelScorer {
5983
5999
type ScoreParams = ( ) ;
5984
- fn channel_penalty_msat ( & self , short_channel_id : u64 , _: & NodeId , _: & NodeId , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
6000
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
6001
+ let short_channel_id = match candidate. short_channel_id ( ) {
6002
+ Some ( id) => id,
6003
+ None => return 0 ,
6004
+ } ;
5985
6005
if short_channel_id == self . short_channel_id { u64:: max_value ( ) } else { 0 }
5986
6006
}
5987
6007
}
@@ -5997,8 +6017,12 @@ mod tests {
5997
6017
5998
6018
impl ScoreLookUp for BadNodeScorer {
5999
6019
type ScoreParams = ( ) ;
6000
- fn channel_penalty_msat ( & self , _: u64 , _: & NodeId , target : & NodeId , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
6001
- if * target == self . node_id { u64:: max_value ( ) } else { 0 }
6020
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
6021
+ let target = match candidate. target ( ) {
6022
+ Some ( target) => target,
6023
+ None => return 0 ,
6024
+ } ;
6025
+ if target == self . node_id { u64:: max_value ( ) } else { 0 }
6002
6026
}
6003
6027
}
6004
6028
@@ -6484,26 +6508,33 @@ mod tests {
6484
6508
} ;
6485
6509
scorer_params. set_manual_penalty ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) , 123 ) ;
6486
6510
scorer_params. set_manual_penalty ( & NodeId :: from_pubkey ( & nodes[ 4 ] ) , 456 ) ;
6487
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & NodeId :: from_pubkey( & nodes[ 3 ] ) , & NodeId :: from_pubkey( & nodes[ 4 ] ) , usage, & scorer_params) , 456 ) ;
6511
+ let network_graph = network_graph. read_only ( ) ;
6512
+ let channels = network_graph. channels ( ) ;
6513
+ let channel = channels. get ( & 5 ) . unwrap ( ) ;
6514
+ let info = channel. as_directed_from ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) . unwrap ( ) ;
6515
+ let candidate: CandidateRouteHop = CandidateRouteHop :: PublicHop {
6516
+ info : info. 0 ,
6517
+ short_channel_id : 5 ,
6518
+ } ;
6519
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & scorer_params) , 456 ) ;
6488
6520
6489
6521
// Then check we can get a normal route
6490
6522
let payment_params = PaymentParameters :: from_node_id ( nodes[ 10 ] , 42 ) ;
6491
6523
let route_params = RouteParameters :: from_payment_params_and_value (
6492
6524
payment_params, 100 ) ;
6493
- let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
6494
- Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6525
+ // let route = get_route(&our_id, &route_params, &network_graph.read_only(), None,
6526
+ // Arc::clone(&logger), &scorer, &scorer_params, &random_seed_bytes);
6527
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6495
6528
assert ! ( route. is_ok( ) ) ;
6496
6529
6497
6530
// Then check that we can't get a route if we ban an intermediate node.
6498
6531
scorer_params. add_banned ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) ;
6499
- let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
6500
- Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6532
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6501
6533
assert ! ( route. is_err( ) ) ;
6502
6534
6503
6535
// Finally make sure we can route again, when we remove the ban.
6504
6536
scorer_params. remove_banned ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) ;
6505
- let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
6506
- Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6537
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6507
6538
assert ! ( route. is_ok( ) ) ;
6508
6539
}
6509
6540
0 commit comments