]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Also benchmark sending funds with a FilesystemPersister
authorMatt Corallo <git@bluematt.me>
Thu, 1 Apr 2021 00:16:21 +0000 (20:16 -0400)
committerMatt Corallo <git@bluematt.me>
Thu, 1 Apr 2021 19:15:36 +0000 (15:15 -0400)
lightning-persister/Cargo.toml
lightning-persister/src/lib.rs
lightning/src/lib.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs

index 0a9821f14cfc86768a57f48b1e31af2e80c07868..a6e7242b0cb9c13e0eae26ea6bb43063870eb8c1 100644 (file)
@@ -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" }
index afcda803397597f12d0d3a597dcf7bff44b3c248..44586422cfb48cd16131524770e62e3e69a67a4d 100644 (file)
@@ -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);
+       }
+}
index 2d764c8b71b1355200ca062087fcb22044b5c24b..9bf9470458f8310f005788769d781b74055fd835 100644 (file)
@@ -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;
index 848846b8c469647bd878cc30468e338c0b1476d0..19fdd97a65a586fabb9a22b2f482dca995facf97 100644 (file)
@@ -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<InMemorySigner>> {
                node: &'a ChannelManager<InMemorySigner,
                        &'a ChainMonitor<InMemorySigner, &'a test_utils::TestChainSource,
                                &'a test_utils::TestBroadcaster, &'a test_utils::TestFeeEstimator,
-                               &'a test_utils::TestLogger, &'a test_utils::TestPersister>,
+                               &'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<P: Persist<InMemorySigner>>(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);
index 9adfeb292fd66e74db9037e88b117298dedb04ef..3c641dd74af4114a05b6c5ec032d810ac40ec836 100644 (file)
@@ -866,7 +866,7 @@ macro_rules! expect_pending_htlcs_forwardable {
        }}
 }
 
-#[cfg(test)]
+#[cfg(any(test, feature = "unstable"))]
 macro_rules! expect_payment_received {
        ($node: expr, $expected_payment_hash: expr, $expected_recv_value: expr) => {
                let events = $node.node.get_and_clear_pending_events();