@@ -17,7 +17,7 @@ use bitcoin::secp256k1::PublicKey;
17
17
use ln:: channelmanager:: ChannelDetails ;
18
18
use ln:: features:: { ChannelFeatures , InvoiceFeatures , NodeFeatures } ;
19
19
use ln:: msgs:: { DecodeError , ErrorAction , LightningError , MAX_VALUE_MSAT } ;
20
- use routing:: scoring:: Score ;
20
+ use routing:: scoring:: { ChannelUsage , Score } ;
21
21
use routing:: network_graph:: { DirectedChannelInfoWithUpdate , EffectiveCapacity , NetworkGraph , ReadOnlyNetworkGraph , NodeId , RoutingFees } ;
22
22
use util:: ser:: { Writeable , Readable } ;
23
23
use util:: logger:: { Level , Logger } ;
@@ -1066,10 +1066,16 @@ where L::Target: Logger {
1066
1066
}
1067
1067
}
1068
1068
1069
- let available_liquidity_msat = htlc_maximum_msat - used_liquidity_msat;
1070
- let path_penalty_msat = $next_hops_path_penalty_msat. saturating_add(
1071
- scorer. channel_penalty_msat( short_channel_id, amount_to_transfer_over_msat,
1072
- available_liquidity_msat, & $src_node_id, & $dest_node_id) ) ;
1069
+ let channel_usage = ChannelUsage {
1070
+ amount_msat: amount_to_transfer_over_msat,
1071
+ inflight_htlc_msat: used_liquidity_msat,
1072
+ effective_capacity: $candidate. effective_capacity( ) ,
1073
+ } ;
1074
+ let channel_penalty_msat = scorer. channel_penalty_msat(
1075
+ short_channel_id, & $src_node_id, & $dest_node_id, channel_usage
1076
+ ) ;
1077
+ let path_penalty_msat = $next_hops_path_penalty_msat
1078
+ . saturating_add( channel_penalty_msat) ;
1073
1079
let new_graph_node = RouteGraphNode {
1074
1080
node_id: $src_node_id,
1075
1081
lowest_fee_to_peer_through_node: total_fee_msat,
@@ -1306,10 +1312,18 @@ where L::Target: Logger {
1306
1312
hop_used = false ;
1307
1313
}
1308
1314
1309
- let amount_to_transfer_msat = final_value_msat + aggregate_next_hops_fee_msat;
1310
- let capacity_msat = candidate. effective_capacity ( ) . as_msat ( ) ;
1315
+ let used_liquidity_msat = used_channel_liquidities
1316
+ . get ( & ( hop. short_channel_id , source < target) ) . copied ( ) . unwrap_or ( 0 ) ;
1317
+ let channel_usage = ChannelUsage {
1318
+ amount_msat : final_value_msat + aggregate_next_hops_fee_msat,
1319
+ inflight_htlc_msat : used_liquidity_msat,
1320
+ effective_capacity : candidate. effective_capacity ( ) ,
1321
+ } ;
1322
+ let channel_penalty_msat = scorer. channel_penalty_msat (
1323
+ hop. short_channel_id , & source, & target, channel_usage
1324
+ ) ;
1311
1325
aggregate_next_hops_path_penalty_msat = aggregate_next_hops_path_penalty_msat
1312
- . saturating_add ( scorer . channel_penalty_msat ( hop . short_channel_id , amount_to_transfer_msat , capacity_msat , & source , & target ) ) ;
1326
+ . saturating_add ( channel_penalty_msat) ;
1313
1327
1314
1328
aggregate_next_hops_cltv_delta = aggregate_next_hops_cltv_delta
1315
1329
. saturating_add ( hop. cltv_expiry_delta as u32 ) ;
@@ -1777,7 +1791,7 @@ mod tests {
1777
1791
use routing:: router:: { get_route, add_random_cltv_offset, default_node_features,
1778
1792
PaymentParameters , Route , RouteHint , RouteHintHop , RouteHop , RoutingFees ,
1779
1793
DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA , MAX_PATH_LENGTH_ESTIMATE } ;
1780
- use routing:: scoring:: Score ;
1794
+ use routing:: scoring:: { ChannelUsage , Score } ;
1781
1795
use chain:: transaction:: OutPoint ;
1782
1796
use chain:: keysinterface:: KeysInterface ;
1783
1797
use ln:: features:: { ChannelFeatures , InitFeatures , InvoiceFeatures , NodeFeatures } ;
@@ -5169,7 +5183,7 @@ mod tests {
5169
5183
fn write < W : Writer > ( & self , _w : & mut W ) -> Result < ( ) , :: io:: Error > { unimplemented ! ( ) }
5170
5184
}
5171
5185
impl Score for BadChannelScorer {
5172
- fn channel_penalty_msat ( & self , short_channel_id : u64 , _send_amt : u64 , _capacity_msat : u64 , _source : & NodeId , _target : & NodeId ) -> u64 {
5186
+ fn channel_penalty_msat ( & self , short_channel_id : u64 , _ : & NodeId , _ : & NodeId , _ : ChannelUsage ) -> u64 {
5173
5187
if short_channel_id == self . short_channel_id { u64:: max_value ( ) } else { 0 }
5174
5188
}
5175
5189
@@ -5187,7 +5201,7 @@ mod tests {
5187
5201
}
5188
5202
5189
5203
impl Score for BadNodeScorer {
5190
- fn channel_penalty_msat ( & self , _short_channel_id : u64 , _send_amt : u64 , _capacity_msat : u64 , _source : & NodeId , target : & NodeId ) -> u64 {
5204
+ fn channel_penalty_msat ( & self , _ : u64 , _ : & NodeId , target : & NodeId , _ : ChannelUsage ) -> u64 {
5191
5205
if * target == self . node_id { u64:: max_value ( ) } else { 0 }
5192
5206
}
5193
5207
0 commit comments