X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-rapid-gossip-sync%2Fsrc%2Flib.rs;h=00aac9fd35873a8b31a218c2fa692a1664302c9a;hb=85b573ddad70f3c5ee36e0992d587842af507a8d;hp=ff0e481b39711cdb41166f2627d23d322838064a;hpb=2f36c921b68ade77e7ef097ce33bf3546e42904c;p=rust-lightning diff --git a/lightning-rapid-gossip-sync/src/lib.rs b/lightning-rapid-gossip-sync/src/lib.rs index ff0e481b..00aac9fd 100644 --- a/lightning-rapid-gossip-sync/src/lib.rs +++ b/lightning-rapid-gossip-sync/src/lib.rs @@ -53,9 +53,8 @@ //! # } //! # let logger = FakeLogger {}; //! -//! let block_hash = genesis_block(Network::Bitcoin).header.block_hash(); -//! let network_graph = NetworkGraph::new(block_hash, &logger); -//! let rapid_sync = RapidGossipSync::new(&network_graph); +//! let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); +//! let rapid_sync = RapidGossipSync::new(&network_graph, &logger); //! let snapshot_contents: &[u8] = &[0; 0]; //! let new_last_sync_timestamp_result = rapid_sync.update_network_graph(snapshot_contents); //! ``` @@ -95,14 +94,16 @@ mod processing; pub struct RapidGossipSync>, L: Deref> where L::Target: Logger { network_graph: NG, + logger: L, is_initial_sync_complete: AtomicBool } impl>, L: Deref> RapidGossipSync where L::Target: Logger { /// Instantiate a new [`RapidGossipSync`] instance. - pub fn new(network_graph: NG) -> Self { + pub fn new(network_graph: NG, logger: L) -> Self { Self { network_graph, + logger, is_initial_sync_complete: AtomicBool::new(false) } } @@ -161,7 +162,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; @@ -183,18 +183,17 @@ mod tests { fs::create_dir_all(graph_sync_test_directory).unwrap(); let graph_sync_test_file = test.get_test_file_path(); - fs::write(&graph_sync_test_file, valid_response).unwrap(); + fs::write(graph_sync_test_file, valid_response).unwrap(); test } + fn get_test_directory(&self) -> String { - let graph_sync_test_directory = self.directory.clone() + "/graph-sync-tests"; - graph_sync_test_directory + self.directory.clone() + "/graph-sync-tests" } + fn get_test_file_path(&self) -> String { - let graph_sync_test_directory = self.get_test_directory(); - let graph_sync_test_file = graph_sync_test_directory.to_owned() + "/test_data.lngossip"; - graph_sync_test_file + self.get_test_directory() + "/test_data.lngossip" } } @@ -225,13 +224,12 @@ 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); - let rapid_sync = RapidGossipSync::new(&network_graph); + let rapid_sync = RapidGossipSync::new(&network_graph, &logger); let sync_result = rapid_sync.sync_network_graph_with_file_path(&graph_sync_test_file); if sync_result.is_err() { @@ -258,13 +256,12 @@ 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); - let rapid_sync = RapidGossipSync::new(&network_graph); + let rapid_sync = RapidGossipSync::new(&network_graph, &logger); let start = std::time::Instant::now(); let sync_result = rapid_sync .sync_network_graph_with_file_path("./res/full_graph.lngossip"); @@ -290,7 +287,6 @@ mod tests { pub mod bench { use test::Bencher; - use bitcoin::blockdata::constants::genesis_block; use bitcoin::Network; use lightning::ln::msgs::DecodeError; @@ -301,11 +297,10 @@ 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 rapid_sync = RapidGossipSync::new(&network_graph); + let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); + let rapid_sync = RapidGossipSync::new(&network_graph, &logger); 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 { let error_string = format!("Input file lightning-rapid-gossip-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin\n\n{:?}", io_error);