@@ -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
}
@@ -1837,7 +1846,7 @@ where L::Target: Logger {
1837
1846
effective_capacity,
1838
1847
} ;
1839
1848
let channel_penalty_msat = scid_opt. map_or( 0 ,
1840
- |scid| scorer. channel_penalty_msat( scid , & $src_node_id , & $dest_node_id ,
1849
+ |scid| scorer. channel_penalty_msat( $candidate ,
1841
1850
channel_usage, score_params) ) ;
1842
1851
let path_penalty_msat = $next_hops_path_penalty_msat
1843
1852
. saturating_add( channel_penalty_msat) ;
@@ -1951,7 +1960,7 @@ where L::Target: Logger {
1951
1960
if let Some ( first_channels) = first_hop_targets. get( & $node_id) {
1952
1961
for details in first_channels {
1953
1962
let candidate = CandidateRouteHop :: FirstHop { details, node_id: our_node_id } ;
1954
- add_entry!( candidate, our_node_id, $node_id, $fee_to_target_msat,
1963
+ add_entry!( & candidate, our_node_id, $node_id, $fee_to_target_msat,
1955
1964
$next_hops_value_contribution,
1956
1965
$next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat,
1957
1966
$next_hops_cltv_delta, $next_hops_path_length) ;
@@ -1975,7 +1984,7 @@ where L::Target: Logger {
1975
1984
info: directed_channel,
1976
1985
short_channel_id: * chan_id,
1977
1986
} ;
1978
- add_entry!( candidate, * source, $node_id,
1987
+ add_entry!( & candidate, * source, $node_id,
1979
1988
$fee_to_target_msat,
1980
1989
$next_hops_value_contribution,
1981
1990
$next_hops_path_htlc_minimum_msat,
@@ -2006,7 +2015,7 @@ where L::Target: Logger {
2006
2015
payee_node_id_opt. map ( |payee| first_hop_targets. get ( & payee) . map ( |first_channels| {
2007
2016
for details in first_channels {
2008
2017
let candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
2009
- let added = add_entry ! ( candidate, our_node_id, payee, 0 , path_value_msat,
2018
+ let added = add_entry ! ( & candidate, our_node_id, payee, 0 , path_value_msat,
2010
2019
0 , 0u64 , 0 , 0 ) . is_some ( ) ;
2011
2020
log_trace ! ( logger, "{} direct route to payee via {}" ,
2012
2021
if added { "Added" } else { "Skipped" } , LoggedCandidateHop ( & candidate) ) ;
@@ -2043,7 +2052,7 @@ where L::Target: Logger {
2043
2052
CandidateRouteHop :: OneHopBlinded { hint, hint_idx }
2044
2053
} else { CandidateRouteHop :: Blinded { hint, hint_idx } } ;
2045
2054
let mut path_contribution_msat = path_value_msat;
2046
- if let Some ( hop_used_msat) = add_entry ! ( candidate, intro_node_id, maybe_dummy_payee_node_id,
2055
+ if let Some ( hop_used_msat) = add_entry ! ( & candidate, intro_node_id, maybe_dummy_payee_node_id,
2047
2056
0 , path_contribution_msat, 0 , 0_u64 , 0 , 0 )
2048
2057
{
2049
2058
path_contribution_msat = hop_used_msat;
@@ -2057,7 +2066,7 @@ where L::Target: Logger {
2057
2066
Some ( fee) => fee,
2058
2067
None => continue
2059
2068
} ;
2060
- add_entry ! ( first_hop_candidate, our_node_id, intro_node_id, blinded_path_fee,
2069
+ add_entry ! ( & first_hop_candidate, our_node_id, intro_node_id, blinded_path_fee,
2061
2070
path_contribution_msat, candidate. htlc_minimum_msat( ) , 0_u64 ,
2062
2071
candidate. cltv_expiry_delta( ) ,
2063
2072
candidate. blinded_path( ) . map_or( 1 , |bp| bp. blinded_hops. len( ) as u8 ) ) ;
@@ -2100,7 +2109,7 @@ where L::Target: Logger {
2100
2109
} )
2101
2110
. unwrap_or_else ( || CandidateRouteHop :: PrivateHop { hint : hop, target_node_id : target } ) ;
2102
2111
2103
- if let Some ( hop_used_msat) = add_entry ! ( candidate, source, target,
2112
+ if let Some ( hop_used_msat) = add_entry ! ( & candidate, source, target,
2104
2113
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2105
2114
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
2106
2115
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length)
@@ -2122,7 +2131,7 @@ where L::Target: Logger {
2122
2131
effective_capacity : candidate. effective_capacity ( ) ,
2123
2132
} ;
2124
2133
let channel_penalty_msat = scorer. channel_penalty_msat (
2125
- hop . short_channel_id , & source , & target , channel_usage, score_params
2134
+ & candidate , channel_usage, score_params
2126
2135
) ;
2127
2136
aggregate_next_hops_path_penalty_msat = aggregate_next_hops_path_penalty_msat
2128
2137
. saturating_add ( channel_penalty_msat) ;
@@ -2139,7 +2148,7 @@ where L::Target: Logger {
2139
2148
recommended_value_msat, our_node_pubkey) ;
2140
2149
for details in first_channels {
2141
2150
let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id} ;
2142
- add_entry ! ( first_hop_candidate, our_node_id, NodeId :: from_pubkey( & prev_hop_id) ,
2151
+ add_entry ! ( & first_hop_candidate, our_node_id, NodeId :: from_pubkey( & prev_hop_id) ,
2143
2152
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2144
2153
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
2145
2154
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length) ;
@@ -2180,7 +2189,7 @@ where L::Target: Logger {
2180
2189
recommended_value_msat, our_node_pubkey) ;
2181
2190
for details in first_channels {
2182
2191
let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id} ;
2183
- add_entry ! ( first_hop_candidate, our_node_id,
2192
+ add_entry ! ( & first_hop_candidate, our_node_id,
2184
2193
NodeId :: from_pubkey( & hop. src_node_id) ,
2185
2194
aggregate_next_hops_fee_msat,
2186
2195
aggregate_path_contribution_msat,
@@ -2638,13 +2647,18 @@ fn build_route_from_hops_internal<L: Deref>(
2638
2647
2639
2648
impl ScoreLookUp for HopScorer {
2640
2649
type ScoreParams = ( ) ;
2641
- fn channel_penalty_msat ( & self , _short_channel_id : u64 , source : & NodeId , target : & NodeId ,
2650
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop ,
2642
2651
_usage : ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64
2643
2652
{
2653
+ let target = match candidate. target ( ) {
2654
+ Some ( target) => target,
2655
+ None => return 0 ,
2656
+ } ;
2657
+ let source = candidate. source ( ) ;
2644
2658
let mut cur_id = self . our_node_id ;
2645
2659
for i in 0 ..self . hop_ids . len ( ) {
2646
2660
if let Some ( next_id) = self . hop_ids [ i] {
2647
- if cur_id == * source && next_id == * target {
2661
+ if cur_id == source && next_id == target {
2648
2662
return 0 ;
2649
2663
}
2650
2664
cur_id = next_id;
@@ -2721,6 +2735,8 @@ mod tests {
2721
2735
2722
2736
use core:: convert:: TryInto ;
2723
2737
2738
+ use super :: CandidateRouteHop ;
2739
+
2724
2740
fn get_channel_details ( short_channel_id : Option < u64 > , node_id : PublicKey ,
2725
2741
features : InitFeatures , outbound_capacity_msat : u64 ) -> channelmanager:: ChannelDetails {
2726
2742
channelmanager:: ChannelDetails {
@@ -5737,7 +5753,11 @@ mod tests {
5737
5753
}
5738
5754
impl ScoreLookUp for BadChannelScorer {
5739
5755
type ScoreParams = ( ) ;
5740
- fn channel_penalty_msat ( & self , short_channel_id : u64 , _: & NodeId , _: & NodeId , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5756
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5757
+ let short_channel_id = match candidate. short_channel_id ( ) {
5758
+ Some ( id) => id,
5759
+ None => return 0 ,
5760
+ } ;
5741
5761
if short_channel_id == self . short_channel_id { u64:: max_value ( ) } else { 0 }
5742
5762
}
5743
5763
}
@@ -5753,8 +5773,12 @@ mod tests {
5753
5773
5754
5774
impl ScoreLookUp for BadNodeScorer {
5755
5775
type ScoreParams = ( ) ;
5756
- fn channel_penalty_msat ( & self , _: u64 , _: & NodeId , target : & NodeId , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5757
- if * target == self . node_id { u64:: max_value ( ) } else { 0 }
5776
+ fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5777
+ let target = match candidate. target ( ) {
5778
+ Some ( target) => target,
5779
+ None => return 0 ,
5780
+ } ;
5781
+ if target == self . node_id { u64:: max_value ( ) } else { 0 }
5758
5782
}
5759
5783
}
5760
5784
@@ -6218,21 +6242,29 @@ mod tests {
6218
6242
} ;
6219
6243
scorer_params. set_manual_penalty ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) , 123 ) ;
6220
6244
scorer_params. set_manual_penalty ( & NodeId :: from_pubkey ( & nodes[ 4 ] ) , 456 ) ;
6221
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & NodeId :: from_pubkey( & nodes[ 3 ] ) , & NodeId :: from_pubkey( & nodes[ 4 ] ) , usage, & scorer_params) , 456 ) ;
6245
+ let network_graph = network_graph. read_only ( ) ;
6246
+ let channels = network_graph. channels ( ) ;
6247
+ let channel = channels. get ( & 5 ) . unwrap ( ) ;
6248
+ let info = channel. as_directed_from ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) . unwrap ( ) ;
6249
+ let candidate: CandidateRouteHop = CandidateRouteHop :: PublicHop {
6250
+ info : info. 0 ,
6251
+ short_channel_id : 5 ,
6252
+ } ;
6253
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & scorer_params) , 456 ) ;
6222
6254
6223
6255
// Then check we can get a normal route
6224
6256
let payment_params = PaymentParameters :: from_node_id ( nodes[ 10 ] , 42 ) ;
6225
- let route = get_route ( & our_id, & payment_params, & network_graph. read_only ( ) , None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6257
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6226
6258
assert ! ( route. is_ok( ) ) ;
6227
6259
6228
6260
// Then check that we can't get a route if we ban an intermediate node.
6229
6261
scorer_params. add_banned ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) ;
6230
- let route = get_route ( & our_id, & payment_params, & network_graph. read_only ( ) , None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6262
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6231
6263
assert ! ( route. is_err( ) ) ;
6232
6264
6233
6265
// Finally make sure we can route again, when we remove the ban.
6234
6266
scorer_params. remove_banned ( & NodeId :: from_pubkey ( & nodes[ 3 ] ) ) ;
6235
- let route = get_route ( & our_id, & payment_params, & network_graph. read_only ( ) , None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6267
+ let route = get_route ( & our_id, & payment_params, & network_graph, None , 100 , Arc :: clone ( & logger) , & scorer, & scorer_params, & random_seed_bytes) ;
6236
6268
assert ! ( route. is_ok( ) ) ;
6237
6269
}
6238
6270
0 commit comments