@@ -455,7 +455,7 @@ where
455
455
let inflight_htlcs = self . create_inflight_map ( ) ;
456
456
let route = self . router . find_route (
457
457
& payer, & params, & payment_hash, Some ( & first_hops. iter ( ) . collect :: < Vec < _ > > ( ) ) ,
458
- InFlightHtlcs :: new ( Some ( inflight_htlcs) )
458
+ inflight_htlcs
459
459
) . map_err ( |e| PaymentError :: Routing ( e) ) ?;
460
460
461
461
match send_payment ( & route) {
@@ -560,7 +560,7 @@ where
560
560
561
561
let route = self . router . find_route (
562
562
& payer, & params, & payment_hash, Some ( & first_hops. iter ( ) . collect :: < Vec < _ > > ( ) ) ,
563
- InFlightHtlcs :: new ( Some ( inflight_htlcs) )
563
+ inflight_htlcs
564
564
) ;
565
565
566
566
if route. is_err ( ) {
@@ -619,7 +619,7 @@ where
619
619
///
620
620
/// This function should be called whenever we need information about currently used up liquidity
621
621
/// across payments.
622
- fn create_inflight_map ( & self ) -> HashMap < ( u64 , bool ) , u64 > {
622
+ fn create_inflight_map ( & self ) -> InFlightHtlcs {
623
623
let mut total_inflight_map: HashMap < ( u64 , bool ) , u64 > = HashMap :: new ( ) ;
624
624
// Make an attempt at finding existing payment information from `payment_cache`. If it
625
625
// does not exist, it probably is a fresh payment and we can just return an empty
@@ -651,7 +651,7 @@ where
651
651
}
652
652
}
653
653
654
- total_inflight_map
654
+ InFlightHtlcs ( total_inflight_map)
655
655
}
656
656
}
657
657
@@ -747,11 +747,6 @@ where
747
747
pub struct InFlightHtlcs ( HashMap < ( u64 , bool ) , u64 > ) ;
748
748
749
749
impl InFlightHtlcs {
750
- /// Creates a new instance with an optional map of liquidity information.
751
- pub fn new ( used_liquidity_msat : Option < HashMap < ( u64 , bool ) , u64 > > ) -> Self {
752
- InFlightHtlcs ( used_liquidity_msat. unwrap_or ( HashMap :: new ( ) ) )
753
- }
754
-
755
750
/// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
756
751
/// id.
757
752
pub fn used_liquidity_msat ( & self , source : & NodeId , target : & NodeId , channel_scid : u64 ) -> Option < & u64 > {
@@ -1523,27 +1518,27 @@ mod tests {
1523
1518
1524
1519
let inflight_map = invoice_payer. create_inflight_map ( ) ;
1525
1520
// First path check
1526
- assert_eq ! ( inflight_map. get( & ( 0 , false ) ) . unwrap( ) . clone( ) , 94 ) ;
1527
- assert_eq ! ( inflight_map. get( & ( 1 , true ) ) . unwrap( ) . clone( ) , 84 ) ;
1528
- assert_eq ! ( inflight_map. get( & ( 2 , false ) ) . unwrap( ) . clone( ) , 64 ) ;
1521
+ assert_eq ! ( inflight_map. 0 . get( & ( 0 , false ) ) . unwrap( ) . clone( ) , 94 ) ;
1522
+ assert_eq ! ( inflight_map. 0 . get( & ( 1 , true ) ) . unwrap( ) . clone( ) , 84 ) ;
1523
+ assert_eq ! ( inflight_map. 0 . get( & ( 2 , false ) ) . unwrap( ) . clone( ) , 64 ) ;
1529
1524
1530
1525
// Second path check
1531
- assert_eq ! ( inflight_map. get( & ( 3 , false ) ) . unwrap( ) . clone( ) , 74 ) ;
1532
- assert_eq ! ( inflight_map. get( & ( 4 , false ) ) . unwrap( ) . clone( ) , 64 ) ;
1526
+ assert_eq ! ( inflight_map. 0 . get( & ( 3 , false ) ) . unwrap( ) . clone( ) , 74 ) ;
1527
+ assert_eq ! ( inflight_map. 0 . get( & ( 4 , false ) ) . unwrap( ) . clone( ) , 64 ) ;
1533
1528
1534
1529
invoice_payer. handle_event ( & Event :: PaymentPathSuccessful {
1535
1530
payment_id, payment_hash, path : route. paths [ 0 ] . clone ( )
1536
1531
} ) ;
1537
1532
1538
1533
let inflight_map = invoice_payer. create_inflight_map ( ) ;
1539
1534
1540
- assert_eq ! ( inflight_map. get( & ( 0 , false ) ) , None ) ;
1541
- assert_eq ! ( inflight_map. get( & ( 1 , true ) ) , None ) ;
1542
- assert_eq ! ( inflight_map. get( & ( 2 , false ) ) , None ) ;
1535
+ assert_eq ! ( inflight_map. 0 . get( & ( 0 , false ) ) , None ) ;
1536
+ assert_eq ! ( inflight_map. 0 . get( & ( 1 , true ) ) , None ) ;
1537
+ assert_eq ! ( inflight_map. 0 . get( & ( 2 , false ) ) , None ) ;
1543
1538
1544
1539
// Second path should still be inflight
1545
- assert_eq ! ( inflight_map. get( & ( 3 , false ) ) . unwrap( ) . clone( ) , 74 ) ;
1546
- assert_eq ! ( inflight_map. get( & ( 4 , false ) ) . unwrap( ) . clone( ) , 64 )
1540
+ assert_eq ! ( inflight_map. 0 . get( & ( 3 , false ) ) . unwrap( ) . clone( ) , 74 ) ;
1541
+ assert_eq ! ( inflight_map. 0 . get( & ( 4 , false ) ) . unwrap( ) . clone( ) , 64 )
1547
1542
}
1548
1543
1549
1544
#[ test]
@@ -1697,7 +1692,7 @@ mod tests {
1697
1692
1698
1693
// Only the second path, which failed with `MonitorUpdateFailed` should be added to our
1699
1694
// inflight map because retries are disabled.
1700
- assert_eq ! ( inflight_map. len( ) , 2 ) ;
1695
+ assert_eq ! ( inflight_map. 0 . len( ) , 2 ) ;
1701
1696
}
1702
1697
1703
1698
#[ test]
@@ -1727,7 +1722,7 @@ mod tests {
1727
1722
let inflight_map = invoice_payer. create_inflight_map ( ) ;
1728
1723
1729
1724
// All paths successful, hence we check of the existence of all 5 hops.
1730
- assert_eq ! ( inflight_map. len( ) , 5 ) ;
1725
+ assert_eq ! ( inflight_map. 0 . len( ) , 5 ) ;
1731
1726
}
1732
1727
1733
1728
struct TestRouter {
0 commit comments