X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fshutdown_tests.rs;h=0e03fd8db139353001f8fe1b0f12e717a213e49b;hb=920d96edb6595289902f287419de2d002e2dc2ee;hp=9a44953f51e3fab76776f323ea91485a59ecc448;hpb=6960210f604964583bfe704d6f956cadddcd15a2;p=rust-lightning diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index 9a44953f..0e03fd8d 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -14,9 +14,11 @@ use crate::sign::{EntropySource, SignerProvider}; use crate::chain::ChannelMonitorUpdateStatus; use crate::chain::transaction::OutPoint; use crate::events::{Event, MessageSendEvent, HTLCDestination, MessageSendEventsProvider, ClosureReason}; -use crate::ln::channelmanager::{self, PaymentSendFailure, PaymentId, RecipientOnionFields, Retry, ChannelShutdownState, ChannelDetails}; +use crate::ln::channel_state::{ChannelDetails, ChannelShutdownState}; +use crate::ln::channelmanager::{self, PaymentSendFailure, PaymentId, RecipientOnionFields, Retry}; use crate::routing::router::{PaymentParameters, get_route, RouteParameters}; -use crate::ln::{ChannelId, msgs}; +use crate::ln::msgs; +use crate::ln::types::ChannelId; use crate::ln::msgs::{ChannelMessageHandler, ErrorAction}; use crate::ln::onion_utils::INVALID_ONION_BLINDING; use crate::ln::script::ShutdownScript; @@ -27,12 +29,13 @@ use crate::util::config::UserConfig; use crate::util::string::UntrustedString; use crate::prelude::*; -use bitcoin::{Transaction, TxOut}; +use bitcoin::{Transaction, TxOut, WitnessProgram, WitnessVersion}; +use bitcoin::amount::Amount; use bitcoin::blockdata::locktime::absolute::LockTime; use bitcoin::blockdata::script::Builder; use bitcoin::blockdata::opcodes; -use bitcoin::network::constants::Network; -use bitcoin::address::{WitnessProgram, WitnessVersion}; +use bitcoin::network::Network; +use bitcoin::transaction::Version; use crate::ln::functional_test_utils::*; @@ -299,11 +302,12 @@ fn expect_channel_shutdown_state_with_force_closure() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1); + let error_message = "Channel force-closed"; expect_channel_shutdown_state!(nodes[0], chan_1.2, ChannelShutdownState::NotShuttingDown); expect_channel_shutdown_state!(nodes[1], chan_1.2, ChannelShutdownState::NotShuttingDown); - nodes[1].node.force_close_broadcasting_latest_txn(&chan_1.2, &nodes[0].node.get_our_node_id()).unwrap(); + nodes[1].node.force_close_broadcasting_latest_txn(&chan_1.2, &nodes[0].node.get_our_node_id(), error_message.to_string()).unwrap(); check_closed_broadcast!(nodes[1], true); check_added_monitors!(nodes[1], 1); @@ -1168,17 +1172,17 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) { assert_eq!(txn[0].output.len(), 2); if timeout_step != TimeoutStep::NoTimeout { - assert!((txn[0].output[0].script_pubkey.is_v0_p2wpkh() && - txn[0].output[1].script_pubkey.is_v0_p2wsh()) || - (txn[0].output[1].script_pubkey.is_v0_p2wpkh() && - txn[0].output[0].script_pubkey.is_v0_p2wsh())); + assert!((txn[0].output[0].script_pubkey.is_p2wpkh() && + txn[0].output[1].script_pubkey.is_p2wsh()) || + (txn[0].output[1].script_pubkey.is_p2wpkh() && + txn[0].output[0].script_pubkey.is_p2wsh())); check_closed_broadcast!(nodes[1], true); check_added_monitors!(nodes[1], 1); check_closed_event!(nodes[1], 1, ClosureReason::ProcessingError { err: "closing_signed negotiation failed to finish within two timer ticks".to_string() } , [nodes[0].node.get_our_node_id()], 100000); } else { - assert!(txn[0].output[0].script_pubkey.is_v0_p2wpkh()); - assert!(txn[0].output[1].script_pubkey.is_v0_p2wpkh()); + assert!(txn[0].output[0].script_pubkey.is_p2wpkh()); + assert!(txn[0].output[1].script_pubkey.is_p2wpkh()); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -1408,12 +1412,12 @@ fn batch_funding_failure() { assert_eq!(events.len(), 2); // Build a transaction which only has the output for one of the two channels we're trying to // confirm. Previously this led to a deadlock in channel closure handling. - let mut tx = Transaction { version: 2, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() }; + let mut tx = Transaction { version: Version::TWO, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() }; let mut chans = Vec::new(); for (idx, ev) in events.iter().enumerate() { if let Event::FundingGenerationReady { temporary_channel_id, counterparty_node_id, output_script, .. } = ev { if idx == 0 { - tx.output.push(TxOut { value: 1_000_000, script_pubkey: output_script.clone() }); + tx.output.push(TxOut { value: Amount::from_sat(1_000_000), script_pubkey: output_script.clone() }); } chans.push((temporary_channel_id, counterparty_node_id)); } else { panic!(); } @@ -1430,23 +1434,32 @@ fn batch_funding_failure() { nodes[0].node.batch_funding_transaction_generated(&chans, tx).unwrap_err(); let msgs = nodes[0].node.get_and_clear_pending_msg_events(); - assert_eq!(msgs.len(), 2); + assert_eq!(msgs.len(), 3); // We currently spuriously send `FundingCreated` for the first channel and then immediately // fail both channels, which isn't ideal but should be fine. assert!(msgs.iter().any(|msg| { if let MessageSendEvent::HandleError { action: msgs::ErrorAction::SendErrorMessage { msg: msgs::ErrorMessage { channel_id, .. }, .. }, .. } = msg { - assert_eq!(*channel_id, temp_chan_id_b); - true + *channel_id == temp_chan_id_b } else { false } })); - assert!(msgs.iter().any(|msg| { + let funding_created_pos = msgs.iter().position(|msg| { if let MessageSendEvent::SendFundingCreated { msg: msgs::FundingCreated { temporary_channel_id, .. }, .. } = msg { assert_eq!(*temporary_channel_id, temp_chan_id_a); true } else { false } - })); + }).unwrap(); + let funded_channel_close_pos = msgs.iter().position(|msg| { + if let MessageSendEvent::HandleError { action: msgs::ErrorAction::SendErrorMessage { + msg: msgs::ErrorMessage { channel_id, .. }, .. + }, .. } = msg { + *channel_id == post_funding_chan_id_a + } else { false } + }).unwrap(); + + // The error message uses the funded channel_id so must come after the funding_created + assert!(funded_channel_close_pos > funding_created_pos); check_closed_events(&nodes[0], &close); assert_eq!(nodes[0].node.list_channels().len(), 0);