@@ -350,23 +350,25 @@ where
350
350
/// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
351
351
/// in-use channel liquidity.
352
352
#[ derive( Clone ) ]
353
- pub struct InFlightHtlcs (
353
+ pub struct InFlightHtlcs {
354
354
// A map with liquidity value (in msat) keyed by a short channel id and the direction the HTLC
355
355
// is traveling in. The direction boolean is determined by checking if the HTLC source's public
356
356
// key is less than its destination. See `InFlightHtlcs::used_liquidity_msat` for more
357
357
// details.
358
- HashMap < ( u64 , bool ) , u64 > ,
359
- ) ;
358
+ unblinded_hops : HashMap < ( u64 , bool ) , u64 > ,
359
+ }
360
360
361
361
impl InFlightHtlcs {
362
362
/// Constructs an empty `InFlightHtlcs`.
363
- #[ rustfmt:: skip]
364
- pub fn new ( ) -> Self { InFlightHtlcs ( new_hash_map ( ) ) }
363
+ pub fn new ( ) -> Self {
364
+ InFlightHtlcs { unblinded_hops : new_hash_map ( ) }
365
+ }
365
366
366
367
/// Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
367
- #[ rustfmt:: skip]
368
368
pub fn process_path ( & mut self , path : & Path , payer_node_id : PublicKey ) {
369
- if path. hops . is_empty ( ) { return } ;
369
+ if path. hops . is_empty ( ) {
370
+ return ;
371
+ }
370
372
371
373
let mut cumulative_msat = 0 ;
372
374
if let Some ( tail) = & path. blinded_tail {
@@ -378,17 +380,17 @@ impl InFlightHtlcs {
378
380
// the router excludes the payer node. In the following lines, the payer's information is
379
381
// hardcoded with an inflight value of 0 so that we can correctly represent the first hop
380
382
// in our sliding window of two.
381
- let reversed_hops_with_payer = path. hops . iter ( ) . rev ( ) . skip ( 1 )
382
- . map ( |hop| hop. pubkey )
383
- . chain ( core:: iter:: once ( payer_node_id) ) ;
383
+ let reversed_hops = path. hops . iter ( ) . rev ( ) . skip ( 1 ) . map ( |hop| hop. pubkey ) ;
384
+ let reversed_hops_with_payer = reversed_hops. chain ( core:: iter:: once ( payer_node_id) ) ;
384
385
385
386
// Taking the reversed vector from above, we zip it with just the reversed hops list to
386
387
// work "backwards" of the given path, since the last hop's `fee_msat` actually represents
387
388
// the total amount sent.
388
389
for ( next_hop, prev_hop) in path. hops . iter ( ) . rev ( ) . zip ( reversed_hops_with_payer) {
389
390
cumulative_msat += next_hop. fee_msat ;
390
- self . 0
391
- . entry ( ( next_hop. short_channel_id , NodeId :: from_pubkey ( & prev_hop) < NodeId :: from_pubkey ( & next_hop. pubkey ) ) )
391
+ let direction = NodeId :: from_pubkey ( & prev_hop) < NodeId :: from_pubkey ( & next_hop. pubkey ) ;
392
+ self . unblinded_hops
393
+ . entry ( ( next_hop. short_channel_id , direction) )
392
394
. and_modify ( |used_liquidity_msat| * used_liquidity_msat += cumulative_msat)
393
395
. or_insert ( cumulative_msat) ;
394
396
}
@@ -399,7 +401,7 @@ impl InFlightHtlcs {
399
401
pub fn add_inflight_htlc (
400
402
& mut self , source : & NodeId , target : & NodeId , channel_scid : u64 , used_msat : u64 ,
401
403
) {
402
- self . 0
404
+ self . unblinded_hops
403
405
. entry ( ( channel_scid, source < target) )
404
406
. and_modify ( |used_liquidity_msat| * used_liquidity_msat += used_msat)
405
407
. or_insert ( used_msat) ;
@@ -410,19 +412,20 @@ impl InFlightHtlcs {
410
412
pub fn used_liquidity_msat (
411
413
& self , source : & NodeId , target : & NodeId , channel_scid : u64 ,
412
414
) -> Option < u64 > {
413
- self . 0 . get ( & ( channel_scid, source < target) ) . map ( |v| * v)
415
+ self . unblinded_hops . get ( & ( channel_scid, source < target) ) . map ( |v| * v)
414
416
}
415
417
}
416
418
417
419
impl Writeable for InFlightHtlcs {
418
- #[ rustfmt:: skip]
419
- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > { self . 0 . write ( writer) }
420
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
421
+ self . unblinded_hops . write ( writer)
422
+ }
420
423
}
421
424
422
425
impl Readable for InFlightHtlcs {
423
426
fn read < R : io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
424
- let infight_map : HashMap < ( u64 , bool ) , u64 > = Readable :: read ( reader) ?;
425
- Ok ( Self ( infight_map ) )
427
+ let unblinded_hops : HashMap < ( u64 , bool ) , u64 > = Readable :: read ( reader) ?;
428
+ Ok ( Self { unblinded_hops } )
426
429
}
427
430
}
428
431
@@ -8002,8 +8005,8 @@ mod tests {
8002
8005
} ) ,
8003
8006
} ;
8004
8007
inflight_htlcs. process_path ( & path, ln_test_utils:: pubkey ( 44 ) ) ;
8005
- assert_eq ! ( * inflight_htlcs. 0 . get( & ( 42 , true ) ) . unwrap( ) , 301 ) ;
8006
- assert_eq ! ( * inflight_htlcs. 0 . get( & ( 43 , false ) ) . unwrap( ) , 201 ) ;
8008
+ assert_eq ! ( * inflight_htlcs. unblinded_hops . get( & ( 42 , true ) ) . unwrap( ) , 301 ) ;
8009
+ assert_eq ! ( * inflight_htlcs. unblinded_hops . get( & ( 43 , false ) ) . unwrap( ) , 201 ) ;
8007
8010
}
8008
8011
8009
8012
#[ test]
0 commit comments