X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fshutdown_tests.rs;h=b712212ab75a7208431949765324a63b8e7b32a7;hb=26fe0f753dc5116ab6fe5d078c9f30a318559502;hp=db76a2c760ccb917d6f98cbbd57735c0114156a8;hpb=2c4f16d5e39e6d4e90d1b9836cceaad11810fbaa;p=rust-lightning diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index db76a2c7..b712212a 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -11,10 +11,8 @@ use chain::keysinterface::KeysInterface; use chain::transaction::OutPoint; -use ln::{PaymentPreimage, PaymentHash}; use ln::channelmanager::PaymentSendFailure; use routing::router::{Payee, get_route}; -use routing::network_graph::NetworkUpdate; use ln::features::{InitFeatures, InvoiceFeatures}; use ln::msgs; use ln::msgs::{ChannelMessageHandler, ErrorAction}; @@ -28,9 +26,6 @@ use util::config::UserConfig; use bitcoin::blockdata::script::Builder; use bitcoin::blockdata::opcodes; -use bitcoin::hashes::sha256::Hash as Sha256; -use bitcoin::hashes::Hash; - use regex; use core::default::Default; @@ -420,13 +415,17 @@ fn test_upfront_shutdown_script() { let flags = InitFeatures::known(); let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 1000000, 1000000, flags.clone(), flags.clone()); nodes[0].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap(); - let mut node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id()); + let node_0_orig_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id()); + let mut node_0_shutdown = node_0_orig_shutdown.clone(); node_0_shutdown.scriptpubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script().to_p2sh(); - // Test we enforce upfront_scriptpbukey if by providing a diffrent one at closing that we disconnect peer + // Test we enforce upfront_scriptpbukey if by providing a different one at closing that we warn + // the peer and ignore the message. nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &InitFeatures::known(), &node_0_shutdown); - assert!(regex::Regex::new(r"Got shutdown request with a scriptpubkey \([A-Fa-f0-9]+\) which did not match their previous scriptpubkey.").unwrap().is_match(check_closed_broadcast!(nodes[2], true).unwrap().data.as_str())); - check_closed_event!(nodes[2], 1, ClosureReason::ProcessingError { err: "Got shutdown request with a scriptpubkey (a91441c98a140039816273e50db317422c11c2bfcc8887) which did not match their previous scriptpubkey.".to_string() }); - check_added_monitors!(nodes[2], 1); + assert!(regex::Regex::new(r"Got shutdown request with a scriptpubkey \([A-Fa-f0-9]+\) which did not match their previous scriptpubkey.") + .unwrap().is_match(&check_warn_msg!(nodes[2], nodes[0].node.get_our_node_id(), chan.2))); + // This allows nodes[2] to retry the shutdown message, which should get a response: + nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &InitFeatures::known(), &node_0_orig_shutdown); + get_event_msg!(nodes[2], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); // We test that in case of peer committing upfront to a script, if it doesn't change at closing, we sign let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 1000000, 1000000, flags.clone(), flags.clone()); @@ -673,17 +672,8 @@ fn test_unsupported_anysegwit_shutdown_script() { node_0_shutdown.scriptpubkey = unsupported_shutdown_script.into_inner(); nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_cfgs[1].features, &node_0_shutdown); - let events = nodes[0].node.get_and_clear_pending_msg_events(); - assert_eq!(events.len(), 2); - match events[1] { - MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => { - assert_eq!(node_id, nodes[1].node.get_our_node_id()); - assert_eq!(msg.data, "Got a nonstandard scriptpubkey (60020028) from remote peer".to_owned()); - }, - _ => panic!("Unexpected event"), - } - check_added_monitors!(nodes[0], 1); - check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: "Got a nonstandard scriptpubkey (60020028) from remote peer".to_string() }); + assert_eq!(&check_warn_msg!(nodes[0], nodes[1].node.get_our_node_id(), chan.2), + "Got a nonstandard scriptpubkey (60020028) from remote peer"); } #[test] @@ -709,17 +699,8 @@ fn test_invalid_shutdown_script() { .into_script(); nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &InitFeatures::known(), &node_0_shutdown); - let events = nodes[0].node.get_and_clear_pending_msg_events(); - assert_eq!(events.len(), 2); - match events[1] { - MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => { - assert_eq!(node_id, nodes[1].node.get_our_node_id()); - assert_eq!(msg.data, "Got a nonstandard scriptpubkey (00020000) from remote peer".to_owned()) - }, - _ => panic!("Unexpected event"), - } - check_added_monitors!(nodes[0], 1); - check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: "Got a nonstandard scriptpubkey (00020000) from remote peer".to_string() }); + assert_eq!(&check_warn_msg!(nodes[0], nodes[1].node.get_our_node_id(), chan.2), + "Got a nonstandard scriptpubkey (00020000) from remote peer"); } #[derive(PartialEq)] @@ -767,10 +748,8 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) { if timeout_step != TimeoutStep::AfterShutdown { nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); - // At this point nodes[1] should send back a warning message indicating it disagrees with the - // given channel-closing fee. Currently we do not implement warning messages so instead we - // remain silent here. - assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); + assert!(check_warn_msg!(nodes[1], nodes[0].node.get_our_node_id(), chan_id) + .starts_with("Unable to come to consensus about closing feerate")); // Now deliver a mutated closing_signed indicating a higher acceptable fee range, which // nodes[1] should happily accept and respond to.