@@ -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
}
@@ -1893,7 +1902,7 @@ where L::Target: Logger {
1893
1902
effective_capacity,
1894
1903
} ;
1895
1904
let channel_penalty_msat = scid_opt. map_or( 0 ,
1896
- |scid| scorer. channel_penalty_msat( scid , & $src_node_id , & $dest_node_id ,
1905
+ |scid| scorer. channel_penalty_msat( $candidate ,
1897
1906
channel_usage, score_params) ) ;
1898
1907
let path_penalty_msat = $next_hops_path_penalty_msat
1899
1908
. saturating_add( channel_penalty_msat) ;
@@ -2007,7 +2016,7 @@ where L::Target: Logger {
2007
2016
if let Some ( first_channels) = first_hop_targets. get( & $node_id) {
2008
2017
for details in first_channels {
2009
2018
let candidate = CandidateRouteHop :: FirstHop { details, node_id: our_node_id } ;
2010
- add_entry!( candidate, our_node_id, $node_id, $fee_to_target_msat,
2019
+ add_entry!( & candidate, our_node_id, $node_id, $fee_to_target_msat,
2011
2020
$next_hops_value_contribution,
2012
2021
$next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat,
2013
2022
$next_hops_cltv_delta, $next_hops_path_length) ;
@@ -2031,7 +2040,7 @@ where L::Target: Logger {
2031
2040
info: directed_channel,
2032
2041
short_channel_id: * chan_id,
2033
2042
} ;
2034
- add_entry!( candidate, * source, $node_id,
2043
+ add_entry!( & candidate, * source, $node_id,
2035
2044
$fee_to_target_msat,
2036
2045
$next_hops_value_contribution,
2037
2046
$next_hops_path_htlc_minimum_msat,
@@ -2062,7 +2071,7 @@ where L::Target: Logger {
2062
2071
payee_node_id_opt. map ( |payee| first_hop_targets. get ( & payee) . map ( |first_channels| {
2063
2072
for details in first_channels {
2064
2073
let candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
2065
- let added = add_entry ! ( candidate, our_node_id, payee, 0 , path_value_msat,
2074
+ let added = add_entry ! ( & candidate, our_node_id, payee, 0 , path_value_msat,
2066
2075
0 , 0u64 , 0 , 0 ) . is_some ( ) ;
2067
2076
log_trace ! ( logger, "{} direct route to payee via {}" ,
2068
2077
if added { "Added" } else { "Skipped" } , LoggedCandidateHop ( & candidate) ) ;
@@ -2099,7 +2108,7 @@ where L::Target: Logger {
2099
2108
CandidateRouteHop :: OneHopBlinded { hint, hint_idx }
2100
2109
} else { CandidateRouteHop :: Blinded { hint, hint_idx } } ;
2101
2110
let mut path_contribution_msat = path_value_msat;
2102
- if let Some ( hop_used_msat) = add_entry ! ( candidate, intro_node_id, maybe_dummy_payee_node_id,
2111
+ if let Some ( hop_used_msat) = add_entry ! ( & candidate, intro_node_id, maybe_dummy_payee_node_id,
2103
2112
0 , path_contribution_msat, 0 , 0_u64 , 0 , 0 )
2104
2113
{
2105
2114
path_contribution_msat = hop_used_msat;
@@ -2113,7 +2122,7 @@ where L::Target: Logger {
2113
2122
Some ( fee) => fee,
2114
2123
None => continue
2115
2124
} ;
2116
- add_entry ! ( first_hop_candidate, our_node_id, intro_node_id, blinded_path_fee,
2125
+ add_entry ! ( & first_hop_candidate, our_node_id, intro_node_id, blinded_path_fee,
2117
2126
path_contribution_msat, candidate. htlc_minimum_msat( ) , 0_u64 ,
2118
2127
candidate. cltv_expiry_delta( ) ,
2119
2128
candidate. blinded_path( ) . map_or( 1 , |bp| bp. blinded_hops. len( ) as u8 ) ) ;
@@ -2156,7 +2165,7 @@ where L::Target: Logger {
2156
2165
} )
2157
2166
. unwrap_or_else ( || CandidateRouteHop :: PrivateHop { hint : hop, target_node_id : target } ) ;
2158
2167
2159
- if let Some ( hop_used_msat) = add_entry ! ( candidate, source, target,
2168
+ if let Some ( hop_used_msat) = add_entry ! ( & candidate, source, target,
2160
2169
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2161
2170
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
2162
2171
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length)
@@ -2178,7 +2187,7 @@ where L::Target: Logger {
2178
2187
effective_capacity : candidate. effective_capacity ( ) ,
2179
2188
} ;
2180
2189
let channel_penalty_msat = scorer. channel_penalty_msat (
2181
- hop . short_channel_id , & source , & target , channel_usage, score_params
2190
+ & candidate , channel_usage, score_params
2182
2191
) ;
2183
2192
aggregate_next_hops_path_penalty_msat = aggregate_next_hops_path_penalty_msat
2184
2193
. saturating_add ( channel_penalty_msat) ;
@@ -2195,7 +2204,7 @@ where L::Target: Logger {
2195
2204
recommended_value_msat, our_node_pubkey) ;
2196
2205
for details in first_channels {
2197
2206
let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id} ;
2198
- add_entry ! ( first_hop_candidate, our_node_id, NodeId :: from_pubkey( & prev_hop_id) ,
2207
+ add_entry ! ( & first_hop_candidate, our_node_id, NodeId :: from_pubkey( & prev_hop_id) ,
2199
2208
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2200
2209
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
2201
2210
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length) ;
@@ -2236,7 +2245,7 @@ where L::Target: Logger {
2236
2245
recommended_value_msat, our_node_pubkey) ;
2237
2246
for details in first_channels {
2238
2247
let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id} ;
2239
- add_entry ! ( first_hop_candidate, our_node_id,
2248
+ add_entry ! ( & first_hop_candidate, our_node_id,
2240
2249
NodeId :: from_pubkey( & hop. src_node_id) ,
2241
2250
aggregate_next_hops_fee_msat,
2242
2251
aggregate_path_contribution_msat,
@@ -2692,13 +2701,18 @@ fn build_route_from_hops_internal<L: Deref>(
2692
2701
2693
2702
impl ScoreLookUp for HopScorer {
2694
2703
type ScoreParams = ( ) ;
2695
- fn channel_penalty_msat ( & self , _short_channel_id : u64 , source : & NodeId , target : & NodeId ,
2704
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop ,
2696
2705
_usage : ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64
2697
2706
{
2707
+ let target = match candidate. target ( ) {
2708
+ Some ( target) => target,
2709
+ None => return 0 ,
2710
+ } ;
2711
+ let source = candidate. source ( ) ;
2698
2712
let mut cur_id = self . our_node_id ;
2699
2713
for i in 0 ..self . hop_ids . len ( ) {
2700
2714
if let Some ( next_id) = self . hop_ids [ i] {
2701
- if cur_id == * source && next_id == * target {
2715
+ if cur_id == source && next_id == target {
2702
2716
return 0 ;
2703
2717
}
2704
2718
cur_id = next_id;
@@ -2774,6 +2788,8 @@ mod tests {
2774
2788
2775
2789
use core:: convert:: TryInto ;
2776
2790
2791
+ use super :: CandidateRouteHop ;
2792
+
2777
2793
fn get_channel_details ( short_channel_id : Option < u64 > , node_id : PublicKey ,
2778
2794
features : InitFeatures , outbound_capacity_msat : u64 ) -> channelmanager:: ChannelDetails {
2779
2795
channelmanager:: ChannelDetails {
@@ -2869,7 +2885,7 @@ mod tests {
2869
2885
Arc :: clone ( & logger) , & scorer, & ( ) , & random_seed_bytes) {
2870
2886
assert_eq ! ( err, "First hop cannot have our_node_pubkey as a destination." ) ;
2871
2887
} else { panic ! ( ) ; }
2872
-
2888
+
2873
2889
let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
2874
2890
Arc :: clone ( & logger) , & scorer, & ( ) , & random_seed_bytes) . unwrap ( ) ;
2875
2891
assert_eq ! ( route. paths[ 0 ] . hops. len( ) , 2 ) ;
@@ -5950,7 +5966,11 @@ mod tests {
5950
5966
}
5951
5967
impl ScoreLookUp for BadChannelScorer {
5952
5968
type ScoreParams = ( ) ;
5953
- fn channel_penalty_msat ( & self , short_channel_id : u64 , _: & NodeId , _: & NodeId , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5969
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5970
+ let short_channel_id = match candidate. short_channel_id ( ) {
5971
+ Some ( id) => id,
5972
+ None => return 0 ,
5973
+ } ;
5954
5974
if short_channel_id == self . short_channel_id { u64:: max_value ( ) } else { 0 }
5955
5975
}
5956
5976
}
@@ -5966,8 +5986,12 @@ mod tests {
5966
5986
5967
5987
impl ScoreLookUp for BadNodeScorer {
5968
5988
type ScoreParams = ( ) ;
5969
- fn channel_penalty_msat ( & self , _: u64 , _: & NodeId , target : & NodeId , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5970
- if * target == self . node_id { u64:: max_value ( ) } else { 0 }
5989
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5990
+ let target = match candidate. target ( ) {
5991
+ Some ( target) => target,
5992
+ None => return 0 ,
5993
+ } ;
5994
+ if target == self . node_id { u64:: max_value ( ) } else { 0 }
5971
5995
}
5972
5996
}
5973
5997
@@ -6453,26 +6477,33 @@ mod tests {
6453
6477
} ;
6454
6478
scorer_params. set_manual_penalty ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) , 123 ) ;
6455
6479
scorer_params. set_manual_penalty ( & NodeId :: from_pubkey ( & nodes[ 4 ] ) , 456 ) ;
6456
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & NodeId :: from_pubkey( & nodes[ 3 ] ) , & NodeId :: from_pubkey( & nodes[ 4 ] ) , usage, & scorer_params) , 456 ) ;
6480
+ let network_graph = network_graph. read_only ( ) ;
6481
+ let channels = network_graph. channels ( ) ;
6482
+ let channel = channels. get ( & 5 ) . unwrap ( ) ;
6483
+ let info = channel. as_directed_from ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) . unwrap ( ) ;
6484
+ let candidate: CandidateRouteHop = CandidateRouteHop :: PublicHop {
6485
+ info : info. 0 ,
6486
+ short_channel_id : 5 ,
6487
+ } ;
6488
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & scorer_params) , 456 ) ;
6457
6489
6458
6490
// Then check we can get a normal route
6459
6491
let payment_params = PaymentParameters :: from_node_id ( nodes[ 10 ] , 42 ) ;
6460
6492
let route_params = RouteParameters :: from_payment_params_and_value (
6461
6493
payment_params, 100 ) ;
6462
- let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
6463
- Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6494
+ // let route = get_route(&our_id, &route_params, &network_graph.read_only(), None,
6495
+ // Arc::clone(&logger), &scorer, &scorer_params, &random_seed_bytes);
6496
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6464
6497
assert ! ( route. is_ok( ) ) ;
6465
6498
6466
6499
// Then check that we can't get a route if we ban an intermediate node.
6467
6500
scorer_params. add_banned ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) ;
6468
- let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
6469
- Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6501
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6470
6502
assert ! ( route. is_err( ) ) ;
6471
6503
6472
6504
// Finally make sure we can route again, when we remove the ban.
6473
6505
scorer_params. remove_banned ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) ;
6474
- let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
6475
- Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6506
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6476
6507
assert ! ( route. is_ok( ) ) ;
6477
6508
}
6478
6509
0 commit comments