@@ -1237,66 +1237,63 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
1237
1237
let amount_msat = path. final_value_msat ( ) ;
1238
1238
log_trace ! ( self . logger, "Scoring path through to SCID {} as having failed at {} msat" , short_channel_id, amount_msat) ;
1239
1239
let network_graph = self . network_graph . read_only ( ) ;
1240
- for ( hop_idx, ( pubkey , scid ) ) in path. node_id_scid_iter ( ) . enumerate ( ) {
1241
- let target = NodeId :: from_pubkey ( & pubkey) ;
1240
+ for ( hop_idx, hop ) in path. hops . iter ( ) . enumerate ( ) {
1241
+ let target = NodeId :: from_pubkey ( & hop . pubkey ) ;
1242
1242
let channel_directed_from_source = network_graph. channels ( )
1243
- . get ( & scid )
1243
+ . get ( & hop . short_channel_id )
1244
1244
. and_then ( |channel| channel. as_directed_to ( & target) ) ;
1245
1245
1246
- let at_failed_channel = scid == short_channel_id;
1246
+ let at_failed_channel = hop . short_channel_id == short_channel_id;
1247
1247
if at_failed_channel && hop_idx == 0 {
1248
- log_warn ! ( self . logger, "Payment failed at the first hop - we do not attempt to learn channel info in such cases as we can directly observe local state.\n \t Because we know the local state, we should generally not see failures here - this may be an indication that your channel peer on channel {} is broken and you may wish to close the channel." , scid ) ;
1248
+ log_warn ! ( self . logger, "Payment failed at the first hop - we do not attempt to learn channel info in such cases as we can directly observe local state.\n \t Because we know the local state, we should generally not see failures here - this may be an indication that your channel peer on channel {} is broken and you may wish to close the channel." , hop . short_channel_id ) ;
1249
1249
}
1250
1250
1251
1251
// Only score announced channels.
1252
1252
if let Some ( ( channel, source) ) = channel_directed_from_source {
1253
1253
let capacity_msat = channel. effective_capacity ( ) . as_msat ( ) ;
1254
1254
if at_failed_channel {
1255
1255
self . channel_liquidities
1256
- . entry ( scid )
1256
+ . entry ( hop . short_channel_id )
1257
1257
. or_insert_with ( ChannelLiquidity :: new)
1258
1258
. as_directed_mut ( source, & target, 0 , capacity_msat, & self . params )
1259
- . failed_at_channel ( amount_msat, format_args ! ( "SCID {}, towards {:?}" , scid , target) , & self . logger ) ;
1259
+ . failed_at_channel ( amount_msat, format_args ! ( "SCID {}, towards {:?}" , hop . short_channel_id , target) , & self . logger ) ;
1260
1260
} else {
1261
1261
self . channel_liquidities
1262
- . entry ( scid )
1262
+ . entry ( hop . short_channel_id )
1263
1263
. or_insert_with ( ChannelLiquidity :: new)
1264
1264
. as_directed_mut ( source, & target, 0 , capacity_msat, & self . params )
1265
- . failed_downstream ( amount_msat, format_args ! ( "SCID {}, towards {:?}" , scid , target) , & self . logger ) ;
1265
+ . failed_downstream ( amount_msat, format_args ! ( "SCID {}, towards {:?}" , hop . short_channel_id , target) , & self . logger ) ;
1266
1266
}
1267
1267
} else {
1268
1268
log_debug ! ( self . logger, "Not able to penalize channel with SCID {} as we do not have graph info for it (likely a route-hint last-hop)." ,
1269
- scid ) ;
1269
+ hop . short_channel_id ) ;
1270
1270
}
1271
1271
if at_failed_channel { break ; }
1272
1272
}
1273
1273
}
1274
1274
1275
1275
fn payment_path_successful ( & mut self , path : & Path ) {
1276
1276
let amount_msat = path. final_value_msat ( ) ;
1277
- let final_scid = path. blinded_tail . as_ref ( ) . map_or_else (
1278
- || path. hops . last ( ) . map_or ( 0 , |hop| hop. short_channel_id ) ,
1279
- |tail| tail. intro_node_scid ) ;
1280
1277
log_trace ! ( self . logger, "Scoring path through SCID {} as having succeeded at {} msat." ,
1281
- final_scid , amount_msat) ;
1278
+ path . hops . split_last ( ) . map ( | ( hop , _ ) | hop . short_channel_id ) . unwrap_or ( 0 ) , amount_msat) ;
1282
1279
let network_graph = self . network_graph . read_only ( ) ;
1283
- for ( pubkey , scid ) in path. node_id_scid_iter ( ) {
1284
- let target = NodeId :: from_pubkey ( & pubkey) ;
1280
+ for hop in & path. hops {
1281
+ let target = NodeId :: from_pubkey ( & hop . pubkey ) ;
1285
1282
let channel_directed_from_source = network_graph. channels ( )
1286
- . get ( & scid )
1283
+ . get ( & hop . short_channel_id )
1287
1284
. and_then ( |channel| channel. as_directed_to ( & target) ) ;
1288
1285
1289
1286
// Only score announced channels.
1290
1287
if let Some ( ( channel, source) ) = channel_directed_from_source {
1291
1288
let capacity_msat = channel. effective_capacity ( ) . as_msat ( ) ;
1292
1289
self . channel_liquidities
1293
- . entry ( scid )
1290
+ . entry ( hop . short_channel_id )
1294
1291
. or_insert_with ( ChannelLiquidity :: new)
1295
1292
. as_directed_mut ( source, & target, 0 , capacity_msat, & self . params )
1296
- . successful ( amount_msat, format_args ! ( "SCID {}, towards {:?}" , scid , target) , & self . logger ) ;
1293
+ . successful ( amount_msat, format_args ! ( "SCID {}, towards {:?}" , hop . short_channel_id , target) , & self . logger ) ;
1297
1294
} else {
1298
1295
log_debug ! ( self . logger, "Not able to learn for channel with SCID {} as we do not have graph info for it (likely a route-hint last-hop)." ,
1299
- scid ) ;
1296
+ hop . short_channel_id ) ;
1300
1297
}
1301
1298
}
1302
1299
}
@@ -1705,7 +1702,7 @@ impl<T: Time> Readable for ChannelLiquidity<T> {
1705
1702
#[ cfg( test) ]
1706
1703
mod tests {
1707
1704
use super :: { ChannelLiquidity , HistoricalBucketRangeTracker , ProbabilisticScoringParameters , ProbabilisticScorerUsingTime } ;
1708
- use crate :: blinded_path:: BlindedPath ;
1705
+ use crate :: blinded_path:: { BlindedHop , BlindedPath } ;
1709
1706
use crate :: util:: config:: UserConfig ;
1710
1707
use crate :: util:: time:: Time ;
1711
1708
use crate :: util:: time:: tests:: SinceEpoch ;
@@ -2876,8 +2873,8 @@ mod tests {
2876
2873
}
2877
2874
2878
2875
#[ test]
2879
- fn scores_intro_node_scid ( ) {
2880
- // Make sure we'll score the scid contained in the blinded portion of a path
2876
+ fn scores_with_blinded_path ( ) {
2877
+ // Make sure we'll account for a blinded path's final_value_msat in scoring
2881
2878
let logger = TestLogger :: new ( ) ;
2882
2879
let network_graph = network_graph ( & logger) ;
2883
2880
let params = ProbabilisticScoringParameters {
@@ -2896,18 +2893,19 @@ mod tests {
2896
2893
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 300 ) ;
2897
2894
2898
2895
let mut path = payment_path_for_amount ( 768 ) ;
2899
- let last_hop = path. hops . pop ( ) . unwrap ( ) ;
2900
- let _intro_node_hop = path. hops . pop ( ) . unwrap ( ) ;
2896
+ let recipient_hop = path. hops . pop ( ) . unwrap ( ) ;
2897
+ let blinded_path = BlindedPath {
2898
+ introduction_node_id : path. hops . last ( ) . as_ref ( ) . unwrap ( ) . pubkey ,
2899
+ blinding_point : test_utils:: pubkey ( 42 ) ,
2900
+ blinded_hops : vec ! [
2901
+ BlindedHop { blinded_node_id: test_utils:: pubkey( 44 ) , encrypted_payload: Vec :: new( ) }
2902
+ ] ,
2903
+ } ;
2901
2904
path. blinded_tail = Some ( BlindedTail {
2902
- path : BlindedPath {
2903
- introduction_node_id : target_pubkey ( ) ,
2904
- blinding_point : test_utils:: pubkey ( 42 ) ,
2905
- blinded_hops : Vec :: new ( ) ,
2906
- } ,
2907
- fee_msat : 2 ,
2908
- cltv_expiry_delta : last_hop. cltv_expiry_delta ,
2909
- final_value_msat : last_hop. fee_msat ,
2910
- intro_node_scid : 42 ,
2905
+ hops : blinded_path. blinded_hops ,
2906
+ blinding_point : blinded_path. blinding_point ,
2907
+ final_cltv_expiry_delta : recipient_hop. cltv_expiry_delta ,
2908
+ final_value_msat : recipient_hop. fee_msat ,
2911
2909
} ) ;
2912
2910
2913
2911
scorer. payment_path_failed ( & path, 42 ) ;
0 commit comments