X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=inline;f=lightning-rapid-gossip-sync%2Fsrc%2Flib.rs;h=70758e1fe07e6a5ae0f5a430ac374ee3ae5708be;hb=8c6cb9953a3b00ce3da25fbdfd8ada0ec48fc63f;hp=278cede397411720415b89d20a6c9ccaecb1160d;hpb=574870e9f8faf44244dbfec2d146eb69e245d660;p=rust-lightning diff --git a/lightning-rapid-gossip-sync/src/lib.rs b/lightning-rapid-gossip-sync/src/lib.rs index 278cede3..70758e1f 100644 --- a/lightning-rapid-gossip-sync/src/lib.rs +++ b/lightning-rapid-gossip-sync/src/lib.rs @@ -1,6 +1,9 @@ +// Prefix these with `rustdoc::` when we update our MSRV to be >= 1.52 to remove warnings. +#![deny(broken_intra_doc_links)] +#![deny(private_intra_doc_links)] + #![deny(missing_docs)] #![deny(unsafe_code)] -#![deny(broken_intra_doc_links)] #![deny(non_upper_case_globals)] #![deny(non_camel_case_types)] #![deny(non_snake_case)] @@ -32,8 +35,15 @@ //! use lightning::routing::gossip::NetworkGraph; //! use lightning_rapid_gossip_sync::RapidGossipSync; //! +//! # use lightning::util::logger::{Logger, Record}; +//! # struct FakeLogger {} +//! # impl Logger for FakeLogger { +//! # fn log(&self, record: &Record) { unimplemented!() } +//! # } +//! # let logger = FakeLogger {}; +//! //! let block_hash = genesis_block(Network::Bitcoin).header.block_hash(); -//! let network_graph = NetworkGraph::new(block_hash); +//! let network_graph = NetworkGraph::new(block_hash, &logger); //! let rapid_sync = RapidGossipSync::new(&network_graph); //! let new_last_sync_timestamp_result = rapid_sync.sync_network_graph_with_file_path("./rapid_sync.lngossip"); //! ``` @@ -63,6 +73,7 @@ use std::ops::Deref; use std::sync::atomic::{AtomicBool, Ordering}; use lightning::routing::gossip::NetworkGraph; +use lightning::util::logger::Logger; use crate::error::GraphSyncError; @@ -76,12 +87,13 @@ pub mod processing; /// See [crate-level documentation] for usage. /// /// [crate-level documentation]: crate -pub struct RapidGossipSync> { +pub struct RapidGossipSync>, L: Deref> +where L::Target: Logger { network_graph: NG, is_initial_sync_complete: AtomicBool } -impl> RapidGossipSync { +impl>, L: Deref> RapidGossipSync where L::Target: Logger { /// Instantiate a new [`RapidGossipSync`] instance pub fn new(network_graph: NG) -> Self { Self { @@ -128,6 +140,7 @@ mod tests { use lightning::ln::msgs::DecodeError; use lightning::routing::gossip::NetworkGraph; + use lightning::util::test_utils::TestLogger; use crate::RapidGossipSync; #[test] @@ -187,7 +200,8 @@ mod tests { let graph_sync_test_file = sync_test.get_test_file_path(); let block_hash = genesis_block(Network::Bitcoin).block_hash(); - let network_graph = NetworkGraph::new(block_hash); + let logger = TestLogger::new(); + let network_graph = NetworkGraph::new(block_hash, &logger); assert_eq!(network_graph.read_only().channels().len(), 0); @@ -219,7 +233,8 @@ mod tests { #[test] fn measure_native_read_from_file() { let block_hash = genesis_block(Network::Bitcoin).block_hash(); - let network_graph = NetworkGraph::new(block_hash); + let logger = TestLogger::new(); + let network_graph = NetworkGraph::new(block_hash, &logger); assert_eq!(network_graph.read_only().channels().len(), 0); @@ -228,7 +243,7 @@ mod tests { 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); + 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-285cb27df79-2022-07-21.bin\n\n{:?}", io_error); #[cfg(not(require_route_graph_test))] { println!("{}", error_string); @@ -254,14 +269,16 @@ pub mod bench { use lightning::ln::msgs::DecodeError; use lightning::routing::gossip::NetworkGraph; + use lightning::util::test_utils::TestLogger; use crate::RapidGossipSync; #[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); + let network_graph = NetworkGraph::new(block_hash, &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 {