Skip to content

Commit e799bf6

Browse files
committed
f wip test
1 parent 6c13169 commit e799bf6

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,6 +3690,77 @@ fn test_htlc_timeout() {
36903690
do_test_htlc_timeout(false);
36913691
}
36923692

3693+
fn do_test_holding_cell_htlc_add_timeouts(forwarded_htlc: bool) {
3694+
// Tests that HTLCs in the holding cell are timed out after the requisite number of blocks.
3695+
let chanmon_cfgs = create_chanmon_cfgs(3);
3696+
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
3697+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
3698+
let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
3699+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
3700+
create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported());
3701+
3702+
// Route a first payment to get the 1 -> 2 channel in awaiting_raa...
3703+
let route = nodes[1].router.get_route(&nodes[2].node.get_our_node_id(), None, &Vec::new(), 100000, TEST_FINAL_CLTV).unwrap();
3704+
let (_, first_payment_hash) = get_payment_preimage_hash!(nodes[0]);
3705+
nodes[1].node.send_payment(&route, first_payment_hash, &None).unwrap();
3706+
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);
3707+
check_added_monitors!(nodes[1], 1);
3708+
3709+
// Now attempt to route a second payment, which should be placed in the holding cell
3710+
let (_, second_payment_hash) = get_payment_preimage_hash!(nodes[0]);
3711+
if forwarded_htlc {
3712+
let route = nodes[0].router.get_route(&nodes[2].node.get_our_node_id(), None, &Vec::new(), 100000, TEST_FINAL_CLTV).unwrap();
3713+
nodes[0].node.send_payment(&route, second_payment_hash, &None).unwrap();
3714+
check_added_monitors!(nodes[0], 1);
3715+
let payment_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0));
3716+
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
3717+
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
3718+
expect_pending_htlcs_forwardable!(nodes[1]);
3719+
check_added_monitors!(nodes[1], 0);
3720+
} else {
3721+
nodes[1].node.send_payment(&route, second_payment_hash, &None).unwrap();
3722+
check_added_monitors!(nodes[1], 0);
3723+
}
3724+
3725+
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
3726+
nodes[1].block_notifier.block_connected_checked(&header, 101, &[], &[]);
3727+
for i in 102..TEST_FINAL_CLTV + 100 + 1 - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS {
3728+
header.prev_blockhash = header.bitcoin_hash();
3729+
nodes[1].block_notifier.block_connected_checked(&header, i, &[], &[]);
3730+
}
3731+
3732+
if forwarded_htlc {
3733+
expect_pending_htlcs_forwardable!(nodes[1]);
3734+
check_added_monitors!(nodes[1], 1);
3735+
let fail_commit = nodes[1].node.get_and_clear_pending_msg_events();
3736+
assert_eq!(fail_commit.len(), 1);
3737+
match fail_commit[0] {
3738+
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fail_htlcs, ref commitment_signed, .. }, .. } => {
3739+
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]);
3740+
commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, true, true);
3741+
},
3742+
_ => unreachable!(),
3743+
}
3744+
expect_payment_failed!(nodes[0], second_payment_hash, false);
3745+
if let &MessageSendEvent::PaymentFailureNetworkUpdate { ref update } = &nodes[0].node.get_and_clear_pending_msg_events()[0] {
3746+
match update {
3747+
&HTLCFailChannelUpdate::ChannelUpdateMessage { .. } => {},
3748+
_ => panic!("Unexpected event"),
3749+
}
3750+
} else {
3751+
panic!("Unexpected event");
3752+
}
3753+
} else {
3754+
expect_payment_failed!(nodes[1], second_payment_hash, true);
3755+
}
3756+
}
3757+
3758+
#[test]
3759+
fn test_holding_cell_htlc_add_timeouts() {
3760+
do_test_holding_cell_htlc_add_timeouts(false);
3761+
do_test_holding_cell_htlc_add_timeouts(true);
3762+
}
3763+
36933764
#[test]
36943765
fn test_invalid_channel_announcement() {
36953766
//Test BOLT 7 channel_announcement msg requirement for final node, gather data to build customed channel_announcement msgs

0 commit comments

Comments
 (0)