X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Fchanmon_update_fail_tests.rs;h=5ff531cb9dcce32575ed7391ee70262341830d0f;hb=refs%2Fheads%2F2019-07-more-chanmon-fuzz;hp=fc481f8aac7bb8e5b3326e12e5f8d5dc83ddb895;hpb=a138a9af010d5c6e80caaae56a3116051f3df653;p=rust-lightning diff --git a/src/ln/chanmon_update_fail_tests.rs b/src/ln/chanmon_update_fail_tests.rs index fc481f8a..5ff531cb 100644 --- a/src/ln/chanmon_update_fail_tests.rs +++ b/src/ln/chanmon_update_fail_tests.rs @@ -6,22 +6,20 @@ use ln::channelmanager::{RAACommitmentOrder, PaymentPreimage, PaymentHash}; use ln::channelmonitor::ChannelMonitorUpdateErr; use ln::msgs; -use ln::msgs::ChannelMessageHandler; +use ln::msgs::{ChannelMessageHandler, LocalFeatures}; use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider}; use util::errors::APIError; use bitcoin_hashes::sha256::Hash as Sha256; use bitcoin_hashes::Hash; -use std::time::Instant; - use ln::functional_test_utils::*; #[test] fn test_simple_monitor_permanent_update_fail() { // Test that we handle a simple permanent monitor update failure - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); let (_, payment_hash_1) = get_payment_preimage_hash!(nodes[0]); @@ -50,8 +48,8 @@ fn test_simple_monitor_permanent_update_fail() { fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) { // Test that we can recover from a simple temporary monitor update failure optionally with // a disconnect in between - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); let (payment_preimage_1, payment_hash_1) = get_payment_preimage_hash!(nodes[0]); @@ -149,8 +147,8 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { // * We then walk through more message exchanges to get the original update_add_htlc // through, swapping message ordering based on disconnect_count & 8 and optionally // disconnect/reconnecting based on disconnect_count. - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000); @@ -475,8 +473,8 @@ fn test_monitor_temporary_update_fail_c() { #[test] fn test_monitor_update_fail_cs() { // Tests handling of a monitor update failure when processing an incoming commitment_signed - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); let (payment_preimage, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -554,8 +552,8 @@ fn test_monitor_update_fail_no_rebroadcast() { // Tests handling of a monitor update failure when no message rebroadcasting on // test_restore_channel_monitor() is required. Backported from // chanmon_fail_consistency fuzz tests. - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); let (payment_preimage_1, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -596,8 +594,8 @@ fn test_monitor_update_fail_no_rebroadcast() { fn test_monitor_update_raa_while_paused() { // Tests handling of an RAA while monitor updating has already been marked failed. // Backported from chanmon_fail_consistency fuzz tests as this used to be broken. - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); send_payment(&nodes[0], &[&nodes[1]], 5000000); @@ -663,9 +661,9 @@ fn test_monitor_update_raa_while_paused() { fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { // Tests handling of a monitor update failure when processing an incoming RAA - let mut nodes = create_network(3); - create_announced_chan_between_nodes(&nodes, 0, 1); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2); + let mut nodes = create_network(3, &[None, None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, LocalFeatures::new(), LocalFeatures::new()); // Rebalance a bit so that we can send backwards from 2 to 1. send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000); @@ -674,7 +672,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { let (_, payment_hash_1) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000); // Fail the payment backwards, failing the monitor update on nodes[1]'s receipt of the RAA - assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1, 0)); + assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1)); expect_pending_htlcs_forwardable!(nodes[2]); check_added_monitors!(nodes[2], 1); @@ -916,9 +914,9 @@ fn test_monitor_update_fail_reestablish() { // Simple test for message retransmission after monitor update failure on // channel_reestablish generating a monitor update (which comes from freeing holding cell // HTLCs). - let mut nodes = create_network(3); - create_announced_chan_between_nodes(&nodes, 0, 1); - create_announced_chan_between_nodes(&nodes, 1, 2); + let mut nodes = create_network(3, &[None, None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); + create_announced_chan_between_nodes(&nodes, 1, 2, LocalFeatures::new(), LocalFeatures::new()); let (our_payment_preimage, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000); @@ -994,8 +992,8 @@ fn raa_no_response_awaiting_raa_state() { // due to a previous monitor update failure, we still set AwaitingRemoteRevoke on the channel // in question (assuming it intends to respond with a CS after monitor updating is restored). // Backported from chanmon_fail_consistency fuzz tests as this used to be broken. - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); let (payment_preimage_1, payment_hash_1) = get_payment_preimage_hash!(nodes[0]); @@ -1107,8 +1105,8 @@ fn claim_while_disconnected_monitor_update_fail() { // Backported from chanmon_fail_consistency fuzz tests as an unmerged version of the handling // code introduced a regression in this test (specifically, this caught a removal of the // channel_reestablish handling ensuring the order was sensical given the messages used). - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); // Forward a payment for B to claim let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000); @@ -1222,8 +1220,8 @@ fn monitor_failed_no_reestablish_response() { // response to a commitment_signed. // Backported from chanmon_fail_consistency fuzz tests as it caught a long-standing // debug_assert!() failure in channel_reestablish handling. - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); // Route the payment and deliver the initial commitment_signed (with a monitor update failure // on receipt). @@ -1288,8 +1286,8 @@ fn first_message_on_recv_ordering() { // have no pending response but will want to send a RAA/CS (with the updates for the second // payment applied). // Backported from chanmon_fail_consistency fuzz tests as it caught a bug here. - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); // Route the first payment outbound, holding the last RAA for B until we are set up so that we // can deliver it and fail the monitor update. @@ -1373,9 +1371,9 @@ fn test_monitor_update_fail_claim() { // update to claim the payment. We then send a payment C->B->A, making the forward of this // payment from B to A fail due to the paused channel. Finally, we restore the channel monitor // updating and claim the payment on B. - let mut nodes = create_network(3); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1); - create_announced_chan_between_nodes(&nodes, 1, 2); + let mut nodes = create_network(3, &[None, None, None]); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); + create_announced_chan_between_nodes(&nodes, 1, 2, LocalFeatures::new(), LocalFeatures::new()); // Rebalance a bit so that we can send backwards from 3 to 2. send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000); @@ -1443,15 +1441,15 @@ fn test_monitor_update_on_pending_forwards() { // We do this with a simple 3-node network, sending a payment from A to C and one from C to A. // The payment from A to C will be failed by C and pending a back-fail to A, while the payment // from C to A will be pending a forward to A. - let mut nodes = create_network(3); - create_announced_chan_between_nodes(&nodes, 0, 1); - create_announced_chan_between_nodes(&nodes, 1, 2); + let mut nodes = create_network(3, &[None, None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); + create_announced_chan_between_nodes(&nodes, 1, 2, LocalFeatures::new(), LocalFeatures::new()); // Rebalance a bit so that we can send backwards from 3 to 1. send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000); let (_, payment_hash_1) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000); - assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1, 1000000)); + assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1)); expect_pending_htlcs_forwardable!(nodes[2]); check_added_monitors!(nodes[2], 1); @@ -1495,7 +1493,6 @@ fn test_monitor_update_on_pending_forwards() { Event::PendingHTLCsForwardable { .. } => { }, _ => panic!("Unexpected event"), }; - nodes[0].node.channel_state.lock().unwrap().next_forward = Instant::now(); nodes[0].node.process_pending_htlc_forwards(); expect_payment_received!(nodes[0], payment_hash_2, 1000000); @@ -1508,8 +1505,8 @@ fn monitor_update_claim_fail_no_response() { // to channel being AwaitingRAA). // Backported from chanmon_fail_consistency fuzz tests as an unmerged version of the handling // code was broken. - let mut nodes = create_network(2); - create_announced_chan_between_nodes(&nodes, 0, 1); + let mut nodes = create_network(2, &[None, None]); + create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new()); // Forward a payment for B to claim let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);