diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index f1e8a41a3be..ae4794fa9a7 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -9889,51 +9889,53 @@ fn test_payment_with_custom_min_cltv_expiry_delta() { do_payment_with_custom_min_final_cltv_expiry(true, true); } -#[test] -fn test_disconnects_peer_awaiting_response_ticks() { - // Tests that nodes which are awaiting on a response critical for channel responsiveness - // disconnect their counterparty after `DISCONNECT_PEER_AWAITING_RESPONSE_TICKS`. - let mut chanmon_cfgs = create_chanmon_cfgs(2); - let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); - let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - - // Asserts a disconnect event is queued to the user. - let check_disconnect_event = |node: &Node, should_disconnect: bool| { - let disconnect_event = node.node.get_and_clear_pending_msg_events().iter().find_map(|event| - if let MessageSendEvent::HandleError { action, .. } = event { - if let msgs::ErrorAction::DisconnectPeerWithWarning { .. } = action { - Some(()) - } else { - None - } +// Disconnect awaiting response helpers + +// Asserts a disconnect event is queued to the user. +fn check_disconnect_event(node: &Node, should_disconnect: bool) { + let disconnect_event = node.node.get_and_clear_pending_msg_events().iter().find_map(|event| + if let MessageSendEvent::HandleError { action, .. } = event { + if let msgs::ErrorAction::DisconnectPeerWithWarning { .. } = action { + Some(()) } else { None } - ); - assert_eq!(disconnect_event.is_some(), should_disconnect); - }; + } else { + None + } + ); + assert_eq!(disconnect_event.is_some(), should_disconnect); +} - // Fires timer ticks ensuring we only attempt to disconnect peers after reaching - // `DISCONNECT_PEER_AWAITING_RESPONSE_TICKS`. - let check_disconnect = |node: &Node| { - // No disconnect without any timer ticks. +// Fires timer ticks ensuring we only attempt to disconnect peers after reaching +// `DISCONNECT_PEER_AWAITING_RESPONSE_TICKS`. +fn check_disconnect(node: &Node) { + // No disconnect without any timer ticks. + check_disconnect_event(node, false); + + // No disconnect with 1 timer tick less than required. + for _ in 0..DISCONNECT_PEER_AWAITING_RESPONSE_TICKS - 1 { + node.node.timer_tick_occurred(); check_disconnect_event(node, false); + } - // No disconnect with 1 timer tick less than required. - for _ in 0..DISCONNECT_PEER_AWAITING_RESPONSE_TICKS - 1 { - node.node.timer_tick_occurred(); - check_disconnect_event(node, false); - } + // Disconnect after reaching the required ticks. + node.node.timer_tick_occurred(); + check_disconnect_event(node, true); - // Disconnect after reaching the required ticks. - node.node.timer_tick_occurred(); - check_disconnect_event(node, true); + // Disconnect again on the next tick if the peer hasn't been disconnected yet. + node.node.timer_tick_occurred(); + check_disconnect_event(node, true); +} - // Disconnect again on the next tick if the peer hasn't been disconnected yet. - node.node.timer_tick_occurred(); - check_disconnect_event(node, true); - }; +#[test] +fn test_disconnects_peer_awaiting_response_ticks() { + // Tests that nodes which are awaiting on a response critical for channel responsiveness + // disconnect their counterparty after `DISCONNECT_PEER_AWAITING_RESPONSE_TICKS`. + let mut chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_chan_between_nodes(&nodes[0], &nodes[1]); @@ -10016,11 +10018,11 @@ fn test_disconnects_peer_awaiting_response_ticks() { check_disconnect_event(node, false); } } +} - // V1 Channel Establishment +#[test] +fn disconnect_peer_on_v1_channel_establish_not_progressing() { // Disconnects on pending channel timeout - - // Set up some fresh nodes. let mut chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);