@@ -3692,13 +3692,7 @@ fn test_dup_events_on_peer_disconnect() {
3692
3692
expect_payment_path_successful!(nodes[0]);
3693
3693
}
3694
3694
3695
-
3696
- // The following test is disabled because we no longer close the channel
3697
- // immediately after funding brodcasts. Instead we wait for some time for
3698
- // the peer to reconnect back, and only close it after it become stale for
3699
- // UNFUNDED_CHANNEL_AGE_LIMIT_TICKS
3700
3695
#[test]
3701
- #[ignore]
3702
3696
fn test_peer_disconnected_before_funding_broadcasted() {
3703
3697
// Test that channels are closed with `ClosureReason::DisconnectedPeer` if the peer disconnects
3704
3698
// before the funding transaction has been broadcasted, and doesn't reconnect back within time.
@@ -3730,12 +3724,19 @@ fn test_peer_disconnected_before_funding_broadcasted() {
3730
3724
assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 0);
3731
3725
}
3732
3726
3733
- // Ensure that the channel is closed after timeout with `ClosureReason::DisconnectedPeer`
3734
- // when the peers are disconnected before the funding transaction was broadcasted.
3727
+ // The peers disconnect before the funding is broadcasted.
3735
3728
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
3736
3729
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
3737
3730
3738
- check_closed_event!(&nodes[0], 2, ClosureReason::DisconnectedPeer, true
3731
+ // The time for peers to reconnect expires.
3732
+ for _ in 0..UNFUNDED_CHANNEL_AGE_LIMIT_TICKS {
3733
+ nodes[0].node.timer_tick_occurred();
3734
+ }
3735
+
3736
+ // Ensure that the channel is closed with `ClosureReason::HolderForceClosed`
3737
+ // when the peers are disconnected and do not reconnect before the funding
3738
+ // transaction is broadcasted.
3739
+ check_closed_event!(&nodes[0], 2, ClosureReason::HolderForceClosed, true
3739
3740
, [nodes[1].node.get_our_node_id()], 1000000);
3740
3741
check_closed_event!(&nodes[1], 1, ClosureReason::DisconnectedPeer, false
3741
3742
, [nodes[0].node.get_our_node_id()], 1000000);
@@ -10512,88 +10513,100 @@ fn test_remove_expired_inbound_unfunded_channels() {
10512
10513
}
10513
10514
10514
10515
#[test]
10515
- fn test_channel_close_when_not_timely_accepted() {
10516
- // Create network of two nodes
10517
- let chanmon_cfgs = create_chanmon_cfgs(2);
10518
- let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
10519
- let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
10520
- let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
10516
+ fn test_channel_close_when_not_timely_accepted() {
10517
+ // Create network of two nodes
10518
+ let chanmon_cfgs = create_chanmon_cfgs(2);
10519
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
10520
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
10521
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
10521
10522
10522
- // Simulate peer-diconnects mid-handshake
10523
- // The channel is initiated from the node 0 side,
10524
- // But the nodes disconnects before node 1 could send accept channel
10525
- let create_chan_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap();
10526
- let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
10527
- assert_eq!(open_channel_msg.temporary_channel_id, create_chan_id);
10523
+ // Simulate peer-disconnects mid-handshake
10524
+ // The channel is initiated from the node 0 side,
10525
+ // but the nodes disconnect before node 1 could send accept channel
10526
+ let create_chan_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap();
10527
+ let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
10528
+ assert_eq!(open_channel_msg.temporary_channel_id, create_chan_id);
10528
10529
10529
- nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
10530
- nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
10530
+ nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
10531
+ nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
10531
10532
10532
- {
10533
- // Make sure that we have not removed the OutboundV1Channel from node[0] immediately.
10534
- let node_0_per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
10535
- let per_peer_state = node_0_per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
10536
- assert_eq!(per_peer_state.channel_by_id.len(), 1);
10537
- }
10533
+ {
10534
+ // Make sure that we have not removed the OutboundV1Channel from node[0] immediately.
10535
+ let node_0_per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
10536
+ let per_peer_state = node_0_per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
10537
+ assert_eq!(per_peer_state.channel_by_id.len(), 1);
10538
+ }
10538
10539
10539
- // In the meantime, some time passes.
10540
- for _ in 0..UNFUNDED_CHANNEL_AGE_LIMIT_TICKS {
10541
- nodes[0].node.timer_tick_occurred();
10542
- }
10540
+ {
10541
+ // Since channel was inbound from node[1] perspective, it should have been immediately dropped.
10542
+ let node_1_per_peer_state = nodes[1].node.per_peer_state.read().unwrap();
10543
+ let per_peer_state = node_1_per_peer_state.get(&nodes[0].node.get_our_node_id());
10544
+ assert!(per_peer_state.is_none());
10545
+ }
10543
10546
10544
- // Since we disconnected from peer and did not connect back within time
10545
- // We should have forced-closed the channel by now.
10546
- check_closed_event!(nodes[0], 1, ClosureReason::HolderForceClosed, [nodes[1].node.get_our_node_id()], 100000);
10547
+ // In the meantime, some time passes.
10548
+ for _ in 0..UNFUNDED_CHANNEL_AGE_LIMIT_TICKS {
10549
+ nodes[0].node.timer_tick_occurred();
10550
+ }
10547
10551
10548
- {
10549
- // Since accept channel message was never received
10550
- // The channel should be forced close by now from node 0 side
10551
- // and the peer removed from per_peer_state
10552
- let node_0_per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
10553
- assert_eq!(node_0_per_peer_state.len(), 0);
10554
- }
10552
+ // Since we disconnected from peer and did not connect back within time,
10553
+ // we should have forced-closed the channel by now.
10554
+ check_closed_event!(nodes[0], 1, ClosureReason::HolderForceClosed, [nodes[1].node.get_our_node_id()], 100000);
10555
10555
10556
+ {
10557
+ // Since accept channel message was never received
10558
+ // The channel should be forced close by now from node 0 side
10559
+ // and the peer removed from per_peer_state
10560
+ let node_0_per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
10561
+ assert_eq!(node_0_per_peer_state.len(), 0);
10556
10562
}
10563
+ }
10557
10564
10558
- #[test]
10559
- fn test_rebroadcast_open_channel_when_reconnect_mid_handshake() {
10560
- // Create network of two nodes
10561
- let chanmon_cfgs = create_chanmon_cfgs(2);
10562
- let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
10563
- let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
10564
- let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
10565
-
10566
- // Simulate peer-diconnects mid-handshake
10567
- // The channel is initiated from the node 0 side,
10568
- // But the nodes disconnects before node 1 could send accept channel
10569
- let create_chan_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap();
10570
- let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
10571
- assert_eq!(open_channel_msg.temporary_channel_id, create_chan_id);
10565
+ #[test]
10566
+ fn test_rebroadcast_open_channel_when_reconnect_mid_handshake() {
10567
+ // Create network of two nodes
10568
+ let chanmon_cfgs = create_chanmon_cfgs(2);
10569
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
10570
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
10571
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
10572
10572
10573
- nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
10574
- nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
10573
+ // Simulate peer-disconnects mid-handshake
10574
+ // The channel is initiated from the node 0 side,
10575
+ // but the nodes disconnect before node 1 could send accept channel
10576
+ let create_chan_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap();
10577
+ let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
10578
+ assert_eq!(open_channel_msg.temporary_channel_id, create_chan_id);
10575
10579
10576
- {
10577
- // Make sure that we have not removed the OutboundV1Channel from node[0] immediately.
10578
- let node_0_per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
10579
- let per_peer_state = node_0_per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
10580
- assert_eq!(per_peer_state.channel_by_id.len(), 1);
10581
- }
10580
+ nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
10581
+ nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
10582
10582
10583
- // The peers now reconnect
10584
- nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init {
10585
- features: nodes[1].node.init_features(), networks: None, remote_network_address: None
10586
- }, true).unwrap();
10587
- nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init {
10588
- features: nodes[0].node.init_features(), networks: None, remote_network_address: None
10589
- }, false).unwrap();
10583
+ {
10584
+ // Make sure that we have not removed the OutboundV1Channel from node[0] immediately.
10585
+ let node_0_per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
10586
+ let per_peer_state = node_0_per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
10587
+ assert_eq!(per_peer_state.channel_by_id.len(), 1);
10588
+ }
10590
10589
10591
- // Make sure the SendOpenChannel message is added to
10592
- // node_0 pending message events
10593
- let events = nodes[0].node.get_and_clear_pending_msg_events();
10594
- assert_eq!(events.len(), 1);
10590
+ {
10591
+ // Since channel was inbound from node[1] perspective, it should have been immediately dropped.
10592
+ let node_1_per_peer_state = nodes[1].node.per_peer_state.read().unwrap();
10593
+ let per_peer_state = node_1_per_peer_state.get(&nodes[0].node.get_our_node_id());
10594
+ assert!(per_peer_state.is_none());
10595
10595
}
10596
10596
10597
+ // The peers now reconnect
10598
+ nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init {
10599
+ features: nodes[1].node.init_features(), networks: None, remote_network_address: None
10600
+ }, true).unwrap();
10601
+ nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init {
10602
+ features: nodes[0].node.init_features(), networks: None, remote_network_address: None
10603
+ }, false).unwrap();
10604
+
10605
+ // Make sure the SendOpenChannel message is added to
10606
+ // node_0 pending message events
10607
+ let events = nodes[0].node.get_and_clear_pending_msg_events();
10608
+ assert_eq!(events.len(), 1);
10609
+ }
10597
10610
10598
10611
fn do_test_multi_post_event_actions(do_reload: bool) {
10599
10612
// Tests handling multiple post-Event actions at once.
@@ -10778,12 +10791,12 @@ fn test_disconnect_in_funding_batch() {
10778
10791
// The remaining peer in the batch disconnects.
10779
10792
nodes[0].node.peer_disconnected(&nodes[2].node.get_our_node_id());
10780
10793
10781
- // After the time expires for allowing peer to connect back
10794
+ // Let the time for the peers to reconnect expire.
10782
10795
for _ in 0..UNFUNDED_CHANNEL_AGE_LIMIT_TICKS {
10783
10796
nodes[0].node.timer_tick_occurred();
10784
10797
}
10785
10798
10786
- // The channels in the batch will close immediately .
10799
+ // The channels in the batch will close after timeout .
10787
10800
let funding_txo_1 = OutPoint { txid: tx.txid(), index: 0 };
10788
10801
let funding_txo_2 = OutPoint { txid: tx.txid(), index: 1 };
10789
10802
let channel_id_1 = funding_txo_1.to_channel_id();
0 commit comments