X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fpayment_tests.rs;h=9e044d1c92d686479d6f76187001ac75c55d92aa;hb=bada71394e96971bcf29fe997ecc9602ec305da4;hp=96de3e107803f14f0c0289331e00ae79ca639ea6;hpb=64c26c8a793f35c55076a2188912e92106900bab;p=rust-lightning diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 96de3e10..9e044d1c 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -13,7 +13,7 @@ use crate::chain::{ChannelMonitorUpdateStatus, Confirm, Listen, Watch}; use crate::chain::channelmonitor::{ANTI_REORG_DELAY, HTLC_FAIL_BACK_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS}; -use crate::chain::keysinterface::EntropySource; +use crate::sign::EntropySource; use crate::chain::transaction::OutPoint; use crate::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentFailureReason}; use crate::ln::channel::EXPIRE_PREV_CONFIG_TICKS; @@ -30,8 +30,6 @@ use crate::util::errors::APIError; use crate::util::ser::Writeable; use crate::util::string::UntrustedString; -use bitcoin::{Block, BlockHeader, TxMerkleNode}; -use bitcoin::hashes::Hash; use bitcoin::network::constants::Network; use crate::prelude::*; @@ -343,7 +341,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { if !confirm_before_reload { let as_broadcasted_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); assert_eq!(as_broadcasted_txn.len(), 1); - assert_eq!(as_broadcasted_txn[0], as_commitment_tx); + assert_eq!(as_broadcasted_txn[0].txid(), as_commitment_tx.txid()); } else { assert!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().is_empty()); } @@ -562,8 +560,8 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) { mine_transaction(&nodes[0], &bs_commitment_tx[0]); mine_transaction(&nodes[1], &bs_commitment_tx[0]); if !use_dust { - connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1 + (MIN_CLTV_EXPIRY_DELTA as u32)); - connect_blocks(&nodes[1], TEST_FINAL_CLTV - 1 + (MIN_CLTV_EXPIRY_DELTA as u32)); + connect_blocks(&nodes[0], TEST_FINAL_CLTV + (MIN_CLTV_EXPIRY_DELTA as u32)); + connect_blocks(&nodes[1], TEST_FINAL_CLTV + (MIN_CLTV_EXPIRY_DELTA as u32)); let as_htlc_timeout = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); check_spends!(as_htlc_timeout[0], bs_commitment_tx[0]); assert_eq!(as_htlc_timeout.len(), 1); @@ -684,7 +682,7 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co connect_blocks(&nodes[0], TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1); let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); assert_eq!(node_txn.len(), 3); - assert_eq!(node_txn[0], node_txn[1]); + assert_eq!(node_txn[0].txid(), node_txn[1].txid()); check_spends!(node_txn[1], funding_tx); check_spends!(node_txn[2], node_txn[1]); let timeout_txn = vec![node_txn[2].clone()]; @@ -693,8 +691,7 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co check_added_monitors!(nodes[1], 1); expect_payment_claimed!(nodes[1], payment_hash, 10_000_000); - let mut header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 }; - connect_block(&nodes[1], &Block { header, txdata: vec![node_txn[1].clone()]}); + connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![node_txn[1].clone()])); check_closed_broadcast!(nodes[1], true); check_added_monitors!(nodes[1], 1); check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed); @@ -702,15 +699,13 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co assert_eq!(claim_txn.len(), 1); check_spends!(claim_txn[0], node_txn[1]); - header.prev_blockhash = nodes[0].best_block_hash(); - connect_block(&nodes[0], &Block { header, txdata: vec![node_txn[1].clone()]}); + connect_block(&nodes[0], &create_dummy_block(nodes[0].best_block_hash(), 42, vec![node_txn[1].clone()])); if confirm_commitment_tx { connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1); } - header.prev_blockhash = nodes[0].best_block_hash(); - let claim_block = Block { header, txdata: if payment_timeout { timeout_txn } else { vec![claim_txn[0].clone()] } }; + let claim_block = create_dummy_block(nodes[0].best_block_hash(), 42, if payment_timeout { timeout_txn } else { vec![claim_txn[0].clone()] }); if payment_timeout { assert!(confirm_commitment_tx); // Otherwise we're spending below our CSV! @@ -857,14 +852,14 @@ fn get_ldk_payment_preimage() { let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(amt_msat), expiry_secs, None).unwrap(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) - .with_features(nodes[1].node.invoice_features()); + .with_bolt11_features(nodes[1].node.invoice_features()).unwrap(); let scorer = test_utils::TestScorer::new(); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); let random_seed_bytes = keys_manager.get_secure_random_bytes(); let route = get_route( &nodes[0].node.get_our_node_id(), &payment_params, &nodes[0].network_graph.read_only(), Some(&nodes[0].node.list_usable_channels().iter().collect::>()), - amt_msat, TEST_FINAL_CLTV, nodes[0].logger, &scorer, &random_seed_bytes).unwrap(); + amt_msat, nodes[0].logger, &scorer, &(), &random_seed_bytes).unwrap(); nodes[0].node.send_payment_with_route(&route, payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0)).unwrap(); check_added_monitors!(nodes[0], 1); @@ -974,7 +969,7 @@ fn failed_probe_yields_event() { let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42); - let (route, _, _, _) = get_route_and_payment_hash!(&nodes[0], nodes[2], &payment_params, 9_998_000, 42); + let (route, _, _, _) = get_route_and_payment_hash!(&nodes[0], nodes[2], &payment_params, 9_998_000); let (payment_hash, payment_id) = nodes[0].node.send_probe(route.paths[0].clone()).unwrap(); @@ -1023,7 +1018,7 @@ fn onchain_failed_probe_yields_event() { let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42); // Send a dust HTLC, which will be treated as if it timed out once the channel hits the chain. - let (route, _, _, _) = get_route_and_payment_hash!(&nodes[0], nodes[2], &payment_params, 1_000, 42); + let (route, _, _, _) = get_route_and_payment_hash!(&nodes[0], nodes[2], &payment_params, 1_000); let (payment_hash, payment_id) = nodes[0].node.send_probe(route.paths[0].clone()).unwrap(); // node[0] -- update_add_htlcs -> node[1] @@ -1409,8 +1404,8 @@ fn do_test_intercepted_payment(test: InterceptTest) { htlc_minimum_msat: None, htlc_maximum_msat: None, }]) - ]) - .with_features(nodes[2].node.invoice_features()); + ]).unwrap() + .with_bolt11_features(nodes[2].node.invoice_features()).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -1418,8 +1413,7 @@ fn do_test_intercepted_payment(test: InterceptTest) { let route = get_route( &nodes[0].node.get_our_node_id(), &route_params.payment_params, &nodes[0].network_graph.read_only(), None, route_params.final_value_msat, - route_params.payment_params.final_cltv_expiry_delta, nodes[0].logger, &scorer, - &random_seed_bytes, + nodes[0].logger, &scorer, &(), &random_seed_bytes, ).unwrap(); let (payment_hash, payment_secret) = nodes[2].node.create_inbound_payment(Some(amt_msat), 60 * 60, None).unwrap(); @@ -1523,10 +1517,7 @@ fn do_test_intercepted_payment(test: InterceptTest) { _ => panic!("Unexpected event") } } else if test == InterceptTest::Timeout { - let mut block = Block { - header: BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 }, - txdata: vec![], - }; + let mut block = create_dummy_block(nodes[0].best_block_hash(), 42, Vec::new()); connect_block(&nodes[0], &block); connect_block(&nodes[1], &block); for _ in 0..TEST_FINAL_CLTV { @@ -1601,7 +1592,7 @@ fn do_automatic_retries(test: AutoRetry) { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -1820,7 +1811,7 @@ fn auto_retry_partial_failure() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2032,7 +2023,7 @@ fn auto_retry_zero_attempts_send_error() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2072,7 +2063,7 @@ fn fails_paying_after_rejected_by_payee() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2119,7 +2110,7 @@ fn retry_multi_path_single_failed_payment() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params: payment_params.clone(), final_value_msat: amt_msat, @@ -2213,7 +2204,7 @@ fn immediate_retry_on_failure() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2302,7 +2293,7 @@ fn no_extra_retries_on_back_to_back_fail() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2504,7 +2495,7 @@ fn test_simple_partial_retry() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2670,7 +2661,7 @@ fn test_threaded_payment_retries() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let mut route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2907,7 +2898,7 @@ fn do_claim_from_closed_chan(fail_payment: bool) { let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[3]); let mut route_params = RouteParameters { payment_params: PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV) - .with_features(nodes[1].node.invoice_features()), + .with_bolt11_features(nodes[1].node.invoice_features()).unwrap(), final_value_msat: 10_000_000, }; let mut route = nodes[0].router.find_route(&nodes[0].node.get_our_node_id(), &route_params, @@ -3051,7 +3042,7 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) { let payment_metadata = vec![44, 49, 52, 142]; let payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV) - .with_features(nodes[1].node.invoice_features()); + .with_bolt11_features(nodes[1].node.invoice_features()).unwrap(); let mut route_params = RouteParameters { payment_params, final_value_msat: amt_msat,