Skip to content

Commit 4c64c33

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

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lightning-background-processor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ edition = "2018"
1212
[dependencies]
1313
bitcoin = "0.27"
1414
lightning = { version = "0.0.100", path = "../lightning", features = ["allow_wallclock_use"] }
15+
lightning-invoice = { version = "0.8.0", path = "../lightning-invoice" }
1516
lightning-persister = { version = "0.0.100", path = "../lightning-persister" }
1617

1718
[dev-dependencies]

lightning-background-processor/src/lib.rs

Lines changed: 18 additions & 1 deletion
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)