/// Represents the network as nodes and channels between them
pub struct NetworkGraph {
+ last_rapid_gossip_sync_timestamp: Mutex<Option<u32>>,
genesis_hash: BlockHash,
// Lock order: channels -> nodes
channels: RwLock<BTreeMap<u64, ChannelInfo>>,
fn clone(&self) -> Self {
let channels = self.channels.read().unwrap();
let nodes = self.nodes.read().unwrap();
+ let last_rapid_gossip_sync_timestamp = self.get_last_rapid_gossip_sync_timestamp();
Self {
genesis_hash: self.genesis_hash.clone(),
channels: RwLock::new(channels.clone()),
nodes: RwLock::new(nodes.clone()),
+ last_rapid_gossip_sync_timestamp: Mutex::new(last_rapid_gossip_sync_timestamp)
}
}
}
node_info.write(writer)?;
}
- write_tlv_fields!(writer, {});
+ let last_rapid_gossip_sync_timestamp = self.get_last_rapid_gossip_sync_timestamp();
+ write_tlv_fields!(writer, {
+ (1, last_rapid_gossip_sync_timestamp, option),
+ });
Ok(())
}
}
let node_info = Readable::read(reader)?;
nodes.insert(node_id, node_info);
}
- read_tlv_fields!(reader, {});
+
+ let mut last_rapid_gossip_sync_timestamp: Option<u32> = None;
+ read_tlv_fields!(reader, {
+ (1, last_rapid_gossip_sync_timestamp, option),
+ });
Ok(NetworkGraph {
genesis_hash,
channels: RwLock::new(channels),
nodes: RwLock::new(nodes),
+ last_rapid_gossip_sync_timestamp: Mutex::new(last_rapid_gossip_sync_timestamp),
})
}
}
genesis_hash,
channels: RwLock::new(BTreeMap::new()),
nodes: RwLock::new(BTreeMap::new()),
+ last_rapid_gossip_sync_timestamp: Mutex::new(None),
}
}
}
}
+ /// The unix timestamp provided by the most recent rapid gossip sync.
+ /// It will be set by the rapid sync process after every sync completion.
+ pub fn get_last_rapid_gossip_sync_timestamp(&self) -> Option<u32> {
+ self.last_rapid_gossip_sync_timestamp.lock().unwrap().clone()
+ }
+
+ /// Update the unix timestamp provided by the most recent rapid gossip sync.
+ /// This should be done automatically by the rapid sync process after every sync completion.
+ pub fn set_last_rapid_gossip_sync_timestamp(&self, last_rapid_gossip_sync_timestamp: u32) {
+ self.last_rapid_gossip_sync_timestamp.lock().unwrap().replace(last_rapid_gossip_sync_timestamp);
+ }
+
/// Clears the `NodeAnnouncementInfo` field for all nodes in the `NetworkGraph` for testing
/// purposes.
#[cfg(test)]
assert!(<NetworkGraph>::read(&mut io::Cursor::new(&w.0)).unwrap() == network_graph);
}
+ #[test]
+ fn network_graph_tlv_serialization() {
+ let mut network_graph = create_network_graph();
+ network_graph.set_last_rapid_gossip_sync_timestamp(42);
+
+ let mut w = test_utils::TestVecWriter(Vec::new());
+ network_graph.write(&mut w).unwrap();
+ let reassembled_network_graph: NetworkGraph = Readable::read(&mut io::Cursor::new(&w.0)).unwrap();
+ assert!(reassembled_network_graph == network_graph);
+ assert_eq!(reassembled_network_graph.get_last_rapid_gossip_sync_timestamp().unwrap(), 42);
+ }
+
#[test]
#[cfg(feature = "std")]
fn calling_sync_routing_table() {