From 3ec07c0c415126b601338a5f7de3fdf5d3d96398 Mon Sep 17 00:00:00 2001 From: Sean Andersen Date: Thu, 21 Apr 2022 17:46:23 -0700 Subject: [PATCH] Introduce RecipientInfo struct for send_payment This work is a pre-req for https://github.com/lightningdevkit/rust-lightning/issues/1298. This moves the `payment_secret` and the `payment_metadata` into a new struct called `RecipientInfo`. This will allow us to add custom onion TLVs, see https://github.com/lightningdevkit/rust-lightning/issues/1298#issuecomment-1094387546 No logic change, just lots of plumbing. --- lightning-invoice/src/payment.rs | 20 +- lightning-invoice/src/utils.rs | 22 +- lightning/src/chain/chainmonitor.rs | 7 +- lightning/src/chain/channelmonitor.rs | 5 +- lightning/src/ln/chanmon_update_fail_tests.rs | 82 ++++--- lightning/src/ln/channelmanager.rs | 27 +-- lightning/src/ln/functional_test_utils.rs | 8 +- lightning/src/ln/functional_tests.rs | 204 ++++++++++++------ lightning/src/ln/mod.rs | 8 + lightning/src/ln/monitor_tests.rs | 10 +- lightning/src/ln/onion_route_tests.rs | 32 ++- lightning/src/ln/payment_tests.rs | 22 +- lightning/src/ln/priv_short_conf_tests.rs | 22 +- lightning/src/ln/shutdown_tests.rs | 9 +- 14 files changed, 316 insertions(+), 162 deletions(-) diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index df875b5bf22..aeb0b0fba9d 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -35,7 +35,7 @@ //! # #[cfg(feature = "no-std")] //! # extern crate core2; //! # -//! # use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret}; +//! # use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret, RecipientInfo}; //! # use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure}; //! # use lightning::ln::msgs::LightningError; //! # use lightning::routing::scoring::Score; @@ -64,8 +64,7 @@ //! # impl Payer for FakePayer { //! # fn node_id(&self) -> PublicKey { unimplemented!() } //! # fn first_hops(&self) -> Vec { unimplemented!() } -//! # fn send_payment(&self, route: &Route, payment_hash: PaymentHash, -//! # payment_secret: &Option, payment_metadata: Option> +//! # fn send_payment(&self, route: &Route, payment_hash: PaymentHash, recipient_info: &RecipientInfo //! # ) -> Result { unimplemented!() } //! # fn send_spontaneous_payment( //! # &self, route: &Route, payment_preimage: PaymentPreimage @@ -139,7 +138,7 @@ use bitcoin_hashes::Hash; use bitcoin_hashes::sha256::Hash as Sha256; use crate::prelude::*; -use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret}; +use lightning::ln::{PaymentHash, PaymentPreimage, RecipientInfo}; use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure}; use lightning::ln::msgs::LightningError; use lightning::routing::scoring::{LockableScore, Score}; @@ -186,8 +185,8 @@ pub trait Payer { fn first_hops(&self) -> Vec; /// Sends a payment over the Lightning Network using the given [`Route`]. - fn send_payment(&self, route: &Route, payment_hash: PaymentHash, - payment_secret: &Option, payment_metadata: Option> + fn send_payment( + &self, route: &Route, payment_hash: PaymentHash, recipient_info: &RecipientInfo ) -> Result; /// Sends a spontaneous payment over the Lightning Network using the given [`Route`]. @@ -309,7 +308,8 @@ where }; let send_payment = |route: &Route| { - self.payer.send_payment(route, payment_hash, &payment_secret, invoice.payment_metadata().cloned()) + let recipient_info = RecipientInfo { payment_secret, payment_metadata: invoice.payment_metadata().cloned() }; + self.payer.send_payment(route, payment_hash, &recipient_info) }; self.pay_internal(&route_params, payment_hash, send_payment) .map_err(|e| { self.payment_cache.lock().unwrap().remove(&payment_hash); e }) @@ -528,7 +528,7 @@ mod tests { use crate::{InvoiceBuilder, Currency}; use utils::create_invoice_from_channelmanager_and_duration_since_epoch; use bitcoin_hashes::sha256::Hash as Sha256; - use lightning::ln::PaymentPreimage; + use lightning::ln::{PaymentPreimage, PaymentSecret}; use lightning::ln::features::{ChannelFeatures, NodeFeatures, InitFeatures}; use lightning::ln::functional_test_utils::*; use lightning::ln::msgs::{ChannelMessageHandler, ErrorAction, LightningError}; @@ -1463,8 +1463,8 @@ mod tests { Vec::new() } - fn send_payment(&self, route: &Route, _payment_hash: PaymentHash, - _payment_secret: &Option, _payment_metadata: Option> + fn send_payment( + &self, route: &Route, _payment_hash: PaymentHash, _recipient_info: &RecipientInfo ) -> Result { self.check_value_msats(Amount::ForInvoice(route.get_total_amount())); self.check_attempts() diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index 3d09e305cc3..0cc8b2391b7 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -9,7 +9,7 @@ use bitcoin_hashes::{Hash, sha256}; use lightning::chain; use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator}; use lightning::chain::keysinterface::{Recipient, KeysInterface, Sign}; -use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret}; +use lightning::ln::{PaymentHash, PaymentPreimage, RecipientInfo}; use lightning::ln::channelmanager::{ChannelDetails, ChannelManager, PaymentId, PaymentSendFailure, MIN_FINAL_CLTV_EXPIRY}; #[cfg(feature = "std")] use lightning::ln::channelmanager::{PhantomRouteHints, MIN_CLTV_EXPIRY_DELTA}; @@ -474,10 +474,10 @@ where self.list_usable_channels() } - fn send_payment(&self, route: &Route, payment_hash: PaymentHash, - payment_secret: &Option, payment_metadata: Option> + fn send_payment( + &self, route: &Route, payment_hash: PaymentHash, recipient_info: &RecipientInfo ) -> Result { - self.send_payment(route, payment_hash, payment_secret, payment_metadata) + self.send_payment(route, payment_hash, recipient_info) } fn send_spontaneous_payment( @@ -505,7 +505,7 @@ mod test { use bitcoin_hashes::Hash; use bitcoin_hashes::sha256::Hash as Sha256; use lightning::chain::keysinterface::PhantomKeysManager; - use lightning::ln::{PaymentPreimage, PaymentHash}; + use lightning::ln::{PaymentPreimage, PaymentHash, RecipientInfo}; use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY}; use lightning::ln::functional_test_utils::*; use lightning::ln::features::InitFeatures; @@ -564,7 +564,11 @@ mod test { let payment_event = { let mut payment_hash = PaymentHash([0; 32]); payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]); - nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), None).unwrap(); + let recipient_info = RecipientInfo { + payment_secret: Some(invoice.payment_secret().clone()), + payment_metadata: None + }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); added_monitors.clear(); @@ -833,7 +837,11 @@ mod test { let (payment_event, fwd_idx) = { let mut payment_hash = PaymentHash([0; 32]); payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]); - nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), None).unwrap(); + let recipient_info = RecipientInfo { + payment_secret: Some(invoice.payment_secret().clone()), + payment_metadata: None + }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); added_monitors.clear(); diff --git a/lightning/src/chain/chainmonitor.rs b/lightning/src/chain/chainmonitor.rs index 2e1188935c4..bc47369a813 100644 --- a/lightning/src/chain/chainmonitor.rs +++ b/lightning/src/chain/chainmonitor.rs @@ -737,6 +737,7 @@ mod tests { use ln::features::InitFeatures; use ln::functional_test_utils::*; use ln::msgs::ChannelMessageHandler; + use ln::RecipientInfo; use util::errors::APIError; use util::events::{ClosureReason, MessageSendEvent, MessageSendEventsProvider}; use util::test_utils::{OnRegisterOutput, TxOutReference}; @@ -901,7 +902,11 @@ mod tests { // If the ChannelManager tries to update the channel, however, the ChainMonitor will pass // the update through to the ChannelMonitor which will refuse it (as the channel is closed). chanmon_cfgs[0].persister.set_update_ret(Ok(())); - unwrap_send_err!(nodes[0].node.send_payment(&route, second_payment_hash, &Some(second_payment_secret), None), + let recipient_info = RecipientInfo { + payment_secret: Some(second_payment_secret), + payment_metadata: None, + }; + unwrap_send_err!(nodes[0].node.send_payment(&route, second_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert!(err.contains("ChannelMonitor storage failure"))); check_added_monitors!(nodes[0], 2); // After the failure we generate a close-channel monitor update diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index eb5189eb94a..151eb708ddc 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -3343,7 +3343,7 @@ mod tests { use chain::package::{weight_offered_htlc, weight_received_htlc, weight_revoked_offered_htlc, weight_revoked_received_htlc, WEIGHT_REVOKED_OUTPUT}; use chain::transaction::OutPoint; use chain::keysinterface::InMemorySigner; - use ln::{PaymentPreimage, PaymentHash}; + use ln::{PaymentPreimage, PaymentHash, RecipientInfo}; use ln::chan_utils; use ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, ChannelTransactionParameters, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters}; use ln::channelmanager::PaymentSendFailure; @@ -3411,7 +3411,8 @@ mod tests { // If the ChannelManager tries to update the channel, however, the ChainMonitor will pass // the update through to the ChannelMonitor which will refuse it (as the channel is closed). let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 100_000); - unwrap_send_err!(nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret), None), + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[1].node.send_payment(&route, payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert!(err.contains("ChannelMonitor storage failure"))); check_added_monitors!(nodes[1], 2); // After the failure we generate a close-channel monitor update diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index de7cab74382..3380f186e19 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -19,6 +19,7 @@ use bitcoin::network::constants::Network; use chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor}; use chain::transaction::OutPoint; use chain::{ChannelMonitorUpdateErr, Listen, Watch}; +use ln::RecipientInfo; use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure}; use ln::channel::AnnouncementSigsState; use ln::features::InitFeatures; @@ -50,7 +51,8 @@ fn test_simple_monitor_permanent_update_fail() { let (route, payment_hash_1, _, payment_secret_1) = get_route_and_payment_hash!(&nodes[0], nodes[1], 1000000); chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::PermanentFailure)); - unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), None), true, APIError::ChannelUnavailable {..}, {}); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_1), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &recipient_info), true, APIError::ChannelUnavailable {..}, {}); check_added_monitors!(nodes[0], 2); let events_1 = nodes[0].node.get_and_clear_pending_msg_events(); @@ -158,7 +160,8 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) { chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure)); { - unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), None), false, APIError::MonitorUpdateFailed, {}); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_1), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &recipient_info), false, APIError::MonitorUpdateFailed, {}); check_added_monitors!(nodes[0], 1); } @@ -209,7 +212,8 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) { let (route, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(&nodes[0], nodes[1], 1000000); { chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure)); - unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None), false, APIError::MonitorUpdateFailed, {}); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &recipient_info), false, APIError::MonitorUpdateFailed, {}); check_added_monitors!(nodes[0], 1); } @@ -273,7 +277,8 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); { chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure)); - unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None), false, APIError::MonitorUpdateFailed, {}); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &recipient_info), false, APIError::MonitorUpdateFailed, {}); check_added_monitors!(nodes[0], 1); } @@ -610,7 +615,8 @@ fn test_monitor_update_fail_cs() { let (route, our_payment_hash, payment_preimage, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); { - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } @@ -702,7 +708,8 @@ fn test_monitor_update_fail_no_rebroadcast() { let (route, our_payment_hash, payment_preimage_1, payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); { - nodes[0].node.send_payment(&route, our_payment_hash, &Some(payment_secret_1), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_1), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } @@ -750,14 +757,16 @@ fn test_monitor_update_raa_while_paused() { send_payment(&nodes[0], &[&nodes[1]], 5000000); let (route, our_payment_hash_1, payment_preimage_1, our_payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); { - nodes[0].node.send_payment(&route, our_payment_hash_1, &Some(our_payment_secret_1), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret_1), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash_1, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } let send_event_1 = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); let (route, our_payment_hash_2, payment_preimage_2, our_payment_secret_2) = get_route_and_payment_hash!(nodes[1], nodes[0], 1000000); { - nodes[1].node.send_payment(&route, our_payment_hash_2, &Some(our_payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret_2), payment_metadata: None }; + nodes[1].node.send_payment(&route, our_payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[1], 1); } let send_event_2 = SendEvent::from_event(nodes[1].node.get_and_clear_pending_msg_events().remove(0)); @@ -846,7 +855,8 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { // holding cell. let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[2], 1000000); { - nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } @@ -871,7 +881,8 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { // being paused waiting a monitor update. let (route, payment_hash_3, _, payment_secret_3) = get_route_and_payment_hash!(nodes[0], nodes[2], 1000000); { - nodes[0].node.send_payment(&route, payment_hash_3, &Some(payment_secret_3), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_3), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_3, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } @@ -890,7 +901,8 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { let (payment_preimage_4, payment_hash_4) = if test_ignore_second_cs { // Try to route another payment backwards from 2 to make sure 1 holds off on responding let (route, payment_hash_4, payment_preimage_4, payment_secret_4) = get_route_and_payment_hash!(nodes[2], nodes[0], 1000000); - nodes[2].node.send_payment(&route, payment_hash_4, &Some(payment_secret_4), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_4), payment_metadata: None }; + nodes[2].node.send_payment(&route, payment_hash_4, &recipient_info).unwrap(); check_added_monitors!(nodes[2], 1); send_event = SendEvent::from_event(nodes[2].node.get_and_clear_pending_msg_events().remove(0)); @@ -1182,9 +1194,11 @@ fn raa_no_response_awaiting_raa_state() { // requires only an RAA response due to AwaitingRAA) we can deliver the RAA and require the CS // generation during RAA while in monitor-update-failed state. { - nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_1), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_1, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); - nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 0); } @@ -1234,7 +1248,8 @@ fn raa_no_response_awaiting_raa_state() { // chanmon_fail_consistency test required it to actually find the bug (by seeing out-of-sync // commitment transaction states) whereas here we can explicitly check for it. { - nodes[0].node.send_payment(&route, payment_hash_3, &Some(payment_secret_3), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_3), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_3, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 0); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); } @@ -1323,7 +1338,8 @@ fn claim_while_disconnected_monitor_update_fail() { // the monitor still failed let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); { - nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } @@ -1413,7 +1429,8 @@ fn monitor_failed_no_reestablish_response() { // on receipt). let (route, payment_hash_1, payment_preimage_1, payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); { - nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_1), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_1, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } @@ -1486,7 +1503,8 @@ fn first_message_on_recv_ordering() { // can deliver it and fail the monitor update. let (route, payment_hash_1, payment_preimage_1, payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); { - nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_1), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_1, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } @@ -1509,7 +1527,8 @@ fn first_message_on_recv_ordering() { // Route the second payment, generating an update_add_htlc/commitment_signed let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); { - nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -1592,7 +1611,8 @@ fn test_monitor_update_fail_claim() { let (route, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(nodes[2], nodes[0], 1_000_000); { - nodes[2].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[2].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[2], 1); } @@ -1609,7 +1629,8 @@ fn test_monitor_update_fail_claim() { commitment_signed_dance!(nodes[1], nodes[2], payment_event.commitment_msg, false, true); let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]); - nodes[2].node.send_payment(&route, payment_hash_3, &Some(payment_secret_3), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_3), payment_metadata: None }; + nodes[2].node.send_payment(&route, payment_hash_3, &recipient_info).unwrap(); check_added_monitors!(nodes[2], 1); let mut events = nodes[2].node.get_and_clear_pending_msg_events(); @@ -1699,7 +1720,8 @@ fn test_monitor_update_on_pending_forwards() { let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[2], nodes[0], 1000000); { - nodes[2].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[2].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[2], 1); } @@ -1759,7 +1781,8 @@ fn monitor_update_claim_fail_no_response() { // Now start forwarding a second payment, skipping the last RAA so B is in AwaitingRAA let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); { - nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } @@ -1944,7 +1967,8 @@ fn test_path_paused_mpp() { // Now check that we get the right return value, indicating that the first path succeeded but // the second got a MonitorUpdateFailed err. This implies PaymentSendFailure::PartialFailure as // some paths succeeded, preventing retry. - if let Err(PaymentSendFailure::PartialFailure { results, ..}) = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None) { + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + if let Err(PaymentSendFailure::PartialFailure { results, ..}) = nodes[0].node.send_payment(&route, payment_hash, &recipient_info) { assert_eq!(results.len(), 2); if let Ok(()) = results[0] {} else { panic!(); } if let Err(APIError::MonitorUpdateFailed) = results[1] {} else { panic!(); } @@ -1989,7 +2013,8 @@ fn test_pending_update_fee_ack_on_reconnect() { send_payment(&nodes[0], &[&nodes[1]], 100_000_00); let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(&nodes[1], nodes[0], 1_000_000); - nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[1].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[1], 1); let bs_initial_send_msgs = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); // bs_initial_send_msgs are not delivered until they are re-generated after reconnect @@ -2237,12 +2262,14 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) { // will not be freed from the holding cell. let (payment_preimage_0, _, _) = route_payment(&nodes[1], &[&nodes[0]], 100000); - nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_1), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_1, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let send = SendEvent::from_node(&nodes[0]); assert_eq!(send.msgs.len(), 1); - nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 0); chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure)); @@ -2432,7 +2459,8 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f // In order to get the HTLC claim into the holding cell at nodes[1], we need nodes[1] to be // awaiting a remote revoke_and_ack from nodes[0]. let (route, second_payment_hash, _, second_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000); - nodes[0].node.send_payment(&route, second_payment_hash, &Some(second_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(second_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, second_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let send_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 1f9c7b75bda..5fc81092ead 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -40,7 +40,7 @@ use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitor use chain::transaction::{OutPoint, TransactionData}; // Since this struct is returned in `list_channels` methods, expose it here in case users want to // construct one themselves. -use ln::{inbound_payment, PaymentHash, PaymentPreimage, PaymentSecret}; +use ln::{inbound_payment, PaymentHash, PaymentPreimage, PaymentSecret, RecipientInfo}; use ln::channel::{Channel, ChannelError, ChannelUpdateStatus, UpdateFulfillCommitFetch}; use ln::features::{ChannelTypeFeatures, InitFeatures, NodeFeatures}; use routing::router::{PaymentParameters, Route, RouteHop, RoutePath, RouteParameters}; @@ -2473,6 +2473,7 @@ impl ChannelMana /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a /// different route unless you intend to pay twice! /// + /// Provide recipient_info to include payment_secret or payment_metadata), note that the /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route @@ -2481,11 +2482,11 @@ impl ChannelMana /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature /// bit set (either as required or as available). If multiple paths are present in the Route, /// we assume the invoice had the basic_mpp feature set. - pub fn send_payment(&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option, payment_metadata: Option>) -> Result { - self.send_payment_internal(route, payment_hash, payment_secret, payment_metadata, None, None, None) + pub fn send_payment(&self, route: &Route, payment_hash: PaymentHash, recipient_info: &RecipientInfo) -> Result { + self.send_payment_internal(route, payment_hash, &recipient_info.payment_secret, &recipient_info.payment_metadata, None, None, None) } - fn send_payment_internal(&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option, payment_metadata: Option>, keysend_preimage: Option, payment_id: Option, recv_value_msat: Option) -> Result { + fn send_payment_internal(&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option, payment_metadata: &Option>, keysend_preimage: Option, payment_id: Option, recv_value_msat: Option) -> Result { if route.paths.len() < 1 { return Err(PaymentSendFailure::ParameterError(APIError::RouteError{err: "There must be at least one path to send over"})); } @@ -2627,7 +2628,7 @@ impl ChannelMana })) } }; - return self.send_payment_internal(route, payment_hash, &payment_secret, payment_metadata, None, Some(payment_id), Some(total_msat)).map(|_| ()) + return self.send_payment_internal(route, payment_hash, &payment_secret, &payment_metadata, None, Some(payment_id), Some(total_msat)).map(|_| ()) } /// Signals that no further retries for the given payment will occur. @@ -2681,7 +2682,7 @@ impl ChannelMana None => PaymentPreimage(self.keys_manager.get_secure_random_bytes()), }; let payment_hash = PaymentHash(Sha256::hash(&preimage.0).into_inner()); - match self.send_payment_internal(route, payment_hash, &None, None, Some(preimage), None, None) { + match self.send_payment_internal(route, payment_hash, &None, &None, Some(preimage), None, None) { Ok(payment_id) => Ok((payment_hash, payment_id)), Err(e) => Err(e) } @@ -6856,7 +6857,7 @@ mod tests { use bitcoin::hashes::sha256::Hash as Sha256; use core::time::Duration; use core::sync::atomic::Ordering; - use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; + use ln::{PaymentPreimage, PaymentHash, PaymentSecret, RecipientInfo}; use ln::channelmanager::{PaymentId, PaymentSendFailure}; use ln::channelmanager::inbound_payment; use ln::features::InitFeatures; @@ -7178,7 +7179,8 @@ mod tests { // Next, attempt a regular payment and make sure it fails. let payment_secret = PaymentSecret([43; 32]); - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -7235,7 +7237,7 @@ mod tests { let test_preimage = PaymentPreimage([42; 32]); let mismatch_payment_hash = PaymentHash([43; 32]); - let _ = nodes[0].node.send_payment_internal(&route, mismatch_payment_hash, &None, None, Some(test_preimage), None, None).unwrap(); + let _ = nodes[0].node.send_payment_internal(&route, mismatch_payment_hash, &None, &None, Some(test_preimage), None, None).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); @@ -7280,7 +7282,7 @@ mod tests { let test_preimage = PaymentPreimage([42; 32]); let test_secret = PaymentSecret([43; 32]); let payment_hash = PaymentHash(Sha256::hash(&test_preimage.0).into_inner()); - let _ = nodes[0].node.send_payment_internal(&route, payment_hash, &Some(test_secret), None, Some(test_preimage), None, None).unwrap(); + let _ = nodes[0].node.send_payment_internal(&route, payment_hash, &Some(test_secret), &None, Some(test_preimage), None, None).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); @@ -7317,7 +7319,8 @@ mod tests { route.paths[1][0].short_channel_id = chan_2_id; route.paths[1][1].short_channel_id = chan_4_id; - match nodes[0].node.send_payment(&route, payment_hash, &None, None).unwrap_err() { + let recipient_info = RecipientInfo { payment_secret: None, payment_metadata: None }; + match nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap_err() { PaymentSendFailure::ParameterError(APIError::APIMisuseError { ref err }) => { assert!(regex::Regex::new(r"Payment secret is required for multi-path payments").unwrap().is_match(err)) }, _ => panic!("unexpected error") @@ -7488,7 +7491,7 @@ pub mod bench { let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()); let payment_secret = $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200).unwrap(); - $node_a.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + $node_asend_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); let payment_event = SendEvent::from_event($node_a.get_and_clear_pending_msg_events().pop().unwrap()); $node_b.handle_update_add_htlc(&$node_a.get_our_node_id(), &payment_event.msgs[0]); $node_b.handle_commitment_signed(&$node_a.get_our_node_id(), &payment_event.commitment_msg); diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 922717cca10..b7e5370c11f 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -13,7 +13,7 @@ use chain::{BestBlock, Confirm, Listen, Watch, keysinterface::KeysInterface}; use chain::channelmonitor::ChannelMonitor; use chain::transaction::OutPoint; -use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; +use ln::{PaymentPreimage, PaymentHash, PaymentSecret, RecipientInfo}; use ln::channelmanager::{ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, PaymentId, MIN_CLTV_EXPIRY_DELTA}; use routing::network_graph::{NetGraphMsgHandler, NetworkGraph}; use routing::router::{PaymentParameters, Route, get_route}; @@ -1457,7 +1457,8 @@ macro_rules! expect_payment_failed_conditions { } pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_paths: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret) -> PaymentId { - let payment_id = origin_node.node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + let payment_id = origin_node.node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(origin_node, expected_paths.len()); pass_along_route(origin_node, expected_paths, recv_value, our_payment_hash, our_payment_secret); payment_id @@ -1687,7 +1688,8 @@ pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_rou } let (_, our_payment_hash, our_payment_preimage) = get_payment_preimage_hash!(expected_route.last().unwrap()); - unwrap_send_err!(origin_node.node.send_payment(&route, our_payment_hash, &Some(our_payment_preimage), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_preimage), payment_metadata: None }; + unwrap_send_err!(origin_node.node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert!(err.contains("Cannot send value that would put us over the max HTLC value in flight our peer will accept"))); } diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 1c58342eb02..8c2ed3cd514 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -17,7 +17,7 @@ use chain::channelmonitor; use chain::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY}; use chain::transaction::OutPoint; use chain::keysinterface::{BaseSign, KeysInterface}; -use ln::{PaymentPreimage, PaymentSecret, PaymentHash}; +use ln::{PaymentPreimage, PaymentSecret, PaymentHash, RecipientInfo}; use ln::channel::{commitment_tx_base_weight, COMMITMENT_TX_WEIGHT_PER_HTLC, CONCURRENT_INBOUND_HTLC_FEE_BUFFER, FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE, MIN_AFFORDABLE_HTLC_COUNT}; use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, PaymentId, RAACommitmentOrder, PaymentSendFailure, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, PAYMENT_EXPIRY_BLOCKS }; use ln::channel::{Channel, ChannelError}; @@ -224,7 +224,8 @@ fn test_async_inbound_update_fee() { // ...but before it's delivered, nodes[1] starts to send a payment back to nodes[0]... let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 40000); - nodes[1].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[1].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[1], 1); let payment_event = { @@ -323,7 +324,8 @@ fn test_update_fee_unordered_raa() { // ...but before it's delivered, nodes[1] starts to send a payment back to nodes[0]... let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 40000); - nodes[1].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[1].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[1], 1); let payment_event = { @@ -751,7 +753,8 @@ fn test_update_fee_with_fundee_update_add_htlc() { let (route, our_payment_hash, our_payment_preimage, our_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 800000); // nothing happens since node[1] is in AwaitingRemoteRevoke - nodes[1].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[1].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); { let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 0); @@ -1086,7 +1089,8 @@ fn holding_cell_htlc_counting() { let mut payments = Vec::new(); for _ in 0..::ln::channel::OUR_MAX_HTLCS { let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[2], 100000); - nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[1].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); payments.push((payment_preimage, payment_hash)); } check_added_monitors!(nodes[1], 1); @@ -1101,7 +1105,8 @@ fn holding_cell_htlc_counting() { // another HTLC. let (route, payment_hash_1, _, payment_secret_1) = get_route_and_payment_hash!(nodes[1], nodes[2], 100000); { - unwrap_send_err!(nodes[1].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_1), payment_metadata: None }; + unwrap_send_err!(nodes[1].node.send_payment(&route, payment_hash_1, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert!(regex::Regex::new(r"Cannot push more than their max accepted HTLCs \(\d+\)").unwrap().is_match(err))); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); nodes[1].logger.assert_log_contains("lightning::ln::channelmanager".to_string(), "Cannot push more than their max accepted HTLCs".to_string(), 1); @@ -1110,7 +1115,8 @@ fn holding_cell_htlc_counting() { // This should also be true if we try to forward a payment. let (route, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[2], 100000); { - nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); } @@ -1316,7 +1322,8 @@ fn test_basic_channel_reserve() { let commit_tx_fee = 2 * commit_tx_fee_msat(get_feerate!(nodes[0], chan.2), 1 + 1, get_opt_anchors!(nodes[0], chan.2)); let max_can_send = 5000000 - channel_reserve - commit_tx_fee; let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], max_can_send + 1); - let err = nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).err().unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + let err = nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).err().unwrap(); match err { PaymentSendFailure::AllFailedRetrySafe(ref fails) => { match &fails[0] { @@ -1491,7 +1498,8 @@ fn test_chan_reserve_violation_outbound_htlc_inbound_chan() { // However one more HTLC should be significantly over the reserve amount and fail. let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 1_000_000); - unwrap_send_err!(nodes[1].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[1].node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, "Cannot send value that would put counterparty balance under holder-announced channel reserve value")); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Cannot send value that would put counterparty balance under holder-announced channel reserve value".to_string(), 1); @@ -1582,7 +1590,8 @@ fn test_chan_reserve_dust_inbound_htlcs_outbound_chan() { // One more than the dust amt should fail, however. let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], dust_amt + 1); - unwrap_send_err!(nodes[1].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[1].node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, "Cannot send value that would put counterparty balance under holder-announced channel reserve value")); } @@ -1676,7 +1685,8 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() { // Add a pending HTLC. let (route_1, our_payment_hash_1, _, our_payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[2], amt_msat_1); let payment_event_1 = { - nodes[0].node.send_payment(&route_1, our_payment_hash_1, &Some(our_payment_secret_1), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret_1), payment_metadata: None }; + nodes[0].node.send_payment(&route_1, our_payment_hash_1, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -1782,7 +1792,8 @@ fn test_channel_reserve_holding_cell_htlcs() { let (mut route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], recv_value_0); route.paths[0].last_mut().unwrap().fee_msat += 1; assert!(route.paths[0].iter().rev().skip(1).all(|h| h.fee_msat == feemsat)); - unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert!(regex::Regex::new(r"Cannot send value that would put us over the max HTLC value in flight our peer will accept \(\d+\)").unwrap().is_match(err))); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); nodes[0].logger.assert_log_contains("lightning::ln::channelmanager".to_string(), "Cannot send value that would put us over the max HTLC value in flight our peer will accept".to_string(), 1); @@ -1833,7 +1844,8 @@ fn test_channel_reserve_holding_cell_htlcs() { let (route_1, our_payment_hash_1, our_payment_preimage_1, our_payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[2], recv_value_1); let payment_event_1 = { - nodes[0].node.send_payment(&route_1, our_payment_hash_1, &Some(our_payment_secret_1), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret_1), payment_metadata: None }; + nodes[0].node.send_payment(&route_1, our_payment_hash_1, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -1846,7 +1858,8 @@ fn test_channel_reserve_holding_cell_htlcs() { let recv_value_2 = stat01.value_to_self_msat - amt_msat_1 - stat01.channel_reserve_msat - total_fee_msat - commit_tx_fee_2_htlcs; { let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], recv_value_2 + 1); - unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert!(regex::Regex::new(r"Cannot send value that would put our balance under counterparty-announced channel reserve value \(\d+\)").unwrap().is_match(err))); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); } @@ -1864,7 +1877,8 @@ fn test_channel_reserve_holding_cell_htlcs() { // now see if they go through on both sides let (route_21, our_payment_hash_21, our_payment_preimage_21, our_payment_secret_21) = get_route_and_payment_hash!(nodes[0], nodes[2], recv_value_21); // but this will stuck in the holding cell - nodes[0].node.send_payment(&route_21, our_payment_hash_21, &Some(our_payment_secret_21), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret_21), payment_metadata: None }; + nodes[0].node.send_payment(&route_21, our_payment_hash_21, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 0); let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 0); @@ -1872,7 +1886,8 @@ fn test_channel_reserve_holding_cell_htlcs() { // test with outbound holding cell amount > 0 { let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], recv_value_22+1); - unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert!(regex::Regex::new(r"Cannot send value that would put our balance under counterparty-announced channel reserve value \(\d+\)").unwrap().is_match(err))); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); nodes[0].logger.assert_log_contains("lightning::ln::channelmanager".to_string(), "Cannot send value that would put our balance under counterparty-announced channel reserve value".to_string(), 2); @@ -1880,7 +1895,8 @@ fn test_channel_reserve_holding_cell_htlcs() { let (route_22, our_payment_hash_22, our_payment_preimage_22, our_payment_secret_22) = get_route_and_payment_hash!(nodes[0], nodes[2], recv_value_22); // this will also stuck in the holding cell - nodes[0].node.send_payment(&route_22, our_payment_hash_22, &Some(our_payment_secret_22), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret_22), payment_metadata: None }; + nodes[0].node.send_payment(&route_22, our_payment_hash_22, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 0); assert!(nodes[0].node.get_and_clear_pending_events().is_empty()); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); @@ -2015,7 +2031,8 @@ fn channel_reserve_in_flight_removes() { // Start routing the third HTLC (this is just used to get everyone in the right state). let (route, payment_hash_3, payment_preimage_3, payment_secret_3) = get_route_and_payment_hash!(nodes[0], nodes[1], 100000); let send_1 = { - nodes[0].node.send_payment(&route, payment_hash_3, &Some(payment_secret_3), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_3), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_3, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -2087,7 +2104,8 @@ fn channel_reserve_in_flight_removes() { // to A to ensure that A doesn't count the almost-removed HTLC in update_add processing. let (route, payment_hash_4, payment_preimage_4, payment_secret_4) = get_route_and_payment_hash!(nodes[1], nodes[0], 10000); let send_2 = { - nodes[1].node.send_payment(&route, payment_hash_4, &Some(payment_secret_4), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_4), payment_metadata: None }; + nodes[1].node.send_payment(&route, payment_hash_4, &recipient_info).unwrap(); check_added_monitors!(nodes[1], 1); let mut events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -3110,7 +3128,8 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use // Add a fourth HTLC, this one will get sequestered away in nodes[1]'s holding cell waiting // on nodes[2]'s RAA. let (route, fourth_payment_hash, _, fourth_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[2], 1000000); - nodes[1].node.send_payment(&route, fourth_payment_hash, &Some(fourth_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(fourth_payment_secret), payment_metadata: None }; + nodes[1].node.send_payment(&route, fourth_payment_hash, &recipient_info).unwrap(); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); check_added_monitors!(nodes[1], 0); @@ -3267,7 +3286,8 @@ fn fail_backward_pending_htlc_upon_channel_failure() { // Alice -> Bob: Route a payment but without Bob sending revoke_and_ack. { let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 50_000); - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let payment_event = { @@ -3282,7 +3302,8 @@ fn fail_backward_pending_htlc_upon_channel_failure() { // Alice -> Bob: Route another payment but now Alice waits for Bob's earlier revoke_and_ack. let (route, failed_payment_hash, _, failed_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 50_000); { - nodes[0].node.send_payment(&route, failed_payment_hash, &Some(failed_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(failed_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, failed_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 0); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); @@ -3375,7 +3396,8 @@ fn test_force_close_fail_back() { let (route, our_payment_hash, our_payment_preimage, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 1000000); let mut payment_event = { - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -3550,7 +3572,8 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken let (route, payment_hash_1, payment_preimage_1, payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); let payment_event = { - nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_1), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_1, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -3993,7 +4016,8 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { // Now try to send a second payment which will fail to send let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); - nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let events_1 = nodes[0].node.get_and_clear_pending_msg_events(); @@ -4209,7 +4233,8 @@ fn do_test_holding_cell_htlc_add_timeouts(forwarded_htlc: bool) { // Route a first payment to get the 1 -> 2 channel in awaiting_raa... let (route, first_payment_hash, _, first_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[2], 100000); { - nodes[1].node.send_payment(&route, first_payment_hash, &Some(first_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(first_payment_secret), payment_metadata: None }; + nodes[1].node.send_payment(&route, first_payment_hash, &recipient_info).unwrap(); } assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1); check_added_monitors!(nodes[1], 1); @@ -4217,7 +4242,8 @@ fn do_test_holding_cell_htlc_add_timeouts(forwarded_htlc: bool) { // Now attempt to route a second payment, which should be placed in the holding cell let sending_node = if forwarded_htlc { &nodes[0] } else { &nodes[1] }; let (route, second_payment_hash, _, second_payment_secret) = get_route_and_payment_hash!(sending_node, nodes[2], 100000); - sending_node.node.send_payment(&route, second_payment_hash, &Some(second_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(second_payment_secret), payment_metadata: None }; + sending_node.node.send_payment(&route, second_payment_hash, &recipient_info).unwrap(); if forwarded_htlc { check_added_monitors!(nodes[0], 1); let payment_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); @@ -5842,7 +5868,8 @@ fn do_htlc_claim_current_remote_commitment_only(use_dust: bool) { let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], if use_dust { 50000 } else { 3000000 }); - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let _as_update = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); @@ -6088,7 +6115,8 @@ fn test_fail_holding_cell_htlc_upon_free() { let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], max_can_send); // Send a payment which passes reserve checks but gets stuck in the holding cell. - let our_payment_id = nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + let our_payment_id = nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); chan_stat = get_channel_value_stat!(nodes[0], chan.2); assert_eq!(chan_stat.holding_cell_outbound_amount_msat, max_can_send); @@ -6170,10 +6198,12 @@ fn test_free_and_fail_holding_cell_htlcs() { let (route_2, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], amt_2); // Send 2 payments which pass reserve checks but get stuck in the holding cell. - nodes[0].node.send_payment(&route_1, payment_hash_1, &Some(payment_secret_1), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_1), payment_metadata: None }; + nodes[0].node.send_payment(&route_1, payment_hash_1, &recipient_info).unwrap(); chan_stat = get_channel_value_stat!(nodes[0], chan.2); assert_eq!(chan_stat.holding_cell_outbound_amount_msat, amt_1); - let payment_id_2 = nodes[0].node.send_payment(&route_2, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + let payment_id_2 = nodes[0].node.send_payment(&route_2, payment_hash_2, &recipient_info).unwrap(); chan_stat = get_channel_value_stat!(nodes[0], chan.2); assert_eq!(chan_stat.holding_cell_outbound_amount_msat, amt_1 + amt_2); @@ -6295,7 +6325,8 @@ fn test_fail_holding_cell_htlc_upon_free_multihop() { let max_can_send = 5000000 - channel_reserve - 2*commit_tx_fee_msat(feerate, 1 + 1, opt_anchors) - total_routing_fee_msat; let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], max_can_send); let payment_event = { - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -6397,7 +6428,8 @@ fn test_update_add_htlc_bolt2_sender_value_below_minimum_msat() { let (mut route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100000); route.paths[0][0].fee_msat = 100; - unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert!(regex::Regex::new(r"Cannot send less than their minimum HTLC value \(\d+\)").unwrap().is_match(err))); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); nodes[0].logger.assert_log_contains("lightning::ln::channelmanager".to_string(), "Cannot send less than their minimum HTLC value".to_string(), 1); @@ -6414,7 +6446,8 @@ fn test_update_add_htlc_bolt2_sender_zero_value_msat() { let (mut route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100000); route.paths[0][0].fee_msat = 0; - unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, "Cannot send 0-msat HTLC")); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); @@ -6431,7 +6464,8 @@ fn test_update_add_htlc_bolt2_receiver_zero_value_msat() { let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known()); let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100000); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); updates.update_add_htlcs[0].amount_msat = 0; @@ -6457,7 +6491,8 @@ fn test_update_add_htlc_bolt2_sender_cltv_expiry_too_high() { .with_features(InvoiceFeatures::known()); let (mut route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], payment_params, 100000000, 0); route.paths[0].last_mut().unwrap().cltv_expiry_delta = 500000001; - unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None), true, APIError::RouteError { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::RouteError { ref err }, assert_eq!(err, &"Channel CLTV overflowed?")); } @@ -6476,7 +6511,8 @@ fn test_update_add_htlc_bolt2_sender_exceed_max_htlc_num_and_htlc_id_increment() for i in 0..max_accepted_htlcs { let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100000); let payment_event = { - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -6496,7 +6532,8 @@ fn test_update_add_htlc_bolt2_sender_exceed_max_htlc_num_and_htlc_id_increment() expect_payment_received!(nodes[1], our_payment_hash, our_payment_secret, 100000); } let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100000); - unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert!(regex::Regex::new(r"Cannot push more than their max accepted HTLCs \(\d+\)").unwrap().is_match(err))); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); @@ -6520,7 +6557,8 @@ fn test_update_add_htlc_bolt2_sender_exceed_max_htlc_value_in_flight() { // Manually create a route over our max in flight (which our router normally automatically // limits us to. route.paths[0][0].fee_msat = max_in_flight + 1; - unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None), true, APIError::ChannelUnavailable { ref err }, + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert!(regex::Regex::new(r"Cannot send value that would put us over the max HTLC value in flight our peer will accept \(\d+\)").unwrap().is_match(err))); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); @@ -6546,7 +6584,8 @@ fn test_update_add_htlc_bolt2_receiver_check_amount_received_more_than_min() { } let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], htlc_minimum_msat); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); updates.update_add_htlcs[0].amount_msat = htlc_minimum_msat-1; @@ -6576,7 +6615,8 @@ fn test_update_add_htlc_bolt2_receiver_sender_can_afford_amount_sent() { let max_can_send = 5000000 - channel_reserve - commit_tx_fee_outbound; let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], max_can_send); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); @@ -6643,7 +6683,8 @@ fn test_update_add_htlc_bolt2_receiver_check_max_in_flight_msat() { let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known()); let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); updates.update_add_htlcs[0].amount_msat = get_channel_value_stat!(nodes[1], chan.2).counterparty_max_htlc_value_in_flight_msat + 1; @@ -6666,7 +6707,8 @@ fn test_update_add_htlc_bolt2_receiver_check_cltv_expiry() { create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known()); let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); updates.update_add_htlcs[0].cltv_expiry = 500000000; @@ -6691,7 +6733,8 @@ fn test_update_add_htlc_bolt2_receiver_check_repeated_id_ignore() { create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); @@ -6736,7 +6779,8 @@ fn test_update_fulfill_htlc_bolt2_update_fulfill_htlc_before_commitment() { let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let (route, our_payment_hash, our_payment_preimage, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); @@ -6768,7 +6812,8 @@ fn test_update_fulfill_htlc_bolt2_update_fail_htlc_before_commitment() { let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); @@ -6799,7 +6844,8 @@ fn test_update_fulfill_htlc_bolt2_update_fail_malformed_htlc_before_commitment() let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); @@ -6914,7 +6960,8 @@ fn test_update_fulfill_htlc_bolt2_missing_badonion_bit_for_malformed_htlc_messag create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known()); let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); @@ -6965,7 +7012,8 @@ fn test_update_fulfill_htlc_bolt2_after_malformed_htlc_message_must_forward_upda //First hop let mut payment_event = { - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -7418,7 +7466,8 @@ fn test_check_htlc_underpaying() { let route = get_route(&nodes[0].node.get_our_node_id(), &payment_params, &nodes[0].network_graph.read_only(), None, 10_000, TEST_FINAL_CLTV, nodes[0].logger, &scorer, &random_seed_bytes).unwrap(); let (_, our_payment_hash, _) = get_payment_preimage_hash!(nodes[0]); let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash(our_payment_hash, Some(100_000), 7200).unwrap(); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -8043,7 +8092,8 @@ fn test_pending_claimed_htlc_no_balance_underflow() { route.payment_params = None; // This is all wrong, but unnecessary route.paths[0][0].pubkey = nodes[0].node.get_our_node_id(); let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[0]); - nodes[1].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[1].node.send_payment(&route, payment_hash_2, &recipient_info).unwrap(); assert_eq!(nodes[1].node.list_channels()[0].balance_msat, 1_000_000); } @@ -8374,7 +8424,8 @@ fn test_preimage_storage() { { let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 7200).unwrap(); let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000); - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); let mut payment_event = SendEvent::from_event(events.pop().unwrap()); @@ -8444,7 +8495,8 @@ fn test_secret_timeout() { { let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000); - nodes[0].node.send_payment(&route, payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); let mut payment_event = SendEvent::from_event(events.pop().unwrap()); @@ -8515,17 +8567,20 @@ fn test_bad_secret_hash() { let expected_error_data = [0, 0, 0, 0, 0, 1, 0x86, 0xa0, 0, 0, 0, CHAN_CONFIRM_DEPTH as u8]; // Send a payment with the right payment hash but the wrong payment secret - nodes[0].node.send_payment(&route, our_payment_hash, &Some(random_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(random_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); handle_unknown_invalid_payment_data!(); expect_payment_failed!(nodes[0], our_payment_hash, true, expected_error_code, expected_error_data); // Send a payment with a random payment hash, but the right payment secret - nodes[0].node.send_payment(&route, random_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, random_payment_hash, &recipient_info).unwrap(); handle_unknown_invalid_payment_data!(); expect_payment_failed!(nodes[0], random_payment_hash, true, expected_error_code, expected_error_data); // Send a payment with a random payment hash and random payment secret - nodes[0].node.send_payment(&route, random_payment_hash, &Some(random_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(random_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, random_payment_hash, &recipient_info).unwrap(); handle_unknown_invalid_payment_data!(); expect_payment_failed!(nodes[0], random_payment_hash, true, expected_error_code, expected_error_data); } @@ -8665,7 +8720,8 @@ fn test_concurrent_monitor_claim() { // Route another payment to generate another update with still previous HTLC pending let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 3000000); { - nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[1].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); } check_added_monitors!(nodes[1], 1); @@ -9340,7 +9396,8 @@ fn test_forwardable_regen() { // First send a payment to nodes[1] let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000); - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -9353,7 +9410,8 @@ fn test_forwardable_regen() { // Next send a payment which is forwarded by nodes[1] let (route_2, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[2], 200_000); - nodes[0].node.send_payment(&route_2, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route_2, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -9461,7 +9519,8 @@ fn test_dup_htlc_second_fail_panic() { let (_, our_payment_hash, our_payment_secret) = get_payment_preimage_hash!(&nodes[1]); { - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -9473,7 +9532,8 @@ fn test_dup_htlc_second_fail_panic() { expect_payment_received!(nodes[1], our_payment_hash, our_payment_secret, 10_000); { - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -9661,7 +9721,8 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e // Note, we need sent payment to be above outbound dust threshold on counterparty_tx of 2132 sats for i in 0..dust_outbound_htlc_on_holder_tx { let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], dust_outbound_htlc_on_holder_tx_msat); - if let Err(_) = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None) { panic!("Unexpected event at dust HTLC {}", i); } + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + if let Err(_) = nodes[0].node.send_payment(&route, payment_hash, &recipient_info) { panic!("Unexpected event at dust HTLC {}", i); } } } else { // Inbound dust threshold: 2324 sats (`dust_buffer_feerate` * HTLC_SUCCESS_TX_WEIGHT / 1000 + holder's `dust_limit_satoshis`) @@ -9677,11 +9738,12 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e // Outbound dust balance: 5000 sats for i in 0..dust_htlc_on_counterparty_tx { let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], dust_htlc_on_counterparty_tx_msat); - if let Err(_) = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None) { panic!("Unexpected event at dust HTLC {}", i); } + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + if let Err(_) = nodes[0].node.send_payment(&route, payment_hash, &recipient_info) { panic!("unexpected event at dust htlc {}", i); } } } else { - // Inbound dust threshold: 2031 sats (`dust_buffer_feerate` * HTLC_TIMEOUT_TX_WEIGHT / 1000 + counteparty's `dust_limit_satoshis`) - // Inbound dust balance: 5000 sats + // inbound dust threshold: 2031 sats (`dust_buffer_feerate` * htlc_timeout_tx_weight / 1000 + counteparty's `dust_limit_satoshis`) + // inbound dust balance: 5000 sats for _ in 0..dust_htlc_on_counterparty_tx { route_payment(&nodes[1], &[&nodes[0]], dust_htlc_on_counterparty_tx_msat); } @@ -9696,13 +9758,16 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e if on_holder_tx { let dust_outbound_overflow = dust_outbound_htlc_on_holder_tx_msat * (dust_outbound_htlc_on_holder_tx + 1); let dust_inbound_overflow = dust_inbound_htlc_on_holder_tx_msat * dust_inbound_htlc_on_holder_tx + dust_outbound_htlc_on_holder_tx_msat; - unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, &format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx", if dust_outbound_balance { dust_outbound_overflow } else { dust_inbound_overflow }, config.channel_options.max_dust_htlc_exposure_msat))); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, &format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx", if dust_outbound_balance { dust_outbound_overflow } else { dust_inbound_overflow }, config.channel_options.max_dust_htlc_exposure_msat))); } else { - unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, &format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx", dust_overflow, config.channel_options.max_dust_htlc_exposure_msat))); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, &format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx", dust_overflow, config.channel_options.max_dust_htlc_exposure_msat))); } } else if exposure_breach_event == ExposureEvent::AtHTLCReception { let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], if on_holder_tx { dust_inbound_htlc_on_holder_tx_msat } else { dust_htlc_on_counterparty_tx_msat }); - nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[1].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[1], 1); let mut events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -9720,7 +9785,8 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e } } else if exposure_breach_event == ExposureEvent::AtUpdateFeeOutbound { let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 2_500_000); - if let Err(_) = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None) { panic!("Unexpected event at update_fee-swallowed HTLC", ); } + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + if let Err(_) = nodes[0].node.send_payment(&route, payment_hash, &recipient_info) { panic!("Unexpected event at update_fee-swallowed HTLC", ); } { let mut feerate_lock = chanmon_cfgs[0].fee_estimator.sat_per_kw.lock().unwrap(); *feerate_lock = *feerate_lock * 10; diff --git a/lightning/src/ln/mod.rs b/lightning/src/ln/mod.rs index 1e5f49f07df..63ed18b1f30 100644 --- a/lightning/src/ln/mod.rs +++ b/lightning/src/ln/mod.rs @@ -86,6 +86,14 @@ pub struct PaymentPreimage(pub [u8;32]); /// (C-not exported) as we just use [u8; 32] directly #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)] pub struct PaymentSecret(pub [u8;32]); +/// recipient-info type, use to provide payment_secret or bolt11 payment_metadata +#[derive(Clone, Debug, PartialEq)] +pub struct RecipientInfo { + /// optional payment_secret + pub payment_secret: Option, + /// optional bolt11 payment_metadata + pub payment_metadata: Option>, +} use prelude::*; use bitcoin::bech32; diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index b9c30644e70..258fda71631 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -11,6 +11,7 @@ use chain::channelmonitor::{ANTI_REORG_DELAY, Balance}; use chain::transaction::OutPoint; +use ln::RecipientInfo; use ln::channel; use ln::channelmanager::BREAKDOWN_TIMEOUT; use ln::features::InitFeatures; @@ -51,7 +52,8 @@ fn chanmon_fail_from_stale_commitment() { let (update_a, _, chan_id_2, _) = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 1_000_000); - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let bs_txn = get_local_commitment_txn!(nodes[1], chan_id_2); @@ -560,7 +562,8 @@ fn test_balances_on_local_commitment_htlcs() { let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 10_000_000); let htlc_cltv_timeout = nodes[0].best_block_info().1 + TEST_FINAL_CLTV + 1; // Note ChannelManager adds one to CLTV timeouts for safety - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); @@ -571,7 +574,8 @@ fn test_balances_on_local_commitment_htlcs() { expect_payment_received!(nodes[1], payment_hash, payment_secret, 10_000_000); let (route_2, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 20_000_000); - nodes[0].node.send_payment(&route_2, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route_2, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs index ac8ba4cb854..3ddd1a95a48 100644 --- a/lightning/src/ln/onion_route_tests.rs +++ b/lightning/src/ln/onion_route_tests.rs @@ -13,7 +13,7 @@ use chain::channelmonitor::{CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS}; use chain::keysinterface::{KeysInterface, Recipient}; -use ln::{PaymentHash, PaymentSecret}; +use ln::{PaymentHash, PaymentSecret, RecipientInfo}; use ln::channelmanager::{HTLCForwardInfo, CLTV_FAR_FAR_AWAY, MIN_CLTV_EXPIRY_DELTA, PendingHTLCInfo, PendingHTLCRouting}; use ln::onion_utils; use routing::network_graph::{NetworkUpdate, RoutingFees, NodeId}; @@ -79,7 +79,8 @@ fn run_onion_failure_test_with_fail_intercept(_name: &str, test_case: } // 0 ~~> 2 send payment - nodes[0].node.send_payment(&route, payment_hash.clone(), &Some(*payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(*payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash.clone(), &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); // temper update_add (0 => 1) @@ -271,7 +272,8 @@ fn test_fee_failures() { // positive case let (route, payment_hash_success, payment_preimage_success, payment_secret_success) = get_route_and_payment_hash!(nodes[0], nodes[2], 40_000); - nodes[0].node.send_payment(&route, payment_hash_success, &Some(payment_secret_success), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_success), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_success, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 40_000, payment_hash_success, payment_secret_success); claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage_success); @@ -292,7 +294,8 @@ fn test_fee_failures() { } let (payment_preimage_success, payment_hash_success, payment_secret_success) = get_payment_preimage_hash!(nodes[2]); - nodes[0].node.send_payment(&route, payment_hash_success, &Some(payment_secret_success), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_success), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash_success, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 40_000, payment_hash_success, payment_secret_success); claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage_success); @@ -796,7 +799,8 @@ fn test_phantom_onion_hmac_failure() { let (route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel); // Route the HTLC through to the destination. - nodes[0].node.send_payment(&route, payment_hash.clone(), &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash.clone(), &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); @@ -857,7 +861,8 @@ fn test_phantom_invalid_onion_payload() { // We'll use the session priv later when constructing an invalid onion packet. let session_priv = [3; 32]; *nodes[0].keys_manager.override_random_bytes.lock().unwrap() = Some(session_priv); - nodes[0].node.send_payment(&route, payment_hash.clone(), &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash.clone(), &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); @@ -928,7 +933,8 @@ fn test_phantom_final_incorrect_cltv_expiry() { let (route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel); // Route the HTLC through to the destination. - nodes[0].node.send_payment(&route, payment_hash.clone(), &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash.clone(), &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); @@ -987,7 +993,8 @@ fn test_phantom_failure_too_low_cltv() { route.paths[0][1].cltv_expiry_delta = 5; // Route the HTLC through to the destination. - nodes[0].node.send_payment(&route, payment_hash.clone(), &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash.clone(), &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); @@ -1030,7 +1037,8 @@ fn test_phantom_failure_too_low_recv_amt() { let (mut route, phantom_scid) = get_phantom_route!(nodes, bad_recv_amt_msat, channel); // Route the HTLC through to the destination. - nodes[0].node.send_payment(&route, payment_hash.clone(), &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash.clone(), &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); @@ -1082,7 +1090,8 @@ fn test_phantom_dust_exposure_failure() { let (mut route, _) = get_phantom_route!(nodes, max_dust_exposure + 1, channel); // Route the HTLC through to the destination. - nodes[0].node.send_payment(&route, payment_hash.clone(), &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash.clone(), &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); @@ -1121,7 +1130,8 @@ fn test_phantom_failure_reject_payment() { let (mut route, phantom_scid) = get_phantom_route!(nodes, recv_amt_msat, channel); // Route the HTLC through to the destination. - nodes[0].node.send_payment(&route, payment_hash.clone(), &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash.clone(), &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 83ad4e1590a..d5e06c2bbf2 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -15,6 +15,7 @@ use chain::{ChannelMonitorUpdateErr, Confirm, Listen, Watch}; use chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor, LATENCY_GRACE_PERIOD_BLOCKS}; use chain::transaction::OutPoint; use chain::keysinterface::KeysInterface; +use ln::RecipientInfo; use ln::channelmanager::{BREAKDOWN_TIMEOUT, ChannelManager, ChannelManagerReadArgs, MPP_TIMEOUT_TICKS, PaymentId, PaymentSendFailure}; use ln::features::{InitFeatures, InvoiceFeatures}; use ln::msgs; @@ -52,7 +53,8 @@ fn retry_single_path_payment() { send_payment(&nodes[1], &vec!(&nodes[2])[..], 2_000_000); // Make sure the payment fails on the first hop. - let payment_id = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + let payment_id = nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -137,7 +139,8 @@ fn mpp_retry() { route.paths[1][1].short_channel_id = chan_4_id; // Initiate the MPP payment. - let payment_id = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + let payment_id = nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 2); // one monitor per path let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 2); @@ -221,7 +224,8 @@ fn do_mpp_receive_timeout(send_partial_mpp: bool) { route.paths[1][1].short_channel_id = chan_4_id; // Initiate the MPP payment. - let _ = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + let _ = nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 2); // one monitor per path let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 2); @@ -289,7 +293,8 @@ fn retry_expired_payment() { send_payment(&nodes[1], &vec!(&nodes[2])[..], 2_000_000); // Make sure the payment fails on the first hop. - let payment_id = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + let payment_id = nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -340,7 +345,8 @@ fn no_pending_leak_on_initial_send_failure() { nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false); nodes[1].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false); - unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None), + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash, &recipient_info), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, "Peer for first hop currently disconnected/pending monitor update!")); @@ -377,7 +383,8 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { // out and retry. let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 1_000_000); let (payment_preimage_1, _, _, payment_id_1) = send_along_route(&nodes[0], route.clone(), &[&nodes[1], &nodes[2]], 1_000_000); - let payment_id = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + let payment_id = nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); @@ -810,7 +817,8 @@ fn get_ldk_payment_preimage() { &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(); - let _payment_id = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + let _payment_id = nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); // Make sure to use `get_payment_preimage` diff --git a/lightning/src/ln/priv_short_conf_tests.rs b/lightning/src/ln/priv_short_conf_tests.rs index db10d1a9687..623207a2bf8 100644 --- a/lightning/src/ln/priv_short_conf_tests.rs +++ b/lightning/src/ln/priv_short_conf_tests.rs @@ -17,6 +17,7 @@ use chain::keysinterface::{Recipient, KeysInterface}; use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, MIN_CLTV_EXPIRY_DELTA}; use routing::network_graph::RoutingFees; use routing::router::{PaymentParameters, RouteHint, RouteHintHop}; +use ln::RecipientInfo; use ln::features::{InitFeatures, InvoiceFeatures}; use ln::msgs; use ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, OptionalField}; @@ -76,7 +77,8 @@ fn test_priv_forwarding_rejection() { .with_route_hints(last_hops); let (route, our_payment_hash, our_payment_preimage, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 10_000, TEST_FINAL_CLTV); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let payment_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); @@ -159,7 +161,8 @@ fn test_priv_forwarding_rejection() { get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[2].node.get_our_node_id()); get_event_msg!(nodes[2], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 10_000, our_payment_hash, our_payment_secret); claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], our_payment_preimage); @@ -277,7 +280,8 @@ fn test_routed_scid_alias() { .with_route_hints(hop_hints); let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000, 42); assert_eq!(route.paths[0][1].short_channel_id, last_hop[0].inbound_scid_alias.unwrap()); - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 100_000, payment_hash, payment_secret); @@ -430,7 +434,8 @@ fn test_inbound_scid_privacy() { .with_route_hints(hop_hints.clone()); let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000, 42); assert_eq!(route.paths[0][1].short_channel_id, last_hop[0].inbound_scid_alias.unwrap()); - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 100_000, payment_hash, payment_secret); @@ -445,7 +450,8 @@ fn test_inbound_scid_privacy() { .with_route_hints(hop_hints); let (route_2, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params_2, 100_000, 42); assert_eq!(route_2.paths[0][1].short_channel_id, last_hop[0].short_channel_id.unwrap()); - nodes[0].node.send_payment(&route_2, payment_hash_2, &Some(payment_secret_2), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret_2), payment_metadata: None }; + nodes[0].node.send_payment(&route_2, payment_hash_2, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let payment_event = SendEvent::from_node(&nodes[0]); @@ -500,7 +506,8 @@ fn test_scid_alias_returned() { route.paths[0][1].fee_msat = 10_000_000; // Overshoot the last channel's value // Route the HTLC through to the destination. - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]); @@ -539,7 +546,8 @@ fn test_scid_alias_returned() { route.paths[0][0].fee_msat = 0; // But set fee paid to the middle hop to 0 // Route the HTLC through to the destination. - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]); diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index a83c3b8c037..69e205dbfc3 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -11,6 +11,7 @@ use chain::keysinterface::KeysInterface; use chain::transaction::OutPoint; +use ln::RecipientInfo; use ln::channelmanager::PaymentSendFailure; use routing::router::{PaymentParameters, get_route}; use ln::features::{InitFeatures, InvoiceFeatures}; @@ -98,8 +99,9 @@ fn updates_shutdown_wait() { let route_1 = get_route(&nodes[0].node.get_our_node_id(), &payment_params_1, &nodes[0].network_graph.read_only(), None, 100000, TEST_FINAL_CLTV, &logger, &scorer, &random_seed_bytes).unwrap(); let payment_params_2 = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known()); let route_2 = get_route(&nodes[1].node.get_our_node_id(), &payment_params_2, &nodes[1].network_graph.read_only(), None, 100000, TEST_FINAL_CLTV, &logger, &scorer, &random_seed_bytes).unwrap(); - unwrap_send_err!(nodes[0].node.send_payment(&route_1, payment_hash, &Some(payment_secret), None), true, APIError::ChannelUnavailable {..}, {}); - unwrap_send_err!(nodes[1].node.send_payment(&route_2, payment_hash, &Some(payment_secret), None), true, APIError::ChannelUnavailable {..}, {}); + let recipient_info = RecipientInfo { payment_secret: Some(payment_secret), payment_metadata: None }; + unwrap_send_err!(nodes[0].node.send_payment(&route_1, payment_hash, &recipient_info), true, APIError::ChannelUnavailable {..}, {}); + unwrap_send_err!(nodes[1].node.send_payment(&route_2, payment_hash, &recipient_info), true, APIError::ChannelUnavailable {..}, {}); assert!(nodes[2].node.claim_funds(payment_preimage)); check_added_monitors!(nodes[2], 1); @@ -157,7 +159,8 @@ fn htlc_fail_async_shutdown() { let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 100000); - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), None).unwrap(); + let recipient_info = RecipientInfo { payment_secret: Some(our_payment_secret), payment_metadata: None }; + nodes[0].node.send_payment(&route, our_payment_hash, &recipient_info).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); assert_eq!(updates.update_add_htlcs.len(), 1);