Skip to content

Commit

Permalink
Test PaymentRetryHandler in BackgroundProcessor
Browse files Browse the repository at this point in the history
Proof of concept showing PaymentRetryHandler can be used with an
Arc<ChannelManager> passed to BackgroundProcessor. Likely do not need to
merge this commit.
  • Loading branch information
jkczyz committed Aug 24, 2021
1 parent 9ea1d25 commit 910814f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions lightning-background-processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = "2018"
[dependencies]
bitcoin = "0.27"
lightning = { version = "0.0.99", path = "../lightning", features = ["allow_wallclock_use"] }
lightning-invoice = { version = "0.7.0", path = "../lightning-invoice" }
lightning-persister = { version = "0.0.99", path = "../lightning-persister" }

[dev-dependencies]
Expand Down
20 changes: 19 additions & 1 deletion lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,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,
Expand Down Expand Up @@ -248,10 +248,13 @@ mod tests {
use lightning::ln::features::InitFeatures;
use lightning::ln::msgs::{ChannelMessageHandler, Init};
use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor};
use lightning::routing::network_graph::NetworkGraph;
use lightning::util::config::UserConfig;
use lightning::util::events::{Event, MessageSendEventsProvider, MessageSendEvent};
use lightning::util::ser::Writeable;
use lightning::util::test_utils;
use lightning_invoice::payment::InvoicePayer;
use lightning_invoice::utils::DefaultRouter;
use lightning_persister::FilesystemPersister;
use std::fs;
use std::path::PathBuf;
Expand Down Expand Up @@ -552,4 +555,19 @@ 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 router = DefaultRouter::new(Arc::clone(&nodes[0].logger));
let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()));
let event_handler = |_: &_| {};
let (_, event_handler) = InvoicePayer::new(Arc::clone(&nodes[0].node), router, network_graph, Arc::clone(&nodes[0].logger), event_handler);
let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone());
assert!(bg_processor.stop().is_ok());
}
}

0 comments on commit 910814f

Please sign in to comment.