X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-rapid-gossip-sync%2Fsrc%2Flib.rs;h=3bceb2e28e9239c0a7e8b34790275d4f51f064e2;hb=226c43cc931c8a4c141567606e72712a5c6f378b;hp=06ce7eb2075574df38c2b9cbf44813235e1fba1c;hpb=3852d528018f66eaf87dc846d919228e8339248b;p=rust-lightning diff --git a/lightning-rapid-gossip-sync/src/lib.rs b/lightning-rapid-gossip-sync/src/lib.rs index 06ce7eb2..3bceb2e2 100644 --- a/lightning-rapid-gossip-sync/src/lib.rs +++ b/lightning-rapid-gossip-sync/src/lib.rs @@ -53,8 +53,7 @@ //! # } //! # let logger = FakeLogger {}; //! -//! let block_hash = genesis_block(Network::Bitcoin).header.block_hash(); -//! let network_graph = NetworkGraph::new(block_hash, &logger); +//! let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); //! let rapid_sync = RapidGossipSync::new(&network_graph); //! let snapshot_contents: &[u8] = &[0; 0]; //! let new_last_sync_timestamp_result = rapid_sync.update_network_graph(snapshot_contents); @@ -126,14 +125,22 @@ impl>, L: Deref> RapidGossipSync where L /// Update network graph from binary data. /// Returns the last sync timestamp to be used the next time rapid sync data is queried. /// - /// `network_graph`: network graph to be updated - /// /// `update_data`: `&[u8]` binary stream that comprises the update data pub fn update_network_graph(&self, update_data: &[u8]) -> Result { let mut read_cursor = io::Cursor::new(update_data); self.update_network_graph_from_byte_stream(&mut read_cursor) } + /// Update network graph from binary data. + /// Returns the last sync timestamp to be used the next time rapid sync data is queried. + /// + /// `update_data`: `&[u8]` binary stream that comprises the update data + /// `current_time_unix`: `Option` optional current timestamp to verify data age + pub fn update_network_graph_no_std(&self, update_data: &[u8], current_time_unix: Option) -> Result { + let mut read_cursor = io::Cursor::new(update_data); + self.update_network_graph_from_byte_stream_no_std(&mut read_cursor, current_time_unix) + } + /// Gets a reference to the underlying [`NetworkGraph`] which was provided in /// [`RapidGossipSync::new`]. /// @@ -153,7 +160,6 @@ impl>, L: Deref> RapidGossipSync where L mod tests { use std::fs; - use bitcoin::blockdata::constants::genesis_block; use bitcoin::Network; use lightning::ln::msgs::DecodeError; @@ -217,9 +223,8 @@ mod tests { let sync_test = FileSyncTest::new(tmp_directory, &valid_response); let graph_sync_test_file = sync_test.get_test_file_path(); - let block_hash = genesis_block(Network::Bitcoin).block_hash(); let logger = TestLogger::new(); - let network_graph = NetworkGraph::new(block_hash, &logger); + let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); assert_eq!(network_graph.read_only().channels().len(), 0); @@ -250,9 +255,8 @@ mod tests { #[test] fn measure_native_read_from_file() { - let block_hash = genesis_block(Network::Bitcoin).block_hash(); let logger = TestLogger::new(); - let network_graph = NetworkGraph::new(block_hash, &logger); + let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); assert_eq!(network_graph.read_only().channels().len(), 0); @@ -282,7 +286,6 @@ mod tests { pub mod bench { use test::Bencher; - use bitcoin::blockdata::constants::genesis_block; use bitcoin::Network; use lightning::ln::msgs::DecodeError; @@ -293,10 +296,9 @@ pub mod bench { #[bench] fn bench_reading_full_graph_from_file(b: &mut Bencher) { - let block_hash = genesis_block(Network::Bitcoin).block_hash(); let logger = TestLogger::new(); b.iter(|| { - let network_graph = NetworkGraph::new(block_hash, &logger); + let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); let rapid_sync = RapidGossipSync::new(&network_graph); let sync_result = rapid_sync.sync_network_graph_with_file_path("./res/full_graph.lngossip"); if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {