@@ -16956,11 +16956,15 @@ mod tests {
16956
16956
16957
16957
#[test]
16958
16958
#[rustfmt::skip]
16959
+ #[should_panic(expected = "Lost a channel ae3367da2c13bc1ceb86bf56418f62828f7ce9d6bfb15a46af5ba1f1ed8b124f")]
16959
16960
fn test_peer_storage() {
16960
16961
let chanmon_cfgs = create_chanmon_cfgs(2);
16962
+ let (persister, chain_monitor);
16961
16963
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
16964
+ let nodes_0_deserialized;
16962
16965
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
16963
- let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
16966
+ let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
16967
+ let nodes_0_serialized = nodes[0].node.encode();
16964
16968
16965
16969
create_announced_chan_between_nodes(&nodes, 0, 1);
16966
16970
@@ -16969,25 +16973,37 @@ mod tests {
16969
16973
assert_ne!(peer_storage_msg_events_node0.len(), 0);
16970
16974
assert_ne!(peer_storage_msg_events_node1.len(), 0);
16971
16975
16972
- match peer_storage_msg_events_node0[0] {
16973
- MessageSendEvent::SendPeerStorage { ref node_id, ref msg } => {
16974
- assert_eq!(*node_id, nodes[1].node.get_our_node_id());
16975
- nodes[1].node.handle_peer_storage(nodes[0].node.get_our_node_id(), msg.clone());
16976
+ for ps_msg in peer_storage_msg_events_node0 {
16977
+ match ps_msg {
16978
+ MessageSendEvent::SendPeerStorage { ref node_id, ref msg } => {
16979
+ assert_eq!(*node_id, nodes[1].node.get_our_node_id());
16980
+ nodes[1].node.handle_peer_storage(nodes[0].node.get_our_node_id(), msg.clone());
16981
+ }
16982
+ _ => panic!("Unexpected event"),
16976
16983
}
16977
- _ => panic!("Unexpected event"),
16978
16984
}
16979
16985
16980
- match peer_storage_msg_events_node1[0] {
16981
- MessageSendEvent::SendPeerStorage { ref node_id, ref msg } => {
16982
- assert_eq!(*node_id, nodes[0].node.get_our_node_id());
16983
- nodes[0].node.handle_peer_storage(nodes[1].node.get_our_node_id(), msg.clone());
16986
+ for ps_msg in peer_storage_msg_events_node1 {
16987
+ match ps_msg {
16988
+ MessageSendEvent::SendPeerStorage { ref node_id, ref msg } => {
16989
+ assert_eq!(*node_id, nodes[0].node.get_our_node_id());
16990
+ nodes[0].node.handle_peer_storage(nodes[1].node.get_our_node_id(), msg.clone());
16991
+ }
16992
+ _ => panic!("Unexpected event"),
16984
16993
}
16985
- _ => panic!("Unexpected event"),
16986
16994
}
16987
16995
16996
+ send_payment(&nodes[0], &vec!(&nodes[1])[..], 1000);
16997
+ send_payment(&nodes[0], &vec!(&nodes[1])[..], 10000);
16998
+ send_payment(&nodes[0], &vec!(&nodes[1])[..], 9999);
16999
+
16988
17000
nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id());
16989
17001
nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id());
16990
17002
17003
+ // Reload Node!
17004
+ nodes[0].chain_source.clear_watched_txn_and_outputs();
17005
+ reload_node!(nodes[0], test_default_channel_config(), &nodes_0_serialized, &[], persister, chain_monitor, nodes_0_deserialized);
17006
+
16991
17007
nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init {
16992
17008
features: nodes[1].node.init_features(), networks: None, remote_network_address: None
16993
17009
}, true).unwrap();
@@ -16998,10 +17014,11 @@ mod tests {
16998
17014
let node_1_events = nodes[1].node.get_and_clear_pending_msg_events();
16999
17015
assert_eq!(node_1_events.len(), 2);
17000
17016
17017
+ // Since, node-0 does not have any memory it would not send any message.
17001
17018
let node_0_events = nodes[0].node.get_and_clear_pending_msg_events();
17002
- assert_eq!(node_0_events.len(), 2 );
17019
+ assert_eq!(node_0_events.len(), 0 );
17003
17020
17004
- for msg in node_1_events{
17021
+ for msg in node_1_events {
17005
17022
if let MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } = msg {
17006
17023
nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), msg);
17007
17024
assert_eq!(*node_id, nodes[0].node.get_our_node_id());
@@ -17013,35 +17030,8 @@ mod tests {
17013
17030
}
17014
17031
}
17015
17032
17016
- for msg in node_0_events{
17017
- if let MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } = msg {
17018
- nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), msg);
17019
- assert_eq!(*node_id, nodes[1].node.get_our_node_id());
17020
- } else if let MessageSendEvent::SendPeerStorageRetrieval { ref node_id, ref msg } = msg {
17021
- nodes[1].node.handle_peer_storage_retrieval(nodes[0].node.get_our_node_id(), msg.clone());
17022
- assert_eq!(*node_id, nodes[1].node.get_our_node_id());
17023
- } else {
17024
- panic!("Unexpected event")
17025
- }
17026
- }
17027
-
17028
- let node_1_msg_events = nodes[1].node.get_and_clear_pending_msg_events();
17029
17033
let node_0_msg_events = nodes[0].node.get_and_clear_pending_msg_events();
17030
-
17031
- assert_eq!(node_1_msg_events.len(), 3);
17032
- assert_eq!(node_0_msg_events.len(), 3);
17033
-
17034
- for msg in node_1_msg_events {
17035
- if let MessageSendEvent::SendChannelReady { ref node_id, .. } = msg {
17036
- assert_eq!(*node_id, nodes[0].node.get_our_node_id());
17037
- } else if let MessageSendEvent::SendAnnouncementSignatures { ref node_id, .. } = msg {
17038
- assert_eq!(*node_id, nodes[0].node.get_our_node_id());
17039
- } else if let MessageSendEvent::SendChannelUpdate { ref node_id, .. } = msg {
17040
- assert_eq!(*node_id, nodes[0].node.get_our_node_id());
17041
- } else {
17042
- panic!("Unexpected event")
17043
- }
17044
- }
17034
+ assert_eq!(node_0_msg_events.len(), 2);
17045
17035
17046
17036
for msg in node_0_msg_events {
17047
17037
if let MessageSendEvent::SendChannelReady { ref node_id, .. } = msg {
0 commit comments