From: Matt Corallo Date: Fri, 23 Apr 2021 03:00:44 +0000 (+0000) Subject: Drop now-useless PaymentSecret parameters when claiming/failing-back X-Git-Tag: v0.0.14~12^2~6 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=5a1404809fcf2548924b0a7c0d7be73f24e59e09;p=rust-lightning Drop now-useless PaymentSecret parameters when claiming/failing-back --- diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 8ff741c72..59e5b3c72 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -687,12 +687,12 @@ pub fn do_test(data: &[u8], out: Out) { let had_events = !events.is_empty(); for event in events.drain(..) { match event { - events::Event::PaymentReceived { payment_hash, payment_secret, amt, user_payment_id: _ } => { + events::Event::PaymentReceived { payment_hash, payment_secret: _, amt, user_payment_id: _ } => { if claim_set.insert(payment_hash.0) { if $fail { - assert!(nodes[$node].fail_htlc_backwards(&payment_hash, &payment_secret)); + assert!(nodes[$node].fail_htlc_backwards(&payment_hash)); } else { - assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &payment_secret, amt)); + assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), amt)); } } }, diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index be9294c1d..65437cf52 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -371,7 +371,7 @@ pub fn do_test(data: &[u8], logger: &Arc) { }, our_network_key, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0], Arc::clone(&logger))); let mut should_forward = false; - let mut payments_received: Vec<(PaymentHash, Option, u64)> = Vec::new(); + let mut payments_received: Vec<(PaymentHash, u64)> = Vec::new(); let mut payments_sent = 0; let mut pending_funding_generation: Vec<([u8; 32], u64, Script)> = Vec::new(); let mut pending_funding_signatures = HashMap::new(); @@ -476,17 +476,17 @@ pub fn do_test(data: &[u8], logger: &Arc) { } }, 8 => { - for (payment, payment_secret, amt) in payments_received.drain(..) { + for (payment, amt) in payments_received.drain(..) { // SHA256 is defined as XOR of all input bytes placed in the first byte, and 0s // for the remaining bytes. Thus, if not all remaining bytes are 0s we cannot // fulfill this HTLC, but if they are, we can just take the first byte and // place that anywhere in our preimage. if &payment.0[1..] != &[0; 31] { - channelmanager.fail_htlc_backwards(&payment, &payment_secret); + channelmanager.fail_htlc_backwards(&payment); } else { let mut payment_preimage = PaymentPreimage([0; 32]); payment_preimage.0[0] = payment.0[0]; - channelmanager.claim_funds(payment_preimage, &payment_secret, amt); + channelmanager.claim_funds(payment_preimage, amt); } } }, @@ -500,8 +500,8 @@ pub fn do_test(data: &[u8], logger: &Arc) { let _ = channelmanager.create_inbound_payment_for_hash(payment_hash, None, 1, 0); }, 9 => { - for (payment, payment_secret, _) in payments_received.drain(..) { - channelmanager.fail_htlc_backwards(&payment, &payment_secret); + for (payment, _) in payments_received.drain(..) { + channelmanager.fail_htlc_backwards(&payment); } }, 10 => { @@ -580,9 +580,9 @@ pub fn do_test(data: &[u8], logger: &Arc) { Event::FundingGenerationReady { temporary_channel_id, channel_value_satoshis, output_script, .. } => { pending_funding_generation.push((temporary_channel_id, channel_value_satoshis, output_script)); }, - Event::PaymentReceived { payment_hash, payment_secret, amt, user_payment_id: _ } => { + Event::PaymentReceived { payment_hash, payment_secret: _, amt, user_payment_id: _ } => { //TODO: enhance by fetching random amounts from fuzz input? - payments_received.push((payment_hash, payment_secret, amt)); + payments_received.push((payment_hash, amt)); }, Event::PaymentSent {..} => {}, Event::PaymentFailed {..} => {}, diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 1994cf1d6..cb175796b 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -121,7 +121,7 @@ fn test_monitor_and_persister_update_fail() { persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure)); // Try to update ChannelMonitor - assert!(nodes[1].node.claim_funds(preimage, &None, 9_000_000)); + assert!(nodes[1].node.claim_funds(preimage, 9_000_000)); check_added_monitors!(nodes[1], 1); let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); @@ -305,7 +305,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { // Claim the previous payment, which will result in a update_fulfill_htlc/CS from nodes[1] // but nodes[0] won't respond since it is frozen. - assert!(nodes[1].node.claim_funds(payment_preimage_1, &None, 1_000_000)); + assert!(nodes[1].node.claim_funds(payment_preimage_1, 1_000_000)); check_added_monitors!(nodes[1], 1); let events_2 = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events_2.len(), 1); @@ -846,7 +846,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { let (_, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000); // Fail the payment backwards, failing the monitor update on nodes[1]'s receipt of the RAA - assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1, &None)); + assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1)); expect_pending_htlcs_forwardable!(nodes[2]); check_added_monitors!(nodes[2], 1); @@ -1108,7 +1108,7 @@ fn test_monitor_update_fail_reestablish() { nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false); nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false); - assert!(nodes[2].node.claim_funds(our_payment_preimage, &None, 1_000_000)); + assert!(nodes[2].node.claim_funds(our_payment_preimage, 1_000_000)); check_added_monitors!(nodes[2], 1); let mut updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); assert!(updates.update_add_htlcs.is_empty()); @@ -1315,7 +1315,7 @@ fn claim_while_disconnected_monitor_update_fail() { nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false); nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false); - assert!(nodes[1].node.claim_funds(payment_preimage_1, &None, 1_000_000)); + assert!(nodes[1].node.claim_funds(payment_preimage_1, 1_000_000)); check_added_monitors!(nodes[1], 1); nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { features: InitFeatures::empty() }); @@ -1611,7 +1611,7 @@ fn test_monitor_update_fail_claim() { let (payment_preimage_1, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000); *nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure)); - assert!(nodes[1].node.claim_funds(payment_preimage_1, &None, 1_000_000)); + assert!(nodes[1].node.claim_funds(payment_preimage_1, 1_000_000)); check_added_monitors!(nodes[1], 1); let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[0]); @@ -1690,7 +1690,7 @@ fn test_monitor_update_on_pending_forwards() { send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000); let (_, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000); - assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1, &None)); + assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1)); expect_pending_htlcs_forwardable!(nodes[2]); check_added_monitors!(nodes[2], 1); @@ -1777,7 +1777,7 @@ fn monitor_update_claim_fail_no_response() { let as_raa = commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false, true, false, true); *nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure)); - assert!(nodes[1].node.claim_funds(payment_preimage_1, &None, 1_000_000)); + assert!(nodes[1].node.claim_funds(payment_preimage_1, 1_000_000)); check_added_monitors!(nodes[1], 1); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 0); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index bfe7ee39e..524f40454 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2125,7 +2125,7 @@ impl ChannelMana /// along the path (including in our own channel on which we received it). /// Returns false if no payment was found to fail backwards, true if the process of failing the /// HTLC backwards has been started. - pub fn fail_htlc_backwards(&self, payment_hash: &PaymentHash, _payment_secret: &Option) -> bool { + pub fn fail_htlc_backwards(&self, payment_hash: &PaymentHash) -> bool { let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier); let mut channel_state = Some(self.channel_state.lock().unwrap()); @@ -2294,18 +2294,16 @@ impl ChannelMana /// generating message events for the net layer to claim the payment, if possible. Thus, you /// should probably kick the net layer to go send messages if this returns true! /// - /// You must specify the expected amounts for this HTLC, and we will only claim HTLCs - /// available within a few percent of the expected amount. This is critical for several - /// reasons : a) it avoids providing senders with `proof-of-payment` (in the form of the - /// payment_preimage without having provided the full value and b) it avoids certain - /// privacy-breaking recipient-probing attacks which may reveal payment activity to - /// motivated attackers. - /// - /// Note that the privacy concerns in (b) are not relevant in payments with a payment_secret - /// set. Thus, for such payments we will claim any payments which do not under-pay. + /// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or + /// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived` + /// event matches your expectation. If you fail to do so and call this method, you may provide + /// the sender "proof-of-payment" when they did not fulfill the full expected payment. /// /// May panic if called except in response to a PaymentReceived event. - pub fn claim_funds(&self, payment_preimage: PaymentPreimage, _payment_secret: &Option, expected_amount: u64) -> bool { + /// + /// [`create_inbound_payment`]: Self::create_inbound_payment + /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash + pub fn claim_funds(&self, payment_preimage: PaymentPreimage, expected_amount: u64) -> bool { let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner()); let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier); @@ -4848,7 +4846,7 @@ pub mod bench { expect_pending_htlcs_forwardable!(NodeHolder { node: &$node_b }); expect_payment_received!(NodeHolder { node: &$node_b }, payment_hash, payment_secret, 10_000); - assert!($node_b.claim_funds(payment_preimage, &Some(payment_secret), 10_000)); + assert!($node_b.claim_funds(payment_preimage, 10_000)); match $node_b.get_and_clear_pending_msg_events().pop().unwrap() { MessageSendEvent::UpdateHTLCs { node_id, updates } => { diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 5b79cba05..7d1ce9664 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -1052,7 +1052,7 @@ pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, exp for path in expected_paths.iter() { assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id()); } - assert!(expected_paths[0].last().unwrap().node.claim_funds(our_payment_preimage, &None, expected_amount)); + assert!(expected_paths[0].last().unwrap().node.claim_funds(our_payment_preimage, expected_amount)); check_added_monitors!(expected_paths[0].last().unwrap(), expected_paths.len()); macro_rules! msgs_from_ev { @@ -1176,7 +1176,7 @@ pub fn send_payment<'a, 'b, 'c>(origin: &Node<'a, 'b, 'c>, expected_route: &[&No } pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], skip_last: bool, our_payment_hash: PaymentHash) { - assert!(expected_route.last().unwrap().node.fail_htlc_backwards(&our_payment_hash, &None)); + assert!(expected_route.last().unwrap().node.fail_htlc_backwards(&our_payment_hash)); expect_pending_htlcs_forwardable!(expected_route.last().unwrap()); check_added_monitors!(expected_route.last().unwrap(), 1); diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 1f5dcb8fe..b36cb32f3 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -874,7 +874,7 @@ fn updates_shutdown_wait() { unwrap_send_err!(nodes[0].node.send_payment(&route_1, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable {..}, {}); unwrap_send_err!(nodes[1].node.send_payment(&route_2, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable {..}, {}); - assert!(nodes[2].node.claim_funds(our_payment_preimage, &Some(payment_secret), 100_000)); + assert!(nodes[2].node.claim_funds(our_payment_preimage, 100_000)); check_added_monitors!(nodes[2], 1); let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); assert!(updates.update_add_htlcs.is_empty()); @@ -1008,7 +1008,7 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); - let (our_payment_preimage, _, our_payment_secret) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 100000); + let (our_payment_preimage, _, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 100000); nodes[1].node.close_channel(&chan_1.2).unwrap(); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); @@ -1047,7 +1047,7 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - assert!(nodes[2].node.claim_funds(our_payment_preimage, &Some(our_payment_secret), 100_000)); + assert!(nodes[2].node.claim_funds(our_payment_preimage, 100_000)); check_added_monitors!(nodes[2], 1); let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); assert!(updates.update_add_htlcs.is_empty()); @@ -1454,7 +1454,7 @@ fn duplicate_htlc_test() { fn test_duplicate_htlc_different_direction_onchain() { // Test that ChannelMonitor doesn't generate 2 preimage txn // when we have 2 HTLCs with same preimage that go across a node - // in opposite directions. + // in opposite directions, even with the same payment secret. 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]); @@ -1466,7 +1466,7 @@ fn test_duplicate_htlc_different_direction_onchain() { // balancing send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000); - let (payment_preimage, payment_hash, payment_secret) = route_payment(&nodes[0], &vec!(&nodes[1])[..], 900_000); + let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &vec!(&nodes[1])[..], 900_000); let net_graph_msg_handler = &nodes[1].net_graph_msg_handler; let route = get_route(&nodes[1].node.get_our_node_id(), &net_graph_msg_handler.network_graph.read().unwrap(), &nodes[0].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 800_000, TEST_FINAL_CLTV, &logger).unwrap(); @@ -1474,7 +1474,7 @@ fn test_duplicate_htlc_different_direction_onchain() { send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], 800_000, payment_hash, node_a_payment_secret); // Provide preimage to node 0 by claiming payment - nodes[0].node.claim_funds(payment_preimage, &Some(payment_secret), 800_000); + nodes[0].node.claim_funds(payment_preimage, 800_000); check_added_monitors!(nodes[0], 1); // Broadcast node 1 commitment txn @@ -2154,13 +2154,13 @@ fn channel_reserve_in_flight_removes() { // Now claim both of the first two HTLCs on B's end, putting B in AwaitingRAA and generating an // initial fulfill/CS. - assert!(nodes[1].node.claim_funds(payment_preimage_1, &None, b_chan_values.channel_reserve_msat - b_chan_values.value_to_self_msat - 10000)); + assert!(nodes[1].node.claim_funds(payment_preimage_1, b_chan_values.channel_reserve_msat - b_chan_values.value_to_self_msat - 10000)); check_added_monitors!(nodes[1], 1); let bs_removes = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); // This claim goes in B's holding cell, allowing us to have a pending B->A RAA which does not // remove the second HTLC when we send the HTLC back from B to A. - assert!(nodes[1].node.claim_funds(payment_preimage_2, &None, 20000)); + assert!(nodes[1].node.claim_funds(payment_preimage_2, 20000)); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -2320,7 +2320,7 @@ fn channel_monitor_network_test() { macro_rules! claim_funds { ($node: expr, $prev_node: expr, $preimage: expr, $amount: expr) => { { - assert!($node.node.claim_funds($preimage, &None, $amount)); + assert!($node.node.claim_funds($preimage, $amount)); check_added_monitors!($node, 1); let events = $node.node.get_and_clear_pending_msg_events(); @@ -2744,8 +2744,8 @@ fn test_htlc_on_chain_success() { let commitment_tx = get_local_commitment_txn!(nodes[2], chan_2.2); assert_eq!(commitment_tx.len(), 1); check_spends!(commitment_tx[0], chan_2.3); - nodes[2].node.claim_funds(our_payment_preimage, &None, 3_000_000); - nodes[2].node.claim_funds(our_payment_preimage_2, &None, 3_000_000); + nodes[2].node.claim_funds(our_payment_preimage, 3_000_000); + nodes[2].node.claim_funds(our_payment_preimage_2, 3_000_000); check_added_monitors!(nodes[2], 2); let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); assert!(updates.update_add_htlcs.is_empty()); @@ -2922,7 +2922,7 @@ fn do_test_htlc_on_chain_timeout(connect_style: ConnectStyle) { // Broadcast legit commitment tx from C on B's chain let commitment_tx = get_local_commitment_txn!(nodes[2], chan_2.2); check_spends!(commitment_tx[0], chan_2.3); - nodes[2].node.fail_htlc_backwards(&payment_hash, &None); + nodes[2].node.fail_htlc_backwards(&payment_hash); check_added_monitors!(nodes[2], 0); expect_pending_htlcs_forwardable!(nodes[2]); check_added_monitors!(nodes[2], 1); @@ -3124,7 +3124,7 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use let (_, second_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], value); let (_, third_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], value); - assert!(nodes[2].node.fail_htlc_backwards(&first_payment_hash, &None)); + assert!(nodes[2].node.fail_htlc_backwards(&first_payment_hash)); expect_pending_htlcs_forwardable!(nodes[2]); check_added_monitors!(nodes[2], 1); let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); @@ -3137,7 +3137,7 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use let bs_raa = commitment_signed_dance!(nodes[1], nodes[2], updates.commitment_signed, false, true, false, true); // Drop the last RAA from 3 -> 2 - assert!(nodes[2].node.fail_htlc_backwards(&second_payment_hash, &None)); + assert!(nodes[2].node.fail_htlc_backwards(&second_payment_hash)); expect_pending_htlcs_forwardable!(nodes[2]); check_added_monitors!(nodes[2], 1); let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); @@ -3154,7 +3154,7 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[2], 1); - assert!(nodes[2].node.fail_htlc_backwards(&third_payment_hash, &None)); + assert!(nodes[2].node.fail_htlc_backwards(&third_payment_hash)); expect_pending_htlcs_forwardable!(nodes[2]); check_added_monitors!(nodes[2], 1); let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); @@ -3654,7 +3654,7 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) { _ => panic!("Unexpected event"), } - nodes[1].node.claim_funds(payment_preimage_1, &None, 1_000_000); + nodes[1].node.claim_funds(payment_preimage_1, 1_000_000); check_added_monitors!(nodes[1], 1); let events_3 = nodes[1].node.get_and_clear_pending_msg_events(); @@ -3880,7 +3880,7 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { _ => panic!("Unexpected event"), } - assert!(nodes[1].node.claim_funds(payment_preimage_1, &None, 1_000_000)); + assert!(nodes[1].node.claim_funds(payment_preimage_1, 1_000_000)); check_added_monitors!(nodes[1], 1); let events_2 = nodes[1].node.get_and_clear_pending_msg_events(); @@ -4735,7 +4735,7 @@ fn test_static_spendable_outputs_preimage_tx() { assert_eq!(commitment_tx[0].input[0].previous_output.txid, chan_1.3.txid()); // Settle A's commitment tx on B's chain - assert!(nodes[1].node.claim_funds(payment_preimage, &None, 3_000_000)); + assert!(nodes[1].node.claim_funds(payment_preimage, 3_000_000)); check_added_monitors!(nodes[1], 1); mine_transaction(&nodes[1], &commitment_tx[0]); check_added_monitors!(nodes[1], 1); @@ -5016,7 +5016,7 @@ fn test_onchain_to_onchain_claim() { let (payment_preimage, _payment_hash, _payment_secret) = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2]), 3000000); let commitment_tx = get_local_commitment_txn!(nodes[2], chan_2.2); check_spends!(commitment_tx[0], chan_2.3); - nodes[2].node.claim_funds(payment_preimage, &None, 3_000_000); + nodes[2].node.claim_funds(payment_preimage, 3_000_000); check_added_monitors!(nodes[2], 1); let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); assert!(updates.update_add_htlcs.is_empty()); @@ -5144,7 +5144,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() { htlc_timeout_tx = node_txn[1].clone(); } - nodes[2].node.claim_funds(our_payment_preimage, &None, 900_000); + nodes[2].node.claim_funds(our_payment_preimage, 900_000); mine_transaction(&nodes[2], &commitment_txn[0]); check_added_monitors!(nodes[2], 2); let events = nodes[2].node.get_and_clear_pending_msg_events(); @@ -5235,7 +5235,7 @@ fn test_dynamic_spendable_outputs_local_htlc_success_tx() { check_spends!(local_txn[0], chan_1.3); // Give B knowledge of preimage to be able to generate a local HTLC-Success Tx - nodes[1].node.claim_funds(payment_preimage, &None, 9_000_000); + nodes[1].node.claim_funds(payment_preimage, 9_000_000); check_added_monitors!(nodes[1], 1); mine_transaction(&nodes[1], &local_txn[0]); check_added_monitors!(nodes[1], 1); @@ -5340,10 +5340,10 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno // Now fail back three of the over-dust-limit and three of the under-dust-limit payments in one go. // Fail 0th below-dust, 4th above-dust, 8th above-dust, 10th below-dust HTLCs - assert!(nodes[4].node.fail_htlc_backwards(&payment_hash_1, &None)); - assert!(nodes[4].node.fail_htlc_backwards(&payment_hash_3, &None)); - assert!(nodes[4].node.fail_htlc_backwards(&payment_hash_5, &None)); - assert!(nodes[4].node.fail_htlc_backwards(&payment_hash_6, &None)); + assert!(nodes[4].node.fail_htlc_backwards(&payment_hash_1)); + assert!(nodes[4].node.fail_htlc_backwards(&payment_hash_3)); + assert!(nodes[4].node.fail_htlc_backwards(&payment_hash_5)); + assert!(nodes[4].node.fail_htlc_backwards(&payment_hash_6)); check_added_monitors!(nodes[4], 0); expect_pending_htlcs_forwardable!(nodes[4]); check_added_monitors!(nodes[4], 1); @@ -5356,8 +5356,8 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno commitment_signed_dance!(nodes[3], nodes[4], four_removes.commitment_signed, false); // Fail 3rd below-dust and 7th above-dust HTLCs - assert!(nodes[5].node.fail_htlc_backwards(&payment_hash_2, &None)); - assert!(nodes[5].node.fail_htlc_backwards(&payment_hash_4, &None)); + assert!(nodes[5].node.fail_htlc_backwards(&payment_hash_2)); + assert!(nodes[5].node.fail_htlc_backwards(&payment_hash_4)); check_added_monitors!(nodes[5], 0); expect_pending_htlcs_forwardable!(nodes[5]); check_added_monitors!(nodes[5], 1); @@ -5670,7 +5670,7 @@ fn do_htlc_claim_local_commitment_only(use_dust: bool) { // Claim the payment, but don't deliver A's commitment_signed, resulting in the HTLC only being // present in B's local commitment transaction, but none of A's commitment transactions. - assert!(nodes[1].node.claim_funds(our_payment_preimage, &None, if use_dust { 50_000 } else { 3_000_000 })); + assert!(nodes[1].node.claim_funds(our_payment_preimage, if use_dust { 50_000 } else { 3_000_000 })); check_added_monitors!(nodes[1], 1); let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); @@ -5749,7 +5749,7 @@ fn do_htlc_claim_previous_remote_commitment_only(use_dust: bool, check_revoke_no // actually revoked. let htlc_value = if use_dust { 50000 } else { 3000000 }; let (_, our_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1]], htlc_value); - assert!(nodes[1].node.fail_htlc_backwards(&our_payment_hash, &None)); + assert!(nodes[1].node.fail_htlc_backwards(&our_payment_hash)); expect_pending_htlcs_forwardable!(nodes[1]); check_added_monitors!(nodes[1], 1); @@ -6063,7 +6063,7 @@ fn test_free_and_fail_holding_cell_htlcs() { Event::PaymentReceived { .. } => {}, _ => panic!("Unexpected event"), } - nodes[1].node.claim_funds(payment_preimage_1, &None, amt_1); + nodes[1].node.claim_funds(payment_preimage_1, amt_1); check_added_monitors!(nodes[1], 1); let update_msgs = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_msgs.update_fulfill_htlcs[0]); @@ -6706,7 +6706,7 @@ fn test_update_fulfill_htlc_bolt2_incorrect_htlc_id() { let our_payment_preimage = route_payment(&nodes[0], &[&nodes[1]], 100000).0; - nodes[1].node.claim_funds(our_payment_preimage, &None, 100_000); + nodes[1].node.claim_funds(our_payment_preimage, 100_000); check_added_monitors!(nodes[1], 1); let events = nodes[1].node.get_and_clear_pending_msg_events(); @@ -6747,7 +6747,7 @@ fn test_update_fulfill_htlc_bolt2_wrong_preimage() { let our_payment_preimage = route_payment(&nodes[0], &[&nodes[1]], 100000).0; - nodes[1].node.claim_funds(our_payment_preimage, &None, 100_000); + nodes[1].node.claim_funds(our_payment_preimage, 100_000); check_added_monitors!(nodes[1], 1); let events = nodes[1].node.get_and_clear_pending_msg_events(); @@ -6927,7 +6927,7 @@ fn do_test_failure_delay_dust_htlc_local_commitment(announce_latest: bool) { let as_prev_commitment_tx = get_local_commitment_txn!(nodes[0], chan.2); // Fail one HTLC to prune it in the will-be-latest-local commitment tx - assert!(nodes[1].node.fail_htlc_backwards(&payment_hash_2, &None)); + assert!(nodes[1].node.fail_htlc_backwards(&payment_hash_2)); check_added_monitors!(nodes[1], 0); expect_pending_htlcs_forwardable!(nodes[1]); check_added_monitors!(nodes[1], 1); @@ -7492,7 +7492,7 @@ fn test_check_htlc_underpaying() { // Node 3 is expecting payment of 100_000 but receive 10_000, // fail htlc like we didn't know the preimage. - nodes[1].node.claim_funds(payment_preimage, &None, 100_000); + nodes[1].node.claim_funds(payment_preimage, 100_000); nodes[1].node.process_pending_htlc_forwards(); let events = nodes[1].node.get_and_clear_pending_msg_events(); @@ -7875,7 +7875,7 @@ fn test_bump_penalty_txn_on_remote_commitment() { assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.txid()); // Claim a HTLC without revocation (provide B monitor with preimage) - nodes[1].node.claim_funds(payment_preimage, &None, 3_000_000); + nodes[1].node.claim_funds(payment_preimage, 3_000_000); mine_transaction(&nodes[1], &remote_txn[0]); check_added_monitors!(nodes[1], 2); @@ -8155,7 +8155,7 @@ fn test_update_err_monitor_lockdown() { watchtower.chain_monitor.block_connected(&Block { header, txdata: vec![] }, 200); // Try to update ChannelMonitor - assert!(nodes[1].node.claim_funds(preimage, &None, 9_000_000)); + assert!(nodes[1].node.claim_funds(preimage, 9_000_000)); check_added_monitors!(nodes[1], 1); let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); @@ -8434,7 +8434,7 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain // Step (5): // Carol then claims the funds and sends an update_fulfill message to Bob, and they go through the // process of removing the HTLC from their commitment transactions. - assert!(nodes[2].node.claim_funds(payment_preimage, &None, 3_000_000)); + assert!(nodes[2].node.claim_funds(payment_preimage, 3_000_000)); check_added_monitors!(nodes[2], 1); let carol_updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); assert!(carol_updates.update_add_htlcs.is_empty()); diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs index 1de45d689..95a77a090 100644 --- a/lightning/src/ln/onion_route_tests.rs +++ b/lightning/src/ln/onion_route_tests.rs @@ -325,7 +325,7 @@ fn test_onion_failure() { let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap(); msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], NODE|2, &[0;0]); }, ||{ - nodes[2].node.fail_htlc_backwards(&payment_hash, &None); + nodes[2].node.fail_htlc_backwards(&payment_hash); }, true, Some(NODE|2), Some(msgs::HTLCFailChannelUpdate::NodeFailure{node_id: route.paths[0][1].pubkey, is_permanent: false})); let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]); @@ -344,7 +344,7 @@ fn test_onion_failure() { let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap(); msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], PERM|NODE|2, &[0;0]); }, ||{ - nodes[2].node.fail_htlc_backwards(&payment_hash, &None); + nodes[2].node.fail_htlc_backwards(&payment_hash); }, false, Some(PERM|NODE|2), Some(msgs::HTLCFailChannelUpdate::NodeFailure{node_id: route.paths[0][1].pubkey, is_permanent: true})); let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]); @@ -356,7 +356,7 @@ fn test_onion_failure() { let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap(); msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], PERM|NODE|3, &[0;0]); }, ||{ - nodes[2].node.fail_htlc_backwards(&payment_hash, &None); + nodes[2].node.fail_htlc_backwards(&payment_hash); }, true, Some(PERM|NODE|3), Some(msgs::HTLCFailChannelUpdate::NodeFailure{node_id: route.paths[0][0].pubkey, is_permanent: true})); // final node failure @@ -365,7 +365,7 @@ fn test_onion_failure() { let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap(); msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], PERM|NODE|3, &[0;0]); }, ||{ - nodes[2].node.fail_htlc_backwards(&payment_hash, &None); + nodes[2].node.fail_htlc_backwards(&payment_hash); }, false, Some(PERM|NODE|3), Some(msgs::HTLCFailChannelUpdate::NodeFailure{node_id: route.paths[0][1].pubkey, is_permanent: true})); let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]); @@ -439,7 +439,7 @@ fn test_onion_failure() { }, ||{}, true, Some(UPDATE|14), Some(msgs::HTLCFailChannelUpdate::ChannelUpdateMessage{msg: ChannelUpdate::dummy()})); run_onion_failure_test("unknown_payment_hash", 2, &nodes, &route, &payment_hash, &payment_secret, |_| {}, || { - nodes[2].node.fail_htlc_backwards(&payment_hash, &None); + nodes[2].node.fail_htlc_backwards(&payment_hash); }, false, Some(PERM|15), None); let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]); diff --git a/lightning/src/ln/reorg_tests.rs b/lightning/src/ln/reorg_tests.rs index 012d480f2..265659816 100644 --- a/lightning/src/ln/reorg_tests.rs +++ b/lightning/src/ln/reorg_tests.rs @@ -59,7 +59,7 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) { let (our_payment_preimage, our_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000); // Provide preimage to node 2 by claiming payment - nodes[2].node.claim_funds(our_payment_preimage, &None, 1000000); + nodes[2].node.claim_funds(our_payment_preimage, 1000000); check_added_monitors!(nodes[2], 1); get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); @@ -358,8 +358,8 @@ fn test_set_outpoints_partial_claiming() { // Connect blocks on node A to advance height towards TEST_FINAL_CLTV // Provide node A with both preimage - nodes[0].node.claim_funds(payment_preimage_1, &None, 3_000_000); - nodes[0].node.claim_funds(payment_preimage_2, &None, 3_000_000); + nodes[0].node.claim_funds(payment_preimage_1, 3_000_000); + nodes[0].node.claim_funds(payment_preimage_2, 3_000_000); check_added_monitors!(nodes[0], 2); nodes[0].node.get_and_clear_pending_events(); nodes[0].node.get_and_clear_pending_msg_events();