Skip to content

Commit b7e9392

Browse files
committed
test: Modify test_peer_storage to check latest changes
Node should now determine lost states using retrieved peer storage.
1 parent c484bd7 commit b7e9392

File tree

2 files changed

+36
-41
lines changed

2 files changed

+36
-41
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16956,11 +16956,15 @@ mod tests {
1695616956

1695716957
#[test]
1695816958
#[rustfmt::skip]
16959+
#[should_panic(expected = "Lost a channel ae3367da2c13bc1ceb86bf56418f62828f7ce9d6bfb15a46af5ba1f1ed8b124f")]
1695916960
fn test_peer_storage() {
1696016961
let chanmon_cfgs = create_chanmon_cfgs(2);
16962+
let (persister, chain_monitor);
1696116963
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
16964+
let nodes_0_deserialized;
1696216965
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();
1696416968

1696516969
create_announced_chan_between_nodes(&nodes, 0, 1);
1696616970

@@ -16969,25 +16973,37 @@ mod tests {
1696916973
assert_ne!(peer_storage_msg_events_node0.len(), 0);
1697016974
assert_ne!(peer_storage_msg_events_node1.len(), 0);
1697116975

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"),
1697616983
}
16977-
_ => panic!("Unexpected event"),
1697816984
}
1697916985

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"),
1698416993
}
16985-
_ => panic!("Unexpected event"),
1698616994
}
1698716995

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+
1698817000
nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id());
1698917001
nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id());
1699017002

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+
1699117007
nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init {
1699217008
features: nodes[1].node.init_features(), networks: None, remote_network_address: None
1699317009
}, true).unwrap();
@@ -16998,10 +17014,11 @@ mod tests {
1699817014
let node_1_events = nodes[1].node.get_and_clear_pending_msg_events();
1699917015
assert_eq!(node_1_events.len(), 2);
1700017016

17017+
// Since, node-0 does not have any memory it would not send any message.
1700117018
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);
1700317020

17004-
for msg in node_1_events{
17021+
for msg in node_1_events {
1700517022
if let MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } = msg {
1700617023
nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), msg);
1700717024
assert_eq!(*node_id, nodes[0].node.get_our_node_id());
@@ -17013,35 +17030,8 @@ mod tests {
1701317030
}
1701417031
}
1701517032

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();
1702917033
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);
1704517035

1704617036
for msg in node_0_msg_events {
1704717037
if let MessageSendEvent::SendChannelReady { ref node_id, .. } = msg {

lightning/src/util/test_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,11 @@ impl TestChainSource {
18001800
self.watched_outputs.lock().unwrap().remove(&(outpoint, script_pubkey.clone()));
18011801
self.watched_txn.lock().unwrap().remove(&(outpoint.txid, script_pubkey));
18021802
}
1803+
1804+
pub fn clear_watched_txn_and_outputs(&self) {
1805+
self.watched_outputs.lock().unwrap().clear();
1806+
self.watched_txn.lock().unwrap().clear();
1807+
}
18031808
}
18041809

18051810
impl UtxoLookup for TestChainSource {

0 commit comments

Comments
 (0)