Skip to content

Commit 5f3986d

Browse files
committed
Test Router serialization round-trip in functional_tests.
This tests Router serialization round-trip at the end of each functional test in the same way we do ChannelMonitors and ChannelManagers to catch any cases where we were able to get into a state which would have prevented reading a Router back off disk. We further walk all of the announcements which both the original and deserialized Routers would send to peers requesting initial sync to ensure they match.
1 parent b80d3d9 commit 5f3986d

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use chain::transaction::OutPoint;
66
use chain::keysinterface::KeysInterface;
77
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash};
88
use ln::channelmonitor::{ChannelMonitor, ManyChannelMonitor};
9-
use ln::router::{Route, Router};
9+
use ln::router::{Route, Router, RouterReadArgs};
1010
use ln::features::InitFeatures;
1111
use ln::msgs;
1212
use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler};
@@ -97,6 +97,36 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
9797
assert!(self.node.get_and_clear_pending_events().is_empty());
9898
assert!(self.chan_monitor.added_monitors.lock().unwrap().is_empty());
9999

100+
// Check that if we serialize the Router, we can deserialize it again.
101+
{
102+
let mut w = test_utils::TestVecWriter(Vec::new());
103+
self.router.write(&mut w).unwrap();
104+
let deserialized_router = Router::read(&mut ::std::io::Cursor::new(&w.0), RouterReadArgs {
105+
chain_monitor: Arc::clone(&self.chain_monitor) as Arc<chaininterface::ChainWatchInterface>,
106+
logger: Arc::clone(&self.logger) as Arc<Logger>
107+
}).unwrap();
108+
let mut chan_progress = 0;
109+
loop {
110+
let orig_announcements = self.router.get_next_channel_announcements(chan_progress, 255);
111+
let deserialized_announcements = deserialized_router.get_next_channel_announcements(chan_progress, 255);
112+
assert!(orig_announcements == deserialized_announcements);
113+
chan_progress = match orig_announcements.last() {
114+
Some(announcement) => announcement.0.contents.short_channel_id + 1,
115+
None => break,
116+
};
117+
}
118+
let mut node_progress = None;
119+
loop {
120+
let orig_announcements = self.router.get_next_node_announcements(node_progress.as_ref(), 255);
121+
let deserialized_announcements = deserialized_router.get_next_node_announcements(node_progress.as_ref(), 255);
122+
assert!(orig_announcements == deserialized_announcements);
123+
node_progress = match orig_announcements.last() {
124+
Some(announcement) => Some(announcement.contents.node_id),
125+
None => break,
126+
};
127+
}
128+
}
129+
100130
// Check that if we serialize and then deserialize all our channel monitors we get the
101131
// same set of outputs to watch for on chain as we have now. Note that if we write
102132
// tests that fully close channels and remove the monitors at some point this may break.

0 commit comments

Comments
 (0)