@@ -171,17 +171,11 @@ impl InFlightHtlcs {
171
171
172
172
/// Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
173
173
pub fn process_path ( & mut self , path : & Path , payer_node_id : PublicKey ) {
174
- if path. len ( ) == 0 { return } ;
174
+ if path. hops . is_empty ( ) { return } ;
175
175
176
176
let mut cumulative_msat = 0 ;
177
177
if let Some ( tail) = & path. blinded_tail {
178
- cumulative_msat += tail. final_value_msat + tail. fee_msat ;
179
- self . 0
180
- . entry ( ( tail. intro_node_scid ,
181
- NodeId :: from_pubkey ( & path. hops . last ( ) . map_or ( payer_node_id, |hop| hop. pubkey ) ) <
182
- NodeId :: from_pubkey ( & tail. path . introduction_node_id ) ) )
183
- . and_modify ( |used_liquidity_msat| * used_liquidity_msat += cumulative_msat)
184
- . or_insert ( cumulative_msat) ;
178
+ cumulative_msat += tail. final_value_msat ;
185
179
}
186
180
187
181
// total_inflight_map needs to be direction-sensitive when keeping track of the HTLC value
@@ -304,7 +298,7 @@ pub struct Path {
304
298
impl Path {
305
299
/// The length of this path, including the hops of its [`Path::blinded_tail`], if any.
306
300
pub fn len ( & self ) -> usize {
307
- self . hops . len ( ) + self . blinded_tail . as_ref ( ) . map_or ( 0 , |tail| tail. path . blinded_hops . len ( ) )
301
+ self . hops . len ( ) + self . blinded_tail . as_ref ( ) . map_or ( 0 , |tail| tail. hops . len ( ) . saturating_sub ( 1 ) ) // Don't double count the intro node
308
302
}
309
303
}
310
304
@@ -2265,7 +2259,7 @@ fn build_route_from_hops_internal<L: Deref>(
2265
2259
2266
2260
#[ cfg( test) ]
2267
2261
mod tests {
2268
- use crate :: blinded_path:: BlindedPath ;
2262
+ use crate :: blinded_path:: { BlindedHop , BlindedPath } ;
2269
2263
use crate :: routing:: gossip:: { NetworkGraph , P2PGossipSync , NodeId , EffectiveCapacity } ;
2270
2264
use crate :: routing:: utxo:: UtxoResult ;
2271
2265
use crate :: routing:: router:: { get_route, build_route_from_hops_internal, add_random_cltv_offset, default_node_features,
@@ -5769,8 +5763,14 @@ mod tests {
5769
5763
5770
5764
#[ test]
5771
5765
fn blinded_path_inflight_processing ( ) {
5772
- // Ensure we'll score the channel that's inbound to a blinded path's introduction node.
5766
+ // Ensure we'll score the channel that's inbound to a blinded path's introduction node, and
5767
+ // account for the blinded tail's final amount_msat.
5773
5768
let mut inflight_htlcs = InFlightHtlcs :: new ( ) ;
5769
+ let blinded_path = BlindedPath {
5770
+ introduction_node_id : ln_test_utils:: pubkey ( 43 ) ,
5771
+ blinding_point : ln_test_utils:: pubkey ( 48 ) ,
5772
+ blinded_hops : vec ! [ BlindedHop { blinded_node_id: ln_test_utils:: pubkey( 49 ) , encrypted_payload: Vec :: new( ) } ] ,
5773
+ } ;
5774
5774
let path = Path {
5775
5775
hops : vec ! [ RouteHop {
5776
5776
pubkey: ln_test_utils:: pubkey( 42 ) ,
@@ -5779,16 +5779,19 @@ mod tests {
5779
5779
channel_features: ChannelFeatures :: empty( ) ,
5780
5780
fee_msat: 100 ,
5781
5781
cltv_expiry_delta: 0 ,
5782
- } ] ,
5783
- blinded_tail : Some ( BlindedTail {
5784
- path : BlindedPath {
5785
- introduction_node_id : ln_test_utils:: pubkey ( 43 ) ,
5786
- blinding_point : ln_test_utils:: pubkey ( 44 ) ,
5787
- blinded_hops : Vec :: new ( ) ,
5788
- } ,
5789
- intro_node_scid : 43 ,
5782
+ } ,
5783
+ RouteHop {
5784
+ pubkey: blinded_path. introduction_node_id,
5785
+ node_features: NodeFeatures :: empty( ) ,
5786
+ short_channel_id: 43 ,
5787
+ channel_features: ChannelFeatures :: empty( ) ,
5790
5788
fee_msat: 1 ,
5791
5789
cltv_expiry_delta: 0 ,
5790
+ } ] ,
5791
+ blinded_tail : Some ( BlindedTail {
5792
+ hops : blinded_path. blinded_hops ,
5793
+ blinding_point : blinded_path. blinding_point ,
5794
+ final_cltv_expiry_delta : 0 ,
5792
5795
final_value_msat : 200 ,
5793
5796
} ) ,
5794
5797
} ;
0 commit comments