@@ -4672,6 +4672,122 @@ macro_rules! check_spendable_outputs {
4672
4672
}
4673
4673
}
4674
4674
4675
+ #[test]
4676
+ fn test_peer_storage_on_revoked_txn() {
4677
+ let chanmon_cfgs = create_chanmon_cfgs(2);
4678
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
4679
+ let (persister, chain_monitor);
4680
+ let (persister_fund_recoverer, chain_monitor_fund_recoverer);
4681
+
4682
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
4683
+ let nodes_0_deserialized;
4684
+ let nodes_0_deserialized_fund_recoverer;
4685
+ let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
4686
+ let nodes_0_serialized = nodes[0].node.encode();
4687
+
4688
+ let (_a, _b, channel_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 1, 0);
4689
+
4690
+ send_payment(&nodes[1], &vec!(&nodes[0])[..], 10000);
4691
+ send_payment(&nodes[1], &vec!(&nodes[0])[..], 10000);
4692
+
4693
+ let revoked_local_txn = get_local_commitment_txn!(nodes[1], channel_id);
4694
+ assert_eq!(revoked_local_txn[0].input.len(), 1);
4695
+ assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, funding_tx.txid());
4696
+
4697
+ send_payment(&nodes[1], &vec!(&nodes[0])[..], 10000);
4698
+
4699
+ nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
4700
+ nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
4701
+
4702
+ // Lets drop the monitor and clear the chain_monitor as well.
4703
+ nodes[0].chain_source.remove_watched_txn_and_outputs(
4704
+ OutPoint { txid: funding_tx.txid(), index: 0 },
4705
+ funding_tx.output[0].script_pubkey.clone()
4706
+ );
4707
+
4708
+ reload_node!(nodes[0], test_default_channel_config(), &nodes_0_serialized, &[], persister, chain_monitor, nodes_0_deserialized);
4709
+
4710
+ // Reconnect peers to see if we send YourPeerStorage
4711
+ nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init {
4712
+ features: nodes[0].node.init_features(), networks: None, remote_network_address: None
4713
+ }, false).unwrap();
4714
+ let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]);
4715
+ assert_eq!(reestablish_2.len(), 1);
4716
+
4717
+ nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init {
4718
+ features: nodes[1].node.init_features(), networks: None, remote_network_address: None
4719
+ }, true).unwrap();
4720
+ let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]);
4721
+ assert_eq!(reestablish_1.len(), 0);
4722
+
4723
+ nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
4724
+ nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
4725
+
4726
+ let chanstub = get_stub!(nodes[0], channel_id).encode();
4727
+
4728
+ // Lets drop the monitor and clear the chain_monitor as well.
4729
+ nodes[0].chain_source.remove_watched_txn_and_outputs(
4730
+ OutPoint { txid: funding_tx.txid(), index: 0 },
4731
+ funding_tx.output[0].script_pubkey.clone()
4732
+ );
4733
+
4734
+ reload_node_with_stubs!(nodes[0], &nodes_0_serialized, &[], &[&chanstub], persister_fund_recoverer, chain_monitor_fund_recoverer, nodes_0_deserialized_fund_recoverer);
4735
+
4736
+ let fundrecoverer: FundRecoverer<&test_utils::TestKeysInterface, &TestLogger, &test_utils::TestChainMonitor>
4737
+ = FundRecoverer::new(&chain_monitor_fund_recoverer, node_cfgs[0].logger, test_default_channel_config(), ChainParameters{network: Network::Testnet,
4738
+ best_block: BestBlock::from_network(Network::Testnet)});
4739
+
4740
+ fundrecoverer.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init {
4741
+ features: nodes[0].node.init_features(), networks: None, remote_network_address: None
4742
+ }, true).unwrap();
4743
+ let mut closing_msg_events = fundrecoverer.get_and_clear_pending_msg_events();
4744
+ assert_eq!(closing_msg_events.len(), 1);
4745
+ let bogus_chan_reestablish = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut closing_msg_events);
4746
+
4747
+ nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init {
4748
+ features: nodes[0].node.init_features(), networks: None, remote_network_address: None
4749
+ }, true).unwrap();
4750
+ let reestablish_1 = get_chan_reestablish_msgs!(nodes[1], nodes[0]);
4751
+ assert_eq!(reestablish_1.len(), 1);
4752
+
4753
+ match bogus_chan_reestablish {
4754
+ MessageSendEvent::SendChannelReestablish {ref node_id, ref msg} => {
4755
+ assert_eq!(nodes[1].node.get_our_node_id(), *node_id);
4756
+ nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), msg);
4757
+ },
4758
+ _ => panic!("Unexpected event"),
4759
+ }
4760
+
4761
+ fundrecoverer.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_1[0]);
4762
+
4763
+ let block = create_dummy_block(nodes[1].best_block_hash(), 42, vec![revoked_local_txn[0].clone()]);
4764
+ connect_block(&nodes[0], &block);
4765
+ connect_block(&nodes[1], &block);
4766
+ check_closed_broadcast!(nodes[1], true);
4767
+
4768
+ let events_2 = nodes[1].node.get_and_clear_pending_events();
4769
+ assert_eq!(events_2.len(), 1);
4770
+ match events_2[0] {
4771
+ Event::ChannelClosed {..} => {}, // If we actually processed we'd receive the payment
4772
+ _ => panic!("Unexpected event"),
4773
+ }
4774
+ check_added_monitors!(nodes[1], 1);
4775
+
4776
+ let panelty = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
4777
+ assert_eq!(panelty.len(), 1);
4778
+ assert_eq!(panelty[0].input.len(), 1);
4779
+
4780
+ let block = create_dummy_block(nodes[1].best_block_hash(), 42, vec![panelty[0].clone()]);
4781
+ connect_block(&nodes[1], &block);
4782
+ connect_block(&nodes[0], &block);
4783
+
4784
+ connect_blocks(&nodes[0], CHAN_CONFIRM_DEPTH);
4785
+ let spend_txn = check_spendable_outputs!(nodes[0], node_cfgs[0].keys_manager);
4786
+ assert_eq!(spend_txn.len(), 1);
4787
+ assert_eq!(spend_txn[0].input.len(), 1);
4788
+ check_spends!(spend_txn[0], panelty[0]);
4789
+ }
4790
+
4675
4791
#[test]
4676
4792
fn test_claim_sizeable_push_msat() {
4677
4793
// Incidentally test SpendableOutput event generation due to detection of to_local output on commitment tx
0 commit comments