@@ -3695,7 +3695,7 @@ fn test_dup_events_on_peer_disconnect() {
3695
3695
#[test]
3696
3696
fn test_peer_disconnected_before_funding_broadcasted() {
3697
3697
// Test that channels are closed with `ClosureReason::DisconnectedPeer` if the peer disconnects
3698
- // before the funding transaction has been broadcasted.
3698
+ // before the funding transaction has been broadcasted, and doesn't reconnect back within time .
3699
3699
let chanmon_cfgs = create_chanmon_cfgs(2);
3700
3700
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
3701
3701
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
@@ -3724,12 +3724,19 @@ fn test_peer_disconnected_before_funding_broadcasted() {
3724
3724
assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 0);
3725
3725
}
3726
3726
3727
- // Ensure that the channel is closed with `ClosureReason::DisconnectedPeer` when the peers are
3728
- // disconnected before the funding transaction was broadcasted.
3727
+ // The peers disconnect before the funding is broadcasted.
3729
3728
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
3730
3729
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
3731
3730
3732
- 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
3733
3740
, [nodes[1].node.get_our_node_id()], 1000000);
3734
3741
check_closed_event!(&nodes[1], 1, ClosureReason::DisconnectedPeer, false
3735
3742
, [nodes[0].node.get_our_node_id()], 1000000);
@@ -10662,7 +10669,9 @@ fn test_batch_channel_open() {
10662
10669
}
10663
10670
10664
10671
#[test]
10665
- fn test_disconnect_in_funding_batch() {
10672
+ fn test_close_in_funding_batch() {
10673
+ // This test ensures that if one of the channels
10674
+ // in the batch closes, the complete batch will close.
10666
10675
let chanmon_cfgs = create_chanmon_cfgs(3);
10667
10676
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
10668
10677
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
@@ -10686,14 +10695,39 @@ fn test_disconnect_in_funding_batch() {
10686
10695
// The transaction should not have been broadcast before all channels are ready.
10687
10696
assert_eq!(nodes[0].tx_broadcaster.txn_broadcast().len(), 0);
10688
10697
10689
- // The remaining peer in the batch disconnects.
10690
- nodes[0].node.peer_disconnected(&nodes[2].node.get_our_node_id());
10691
-
10692
- // The channels in the batch will close immediately.
10698
+ // Force-close the channel for which we've completed the initial monitor.
10693
10699
let funding_txo_1 = OutPoint { txid: tx.txid(), index: 0 };
10694
10700
let funding_txo_2 = OutPoint { txid: tx.txid(), index: 1 };
10695
10701
let channel_id_1 = ChannelId::v1_from_funding_outpoint(funding_txo_1);
10696
10702
let channel_id_2 = ChannelId::v1_from_funding_outpoint(funding_txo_2);
10703
+
10704
+ nodes[0].node.force_close_broadcasting_latest_txn(&channel_id_1, &nodes[1].node.get_our_node_id()).unwrap();
10705
+
10706
+ // The monitor should become closed.
10707
+ check_added_monitors(&nodes[0], 1);
10708
+ {
10709
+ let mut monitor_updates = nodes[0].chain_monitor.monitor_updates.lock().unwrap();
10710
+ let monitor_updates_1 = monitor_updates.get(&channel_id_1).unwrap();
10711
+ assert_eq!(monitor_updates_1.len(), 1);
10712
+ assert_eq!(monitor_updates_1[0].update_id, CLOSED_CHANNEL_UPDATE_ID);
10713
+ }
10714
+
10715
+ let msg_events = nodes[0].node.get_and_clear_pending_msg_events();
10716
+ match msg_events[0] {
10717
+ MessageSendEvent::HandleError { .. } => (),
10718
+ _ => panic!("Unexpected message."),
10719
+ }
10720
+
10721
+ // We broadcast the commitment transaction as part of the force-close.
10722
+ {
10723
+ let broadcasted_txs = nodes[0].tx_broadcaster.txn_broadcast();
10724
+ assert_eq!(broadcasted_txs.len(), 1);
10725
+ assert!(broadcasted_txs[0].txid() != tx.txid());
10726
+ assert_eq!(broadcasted_txs[0].input.len(), 1);
10727
+ assert_eq!(broadcasted_txs[0].input[0].previous_output.txid, tx.txid());
10728
+ }
10729
+
10730
+ // All channels in the batch should close immediately.
10697
10731
check_closed_events(&nodes[0], &[
10698
10732
ExpectedCloseEvent {
10699
10733
channel_id: Some(channel_id_1),
@@ -10711,19 +10745,6 @@ fn test_disconnect_in_funding_batch() {
10711
10745
},
10712
10746
]);
10713
10747
10714
- // The monitor should become closed.
10715
- check_added_monitors(&nodes[0], 1);
10716
- {
10717
- let mut monitor_updates = nodes[0].chain_monitor.monitor_updates.lock().unwrap();
10718
- let monitor_updates_1 = monitor_updates.get(&channel_id_1).unwrap();
10719
- assert_eq!(monitor_updates_1.len(), 1);
10720
- assert_eq!(monitor_updates_1[0].update_id, CLOSED_CHANNEL_UPDATE_ID);
10721
- }
10722
-
10723
- // The funding transaction should not have been broadcast, and therefore, we don't need
10724
- // to broadcast a force-close transaction for the closed monitor.
10725
- assert_eq!(nodes[0].tx_broadcaster.txn_broadcast().len(), 0);
10726
-
10727
10748
// Ensure the channels don't exist anymore.
10728
10749
assert!(nodes[0].node.list_channels().is_empty());
10729
10750
}
0 commit comments