@@ -4680,6 +4680,102 @@ macro_rules! check_spendable_outputs {
4680
4680
}
4681
4681
}
4682
4682
4683
+ #[test]
4684
+ fn test_peer_storage_on_revoked_txn() {
4685
+ let chanmon_cfgs = create_chanmon_cfgs(2);
4686
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
4687
+ let (persister, chain_monitor);
4688
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
4689
+ let nodes_0_deserialized;
4690
+ let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
4691
+ let nodes_0_serialized = nodes[0].node.encode();
4692
+
4693
+ let (_a, _b, channel_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 1, 0);
4694
+
4695
+ send_payment(&nodes[1], &vec!(&nodes[0])[..], 10000);
4696
+ send_payment(&nodes[1], &vec!(&nodes[0])[..], 10000);
4697
+
4698
+ let revoked_local_txn = get_local_commitment_txn!(nodes[1], channel_id);
4699
+ assert_eq!(revoked_local_txn[0].input.len(), 1);
4700
+ assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, funding_tx.txid());
4701
+
4702
+ send_payment(&nodes[1], &vec!(&nodes[0])[..], 10000);
4703
+
4704
+ nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
4705
+ nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
4706
+
4707
+ // Lets drop the monitor and clear the chain_monitor as well.
4708
+ nodes[0].chain_source.remove_watched_txn_and_outputs(
4709
+ OutPoint { txid: funding_tx.txid(), index: 0 },
4710
+ funding_tx.output[0].script_pubkey.clone()
4711
+ );
4712
+
4713
+ reload_node_with_stubs!(nodes[0], &nodes_0_serialized, &[], &[], persister, chain_monitor, nodes_0_deserialized);
4714
+
4715
+ nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init {
4716
+ features: nodes[0].node.init_features(), networks: None, remote_network_address: None
4717
+ }, true).unwrap();
4718
+ let reestablish_1 = get_chan_reestablish_msgs!(nodes[1], nodes[0]);
4719
+ assert_eq!(reestablish_1.len(), 1);
4720
+
4721
+ nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init {
4722
+ features: nodes[1].node.init_features(), networks: None, remote_network_address: None
4723
+ }, false).unwrap();
4724
+ let reestablish_2 = get_chan_reestablish_msgs!(nodes[0], nodes[1]);
4725
+ assert_eq!(reestablish_2.len(), 0);
4726
+
4727
+ nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_1[0]);
4728
+
4729
+ // Node[0] will generate bogus chennal reestablish and warning so that the peer closes the channel.
4730
+ let mut closing_events = nodes[0].node.get_and_clear_pending_msg_events();
4731
+ assert_eq!(closing_events.len(), 2);
4732
+ let nodes_2_event = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut closing_events);
4733
+ let nodes_0_event = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut closing_events);
4734
+
4735
+ match nodes_2_event {
4736
+ MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } => {
4737
+ assert_eq!(nodes[1].node.get_our_node_id(), *node_id);
4738
+ nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), msg)
4739
+ },
4740
+ _ => panic!("Unexpected event"),
4741
+ }
4742
+
4743
+ let mut err_msgs_0 = Vec::with_capacity(1);
4744
+ if let MessageSendEvent::HandleError { ref action, .. } = nodes_0_event {
4745
+ match action {
4746
+ &ErrorAction::SendErrorMessage { ref msg } => {
4747
+ assert_eq!(msg.data, format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id()));
4748
+ err_msgs_0.push(msg.clone());
4749
+ },
4750
+ _ => panic!("Unexpected event!"),
4751
+ }
4752
+ } else {
4753
+ panic!("Unexpected event!");
4754
+ }
4755
+ assert_eq!(err_msgs_0.len(), 1);
4756
+ nodes[1].node.handle_error(&nodes[0].node.get_our_node_id(), &err_msgs_0[0]);
4757
+
4758
+ let block = create_dummy_block(nodes[1].best_block_hash(), 42, vec![revoked_local_txn[0].clone()]);
4759
+ connect_block(&nodes[0], &block);
4760
+ connect_block(&nodes[1], &block);
4761
+ check_closed_broadcast!(nodes[1], true);
4762
+
4763
+ let events_2 = nodes[1].node.get_and_clear_pending_events();
4764
+ assert_eq!(events_2.len(), 1);
4765
+ match events_2[0] {
4766
+ Event::ChannelClosed {..} => {}, // If we actually processed we'd receive the payment
4767
+ _ => panic!("Unexpected event"),
4768
+ }
4769
+ check_added_monitors!(nodes[1], 1);
4770
+ let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
4771
+ assert_eq!(node_txn.len(), 1);
4772
+ assert_eq!(node_txn[0].input.len(), 1);
4773
+
4774
+ let block = create_dummy_block(nodes[1].best_block_hash(), 42, vec![node_txn[0].clone()]);
4775
+ connect_block(&nodes[0], &block);
4776
+ connect_block(&nodes[1], &block);
4777
+ }
4778
+
4683
4779
#[test]
4684
4780
fn test_claim_sizeable_push_msat() {
4685
4781
// Incidentally test SpendableOutput event generation due to detection of to_local output on commitment tx
0 commit comments