@@ -4680,6 +4680,110 @@ 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, 0, 1);
4694
+
4695
+ let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
4696
+ let revoked_local_txn = get_local_commitment_txn!(nodes[1], channel_id);
4697
+ assert_eq!(revoked_local_txn[0].input.len(), 1);
4698
+ assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, funding_tx.txid());
4699
+
4700
+ claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
4701
+ send_payment(&nodes[0], &vec!(&nodes[1])[..], 1000);
4702
+
4703
+ nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
4704
+ nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
4705
+
4706
+ // Lets drop the monitor and clear the chain_monitor as well.
4707
+ nodes[0].chain_source.remove_watched_txn_and_outputs(
4708
+ OutPoint { txid: funding_tx.txid(), index: 0 },
4709
+ funding_tx.output[0].script_pubkey.clone()
4710
+ );
4711
+
4712
+ reload_node_with_stubs!(nodes[0], &nodes_0_serialized, &[], &[], persister, chain_monitor, nodes_0_deserialized);
4713
+
4714
+ nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init {
4715
+ features: nodes[0].node.init_features(), networks: None, remote_network_address: None
4716
+ }, true).unwrap();
4717
+ let reestablish_1 = get_chan_reestablish_msgs!(nodes[1], nodes[0]);
4718
+ assert_eq!(reestablish_1.len(), 1);
4719
+
4720
+ nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init {
4721
+ features: nodes[1].node.init_features(), networks: None, remote_network_address: None
4722
+ }, false).unwrap();
4723
+ let reestablish_2 = get_chan_reestablish_msgs!(nodes[0], nodes[1]);
4724
+ assert_eq!(reestablish_2.len(), 0);
4725
+
4726
+ nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_1[0]);
4727
+
4728
+ // Node[0] will generate bogus chennal reestablish and warning so that the peer closes the channel.
4729
+ let mut closing_events = nodes[0].node.get_and_clear_pending_msg_events();
4730
+ assert_eq!(closing_events.len(), 2);
4731
+ let nodes_2_event = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut closing_events);
4732
+ let nodes_0_event = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut closing_events);
4733
+
4734
+ match nodes_2_event {
4735
+ MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } => {
4736
+ assert_eq!(nodes[1].node.get_our_node_id(), *node_id);
4737
+ nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), msg)
4738
+ },
4739
+ _ => panic!("Unexpected event"),
4740
+ }
4741
+
4742
+ let mut err_msgs_0 = Vec::with_capacity(1);
4743
+ if let MessageSendEvent::HandleError { ref action, .. } = nodes_0_event {
4744
+ match action {
4745
+ &ErrorAction::SendErrorMessage { ref msg } => {
4746
+ 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()));
4747
+ err_msgs_0.push(msg.clone());
4748
+ },
4749
+ _ => panic!("Unexpected event!"),
4750
+ }
4751
+ } else {
4752
+ panic!("Unexpected event!");
4753
+ }
4754
+ assert_eq!(err_msgs_0.len(), 1);
4755
+ nodes[1].node.handle_error(&nodes[0].node.get_our_node_id(), &err_msgs_0[0]);
4756
+
4757
+ let block = create_dummy_block(nodes[1].best_block_hash(), 42, vec![revoked_local_txn[0].clone()]);
4758
+ connect_block(&nodes[0], &block);
4759
+ connect_block(&nodes[1], &block);
4760
+ check_closed_broadcast!(nodes[1], true);
4761
+
4762
+ let events_2 = nodes[1].node.get_and_clear_pending_events();
4763
+ assert_eq!(events_2.len(), 1);
4764
+ match events_2[0] {
4765
+ Event::ChannelClosed {..} => {}, // If we actually processed we'd receive the payment
4766
+ _ => panic!("Unexpected event"),
4767
+ }
4768
+ check_added_monitors!(nodes[1], 1);
4769
+ connect_blocks(&nodes[0], CHAN_CONFIRM_DEPTH);
4770
+
4771
+
4772
+ // check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed, [nodes[0].node.get_our_node_id()], 100000);
4773
+
4774
+ // let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
4775
+ // assert_eq!(node_txn.len(), 1);
4776
+ // assert_eq!(node_txn[0].input.len(), 2);
4777
+ // check_spends!(node_txn[0], revoked_local_txn[0]);
4778
+
4779
+ // mine_transaction(&nodes[1], &node_txn[0]);
4780
+ // connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
4781
+
4782
+ // let spend_txn = check_spendable_outputs!(nodes[0], node_cfgs[1].keys_manager);
4783
+ // assert_eq!(spend_txn.len(), 1);
4784
+ // check_spends!(spend_txn[0], node_txn[0]);
4785
+ }
4786
+
4683
4787
#[test]
4684
4788
fn test_claim_sizeable_push_msat() {
4685
4789
// Incidentally test SpendableOutput event generation due to detection of to_local output on commitment tx
0 commit comments