Skip to content

Commit 673d36f

Browse files
committed
Add functional test for holding cell HTLCs
1 parent d6d7e37 commit 673d36f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10522,3 +10522,42 @@ fn test_trivial_inflight_htlc_tracking() {
1052210522
assert_eq!(used_liquidity, Some(500000));
1052310523
}
1052410524
}
10525+
10526+
#[test]
10527+
fn test_holding_cell_inflight_htlcs() {
10528+
let chanmon_cfgs = create_chanmon_cfgs(2);
10529+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
10530+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
10531+
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
10532+
let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features()).2;
10533+
10534+
let (route, payment_hash_1, _, payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
10535+
let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[1]);
10536+
10537+
// Queue up two payments - one will be delivered right away, one immediately goes into the
10538+
// holding cell as nodes[0] is AwaitingRAA.
10539+
{
10540+
nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), PaymentId(payment_hash_1.0)).unwrap();
10541+
check_added_monitors!(nodes[0], 1);
10542+
nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap();
10543+
check_added_monitors!(nodes[0], 0);
10544+
}
10545+
10546+
let inflight_htlcs = node_chanmgrs[0].compute_inflight_htlcs();
10547+
10548+
{
10549+
let channel_lock = nodes[0].node.channel_state.lock().unwrap();
10550+
let channel = channel_lock.by_id.get(&channel_id).unwrap();
10551+
10552+
let used_liquidity = inflight_htlcs.used_liquidity_msat(
10553+
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
10554+
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
10555+
channel.get_short_channel_id().unwrap()
10556+
);
10557+
10558+
assert_eq!(used_liquidity, Some(2000000));
10559+
}
10560+
10561+
// Clear pending events so test doesn't throw a "Had excess message on node..." error
10562+
nodes[0].node.get_and_clear_pending_msg_events();
10563+
}

0 commit comments

Comments
 (0)