@@ -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
}
@@ -1886,7 +1895,7 @@ where L::Target: Logger {
1886
1895
effective_capacity,
1887
1896
} ;
1888
1897
let channel_penalty_msat = scid_opt. map_or( 0 ,
1889
- |scid| scorer. channel_penalty_msat( scid , & $src_node_id , & $dest_node_id ,
1898
+ |scid| scorer. channel_penalty_msat( $candidate ,
1890
1899
channel_usage, score_params) ) ;
1891
1900
let path_penalty_msat = $next_hops_path_penalty_msat
1892
1901
. saturating_add( channel_penalty_msat) ;
@@ -2000,7 +2009,7 @@ where L::Target: Logger {
2000
2009
if let Some ( first_channels) = first_hop_targets. get( & $node_id) {
2001
2010
for details in first_channels {
2002
2011
let candidate = CandidateRouteHop :: FirstHop { details, node_id: our_node_id } ;
2003
- add_entry!( candidate, our_node_id, $node_id, $fee_to_target_msat,
2012
+ add_entry!( & candidate, our_node_id, $node_id, $fee_to_target_msat,
2004
2013
$next_hops_value_contribution,
2005
2014
$next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat,
2006
2015
$next_hops_cltv_delta, $next_hops_path_length) ;
@@ -2024,7 +2033,7 @@ where L::Target: Logger {
2024
2033
info: directed_channel,
2025
2034
short_channel_id: * chan_id,
2026
2035
} ;
2027
- add_entry!( candidate, * source, $node_id,
2036
+ add_entry!( & candidate, * source, $node_id,
2028
2037
$fee_to_target_msat,
2029
2038
$next_hops_value_contribution,
2030
2039
$next_hops_path_htlc_minimum_msat,
@@ -2055,7 +2064,7 @@ where L::Target: Logger {
2055
2064
payee_node_id_opt. map ( |payee| first_hop_targets. get ( & payee) . map ( |first_channels| {
2056
2065
for details in first_channels {
2057
2066
let candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
2058
- let added = add_entry ! ( candidate, our_node_id, payee, 0 , path_value_msat,
2067
+ let added = add_entry ! ( & candidate, our_node_id, payee, 0 , path_value_msat,
2059
2068
0 , 0u64 , 0 , 0 ) . is_some ( ) ;
2060
2069
log_trace ! ( logger, "{} direct route to payee via {}" ,
2061
2070
if added { "Added" } else { "Skipped" } , LoggedCandidateHop ( & candidate) ) ;
@@ -2092,7 +2101,7 @@ where L::Target: Logger {
2092
2101
CandidateRouteHop :: OneHopBlinded { hint, hint_idx }
2093
2102
} else { CandidateRouteHop :: Blinded { hint, hint_idx } } ;
2094
2103
let mut path_contribution_msat = path_value_msat;
2095
- if let Some ( hop_used_msat) = add_entry ! ( candidate, intro_node_id, maybe_dummy_payee_node_id,
2104
+ if let Some ( hop_used_msat) = add_entry ! ( & candidate, intro_node_id, maybe_dummy_payee_node_id,
2096
2105
0 , path_contribution_msat, 0 , 0_u64 , 0 , 0 )
2097
2106
{
2098
2107
path_contribution_msat = hop_used_msat;
@@ -2106,7 +2115,7 @@ where L::Target: Logger {
2106
2115
Some ( fee) => fee,
2107
2116
None => continue
2108
2117
} ;
2109
- add_entry ! ( first_hop_candidate, our_node_id, intro_node_id, blinded_path_fee,
2118
+ add_entry ! ( & first_hop_candidate, our_node_id, intro_node_id, blinded_path_fee,
2110
2119
path_contribution_msat, candidate. htlc_minimum_msat( ) , 0_u64 ,
2111
2120
candidate. cltv_expiry_delta( ) ,
2112
2121
candidate. blinded_path( ) . map_or( 1 , |bp| bp. blinded_hops. len( ) as u8 ) ) ;
@@ -2149,7 +2158,7 @@ where L::Target: Logger {
2149
2158
} )
2150
2159
. unwrap_or_else ( || CandidateRouteHop :: PrivateHop { hint : hop, target_node_id : target } ) ;
2151
2160
2152
- if let Some ( hop_used_msat) = add_entry ! ( candidate, source, target,
2161
+ if let Some ( hop_used_msat) = add_entry ! ( & candidate, source, target,
2153
2162
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2154
2163
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
2155
2164
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length)
@@ -2171,7 +2180,7 @@ where L::Target: Logger {
2171
2180
effective_capacity : candidate. effective_capacity ( ) ,
2172
2181
} ;
2173
2182
let channel_penalty_msat = scorer. channel_penalty_msat (
2174
- hop . short_channel_id , & source , & target , channel_usage, score_params
2183
+ & candidate , channel_usage, score_params
2175
2184
) ;
2176
2185
aggregate_next_hops_path_penalty_msat = aggregate_next_hops_path_penalty_msat
2177
2186
. saturating_add ( channel_penalty_msat) ;
@@ -2188,7 +2197,7 @@ where L::Target: Logger {
2188
2197
recommended_value_msat, our_node_pubkey) ;
2189
2198
for details in first_channels {
2190
2199
let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id} ;
2191
- add_entry ! ( first_hop_candidate, our_node_id, NodeId :: from_pubkey( & prev_hop_id) ,
2200
+ add_entry ! ( & first_hop_candidate, our_node_id, NodeId :: from_pubkey( & prev_hop_id) ,
2192
2201
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2193
2202
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
2194
2203
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length) ;
@@ -2229,7 +2238,7 @@ where L::Target: Logger {
2229
2238
recommended_value_msat, our_node_pubkey) ;
2230
2239
for details in first_channels {
2231
2240
let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id} ;
2232
- add_entry ! ( first_hop_candidate, our_node_id,
2241
+ add_entry ! ( & first_hop_candidate, our_node_id,
2233
2242
NodeId :: from_pubkey( & hop. src_node_id) ,
2234
2243
aggregate_next_hops_fee_msat,
2235
2244
aggregate_path_contribution_msat,
@@ -2685,13 +2694,18 @@ fn build_route_from_hops_internal<L: Deref>(
2685
2694
2686
2695
impl ScoreLookUp for HopScorer {
2687
2696
type ScoreParams = ( ) ;
2688
- fn channel_penalty_msat ( & self , _short_channel_id : u64 , source : & NodeId , target : & NodeId ,
2697
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop ,
2689
2698
_usage : ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64
2690
2699
{
2700
+ let target = match candidate. target ( ) {
2701
+ Some ( target) => target,
2702
+ None => return 0 ,
2703
+ } ;
2704
+ let source = candidate. source ( ) ;
2691
2705
let mut cur_id = self . our_node_id ;
2692
2706
for i in 0 ..self . hop_ids . len ( ) {
2693
2707
if let Some ( next_id) = self . hop_ids [ i] {
2694
- if cur_id == * source && next_id == * target {
2708
+ if cur_id == source && next_id == target {
2695
2709
return 0 ;
2696
2710
}
2697
2711
cur_id = next_id;
@@ -2767,6 +2781,8 @@ mod tests {
2767
2781
2768
2782
use core:: convert:: TryInto ;
2769
2783
2784
+ use super :: CandidateRouteHop ;
2785
+
2770
2786
fn get_channel_details ( short_channel_id : Option < u64 > , node_id : PublicKey ,
2771
2787
features : InitFeatures , outbound_capacity_msat : u64 ) -> channelmanager:: ChannelDetails {
2772
2788
channelmanager:: ChannelDetails {
@@ -2862,7 +2878,7 @@ mod tests {
2862
2878
Arc :: clone ( & logger) , & scorer, & ( ) , & random_seed_bytes) {
2863
2879
assert_eq ! ( err, "First hop cannot have our_node_pubkey as a destination." ) ;
2864
2880
} else { panic ! ( ) ; }
2865
-
2881
+
2866
2882
let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
2867
2883
Arc :: clone ( & logger) , & scorer, & ( ) , & random_seed_bytes) . unwrap ( ) ;
2868
2884
assert_eq ! ( route. paths[ 0 ] . hops. len( ) , 2 ) ;
@@ -5943,7 +5959,11 @@ mod tests {
5943
5959
}
5944
5960
impl ScoreLookUp for BadChannelScorer {
5945
5961
type ScoreParams = ( ) ;
5946
- fn channel_penalty_msat ( & self , short_channel_id : u64 , _: & NodeId , _: & NodeId , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5962
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5963
+ let short_channel_id = match candidate. short_channel_id ( ) {
5964
+ Some ( id) => id,
5965
+ None => return 0 ,
5966
+ } ;
5947
5967
if short_channel_id == self . short_channel_id { u64:: max_value ( ) } else { 0 }
5948
5968
}
5949
5969
}
@@ -5959,8 +5979,12 @@ mod tests {
5959
5979
5960
5980
impl ScoreLookUp for BadNodeScorer {
5961
5981
type ScoreParams = ( ) ;
5962
- fn channel_penalty_msat ( & self , _: u64 , _: & NodeId , target : & NodeId , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5963
- if * target == self . node_id { u64:: max_value ( ) } else { 0 }
5982
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5983
+ let target = match candidate. target ( ) {
5984
+ Some ( target) => target,
5985
+ None => return 0 ,
5986
+ } ;
5987
+ if target == self . node_id { u64:: max_value ( ) } else { 0 }
5964
5988
}
5965
5989
}
5966
5990
@@ -6446,26 +6470,33 @@ mod tests {
6446
6470
} ;
6447
6471
scorer_params. set_manual_penalty ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) , 123 ) ;
6448
6472
scorer_params. set_manual_penalty ( & NodeId :: from_pubkey ( & nodes[ 4 ] ) , 456 ) ;
6449
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & NodeId :: from_pubkey( & nodes[ 3 ] ) , & NodeId :: from_pubkey( & nodes[ 4 ] ) , usage, & scorer_params) , 456 ) ;
6473
+ let network_graph = network_graph. read_only ( ) ;
6474
+ let channels = network_graph. channels ( ) ;
6475
+ let channel = channels. get ( & 5 ) . unwrap ( ) ;
6476
+ let info = channel. as_directed_from ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) . unwrap ( ) ;
6477
+ let candidate: CandidateRouteHop = CandidateRouteHop :: PublicHop {
6478
+ info : info. 0 ,
6479
+ short_channel_id : 5 ,
6480
+ } ;
6481
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & scorer_params) , 456 ) ;
6450
6482
6451
6483
// Then check we can get a normal route
6452
6484
let payment_params = PaymentParameters :: from_node_id ( nodes[ 10 ] , 42 ) ;
6453
6485
let route_params = RouteParameters :: from_payment_params_and_value (
6454
6486
payment_params, 100 ) ;
6455
- let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
6456
- Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6487
+ // let route = get_route(&our_id, &route_params, &network_graph.read_only(), None,
6488
+ // Arc::clone(&logger), &scorer, &scorer_params, &random_seed_bytes);
6489
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6457
6490
assert ! ( route. is_ok( ) ) ;
6458
6491
6459
6492
// Then check that we can't get a route if we ban an intermediate node.
6460
6493
scorer_params. add_banned ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) ;
6461
- let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
6462
- Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6494
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6463
6495
assert ! ( route. is_err( ) ) ;
6464
6496
6465
6497
// Finally make sure we can route again, when we remove the ban.
6466
6498
scorer_params. remove_banned ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) ;
6467
- let route = get_route ( & our_id, & route_params, & network_graph. read_only ( ) , None ,
6468
- Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6499
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6469
6500
assert ! ( route. is_ok( ) ) ;
6470
6501
}
6471
6502
0 commit comments