X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmonitor_tests.rs;h=41ecd9da0fbef63970ba37a69291086e30159254;hb=c9d3544314f5823b8ac597996a80f695693d8702;hp=3e1aa7e9c5b1ea6214af591c489d78802edbc938;hpb=397386539d19ea368d1f37566b6b0640b90c9668;p=rust-lightning diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 3e1aa7e9..41ecd9da 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -9,41 +9,26 @@ //! Further functional tests which test blockchain reorganizations. -#[cfg(anchors)] use crate::sign::{ChannelSigner, EcdsaChannelSigner}; -#[cfg(anchors)] -use crate::chain::channelmonitor::LATENCY_GRACE_PERIOD_BLOCKS; -use crate::chain::channelmonitor::{ANTI_REORG_DELAY, Balance}; +use crate::chain::channelmonitor::{ANTI_REORG_DELAY, LATENCY_GRACE_PERIOD_BLOCKS, Balance}; use crate::chain::transaction::OutPoint; use crate::chain::chaininterface::LowerBoundedFeeEstimator; -#[cfg(anchors)] use crate::events::bump_transaction::BumpTransactionEvent; use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, ClosureReason, HTLCDestination}; use crate::ln::channel; -#[cfg(anchors)] use crate::ln::chan_utils; -#[cfg(anchors)] -use crate::ln::channelmanager::ChannelManager; -use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, PaymentId, RecipientOnionFields}; +use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChannelManager, PaymentId, RecipientOnionFields}; use crate::ln::msgs::ChannelMessageHandler; -#[cfg(anchors)] use crate::util::config::UserConfig; -#[cfg(anchors)] use crate::util::crypto::sign; use crate::util::ser::Writeable; use crate::util::test_utils; -#[cfg(anchors)] use bitcoin::blockdata::transaction::EcdsaSighashType; use bitcoin::blockdata::script::Builder; use bitcoin::blockdata::opcodes; -use bitcoin::secp256k1::Secp256k1; -#[cfg(anchors)] -use bitcoin::secp256k1::SecretKey; -#[cfg(anchors)] -use bitcoin::{Amount, PublicKey, Script, TxIn, TxOut, PackedLockTime, Witness}; -use bitcoin::Transaction; -#[cfg(anchors)] +use bitcoin::secp256k1::{Secp256k1, SecretKey}; +use bitcoin::{Amount, PublicKey, Script, Transaction, TxIn, TxOut, PackedLockTime, Witness}; use bitcoin::util::sighash::SighashCache; use crate::prelude::*; @@ -1731,16 +1716,12 @@ fn test_restored_packages_retry() { fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) { // Test that we will retry broadcasting pending claims for a force-closed channel on every // `ChainMonitor::rebroadcast_pending_claims` call. - if anchors { - assert!(cfg!(anchors)); - } let mut chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let mut config = test_default_channel_config(); if anchors { - #[cfg(anchors)] { - config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - } + config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; + config.manually_accept_inbound_channels = true; } let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config), Some(config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1783,34 +1764,27 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) { }; #[allow(unused_assignments)] let mut feerate = 0; - #[cfg(anchors)] { - feerate = if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { - target_feerate_sat_per_1000_weight, mut htlc_descriptors, tx_lock_time, .. - }) = events.pop().unwrap() { - let secp = Secp256k1::new(); - assert_eq!(htlc_descriptors.len(), 1); - let descriptor = htlc_descriptors.pop().unwrap(); - assert_eq!(descriptor.commitment_txid, commitment_txn[0].txid()); - let htlc_output_idx = descriptor.htlc.transaction_output_index.unwrap() as usize; - assert!(htlc_output_idx < commitment_txn[0].output.len()); - tx.lock_time = tx_lock_time; - // Note that we don't care about actually making the HTLC transaction meet the - // feerate for the test, we just want to make sure the feerates we receive from - // the events never decrease. - tx.input.push(descriptor.unsigned_tx_input()); - let signer = nodes[0].keys_manager.derive_channel_keys( - descriptor.channel_value_satoshis, &descriptor.channel_keys_id, - ); - let per_commitment_point = signer.get_per_commitment_point( - descriptor.per_commitment_number, &secp - ); - tx.output.push(descriptor.tx_output(&per_commitment_point, &secp)); - let our_sig = signer.sign_holder_htlc_transaction(&mut tx, 0, &descriptor, &secp).unwrap(); - let witness_script = descriptor.witness_script(&per_commitment_point, &secp); - tx.input[0].witness = descriptor.tx_input_witness(&our_sig, &witness_script); - target_feerate_sat_per_1000_weight as u64 - } else { panic!("unexpected event"); }; - } + feerate = if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { + target_feerate_sat_per_1000_weight, mut htlc_descriptors, tx_lock_time, .. + }) = events.pop().unwrap() { + let secp = Secp256k1::new(); + assert_eq!(htlc_descriptors.len(), 1); + let descriptor = htlc_descriptors.pop().unwrap(); + assert_eq!(descriptor.commitment_txid, commitment_txn[0].txid()); + let htlc_output_idx = descriptor.htlc.transaction_output_index.unwrap() as usize; + assert!(htlc_output_idx < commitment_txn[0].output.len()); + tx.lock_time = tx_lock_time; + // Note that we don't care about actually making the HTLC transaction meet the + // feerate for the test, we just want to make sure the feerates we receive from + // the events never decrease. + tx.input.push(descriptor.unsigned_tx_input()); + tx.output.push(descriptor.tx_output(&secp)); + let signer = descriptor.derive_channel_signer(&nodes[0].keys_manager); + let our_sig = signer.sign_holder_htlc_transaction(&mut tx, 0, &descriptor, &secp).unwrap(); + let witness_script = descriptor.witness_script(&secp); + tx.input[0].witness = descriptor.tx_input_witness(&our_sig, &witness_script); + target_feerate_sat_per_1000_weight as u64 + } else { panic!("unexpected event"); }; (tx, feerate) } else { assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty()); @@ -1875,11 +1849,9 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) { #[test] fn test_monitor_timer_based_claim() { do_test_monitor_rebroadcast_pending_claims(false); - #[cfg(anchors)] do_test_monitor_rebroadcast_pending_claims(true); } -#[cfg(anchors)] #[test] fn test_yield_anchors_events() { // Tests that two parties supporting anchor outputs can open a channel, route payments over @@ -1894,6 +1866,7 @@ fn test_yield_anchors_events() { let mut anchors_config = UserConfig::default(); anchors_config.channel_handshake_config.announced_channel = true; anchors_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; + anchors_config.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(anchors_config), Some(anchors_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1932,9 +1905,7 @@ fn test_yield_anchors_events() { script_pubkey: Script::new_op_return(&[]), }], }; - let signer = nodes[0].keys_manager.derive_channel_keys( - anchor_descriptor.channel_value_satoshis, &anchor_descriptor.channel_keys_id, - ); + let signer = anchor_descriptor.derive_channel_signer(&nodes[0].keys_manager); let funding_sig = signer.sign_holder_anchor_input(&mut anchor_tx, 0, &secp).unwrap(); anchor_tx.input[0].witness = chan_utils::build_anchor_input_witness( &signer.pubkeys().funding_pubkey, &funding_sig @@ -1965,10 +1936,6 @@ fn test_yield_anchors_events() { Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { htlc_descriptors, tx_lock_time, .. }) => { assert_eq!(htlc_descriptors.len(), 1); let htlc_descriptor = &htlc_descriptors[0]; - let signer = nodes[0].keys_manager.derive_channel_keys( - htlc_descriptor.channel_value_satoshis, &htlc_descriptor.channel_keys_id - ); - let per_commitment_point = signer.get_per_commitment_point(htlc_descriptor.per_commitment_number, &secp); let mut htlc_tx = Transaction { version: 2, lock_time: tx_lock_time, @@ -1977,15 +1944,16 @@ fn test_yield_anchors_events() { TxIn { ..Default::default() } // Fee input ], output: vec![ - htlc_descriptor.tx_output(&per_commitment_point, &secp), // HTLC output + htlc_descriptor.tx_output(&secp), // HTLC output TxOut { // Fee input change value: Amount::ONE_BTC.to_sat(), script_pubkey: Script::new_op_return(&[]), } ] }; + let signer = htlc_descriptor.derive_channel_signer(&nodes[0].keys_manager); let our_sig = signer.sign_holder_htlc_transaction(&mut htlc_tx, 0, htlc_descriptor, &secp).unwrap(); - let witness_script = htlc_descriptor.witness_script(&per_commitment_point, &secp); + let witness_script = htlc_descriptor.witness_script(&secp); htlc_tx.input[0].witness = htlc_descriptor.tx_input_witness(&our_sig, &witness_script); htlc_txs.push(htlc_tx); }, @@ -2013,7 +1981,6 @@ fn test_yield_anchors_events() { nodes[0].node.get_and_clear_pending_events(); } -#[cfg(anchors)] #[test] fn test_anchors_aggregated_revoked_htlc_tx() { // Test that `ChannelMonitor`s can properly detect and claim funds from a counterparty claiming @@ -2027,6 +1994,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { let mut anchors_config = UserConfig::default(); anchors_config.channel_handshake_config.announced_channel = true; anchors_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; + anchors_config.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(anchors_config), Some(anchors_config)]); let bob_persister: test_utils::TestPersister; @@ -2144,9 +2112,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { previous_output: anchor_descriptor.outpoint, ..Default::default() }); - let signer = nodes[1].keys_manager.derive_channel_keys( - anchor_descriptor.channel_value_satoshis, &anchor_descriptor.channel_keys_id, - ); + let signer = anchor_descriptor.derive_channel_signer(&nodes[1].keys_manager); signers.push(signer); }, _ => panic!("Unexpected event"), @@ -2249,12 +2215,8 @@ fn test_anchors_aggregated_revoked_htlc_tx() { assert_eq!(htlc_descriptors.len(), 2); for htlc_descriptor in &htlc_descriptors { assert!(!htlc_descriptor.htlc.offered); - let signer = nodes[1].keys_manager.derive_channel_keys( - htlc_descriptor.channel_value_satoshis, &htlc_descriptor.channel_keys_id - ); - let per_commitment_point = signer.get_per_commitment_point(htlc_descriptor.per_commitment_number, &secp); htlc_tx.input.push(htlc_descriptor.unsigned_tx_input()); - htlc_tx.output.push(htlc_descriptor.tx_output(&per_commitment_point, &secp)); + htlc_tx.output.push(htlc_descriptor.tx_output(&secp)); } descriptors.append(&mut htlc_descriptors); htlc_tx.lock_time = tx_lock_time; @@ -2264,12 +2226,9 @@ fn test_anchors_aggregated_revoked_htlc_tx() { } for (idx, htlc_descriptor) in descriptors.into_iter().enumerate() { let htlc_input_idx = idx + 1; - let signer = nodes[1].keys_manager.derive_channel_keys( - htlc_descriptor.channel_value_satoshis, &htlc_descriptor.channel_keys_id - ); + let signer = htlc_descriptor.derive_channel_signer(&nodes[1].keys_manager); let our_sig = signer.sign_holder_htlc_transaction(&htlc_tx, htlc_input_idx, &htlc_descriptor, &secp).unwrap(); - let per_commitment_point = signer.get_per_commitment_point(htlc_descriptor.per_commitment_number, &secp); - let witness_script = htlc_descriptor.witness_script(&per_commitment_point, &secp); + let witness_script = htlc_descriptor.witness_script(&secp); htlc_tx.input[htlc_input_idx].witness = htlc_descriptor.tx_input_witness(&our_sig, &witness_script); } let fee_utxo_sig = {