X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Fln%2Fchanmon_update_fail_tests.rs;h=1437d91bffe0bcee10964486b95258890b690781;hb=f930fc1886dbfdc388be79579ef02e788e2478f5;hp=5772d015b5680fc7bd1b25cd13c6464356ab944d;hpb=f70058ea4c451955e72b15d24b67d941d7f3e467;p=rust-lightning diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 5772d015..1437d91b 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -19,7 +19,8 @@ use ln::functional_test_utils::*; #[test] fn test_simple_monitor_permanent_update_fail() { // Test that we handle a simple permanent monitor update failure - let node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -51,7 +52,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 node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -152,7 +154,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 node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -198,6 +201,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { } nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed); + check_added_monitors!(nodes[0], 1); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1); } @@ -480,7 +484,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 node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -561,7 +566,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 node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -605,7 +611,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 node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -674,7 +681,8 @@ 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 node_cfgs = create_node_cfgs(3); + let chanmon_cfgs = create_chanmon_cfgs(3); + let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -784,6 +792,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { send_event = SendEvent::from_event(nodes[2].node.get_and_clear_pending_msg_events().remove(0)); nodes[1].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &send_event.msgs[0]); nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &send_event.commitment_msg); + check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -929,7 +938,8 @@ 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 node_cfgs = create_node_cfgs(3); + let chanmon_cfgs = create_chanmon_cfgs(3); + let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -1009,7 +1019,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 node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -1124,7 +1135,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 node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -1167,6 +1179,7 @@ fn claim_while_disconnected_monitor_update_fail() { let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]); nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_updates.commitment_signed); + check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1); // Note that nodes[1] not updating monitor here is OK - it wont take action on the new HTLC @@ -1241,7 +1254,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 node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -1309,7 +1323,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 node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -1362,6 +1377,7 @@ fn first_message_on_recv_ordering() { // the appropriate HTLC acceptance). nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1); @@ -1396,7 +1412,8 @@ 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 node_cfgs = create_node_cfgs(3); + let chanmon_cfgs = create_chanmon_cfgs(3); + let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -1471,7 +1488,8 @@ 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 node_cfgs = create_node_cfgs(3); + let chanmon_cfgs = create_chanmon_cfgs(3); + let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -1538,7 +1556,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 node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); @@ -1599,7 +1618,8 @@ fn monitor_update_claim_fail_no_response() { fn do_during_funding_monitor_fail(fail_on_generate: bool, restore_between_fails: bool, fail_on_signed: bool, confirm_a_first: bool, restore_b_before_conf: bool) { // Test that if the monitor update generated by funding_transaction_generated fails we continue // the channel setup happily after the update is restored. - let node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1639,7 +1659,7 @@ fn do_during_funding_monitor_fail(fail_on_generate: bool, restore_between_fails: assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); if fail_on_generate && !restore_between_fails { nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented funding_signed from allowing funding broadcast".to_string(), 1); - check_added_monitors!(nodes[0], 0); + check_added_monitors!(nodes[0], 1); } else { nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1); check_added_monitors!(nodes[0], 1);