X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-rapid-gossip-sync%2Fsrc%2Flib.rs;h=c15eedabbe19b3a8f70d6a15d64c1d2ca705ae6c;hb=37150b4d697f723f278b6cf3f63892df272b9aa5;hp=c8f140cc18955d8225bbf300fcda2aee6ddae267;hpb=2e15df730ff5668ee37678bf7c355b60cdc6cbe8;p=rust-lightning diff --git a/lightning-rapid-gossip-sync/src/lib.rs b/lightning-rapid-gossip-sync/src/lib.rs index c8f140cc..c15eedab 100644 --- a/lightning-rapid-gossip-sync/src/lib.rs +++ b/lightning-rapid-gossip-sync/src/lib.rs @@ -49,7 +49,7 @@ //! # use lightning::util::logger::{Logger, Record}; //! # struct FakeLogger {} //! # impl Logger for FakeLogger { -//! # fn log(&self, record: &Record) { } +//! # fn log(&self, record: Record) { } //! # } //! # let logger = FakeLogger {}; //! @@ -64,10 +64,7 @@ #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] -// Allow and import test features for benching -#![cfg_attr(all(test, feature = "_bench_unstable"), feature(test))] -#[cfg(all(test, feature = "_bench_unstable"))] -extern crate test; +#[cfg(ldk_bench)] extern crate criterion; #[cfg(not(feature = "std"))] extern crate alloc; @@ -287,36 +284,42 @@ mod tests { } } -#[cfg(all(test, feature = "_bench_unstable"))] +#[cfg(ldk_bench)] +/// Benches pub mod bench { - use test::Bencher; - use bitcoin::Network; - use lightning::ln::msgs::DecodeError; + use criterion::Criterion; + + use std::fs; + 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) { + /// Bench! + pub fn bench_reading_full_graph_from_file(b: &mut Criterion) { let logger = TestLogger::new(); - b.iter(|| { + b.bench_function("read_full_graph_from_rgs", |b| b.iter(|| { 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); - #[cfg(not(require_route_graph_test))] - { - println!("{}", error_string); - return; - } - #[cfg(require_route_graph_test)] - panic!("{}", error_string); - } - assert!(sync_result.is_ok()) - }); + let mut file = match fs::read("../lightning-rapid-gossip-sync/res/full_graph.lngossip") { + Ok(f) => f, + Err(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-bc08df7542-2022-05-05.bin\n\n{:?}", + io_error); + #[cfg(not(require_route_graph_test))] + { + println!("{}", error_string); + return; + } + #[cfg(require_route_graph_test)] + panic!("{}", error_string); + }, + }; + rapid_sync.update_network_graph_no_std(&mut file, None).unwrap(); + })); } }