From: Matt Corallo Date: Thu, 1 Apr 2021 00:16:21 +0000 (-0400) Subject: Also benchmark sending funds with a FilesystemPersister X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=79b3e5d6dfabf1e4fd3fb79589b6afa7d4a33d0d;p=rust-lightning Also benchmark sending funds with a FilesystemPersister --- diff --git a/lightning-persister/Cargo.toml b/lightning-persister/Cargo.toml index 0a9821f14..a6e7242b0 100644 --- a/lightning-persister/Cargo.toml +++ b/lightning-persister/Cargo.toml @@ -8,6 +8,9 @@ description = """ Utilities to manage Rust-Lightning channel data persistence and retrieval. """ +[features] +unstable = ["lightning/unstable"] + [dependencies] bitcoin = "0.26" lightning = { version = "0.0.13", path = "../lightning" } diff --git a/lightning-persister/src/lib.rs b/lightning-persister/src/lib.rs index afcda8033..44586422c 100644 --- a/lightning-persister/src/lib.rs +++ b/lightning-persister/src/lib.rs @@ -3,6 +3,9 @@ #![deny(broken_intra_doc_links)] #![deny(missing_docs)] +#![cfg_attr(all(test, feature = "unstable"), feature(test))] +#[cfg(all(test, feature = "unstable"))] extern crate test; + mod util; extern crate lightning; @@ -330,3 +333,15 @@ mod tests { added_monitors.clear(); } } + +#[cfg(all(test, feature = "unstable"))] +pub mod bench { + use test::Bencher; + + #[bench] + fn bench_sends(bench: &mut Bencher) { + let persister_a = super::FilesystemPersister::new("bench_filesystem_persister_a".to_string()); + let persister_b = super::FilesystemPersister::new("bench_filesystem_persister_b".to_string()); + lightning::ln::channelmanager::bench::bench_two_sends(bench, persister_a, persister_b); + } +} diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 2d764c8b7..9bf947045 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -28,8 +28,8 @@ #![allow(bare_trait_objects)] #![allow(ellipsis_inclusive_range_patterns)] -#![cfg_attr(all(test, feature = "unstable"), feature(test))] -#[cfg(all(test, feature = "unstable"))] extern crate test; +#![cfg_attr(all(any(test, feature = "_test_utils"), feature = "unstable"), feature(test))] +#[cfg(all(any(test, feature = "_test_utils"), feature = "unstable"))] extern crate test; extern crate bitcoin; #[cfg(any(test, feature = "_test_utils"))] extern crate hex; diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 848846b8c..19fdd97a6 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -4408,10 +4408,11 @@ mod tests { } } -#[cfg(all(test, feature = "unstable"))] -mod benches { +#[cfg(all(any(test, feature = "_test_utils"), feature = "unstable"))] +pub mod bench { use chain::Listen; use chain::chainmonitor::ChainMonitor; + use chain::channelmonitor::Persist; use chain::keysinterface::{KeysManager, InMemorySigner}; use chain::transaction::OutPoint; use ln::channelmanager::{ChainParameters, ChannelManager, PaymentHash, PaymentPreimage}; @@ -4432,17 +4433,22 @@ mod benches { use test::Bencher; - struct NodeHolder<'a> { + struct NodeHolder<'a, P: Persist> { node: &'a ChannelManager, + &'a test_utils::TestLogger, &'a P>, &'a test_utils::TestBroadcaster, &'a KeysManager, &'a test_utils::TestFeeEstimator, &'a test_utils::TestLogger> } + #[cfg(test)] #[bench] fn bench_sends(bench: &mut Bencher) { + bench_two_sends(bench, test_utils::TestPersister::new(), test_utils::TestPersister::new()); + } + + pub fn bench_two_sends>(bench: &mut Bencher, persister_a: P, persister_b: P) { // Do a simple benchmark of sending a payment back and forth between two nodes. // Note that this is unrealistic as each payment send will require at least two fsync // calls per node. @@ -4456,7 +4462,6 @@ mod benches { config.own_channel_config.minimum_depth = 1; let logger_a = test_utils::TestLogger::with_id("node a".to_owned()); - let persister_a = test_utils::TestPersister::new(); let chain_monitor_a = ChainMonitor::new(None, &tx_broadcaster, &logger_a, &fee_estimator, &persister_a); let seed_a = [1u8; 32]; let keys_manager_a = KeysManager::new(&seed_a, 42, 42); @@ -4468,7 +4473,6 @@ mod benches { let node_a_holder = NodeHolder { node: &node_a }; let logger_b = test_utils::TestLogger::with_id("node a".to_owned()); - let persister_b = test_utils::TestPersister::new(); let chain_monitor_b = ChainMonitor::new(None, &tx_broadcaster, &logger_a, &fee_estimator, &persister_b); let seed_b = [2u8; 32]; let keys_manager_b = KeysManager::new(&seed_b, 42, 42); diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 9adfeb292..8021a4ace 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -866,7 +866,6 @@ macro_rules! expect_pending_htlcs_forwardable { }} } -#[cfg(test)] macro_rules! expect_payment_received { ($node: expr, $expected_payment_hash: expr, $expected_recv_value: expr) => { let events = $node.node.get_and_clear_pending_events();