X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-background-processor%2Fsrc%2Flib.rs;h=21e9d419471ee6cc5fb619a0480642600096513c;hb=1ceb41e08b2d76b23d2505a10a88db8d840895ca;hp=79a8037660c692d7d360799ff147d4cc31878d17;hpb=2bc55b22d3a44130a08f21b364b95807d32e7197;p=rust-lightning diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 79a80376..21e9d419 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -1057,7 +1057,11 @@ mod tests { let events = $node_a.node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); let (temporary_channel_id, tx) = handle_funding_generation_ready!(events[0], $channel_value); - end_open_channel!($node_a, $node_b, temporary_channel_id, tx); + $node_a.node.funding_transaction_generated(&temporary_channel_id, &$node_b.node.get_our_node_id(), tx.clone()).unwrap(); + $node_b.node.handle_funding_created(&$node_a.node.get_our_node_id(), &get_event_msg!($node_a, MessageSendEvent::SendFundingCreated, $node_b.node.get_our_node_id())); + get_event!($node_b, Event::ChannelPending); + $node_a.node.handle_funding_signed(&$node_b.node.get_our_node_id(), &get_event_msg!($node_b, MessageSendEvent::SendFundingSigned, $node_a.node.get_our_node_id())); + get_event!($node_a, Event::ChannelPending); tx }} } @@ -1087,17 +1091,6 @@ mod tests { }} } - macro_rules! end_open_channel { - ($node_a: expr, $node_b: expr, $temporary_channel_id: expr, $tx: expr) => {{ - $node_a.node.funding_transaction_generated(&$temporary_channel_id, &$node_b.node.get_our_node_id(), $tx.clone()).unwrap(); - $node_b.node.handle_funding_created(&$node_a.node.get_our_node_id(), &get_event_msg!($node_a, MessageSendEvent::SendFundingCreated, $node_b.node.get_our_node_id())); - get_event!($node_b, Event::ChannelPending); - - $node_a.node.handle_funding_signed(&$node_b.node.get_our_node_id(), &get_event_msg!($node_b, MessageSendEvent::SendFundingSigned, $node_a.node.get_our_node_id())); - get_event!($node_a, Event::ChannelPending); - }} - } - fn confirm_transaction_depth(node: &mut Node, tx: &Transaction, depth: u32) { for i in 1..=depth { let prev_blockhash = node.best_block.block_hash(); @@ -1237,6 +1230,35 @@ mod tests { } } + #[tokio::test] + #[cfg(feature = "futures")] + async fn test_channel_manager_persist_error_async() { + // Test that if we encounter an error during manager persistence, the thread panics. + let nodes = create_nodes(2, "test_persist_error_sync".to_string()); + open_channel!(nodes[0], nodes[1], 100000); + + let data_dir = nodes[0].persister.get_data_dir(); + let persister = Arc::new(Persister::new(data_dir).with_manager_error(std::io::ErrorKind::Other, "test")); + + let bp_future = super::process_events_async( + persister, |_: _| {async {}}, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), + nodes[0].rapid_gossip_sync(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), + Some(nodes[0].scorer.clone()), move |dur: Duration| { + Box::pin(async move { + tokio::time::sleep(dur).await; + false // Never exit + }) + }, false, + ); + match bp_future.await { + Ok(_) => panic!("Expected error persisting manager"), + Err(e) => { + assert_eq!(e.kind(), std::io::ErrorKind::Other); + assert_eq!(e.get_ref().unwrap().to_string(), "test"); + }, + } + } + #[test] fn test_network_graph_persist_error() { // Test that if we encounter an error during network graph persistence, an error gets returned. @@ -1281,9 +1303,11 @@ mod tests { let persister = Arc::new(Persister::new(data_dir.clone())); // Set up a background event handler for FundingGenerationReady events. - let (sender, receiver) = std::sync::mpsc::sync_channel(1); + let (funding_generation_send, funding_generation_recv) = std::sync::mpsc::sync_channel(1); + let (channel_pending_send, channel_pending_recv) = std::sync::mpsc::sync_channel(1); let event_handler = move |event: Event| match event { - Event::FundingGenerationReady { .. } => sender.send(handle_funding_generation_ready!(event, channel_value)).unwrap(), + Event::FundingGenerationReady { .. } => funding_generation_send.send(handle_funding_generation_ready!(event, channel_value)).unwrap(), + Event::ChannelPending { .. } => channel_pending_send.send(()).unwrap(), Event::ChannelReady { .. } => {}, _ => panic!("Unexpected event: {:?}", event), }; @@ -1292,10 +1316,15 @@ mod tests { // Open a channel and check that the FundingGenerationReady event was handled. begin_open_channel!(nodes[0], nodes[1], channel_value); - let (temporary_channel_id, funding_tx) = receiver + let (temporary_channel_id, funding_tx) = funding_generation_recv .recv_timeout(Duration::from_secs(EVENT_DEADLINE)) .expect("FundingGenerationReady not handled within deadline"); - end_open_channel!(nodes[0], nodes[1], temporary_channel_id, funding_tx); + nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), funding_tx.clone()).unwrap(); + nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id())); + get_event!(nodes[1], Event::ChannelPending); + nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id())); + let _ = channel_pending_recv.recv_timeout(Duration::from_secs(EVENT_DEADLINE)) + .expect("ChannelPending not handled within deadline"); // Confirm the funding transaction. confirm_transaction(&mut nodes[0], &funding_tx);