]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Test InvoicePayer in BackgroundProcessor
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 24 Aug 2021 04:56:59 +0000 (23:56 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Wed, 27 Oct 2021 19:31:20 +0000 (14:31 -0500)
Proof of concept showing InvoicePayer can be used with an
Arc<ChannelManager> passed to BackgroundProcessor. Likely do not need to
merge this commit.

lightning-background-processor/Cargo.toml
lightning-background-processor/src/lib.rs

index 4e45bb2a83c11d58b6528c59cfef3208d07e86ac..d868f14db74883bce4c1997cfbfd4da170fd8018 100644 (file)
@@ -16,4 +16,4 @@ lightning-persister = { version = "0.0.102", path = "../lightning-persister" }
 
 [dev-dependencies]
 lightning = { version = "0.0.102", path = "../lightning", features = ["_test_utils"] }
-
+lightning-invoice = { version = "0.10.0", path = "../lightning-invoice" }
index 16c5eb4f9393193ba9136fd645661625946359e6..c4f40e933ed782152bdaaefaf45b9655594a162b 100644 (file)
@@ -174,7 +174,7 @@ impl BackgroundProcessor {
                Descriptor: 'static + SocketDescriptor + Send + Sync,
                CMH: 'static + Deref + Send + Sync,
                RMH: 'static + Deref + Send + Sync,
-               EH: 'static + EventHandler + Send + Sync,
+               EH: 'static + EventHandler + Send,
                CMP: 'static + Send + ChannelManagerPersister<Signer, CW, T, K, F, L>,
                M: 'static + Deref<Target = ChainMonitor<Signer, CF, T, F, L, P>> + Send + Sync,
                CM: 'static + Deref<Target = ChannelManager<Signer, CW, T, K, F, L>> + Send + Sync,
@@ -317,6 +317,8 @@ mod tests {
        use lightning::util::events::{Event, MessageSendEventsProvider, MessageSendEvent};
        use lightning::util::ser::Writeable;
        use lightning::util::test_utils;
+       use lightning_invoice::payment::{InvoicePayer, RetryAttempts};
+       use lightning_invoice::utils::DefaultRouter;
        use lightning_persister::FilesystemPersister;
        use std::fs;
        use std::path::PathBuf;
@@ -622,4 +624,20 @@ mod tests {
 
                assert!(bg_processor.stop().is_ok());
        }
+
+       #[test]
+       fn test_invoice_payer() {
+               let nodes = create_nodes(2, "test_invoice_payer".to_string());
+
+               // Initiate the background processors to watch each node.
+               let data_dir = nodes[0].persister.get_data_dir();
+               let persister = move |node: &ChannelManager<InMemorySigner, Arc<ChainMonitor>, Arc<test_utils::TestBroadcaster>, Arc<KeysManager>, Arc<test_utils::TestFeeEstimator>, Arc<test_utils::TestLogger>>| FilesystemPersister::persist_manager(data_dir.clone(), node);
+               let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()));
+               let router = DefaultRouter::new(network_graph, Arc::clone(&nodes[0].logger));
+               let scorer = Scorer::default();
+               let invoice_payer = Arc::new(InvoicePayer::new(Arc::clone(&nodes[0].node), router, scorer, Arc::clone(&nodes[0].logger), |_: &_| {}, RetryAttempts(2)));
+               let event_handler = Arc::clone(&invoice_payer);
+               let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone());
+               assert!(bg_processor.stop().is_ok());
+       }
 }