Skip to content

Commit 441f28e

Browse files
committed
Return InFlightHtlcs from create_inflight_map
1 parent 2f811f3 commit 441f28e

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

lightning-invoice/src/payment.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ where
455455
let inflight_htlcs = self.create_inflight_map();
456456
let route = self.router.find_route(
457457
&payer, &params, &payment_hash, Some(&first_hops.iter().collect::<Vec<_>>()),
458-
InFlightHtlcs::new(Some(inflight_htlcs))
458+
inflight_htlcs
459459
).map_err(|e| PaymentError::Routing(e))?;
460460

461461
match send_payment(&route) {
@@ -560,7 +560,7 @@ where
560560

561561
let route = self.router.find_route(
562562
&payer, &params, &payment_hash, Some(&first_hops.iter().collect::<Vec<_>>()),
563-
InFlightHtlcs::new(Some(inflight_htlcs))
563+
inflight_htlcs
564564
);
565565

566566
if route.is_err() {
@@ -619,7 +619,7 @@ where
619619
///
620620
/// This function should be called whenever we need information about currently used up liquidity
621621
/// across payments.
622-
fn create_inflight_map(&self) -> HashMap<(u64, bool), u64> {
622+
fn create_inflight_map(&self) -> InFlightHtlcs {
623623
let mut total_inflight_map: HashMap<(u64, bool), u64> = HashMap::new();
624624
// Make an attempt at finding existing payment information from `payment_cache`. If it
625625
// does not exist, it probably is a fresh payment and we can just return an empty
@@ -651,7 +651,7 @@ where
651651
}
652652
}
653653

654-
total_inflight_map
654+
InFlightHtlcs(total_inflight_map)
655655
}
656656
}
657657

@@ -747,11 +747,6 @@ where
747747
pub struct InFlightHtlcs(HashMap<(u64, bool), u64>);
748748

749749
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-
755750
/// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
756751
/// id.
757752
pub fn used_liquidity_msat(&self, source: &NodeId, target: &NodeId, channel_scid: u64) -> Option<&u64> {
@@ -1523,27 +1518,27 @@ mod tests {
15231518

15241519
let inflight_map = invoice_payer.create_inflight_map();
15251520
// 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);
15291524

15301525
// 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);
15331528

15341529
invoice_payer.handle_event(&Event::PaymentPathSuccessful {
15351530
payment_id, payment_hash, path: route.paths[0].clone()
15361531
});
15371532

15381533
let inflight_map = invoice_payer.create_inflight_map();
15391534

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);
15431538

15441539
// 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)
15471542
}
15481543

15491544
#[test]
@@ -1697,7 +1692,7 @@ mod tests {
16971692

16981693
// Only the second path, which failed with `MonitorUpdateFailed` should be added to our
16991694
// inflight map because retries are disabled.
1700-
assert_eq!(inflight_map.len(), 2);
1695+
assert_eq!(inflight_map.0.len(), 2);
17011696
}
17021697

17031698
#[test]
@@ -1727,7 +1722,7 @@ mod tests {
17271722
let inflight_map = invoice_payer.create_inflight_map();
17281723

17291724
// 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);
17311726
}
17321727

17331728
struct TestRouter {

0 commit comments

Comments
 (0)