Skip to content

Commit 4caedcf

Browse files
committed
Test InvoicePayer in BackgroundProcessor
Proof of concept showing InvoicePayer can be used with an Arc<ChannelManager> passed to BackgroundProcessor. Likely do not need to merge this commit.
1 parent 964f5c7 commit 4caedcf

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lightning-background-processor/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ lightning-persister = { version = "0.0.100", path = "../lightning-persister" }
1616

1717
[dev-dependencies]
1818
lightning = { version = "0.0.100", path = "../lightning", features = ["_test_utils"] }
19-
19+
lightning-invoice = { version = "0.8.0", path = "../lightning-invoice" }

lightning-background-processor/src/lib.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl BackgroundProcessor {
173173
Descriptor: 'static + SocketDescriptor + Send + Sync,
174174
CMH: 'static + Deref + Send + Sync,
175175
RMH: 'static + Deref + Send + Sync,
176-
EH: 'static + EventHandler + Send + Sync,
176+
EH: 'static + EventHandler + Send,
177177
CMP: 'static + Send + ChannelManagerPersister<Signer, CW, T, K, F, L>,
178178
M: 'static + Deref<Target = ChainMonitor<Signer, CF, T, F, L, P>> + Send + Sync,
179179
CM: 'static + Deref<Target = ChannelManager<Signer, CW, T, K, F, L>> + Send + Sync,
@@ -315,6 +315,8 @@ mod tests {
315315
use lightning::util::events::{Event, MessageSendEventsProvider, MessageSendEvent};
316316
use lightning::util::ser::Writeable;
317317
use lightning::util::test_utils;
318+
use lightning_invoice::payment::InvoicePayer;
319+
use lightning_invoice::utils::DefaultRouter;
318320
use lightning_persister::FilesystemPersister;
319321
use std::fs;
320322
use std::path::PathBuf;
@@ -619,4 +621,19 @@ mod tests {
619621

620622
assert!(bg_processor.stop().is_ok());
621623
}
624+
625+
#[test]
626+
fn test_invoice_payer() {
627+
let nodes = create_nodes(2, "test_invoice_payer".to_string());
628+
629+
// Initiate the background processors to watch each node.
630+
let data_dir = nodes[0].persister.get_data_dir();
631+
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);
632+
let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()));
633+
let router = DefaultRouter::new(network_graph, Arc::clone(&nodes[0].logger));
634+
let invoice_payer = Arc::new(InvoicePayer::new(Arc::clone(&nodes[0].node), router, Arc::clone(&nodes[0].logger), |_: &_| {}).with_retry_attempts(2));
635+
let event_handler = Arc::clone(&invoice_payer);
636+
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());
637+
assert!(bg_processor.stop().is_ok());
638+
}
622639
}

0 commit comments

Comments
 (0)