From 808477a5ce6351a512fa82ca66d34d426542f04c Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Fri, 21 Jan 2022 10:39:01 +0100 Subject: [PATCH] Rename `Payee` to `PaymentParameters` --- fuzz/src/chanmon_consistency.rs | 4 +- fuzz/src/full_stack.rs | 10 +- fuzz/src/router.rs | 8 +- lightning-invoice/src/payment.rs | 48 ++-- lightning-invoice/src/utils.rs | 10 +- lightning/src/ln/channel.rs | 2 +- lightning/src/ln/channelmanager.rs | 74 +++--- lightning/src/ln/features.rs | 4 +- lightning/src/ln/functional_test_utils.rs | 18 +- lightning/src/ln/functional_tests.rs | 32 +-- lightning/src/ln/onion_utils.rs | 2 +- lightning/src/ln/payment_tests.rs | 6 +- lightning/src/ln/shutdown_tests.rs | 10 +- lightning/src/routing/router.rs | 294 +++++++++++----------- 14 files changed, 262 insertions(+), 260 deletions(-) diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index f41b17a14..73cbb7a4a 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -308,7 +308,7 @@ fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, p fee_msat: amt, cltv_expiry_delta: 200, }]], - payee: None, + payment_params: None, }, payment_hash, &Some(payment_secret)) { check_payment_err(err); false @@ -334,7 +334,7 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des fee_msat: amt, cltv_expiry_delta: 200, }]], - payee: None, + payment_params: None, }, payment_hash, &Some(payment_secret)) { check_payment_err(err); false diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 34c6f554c..fd0df5a02 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -38,7 +38,7 @@ use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,Ig use lightning::ln::msgs::DecodeError; use lightning::ln::script::ShutdownScript; use lightning::routing::network_graph::{NetGraphMsgHandler, NetworkGraph}; -use lightning::routing::router::{find_route, Payee, RouteParameters}; +use lightning::routing::router::{find_route, PaymentParameters, RouteParameters}; use lightning::routing::scoring::Scorer; use lightning::util::config::UserConfig; use lightning::util::errors::APIError; @@ -446,9 +446,9 @@ pub fn do_test(data: &[u8], logger: &Arc) { }, 4 => { let final_value_msat = slice_to_be24(get_slice!(3)) as u64; - let payee = Payee::from_node_id(get_pubkey!()); + let payment_params = PaymentParameters::from_node_id(get_pubkey!()); let params = RouteParameters { - payee, + payment_params, final_value_msat, final_cltv_expiry_delta: 42, }; @@ -469,9 +469,9 @@ pub fn do_test(data: &[u8], logger: &Arc) { }, 15 => { let final_value_msat = slice_to_be24(get_slice!(3)) as u64; - let payee = Payee::from_node_id(get_pubkey!()); + let payment_params = PaymentParameters::from_node_id(get_pubkey!()); let params = RouteParameters { - payee, + payment_params, final_value_msat, final_cltv_expiry_delta: 42, }; diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index d6aa97e42..efa244d9b 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -16,7 +16,7 @@ use lightning::chain::transaction::OutPoint; use lightning::ln::channelmanager::{ChannelDetails, ChannelCounterparty}; use lightning::ln::features::InitFeatures; use lightning::ln::msgs; -use lightning::routing::router::{find_route, Payee, RouteHint, RouteHintHop, RouteParameters}; +use lightning::routing::router::{find_route, PaymentParameters, RouteHint, RouteHintHop, RouteParameters}; use lightning::routing::scoring::Scorer; use lightning::util::logger::Logger; use lightning::util::ser::Readable; @@ -251,12 +251,12 @@ pub fn do_test(data: &[u8], out: Out) { } let scorer = Scorer::with_fixed_penalty(0); for target in node_pks.iter() { - let params = RouteParameters { - payee: Payee::from_node_id(*target).with_route_hints(last_hops.clone()), + let route_params = RouteParameters { + payment_params: PaymentParameters::from_node_id(*target).with_route_hints(last_hops.clone()), final_value_msat: slice_to_be64(get_slice!(8)), final_cltv_expiry_delta: slice_to_be32(get_slice!(4)), }; - let _ = find_route(&our_pubkey, ¶ms, &net_graph, + let _ = find_route(&our_pubkey, &route_params, &net_graph, first_hops.map(|c| c.iter().collect::>()).as_ref().map(|a| a.as_slice()), Arc::clone(&logger), &scorer); } diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index d73ca5389..f2486969e 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -143,7 +143,7 @@ use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret}; use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure}; use lightning::ln::msgs::LightningError; use lightning::routing::scoring::{LockableScore, Score}; -use lightning::routing::router::{Payee, Route, RouteParameters}; +use lightning::routing::router::{PaymentParameters, Route, RouteParameters}; use lightning::util::events::{Event, EventHandler}; use lightning::util::logger::Logger; use crate::sync::Mutex; @@ -206,7 +206,7 @@ pub trait Payer { pub trait Router { /// Finds a [`Route`] between `payer` and `payee` for a payment with the given values. fn find_route( - &self, payer: &PublicKey, params: &RouteParameters, payment_hash: &PaymentHash, + &self, payer: &PublicKey, route_params: &RouteParameters, payment_hash: &PaymentHash, first_hops: Option<&[&ChannelDetails]>, scorer: &S ) -> Result; } @@ -296,14 +296,14 @@ where }; let payment_secret = Some(invoice.payment_secret().clone()); - let mut payee = Payee::from_node_id(invoice.recover_payee_pub_key()) + let mut payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key()) .with_expiry_time(expiry_time_from_unix_epoch(&invoice).as_secs()) .with_route_hints(invoice.route_hints()); if let Some(features) = invoice.features() { - payee = payee.with_features(features.clone()); + payment_params = payment_params.with_features(features.clone()); } - let params = RouteParameters { - payee, + let route_params = RouteParameters { + payment_params, final_value_msat: invoice.amount_milli_satoshis().or(amount_msats).unwrap(), final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32, }; @@ -311,7 +311,7 @@ where let send_payment = |route: &Route| { self.payer.send_payment(route, payment_hash, &payment_secret) }; - self.pay_internal(¶ms, payment_hash, send_payment) + self.pay_internal(&route_params, payment_hash, send_payment) .map_err(|e| { self.payment_cache.lock().unwrap().remove(&payment_hash); e }) } @@ -330,8 +330,8 @@ where hash_map::Entry::Vacant(entry) => entry.insert(0), }; - let params = RouteParameters { - payee: Payee::for_keysend(pubkey), + let route_params = RouteParameters { + payment_params: PaymentParameters::for_keysend(pubkey), final_value_msat: amount_msats, final_cltv_expiry_delta, }; @@ -339,7 +339,7 @@ where let send_payment = |route: &Route| { self.payer.send_spontaneous_payment(route, payment_preimage) }; - self.pay_internal(¶ms, payment_hash, send_payment) + self.pay_internal(&route_params, payment_hash, send_payment) .map_err(|e| { self.payment_cache.lock().unwrap().remove(&payment_hash); e }) } @@ -462,8 +462,8 @@ fn expiry_time_from_unix_epoch(invoice: &Invoice) -> Duration { } #[cfg(feature = "std")] -fn has_expired(params: &RouteParameters) -> bool { - if let Some(expiry_time) = params.payee.expiry_time { +fn has_expired(route_params: &RouteParameters) -> bool { + if let Some(expiry_time) = route_params.payment_params.expiry_time { Invoice::is_expired_from_epoch(&SystemTime::UNIX_EPOCH, Duration::from_secs(expiry_time)) } else { false } } @@ -533,7 +533,7 @@ mod tests { use lightning::ln::functional_test_utils::*; use lightning::ln::msgs::{ChannelMessageHandler, ErrorAction, LightningError}; use lightning::routing::network_graph::NodeId; - use lightning::routing::router::{Payee, Route, RouteHop}; + use lightning::routing::router::{PaymentParameters, Route, RouteHop}; use lightning::util::test_utils::TestLogger; use lightning::util::errors::APIError; use lightning::util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider}; @@ -882,7 +882,7 @@ mod tests { assert_eq!(*payer.attempts.borrow(), 1); let mut retry_data = TestRouter::retry_for_invoice(&invoice); - retry_data.payee.expiry_time = Some(SystemTime::now() + retry_data.payment_params.expiry_time = Some(SystemTime::now() .checked_sub(Duration::from_secs(2)).unwrap() .duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs()); let event = Event::PaymentPathFailed { @@ -1136,7 +1136,7 @@ mod tests { assert_eq!(*payer.attempts.borrow(), 1); let retry = RouteParameters { - payee: Payee::for_keysend(pubkey), + payment_params: PaymentParameters::for_keysend(pubkey), final_value_msat, final_cltv_expiry_delta, }; @@ -1251,7 +1251,7 @@ mod tests { short_channel_id: 1, fee_msat: final_value_msat / 2, cltv_expiry_delta: 144 }], ], - payee: None, + payment_params: None, } } @@ -1260,15 +1260,15 @@ mod tests { } fn retry_for_invoice(invoice: &Invoice) -> RouteParameters { - let mut payee = Payee::from_node_id(invoice.recover_payee_pub_key()) + let mut payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key()) .with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs()) .with_route_hints(invoice.route_hints()); if let Some(features) = invoice.features() { - payee = payee.with_features(features.clone()); + payment_params = payment_params.with_features(features.clone()); } let final_value_msat = invoice.amount_milli_satoshis().unwrap() / 2; RouteParameters { - payee, + payment_params, final_value_msat, final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32, } @@ -1277,11 +1277,11 @@ mod tests { impl Router for TestRouter { fn find_route( - &self, _payer: &PublicKey, params: &RouteParameters, _payment_hash: &PaymentHash, + &self, _payer: &PublicKey, route_params: &RouteParameters, _payment_hash: &PaymentHash, _first_hops: Option<&[&ChannelDetails]>, _scorer: &S ) -> Result { Ok(Route { - payee: Some(params.payee.clone()), ..Self::route_for_value(params.final_value_msat) + payment_params: Some(route_params.payment_params.clone()), ..Self::route_for_value(route_params.final_value_msat) }) } } @@ -1543,7 +1543,7 @@ mod tests { cltv_expiry_delta: 100, }], ], - payee: Some(Payee::from_node_id(nodes[1].node.get_our_node_id())), + payment_params: Some(PaymentParameters::from_node_id(nodes[1].node.get_our_node_id())), }; let router = ManualRouter(RefCell::new(VecDeque::new())); router.expect_find_route(Ok(route.clone())); @@ -1587,7 +1587,7 @@ mod tests { cltv_expiry_delta: 100, }], ], - payee: Some(Payee::from_node_id(nodes[1].node.get_our_node_id())), + payment_params: Some(PaymentParameters::from_node_id(nodes[1].node.get_our_node_id())), }; let router = ManualRouter(RefCell::new(VecDeque::new())); router.expect_find_route(Ok(route.clone())); @@ -1668,7 +1668,7 @@ mod tests { cltv_expiry_delta: 100, }] ], - payee: Some(Payee::from_node_id(nodes[2].node.get_our_node_id())), + payment_params: Some(PaymentParameters::from_node_id(nodes[2].node.get_our_node_id())), }; let router = ManualRouter(RefCell::new(VecDeque::new())); router.expect_find_route(Ok(route.clone())); diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index ffa84c98e..0a987a4fb 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -198,7 +198,7 @@ mod test { use lightning::ln::functional_test_utils::*; use lightning::ln::features::InitFeatures; use lightning::ln::msgs::ChannelMessageHandler; - use lightning::routing::router::{Payee, RouteParameters, find_route}; + use lightning::routing::router::{PaymentParameters, RouteParameters, find_route}; use lightning::util::events::MessageSendEventsProvider; use lightning::util::test_utils; use utils::create_invoice_from_channelmanager_and_duration_since_epoch; @@ -217,11 +217,11 @@ mod test { assert_eq!(invoice.min_final_cltv_expiry(), MIN_FINAL_CLTV_EXPIRY as u64); assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string()))); - let payee = Payee::from_node_id(invoice.recover_payee_pub_key()) + let payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key()) .with_features(invoice.features().unwrap().clone()) .with_route_hints(invoice.route_hints()); - let params = RouteParameters { - payee, + let route_params = RouteParameters { + payment_params, final_value_msat: invoice.amount_milli_satoshis().unwrap(), final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32, }; @@ -230,7 +230,7 @@ mod test { let logger = test_utils::TestLogger::new(); let scorer = test_utils::TestScorer::with_fixed_penalty(0); let route = find_route( - &nodes[0].node.get_our_node_id(), ¶ms, network_graph, + &nodes[0].node.get_our_node_id(), &route_params, network_graph, Some(&first_hops.iter().collect::>()), &logger, &scorer, ).unwrap(); diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 03633cec1..e5dae3ac7 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -5992,7 +5992,7 @@ mod tests { first_hop_htlc_msat: 548, payment_id: PaymentId([42; 32]), payment_secret: None, - payee: None, + payment_params: None, } }); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 77e9152d4..e234b1ed9 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -45,7 +45,7 @@ use chain::transaction::{OutPoint, TransactionData}; use ln::{PaymentHash, PaymentPreimage, PaymentSecret}; use ln::channel::{Channel, ChannelError, ChannelUpdateStatus, UpdateFulfillCommitFetch}; use ln::features::{InitFeatures, NodeFeatures}; -use routing::router::{Payee, Route, RouteHop, RoutePath, RouteParameters}; +use routing::router::{PaymentParameters, Route, RouteHop, RoutePath, RouteParameters}; use ln::msgs; use ln::msgs::NetAddress; use ln::onion_utils; @@ -491,7 +491,7 @@ pub(crate) enum HTLCSource { first_hop_htlc_msat: u64, payment_id: PaymentId, payment_secret: Option, - payee: Option, + payment_params: Option, }, } #[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash @@ -502,14 +502,14 @@ impl core::hash::Hash for HTLCSource { 0u8.hash(hasher); prev_hop_data.hash(hasher); }, - HTLCSource::OutboundRoute { path, session_priv, payment_id, payment_secret, first_hop_htlc_msat, payee } => { + HTLCSource::OutboundRoute { path, session_priv, payment_id, payment_secret, first_hop_htlc_msat, payment_params } => { 1u8.hash(hasher); path.hash(hasher); session_priv[..].hash(hasher); payment_id.hash(hasher); payment_secret.hash(hasher); first_hop_htlc_msat.hash(hasher); - payee.hash(hasher); + payment_params.hash(hasher); }, } } @@ -523,7 +523,7 @@ impl HTLCSource { first_hop_htlc_msat: 0, payment_id: PaymentId([2; 32]), payment_secret: None, - payee: None, + payment_params: None, } } } @@ -2428,7 +2428,7 @@ impl ChannelMana } // Only public for testing, this should otherwise never be called direcly - pub(crate) fn send_payment_along_path(&self, path: &Vec, payee: &Option, payment_hash: &PaymentHash, payment_secret: &Option, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option) -> Result<(), APIError> { + pub(crate) fn send_payment_along_path(&self, path: &Vec, payment_params: &Option, payment_hash: &PaymentHash, payment_secret: &Option, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option) -> Result<(), APIError> { log_trace!(self.logger, "Attempting to send payment for path with next hop {}", path.first().unwrap().short_channel_id); let prng_seed = self.keys_manager.get_secure_random_bytes(); let session_priv_bytes = self.keys_manager.get_secure_random_bytes(); @@ -2493,7 +2493,7 @@ impl ChannelMana first_hop_htlc_msat: htlc_msat, payment_id, payment_secret: payment_secret.clone(), - payee: payee.clone(), + payment_params: payment_params.clone(), }, onion_packet, &self.logger), channel_state, chan) } { @@ -2622,7 +2622,7 @@ impl ChannelMana let cur_height = self.best_block.read().unwrap().height() + 1; let mut results = Vec::new(); for path in route.paths.iter() { - results.push(self.send_payment_along_path(&path, &route.payee, &payment_hash, payment_secret, total_value, cur_height, payment_id, &keysend_preimage)); + results.push(self.send_payment_along_path(&path, &route.payment_params, &payment_hash, payment_secret, total_value, cur_height, payment_id, &keysend_preimage)); } let mut has_ok = false; let mut has_err = false; @@ -2646,9 +2646,9 @@ impl ChannelMana results, payment_id, failed_paths_retry: if pending_amt_unsent != 0 { - if let Some(payee) = &route.payee { + if let Some(payment_params) = &route.payment_params { Some(RouteParameters { - payee: payee.clone(), + payment_params: payment_params.clone(), final_value_msat: pending_amt_unsent, final_cltv_expiry_delta: max_unsent_cltv_delta, }) @@ -3585,16 +3585,16 @@ impl ChannelMana self.fail_htlc_backwards_internal(channel_state, htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data}); }, - HTLCSource::OutboundRoute { session_priv, payment_id, path, payee, .. } => { + HTLCSource::OutboundRoute { session_priv, payment_id, path, payment_params, .. } => { let mut session_priv_bytes = [0; 32]; session_priv_bytes.copy_from_slice(&session_priv[..]); let mut outbounds = self.pending_outbound_payments.lock().unwrap(); if let hash_map::Entry::Occupied(mut payment) = outbounds.entry(payment_id) { if payment.get_mut().remove(&session_priv_bytes, Some(&path)) && !payment.get().is_fulfilled() { - let retry = if let Some(payee_data) = payee { + let retry = if let Some(payment_params_data) = payment_params { let path_last_hop = path.last().expect("Outbound payments must have had a valid path"); Some(RouteParameters { - payee: payee_data, + payment_params: payment_params_data, final_value_msat: path_last_hop.fee_msat, final_cltv_expiry_delta: path_last_hop.cltv_expiry_delta, }) @@ -3646,7 +3646,7 @@ impl ChannelMana // from block_connected which may run during initialization prior to the chain_monitor // being fully configured. See the docs for `ChannelManagerReadArgs` for more. match source { - HTLCSource::OutboundRoute { ref path, session_priv, payment_id, ref payee, .. } => { + HTLCSource::OutboundRoute { ref path, session_priv, payment_id, ref payment_params, .. } => { let mut session_priv_bytes = [0; 32]; session_priv_bytes.copy_from_slice(&session_priv[..]); let mut outbounds = self.pending_outbound_payments.lock().unwrap(); @@ -3676,10 +3676,10 @@ impl ChannelMana return; } mem::drop(channel_state_lock); - let retry = if let Some(payee_data) = payee { + let retry = if let Some(payment_params_data) = payment_params { let path_last_hop = path.last().expect("Outbound payments must have had a valid path"); Some(RouteParameters { - payee: payee_data.clone(), + payment_params: payment_params_data.clone(), final_value_msat: path_last_hop.fee_msat, final_cltv_expiry_delta: path_last_hop.cltv_expiry_delta, }) @@ -5985,14 +5985,14 @@ impl Readable for HTLCSource { let mut path = Some(Vec::new()); let mut payment_id = None; let mut payment_secret = None; - let mut payee = None; + let mut payment_params = None; read_tlv_fields!(reader, { (0, session_priv, required), (1, payment_id, option), (2, first_hop_htlc_msat, required), (3, payment_secret, option), (4, path, vec_type), - (5, payee, option), + (5, payment_params, option), }); if payment_id.is_none() { // For backwards compat, if there was no payment_id written, use the session_priv bytes @@ -6005,7 +6005,7 @@ impl Readable for HTLCSource { path: path.unwrap(), payment_id: payment_id.unwrap(), payment_secret, - payee, + payment_params, }) } 1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)), @@ -6017,7 +6017,7 @@ impl Readable for HTLCSource { impl Writeable for HTLCSource { fn write(&self, writer: &mut W) -> Result<(), ::io::Error> { match self { - HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret, payee } => { + HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret, payment_params } => { 0u8.write(writer)?; let payment_id_opt = Some(payment_id); write_tlv_fields!(writer, { @@ -6026,7 +6026,7 @@ impl Writeable for HTLCSource { (2, first_hop_htlc_msat, required), (3, payment_secret, option), (4, path, vec_type), - (5, payee, option), + (5, payment_params, option), }); } HTLCSource::PreviousHopData(ref field) => { @@ -6639,7 +6639,7 @@ mod tests { use ln::functional_test_utils::*; use ln::msgs; use ln::msgs::ChannelMessageHandler; - use routing::router::{Payee, RouteParameters, find_route}; + use routing::router::{PaymentParameters, RouteParameters, find_route}; use util::errors::APIError; use util::events::{Event, MessageSendEvent, MessageSendEventsProvider}; use util::test_utils; @@ -6786,7 +6786,7 @@ mod tests { // Use the utility function send_payment_along_path to send the payment with MPP data which // indicates there are more HTLCs coming. let cur_height = CHAN_CONFIRM_DEPTH + 1; // route_payment calls send_payment, which adds 1 to the current height. So we do the same here to match. - nodes[0].node.send_payment_along_path(&route.paths[0], &route.payee, &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None).unwrap(); + nodes[0].node.send_payment_along_path(&route.paths[0], &route.payment_params, &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -6816,7 +6816,7 @@ mod tests { expect_payment_failed!(nodes[0], our_payment_hash, true); // Send the second half of the original MPP payment. - nodes[0].node.send_payment_along_path(&route.paths[0], &route.payee, &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None).unwrap(); + nodes[0].node.send_payment_along_path(&route.paths[0], &route.payment_params, &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -6902,13 +6902,13 @@ mod tests { let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &expected_route, 100_000); // Next, attempt a keysend payment and make sure it fails. - let params = RouteParameters { - payee: Payee::for_keysend(expected_route.last().unwrap().node.get_our_node_id()), + let route_params = RouteParameters { + payment_params: PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id()), final_value_msat: 100_000, final_cltv_expiry_delta: TEST_FINAL_CLTV, }; let route = find_route( - &nodes[0].node.get_our_node_id(), ¶ms, nodes[0].network_graph, None, + &nodes[0].node.get_our_node_id(), &route_params, nodes[0].network_graph, None, nodes[0].logger, &scorer ).unwrap(); nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap(); @@ -6939,7 +6939,7 @@ mod tests { // To start (2), send a keysend payment but don't claim it. let payment_preimage = PaymentPreimage([42; 32]); let route = find_route( - &nodes[0].node.get_our_node_id(), ¶ms, nodes[0].network_graph, None, + &nodes[0].node.get_our_node_id(), &route_params, nodes[0].network_graph, None, nodes[0].logger, &scorer ).unwrap(); let (payment_hash, _) = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap(); @@ -6993,8 +6993,8 @@ mod tests { nodes[1].node.peer_connected(&payer_pubkey, &msgs::Init { features: InitFeatures::known() }); let _chan = create_chan_between_nodes(&nodes[0], &nodes[1], InitFeatures::known(), InitFeatures::known()); - let params = RouteParameters { - payee: Payee::for_keysend(payee_pubkey), + let route_params = RouteParameters { + payment_params: PaymentParameters::for_keysend(payee_pubkey), final_value_msat: 10000, final_cltv_expiry_delta: 40, }; @@ -7002,7 +7002,7 @@ mod tests { let first_hops = nodes[0].node.list_usable_channels(); let scorer = test_utils::TestScorer::with_fixed_penalty(0); let route = find_route( - &payer_pubkey, ¶ms, network_graph, Some(&first_hops.iter().collect::>()), + &payer_pubkey, &route_params, network_graph, Some(&first_hops.iter().collect::>()), nodes[0].logger, &scorer ).unwrap(); @@ -7036,8 +7036,8 @@ mod tests { nodes[1].node.peer_connected(&payer_pubkey, &msgs::Init { features: InitFeatures::known() }); let _chan = create_chan_between_nodes(&nodes[0], &nodes[1], InitFeatures::known(), InitFeatures::known()); - let params = RouteParameters { - payee: Payee::for_keysend(payee_pubkey), + let route_params = RouteParameters { + payment_params: PaymentParameters::for_keysend(payee_pubkey), final_value_msat: 10000, final_cltv_expiry_delta: 40, }; @@ -7045,7 +7045,7 @@ mod tests { let first_hops = nodes[0].node.list_usable_channels(); let scorer = test_utils::TestScorer::with_fixed_penalty(0); let route = find_route( - &payer_pubkey, ¶ms, network_graph, Some(&first_hops.iter().collect::>()), + &payer_pubkey, &route_params, network_graph, Some(&first_hops.iter().collect::>()), nodes[0].logger, &scorer ).unwrap(); @@ -7136,7 +7136,7 @@ pub mod bench { use ln::functional_test_utils::*; use ln::msgs::{ChannelMessageHandler, Init}; use routing::network_graph::NetworkGraph; - use routing::router::{Payee, get_route}; + use routing::router::{PaymentParameters, get_route}; use routing::scoring::Scorer; use util::test_utils; use util::config::UserConfig; @@ -7245,10 +7245,10 @@ pub mod bench { macro_rules! send_payment { ($node_a: expr, $node_b: expr) => { let usable_channels = $node_a.list_usable_channels(); - let payee = Payee::from_node_id($node_b.get_our_node_id()) + let payment_params = PaymentParameters::from_node_id($node_b.get_our_node_id()) .with_features(InvoiceFeatures::known()); let scorer = Scorer::with_fixed_penalty(0); - let route = get_route(&$node_a.get_our_node_id(), &payee, &dummy_graph, + let route = get_route(&$node_a.get_our_node_id(), &payment_params, &dummy_graph, Some(&usable_channels.iter().map(|r| r).collect::>()), 10_000, TEST_FINAL_CLTV, &logger_a, &scorer).unwrap(); let mut payment_preimage = PaymentPreimage([0; 32]); diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index dab841327..0ccce88e9 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -500,10 +500,10 @@ impl InvoiceFeatures { /// Getting a route for a keysend payment to a private node requires providing the payee's /// features (since they were not announced in a node announcement). However, keysend payments /// don't have an invoice to pull the payee's features from, so this method is provided for use in - /// [`Payee::for_keysend`], thus omitting the need for payers to manually construct an + /// [`PaymentParameters::for_keysend`], thus omitting the need for payers to manually construct an /// `InvoiceFeatures` for [`find_route`]. /// - /// [`Payee::for_keysend`]: crate::routing::router::Payee::for_keysend + /// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend /// [`find_route`]: crate::routing::router::find_route pub(crate) fn for_keysend() -> InvoiceFeatures { InvoiceFeatures::empty().set_variable_length_onion_optional() diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 2e8994b58..5ec16f90f 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -16,7 +16,7 @@ use chain::transaction::OutPoint; use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; use ln::channelmanager::{ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, PaymentId}; use routing::network_graph::{NetGraphMsgHandler, NetworkGraph}; -use routing::router::{Payee, Route, get_route}; +use routing::router::{PaymentParameters, Route, get_route}; use ln::features::{InitFeatures, InvoiceFeatures}; use ln::msgs; use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler}; @@ -1075,12 +1075,12 @@ macro_rules! get_route_and_payment_hash { }}; ($send_node: expr, $recv_node: expr, $last_hops: expr, $recv_value: expr, $cltv: expr) => {{ let (payment_preimage, payment_hash, payment_secret) = $crate::get_payment_preimage_hash!($recv_node, Some($recv_value)); - let payee = $crate::routing::router::Payee::from_node_id($recv_node.node.get_our_node_id()) + let payment_params = $crate::routing::router::PaymentParameters::from_node_id($recv_node.node.get_our_node_id()) .with_features($crate::ln::features::InvoiceFeatures::known()) .with_route_hints($last_hops); let scorer = $crate::util::test_utils::TestScorer::with_fixed_penalty(0); let route = $crate::routing::router::get_route( - &$send_node.node.get_our_node_id(), &payee, $send_node.network_graph, + &$send_node.node.get_our_node_id(), &payment_params, $send_node.network_graph, Some(&$send_node.node.list_usable_channels().iter().collect::>()), $recv_value, $cltv, $send_node.logger, &scorer ).unwrap(); @@ -1299,7 +1299,7 @@ macro_rules! expect_payment_failed_conditions { assert_eq!(rejected_by_dest, $rejected_by_dest, "unexpected rejected_by_dest value"); assert!(retry.is_some(), "expected retry.is_some()"); assert_eq!(retry.as_ref().unwrap().final_value_msat, path.last().unwrap().fee_msat, "Retry amount should match last hop in path"); - assert_eq!(retry.as_ref().unwrap().payee.pubkey, path.last().unwrap().pubkey, "Retry payee node_id should match last hop in path"); + assert_eq!(retry.as_ref().unwrap().payment_params.payee_pubkey, path.last().unwrap().pubkey, "Retry payee node_id should match last hop in path"); assert!(error_code.is_some(), "expected error_code.is_some() = true"); assert!(error_data.is_some(), "expected error_data.is_some() = true"); @@ -1531,11 +1531,11 @@ pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: pub const TEST_FINAL_CLTV: u32 = 70; pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash, PaymentSecret) { - let payee = Payee::from_node_id(expected_route.last().unwrap().node.get_our_node_id()) + let payment_params = PaymentParameters::from_node_id(expected_route.last().unwrap().node.get_our_node_id()) .with_features(InvoiceFeatures::known()); let scorer = test_utils::TestScorer::with_fixed_penalty(0); let route = get_route( - &origin_node.node.get_our_node_id(), &payee, &origin_node.network_graph, + &origin_node.node.get_our_node_id(), &payment_params, &origin_node.network_graph, Some(&origin_node.node.list_usable_channels().iter().collect::>()), recv_value, TEST_FINAL_CLTV, origin_node.logger, &scorer).unwrap(); assert_eq!(route.paths.len(), 1); @@ -1549,10 +1549,12 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: } pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) { - let payee = Payee::from_node_id(expected_route.last().unwrap().node.get_our_node_id()) + let payment_params = PaymentParameters::from_node_id(expected_route.last().unwrap().node.get_our_node_id()) .with_features(InvoiceFeatures::known()); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let route = get_route(&origin_node.node.get_our_node_id(), &payee, origin_node.network_graph, None, recv_value, TEST_FINAL_CLTV, origin_node.logger, &scorer).unwrap(); + let route = get_route( + &origin_node.node.get_our_node_id(), &payment_params, origin_node.network_graph, + None, recv_value, TEST_FINAL_CLTV, origin_node.logger, &scorer).unwrap(); assert_eq!(route.paths.len(), 1); assert_eq!(route.paths[0].len(), expected_route.len()); for (node, hop) in expected_route.iter().zip(route.paths[0].iter()) { diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 0993caf4c..dd9d3a3c4 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -24,7 +24,7 @@ use ln::channel::{Channel, ChannelError}; use ln::{chan_utils, onion_utils}; use ln::chan_utils::{htlc_success_tx_weight, htlc_timeout_tx_weight, HTLCOutputInCommitment}; use routing::network_graph::RoutingFees; -use routing::router::{Payee, Route, RouteHop, RouteHint, RouteHintHop, RouteParameters, find_route, get_route}; +use routing::router::{PaymentParameters, Route, RouteHop, RouteHint, RouteHintHop, RouteParameters, find_route, get_route}; use ln::features::{ChannelFeatures, InitFeatures, InvoiceFeatures, NodeFeatures}; use ln::msgs; use ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, ErrorAction}; @@ -1037,7 +1037,7 @@ fn fake_network_test() { }); hops[1].fee_msat = chan_4.1.contents.fee_base_msat as u64 + chan_4.1.contents.fee_proportional_millionths as u64 * hops[2].fee_msat as u64 / 1000000; hops[0].fee_msat = chan_3.0.contents.fee_base_msat as u64 + chan_3.0.contents.fee_proportional_millionths as u64 * hops[1].fee_msat as u64 / 1000000; - let payment_preimage_1 = send_along_route(&nodes[1], Route { paths: vec![hops], payee: None }, &vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0; + let payment_preimage_1 = send_along_route(&nodes[1], Route { paths: vec![hops], payment_params: None }, &vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0; let mut hops = Vec::with_capacity(3); hops.push(RouteHop { @@ -1066,7 +1066,7 @@ fn fake_network_test() { }); hops[1].fee_msat = chan_2.1.contents.fee_base_msat as u64 + chan_2.1.contents.fee_proportional_millionths as u64 * hops[2].fee_msat as u64 / 1000000; hops[0].fee_msat = chan_3.1.contents.fee_base_msat as u64 + chan_3.1.contents.fee_proportional_millionths as u64 * hops[1].fee_msat as u64 / 1000000; - let payment_hash_2 = send_along_route(&nodes[1], Route { paths: vec![hops], payee: None }, &vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1; + let payment_hash_2 = send_along_route(&nodes[1], Route { paths: vec![hops], payment_params: None }, &vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1; // Claim the rebalances... fail_payment(&nodes[1], &vec!(&nodes[3], &nodes[2], &nodes[1])[..], payment_hash_2); @@ -4099,7 +4099,7 @@ fn do_test_htlc_timeout(send_partial_mpp: bool) { // indicates there are more HTLCs coming. let cur_height = CHAN_CONFIRM_DEPTH + 1; // route_payment calls send_payment, which adds 1 to the current height. So we do the same here to match. let payment_id = PaymentId([42; 32]); - nodes[0].node.send_payment_along_path(&route.paths[0], &route.payee, &our_payment_hash, &Some(payment_secret), 200000, cur_height, payment_id, &None).unwrap(); + nodes[0].node.send_payment_along_path(&route.paths[0], &route.payment_params, &our_payment_hash, &Some(payment_secret), 200000, cur_height, payment_id, &None).unwrap(); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -7351,8 +7351,8 @@ fn test_check_htlc_underpaying() { create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known()); - let route = get_route(&nodes[0].node.get_our_node_id(), &payee, nodes[0].network_graph, None, 10_000, TEST_FINAL_CLTV, nodes[0].logger, &scorer).unwrap(); + let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known()); + let route = get_route(&nodes[0].node.get_our_node_id(), &payment_params, nodes[0].network_graph, None, 10_000, TEST_FINAL_CLTV, nodes[0].logger, &scorer).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)).unwrap(); @@ -7752,13 +7752,13 @@ fn test_bump_penalty_txn_on_revoked_htlcs() { let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::known(), InitFeatures::known()); // Lock HTLC in both directions (using a slightly lower CLTV delay to provide timely RBF bumps) - let payee = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known()); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let route = get_route(&nodes[0].node.get_our_node_id(), &payee, &nodes[0].network_graph, None, + let route = get_route(&nodes[0].node.get_our_node_id(), &payment_params, &nodes[0].network_graph, None, 3_000_000, 50, nodes[0].logger, &scorer).unwrap(); let payment_preimage = send_along_route(&nodes[0], route, &[&nodes[1]], 3_000_000).0; - let payee = Payee::from_node_id(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known()); - let route = get_route(&nodes[1].node.get_our_node_id(), &payee, nodes[1].network_graph, None, + let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known()); + let route = get_route(&nodes[1].node.get_our_node_id(), &payment_params, nodes[1].network_graph, None, 3_000_000, 50, nodes[0].logger, &scorer).unwrap(); send_along_route(&nodes[1], route, &[&nodes[0]], 3_000_000); @@ -9285,13 +9285,13 @@ fn test_keysend_payments_to_public_node() { let network_graph = nodes[0].network_graph; let payer_pubkey = nodes[0].node.get_our_node_id(); let payee_pubkey = nodes[1].node.get_our_node_id(); - let params = RouteParameters { - payee: Payee::for_keysend(payee_pubkey), + let route_params = RouteParameters { + payment_params: PaymentParameters::for_keysend(payee_pubkey), final_value_msat: 10000, final_cltv_expiry_delta: 40, }; let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let route = find_route(&payer_pubkey, ¶ms, network_graph, None, nodes[0].logger, &scorer).unwrap(); + let route = find_route(&payer_pubkey, &route_params, network_graph, None, nodes[0].logger, &scorer).unwrap(); let test_preimage = PaymentPreimage([42; 32]); let (payment_hash, _) = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage)).unwrap(); @@ -9317,8 +9317,8 @@ fn test_keysend_payments_to_private_node() { nodes[1].node.peer_connected(&payer_pubkey, &msgs::Init { features: InitFeatures::known() }); let _chan = create_chan_between_nodes(&nodes[0], &nodes[1], InitFeatures::known(), InitFeatures::known()); - let params = RouteParameters { - payee: Payee::for_keysend(payee_pubkey), + let route_params = RouteParameters { + payment_params: PaymentParameters::for_keysend(payee_pubkey), final_value_msat: 10000, final_cltv_expiry_delta: 40, }; @@ -9326,7 +9326,7 @@ fn test_keysend_payments_to_private_node() { let first_hops = nodes[0].node.list_usable_channels(); let scorer = test_utils::TestScorer::with_fixed_penalty(0); let route = find_route( - &payer_pubkey, ¶ms, network_graph, Some(&first_hops.iter().collect::>()), + &payer_pubkey, &route_params, network_graph, Some(&first_hops.iter().collect::>()), nodes[0].logger, &scorer ).unwrap(); diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 12dc0e03b..ec668045e 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -555,7 +555,7 @@ mod tests { short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually }, ]], - payee: None, + payment_params: None, }; let session_priv = SecretKey::from_slice(&hex::decode("4141414141414141414141414141414141414141414141414141414141414141").unwrap()[..]).unwrap(); diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 960a255e9..a86676422 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -18,7 +18,7 @@ use ln::channelmanager::{BREAKDOWN_TIMEOUT, ChannelManager, ChannelManagerReadAr use ln::features::{InitFeatures, InvoiceFeatures}; use ln::msgs; use ln::msgs::ChannelMessageHandler; -use routing::router::{Payee, get_route}; +use routing::router::{PaymentParameters, get_route}; use util::events::{ClosureReason, Event, MessageSendEvent, MessageSendEventsProvider}; use util::test_utils; use util::errors::APIError; @@ -721,11 +721,11 @@ fn get_ldk_payment_preimage() { let expiry_secs = 60 * 60; let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(amt_msat), expiry_secs).unwrap(); - let payee = Payee::from_node_id(nodes[1].node.get_our_node_id()) + let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id()) .with_features(InvoiceFeatures::known()); let scorer = test_utils::TestScorer::with_fixed_penalty(0); let route = get_route( - &nodes[0].node.get_our_node_id(), &payee, &nodes[0].network_graph, + &nodes[0].node.get_our_node_id(), &payment_params, &nodes[0].network_graph, Some(&nodes[0].node.list_usable_channels().iter().collect::>()), amt_msat, TEST_FINAL_CLTV, nodes[0].logger, &scorer).unwrap(); let _payment_id = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)).unwrap(); diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index 7afc982fa..7cfca4b86 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -12,7 +12,7 @@ use chain::keysinterface::KeysInterface; use chain::transaction::OutPoint; use ln::channelmanager::PaymentSendFailure; -use routing::router::{Payee, get_route}; +use routing::router::{PaymentParameters, get_route}; use ln::features::{InitFeatures, InvoiceFeatures}; use ln::msgs; use ln::msgs::{ChannelMessageHandler, ErrorAction}; @@ -91,10 +91,10 @@ fn updates_shutdown_wait() { let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[0]); - let payee_1 = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known()); - let route_1 = get_route(&nodes[0].node.get_our_node_id(), &payee_1, nodes[0].network_graph, None, 100000, TEST_FINAL_CLTV, &logger, &scorer).unwrap(); - let payee_2 = Payee::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(), &payee_2, nodes[1].network_graph, None, 100000, TEST_FINAL_CLTV, &logger, &scorer).unwrap(); + let payment_params_1 = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known()); + let route_1 = get_route(&nodes[0].node.get_our_node_id(), &payment_params_1, nodes[0].network_graph, None, 100000, TEST_FINAL_CLTV, &logger, &scorer).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, None, 100000, TEST_FINAL_CLTV, &logger, &scorer).unwrap(); unwrap_send_err!(nodes[0].node.send_payment(&route_1, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable {..}, {}); unwrap_send_err!(nodes[1].node.send_payment(&route_2, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable {..}, {}); diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 1f6638dae..420bbaed0 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -70,12 +70,12 @@ pub struct Route { /// given path is variable, keeping the length of any path to less than 20 should currently /// ensure it is viable. pub paths: Vec>, - /// The `payee` parameter passed to [`find_route`]. + /// The `payment_params` parameter passed to [`find_route`]. /// This is used by `ChannelManager` to track information which may be required for retries, /// provided back to you via [`Event::PaymentPathFailed`]. /// /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed - pub payee: Option, + pub payment_params: Option, } pub(crate) trait RoutePath { @@ -122,7 +122,7 @@ impl Writeable for Route { } } write_tlv_fields!(writer, { - (1, self.payee, option), + (1, self.payment_params, option), }); Ok(()) } @@ -141,15 +141,15 @@ impl Readable for Route { } paths.push(hops); } - let mut payee = None; + let mut payment_params = None; read_tlv_fields!(reader, { - (1, payee, option), + (1, payment_params, option), }); - Ok(Route { paths, payee }) + Ok(Route { paths, payment_params }) } } -/// Parameters needed to find a [`Route`] for paying a [`Payee`]. +/// Parameters needed to find a [`Route`]. /// /// Passed to [`find_route`] and also provided in [`Event::PaymentPathFailed`] for retrying a failed /// payment path. @@ -157,8 +157,8 @@ impl Readable for Route { /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed #[derive(Clone, Debug)] pub struct RouteParameters { - /// The recipient of the failed payment path. - pub payee: Payee, + /// The parameters of the failed payment path. + pub payment_params: PaymentParameters, /// The amount in msats sent on the failed payment path. pub final_value_msat: u64, @@ -168,7 +168,7 @@ pub struct RouteParameters { } impl_writeable_tlv_based!(RouteParameters, { - (0, payee, required), + (0, payment_params, required), (2, final_value_msat, required), (4, final_cltv_expiry_delta, required), }); @@ -178,9 +178,9 @@ pub const DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = 1008; /// The recipient of a payment. #[derive(Clone, Debug, Hash, PartialEq, Eq)] -pub struct Payee { +pub struct PaymentParameters { /// The node id of the payee. - pub pubkey: PublicKey, + pub payee_pubkey: PublicKey, /// Features supported by the payee. /// @@ -200,19 +200,19 @@ pub struct Payee { pub max_total_cltv_expiry_delta: u32, } -impl_writeable_tlv_based!(Payee, { - (0, pubkey, required), +impl_writeable_tlv_based!(PaymentParameters, { + (0, payee_pubkey, required), (1, max_total_cltv_expiry_delta, (default_value, DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA)), (2, features, option), (4, route_hints, vec_type), (6, expiry_time, option), }); -impl Payee { +impl PaymentParameters { /// Creates a payee with the node id of the given `pubkey`. - pub fn from_node_id(pubkey: PublicKey) -> Self { + pub fn from_node_id(payee_pubkey: PublicKey) -> Self { Self { - pubkey, + payee_pubkey, features: None, route_hints: vec![], expiry_time: None, @@ -221,8 +221,8 @@ impl Payee { } /// Creates a payee with the node id of the given `pubkey` to use for keysend payments. - pub fn for_keysend(pubkey: PublicKey) -> Self { - Self::from_node_id(pubkey).with_features(InvoiceFeatures::for_keysend()) + pub fn for_keysend(payee_pubkey: PublicKey) -> Self { + Self::from_node_id(payee_pubkey).with_features(InvoiceFeatures::for_keysend()) } /// Includes the payee's features. @@ -546,23 +546,23 @@ fn compute_fees(amount_msat: u64, channel_fees: RoutingFees) -> Option { /// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed pub fn find_route( - our_node_pubkey: &PublicKey, params: &RouteParameters, network: &NetworkGraph, + our_node_pubkey: &PublicKey, route_params: &RouteParameters, network: &NetworkGraph, first_hops: Option<&[&ChannelDetails]>, logger: L, scorer: &S ) -> Result where L::Target: Logger { get_route( - our_node_pubkey, ¶ms.payee, network, first_hops, params.final_value_msat, - params.final_cltv_expiry_delta, logger, scorer + our_node_pubkey, &route_params.payment_params, network, first_hops, route_params.final_value_msat, + route_params.final_cltv_expiry_delta, logger, scorer ) } pub(crate) fn get_route( - our_node_pubkey: &PublicKey, payee: &Payee, network: &NetworkGraph, - first_hops: Option<&[&ChannelDetails]>, final_value_msat: u64, final_cltv_expiry_delta: u32, + our_node_pubkey: &PublicKey, payment_params: &PaymentParameters, network: &NetworkGraph, + first_hops: Option<&[&ChannelDetails]>, final_value_msat: u64, final_cltv_expiry_delta: u32, logger: L, scorer: &S ) -> Result where L::Target: Logger { - let payee_node_id = NodeId::from_pubkey(&payee.pubkey); + let payee_node_id = NodeId::from_pubkey(&payment_params.payee_pubkey); let our_node_id = NodeId::from_pubkey(&our_node_pubkey); if payee_node_id == our_node_id { @@ -577,9 +577,9 @@ where L::Target: Logger { return Err(LightningError{err: "Cannot send a payment of 0 msat".to_owned(), action: ErrorAction::IgnoreError}); } - for route in payee.route_hints.iter() { + for route in payment_params.route_hints.iter() { for hop in &route.0 { - if hop.src_node_id == payee.pubkey { + if hop.src_node_id == payment_params.payee_pubkey { return Err(LightningError{err: "Route hint cannot have the payee as the source.".to_owned(), action: ErrorAction::IgnoreError}); } } @@ -661,7 +661,7 @@ where L::Target: Logger { // Allow MPP only if we have a features set from somewhere that indicates the payee supports // it. If the payee supports it they're supposed to include it in the invoice, so that should // work reliably. - let allow_mpp = if let Some(features) = &payee.features { + let allow_mpp = if let Some(features) = &payment_params.features { features.supports_basic_mpp() } else if let Some(node) = network_nodes.get(&payee_node_id) { if let Some(node_info) = node.announcement_info.as_ref() { @@ -669,7 +669,7 @@ where L::Target: Logger { } else { false } } else { false }; log_trace!(logger, "Searching for a route from payer {} to payee {} {} MPP", our_node_pubkey, - payee.pubkey, if allow_mpp { "with" } else { "without" }); + payment_params.payee_pubkey, if allow_mpp { "with" } else { "without" }); // Step (1). // Prepare the data we'll use for payee-to-payer search by @@ -728,7 +728,7 @@ where L::Target: Logger { // - when we want to stop looking for new paths. let mut already_collected_value_msat = 0; - log_trace!(logger, "Building path from {} (payee) to {} (us/payer) for value {} msat.", payee.pubkey, our_node_pubkey, final_value_msat); + log_trace!(logger, "Building path from {} (payee) to {} (us/payer) for value {} msat.", payment_params.payee_pubkey, our_node_pubkey, final_value_msat); macro_rules! add_entry { // Adds entry which goes from $src_node_id to $dest_node_id @@ -802,7 +802,7 @@ where L::Target: Logger { // Do not consider candidates that exceed the maximum total cltv expiry limit. - let max_total_cltv_expiry_delta = payee.max_total_cltv_expiry_delta; + let max_total_cltv_expiry_delta = payment_params.max_total_cltv_expiry_delta; let hop_total_cltv_delta = ($next_hops_cltv_delta as u32) .checked_add($directional_info.cltv_expiry_delta as u32) .unwrap_or(u32::max_value()); @@ -1107,7 +1107,7 @@ where L::Target: Logger { // If a caller provided us with last hops, add them to routing targets. Since this happens // earlier than general path finding, they will be somewhat prioritized, although currently // it matters only if the fees are exactly the same. - for route in payee.route_hints.iter().filter(|route| !route.0.is_empty()) { + for route in payment_params.route_hints.iter().filter(|route| !route.0.is_empty()) { let first_hop_in_route = &(route.0)[0]; let have_hop_src_in_graph = // Only add the hops in this route to our candidate set if either @@ -1119,7 +1119,7 @@ where L::Target: Logger { // We start building the path from reverse, i.e., from payee // to the first RouteHintHop in the path. let hop_iter = route.0.iter().rev(); - let prev_hop_iter = core::iter::once(&payee.pubkey).chain( + let prev_hop_iter = core::iter::once(&payment_params.payee_pubkey).chain( route.0.iter().skip(1).rev().map(|hop| &hop.src_node_id)); let mut hop_used = true; let mut aggregate_next_hops_fee_msat: u64 = 0; @@ -1490,7 +1490,7 @@ where L::Target: Logger { }).collect()); } - if let Some(features) = &payee.features { + if let Some(features) = &payment_params.features { for path in selected_paths.iter_mut() { if let Ok(route_hop) = path.last_mut().unwrap() { route_hop.node_features = features.to_context(); @@ -1500,9 +1500,9 @@ where L::Target: Logger { let route = Route { paths: selected_paths.into_iter().map(|path| path.into_iter().collect()).collect::, _>>()?, - payee: Some(payee.clone()), + payment_params: Some(payment_params.clone()), }; - log_info!(logger, "Got route to {}: {}", payee.pubkey, log_route!(route)); + log_info!(logger, "Got route to {}: {}", payment_params.payee_pubkey, log_route!(route)); Ok(route) } @@ -1510,7 +1510,7 @@ where L::Target: Logger { mod tests { use routing::scoring::Score; use routing::network_graph::{NetworkGraph, NetGraphMsgHandler, NodeId}; - use routing::router::{get_route, Payee, Route, RouteHint, RouteHintHop, RouteHop, RoutingFees}; + use routing::router::{get_route, PaymentParameters, Route, RouteHint, RouteHintHop, RouteHop, RoutingFees}; use chain::transaction::OutPoint; use ln::features::{ChannelFeatures, InitFeatures, InvoiceFeatures, NodeFeatures}; use ln::msgs::{ErrorAction, LightningError, OptionalField, UnsignedChannelAnnouncement, ChannelAnnouncement, RoutingMessageHandler, @@ -1982,16 +1982,16 @@ mod tests { fn simple_route_test() { let (secp_ctx, network_graph, _, _, logger) = build_graph(); let (_, our_id, _, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[2]); + let payment_params = PaymentParameters::from_node_id(nodes[2]); let scorer = test_utils::TestScorer::with_fixed_penalty(0); // Simple route to 2 via 1 - if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payee, &network_graph, None, 0, 42, Arc::clone(&logger), &scorer) { + if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payment_params, &network_graph, None, 0, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Cannot send a payment of 0 msat"); } else { panic!(); } - let route = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 2); assert_eq!(route.paths[0][0].pubkey, nodes[1]); @@ -2013,18 +2013,18 @@ mod tests { fn invalid_first_hop_test() { let (secp_ctx, network_graph, _, _, logger) = build_graph(); let (_, our_id, _, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[2]); + let payment_params = PaymentParameters::from_node_id(nodes[2]); let scorer = test_utils::TestScorer::with_fixed_penalty(0); // Simple route to 2 via 1 let our_chans = vec![get_channel_details(Some(2), our_id, InitFeatures::from_le_bytes(vec![0b11]), 100000)]; - if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payee, &network_graph, Some(&our_chans.iter().collect::>()), 100, 42, Arc::clone(&logger), &scorer) { + if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payment_params, &network_graph, Some(&our_chans.iter().collect::>()), 100, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "First hop cannot have our_node_pubkey as a destination."); } else { panic!(); } - let route = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 2); } @@ -2032,7 +2032,7 @@ mod tests { fn htlc_minimum_test() { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[2]); + let payment_params = PaymentParameters::from_node_id(nodes[2]); let scorer = test_utils::TestScorer::with_fixed_penalty(0); // Simple route to 2 via 1 @@ -2130,7 +2130,7 @@ mod tests { }); // Not possible to send 199_999_999, because the minimum on channel=2 is 200_000_000. - if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payee, &network_graph, None, 199_999_999, 42, Arc::clone(&logger), &scorer) { + if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payment_params, &network_graph, None, 199_999_999, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a path to the given destination"); } else { panic!(); } @@ -2149,7 +2149,7 @@ mod tests { }); // A payment above the minimum should pass - let route = get_route(&our_id, &payee, &network_graph, None, 199_999_999, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 199_999_999, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 2); } @@ -2157,7 +2157,7 @@ mod tests { fn htlc_minimum_overpay_test() { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); let scorer = test_utils::TestScorer::with_fixed_penalty(0); // A route to node#2 via two paths. @@ -2228,7 +2228,7 @@ mod tests { excess_data: Vec::new() }); - let route = get_route(&our_id, &payee, &network_graph, None, 60_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 60_000, 42, Arc::clone(&logger), &scorer).unwrap(); // Overpay fees to hit htlc_minimum_msat. let overpaid_fees = route.paths[0][0].fee_msat + route.paths[1][0].fee_msat; // TODO: this could be better balanced to overpay 10k and not 15k. @@ -2273,14 +2273,14 @@ mod tests { excess_data: Vec::new() }); - let route = get_route(&our_id, &payee, &network_graph, None, 60_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 60_000, 42, Arc::clone(&logger), &scorer).unwrap(); // Fine to overpay for htlc_minimum_msat if it allows us to save fee. assert_eq!(route.paths.len(), 1); assert_eq!(route.paths[0][0].short_channel_id, 12); let fees = route.paths[0][0].fee_msat; assert_eq!(fees, 5_000); - let route = get_route(&our_id, &payee, &network_graph, None, 50_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 50_000, 42, Arc::clone(&logger), &scorer).unwrap(); // Not fine to overpay for htlc_minimum_msat if it requires paying more than fee on // the other channel. assert_eq!(route.paths.len(), 1); @@ -2293,7 +2293,7 @@ mod tests { fn disable_channels_test() { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[2]); + let payment_params = PaymentParameters::from_node_id(nodes[2]); let scorer = test_utils::TestScorer::with_fixed_penalty(0); // // Disable channels 4 and 12 by flags=2 @@ -2323,13 +2323,13 @@ mod tests { }); // If all the channels require some features we don't understand, route should fail - if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer) { + if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a path to the given destination"); } else { panic!(); } // If we specify a channel to node7, that overrides our local channel view and that gets used let our_chans = vec![get_channel_details(Some(42), nodes[7].clone(), InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)]; - let route = get_route(&our_id, &payee, &network_graph, Some(&our_chans.iter().collect::>()), 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, Some(&our_chans.iter().collect::>()), 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 2); assert_eq!(route.paths[0][0].pubkey, nodes[7]); @@ -2351,7 +2351,7 @@ mod tests { fn disable_node_test() { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[2]); + let payment_params = PaymentParameters::from_node_id(nodes[2]); let scorer = test_utils::TestScorer::with_fixed_penalty(0); // Disable nodes 1, 2, and 8 by requiring unknown feature bits @@ -2361,13 +2361,13 @@ mod tests { add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[7], unknown_features.clone(), 1); // If all nodes require some features we don't understand, route should fail - if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer) { + if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a path to the given destination"); } else { panic!(); } // If we specify a channel to node7, that overrides our local channel view and that gets used let our_chans = vec![get_channel_details(Some(42), nodes[7].clone(), InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)]; - let route = get_route(&our_id, &payee, &network_graph, Some(&our_chans.iter().collect::>()), 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, Some(&our_chans.iter().collect::>()), 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 2); assert_eq!(route.paths[0][0].pubkey, nodes[7]); @@ -2396,8 +2396,8 @@ mod tests { let scorer = test_utils::TestScorer::with_fixed_penalty(0); // Route to 1 via 2 and 3 because our channel to 1 is disabled - let payee = Payee::from_node_id(nodes[0]); - let route = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let payment_params = PaymentParameters::from_node_id(nodes[0]); + let route = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 3); assert_eq!(route.paths[0][0].pubkey, nodes[1]); @@ -2422,9 +2422,9 @@ mod tests { assert_eq!(route.paths[0][2].channel_features.le_flags(), &id_to_feature_flags(3)); // If we specify a channel to node7, that overrides our local channel view and that gets used - let payee = Payee::from_node_id(nodes[2]); + let payment_params = PaymentParameters::from_node_id(nodes[2]); let our_chans = vec![get_channel_details(Some(42), nodes[7].clone(), InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)]; - let route = get_route(&our_id, &payee, &network_graph, Some(&our_chans.iter().collect::>()), 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, Some(&our_chans.iter().collect::>()), 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 2); assert_eq!(route.paths[0][0].pubkey, nodes[7]); @@ -2544,14 +2544,14 @@ mod tests { let mut invalid_last_hops = last_hops_multi_private_channels(&nodes); invalid_last_hops.push(invalid_last_hop); { - let payee = Payee::from_node_id(nodes[6]).with_route_hints(invalid_last_hops); - if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer) { + let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(invalid_last_hops); + if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Route hint cannot have the payee as the source."); } else { panic!(); } } - let payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops_multi_private_channels(&nodes)); - let route = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops_multi_private_channels(&nodes)); + let route = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 5); assert_eq!(route.paths[0][0].pubkey, nodes[1]); @@ -2620,12 +2620,12 @@ mod tests { fn ignores_empty_last_hops_test() { let (secp_ctx, network_graph, _, _, logger) = build_graph(); let (_, our_id, _, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[6]).with_route_hints(empty_last_hop(&nodes)); + let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(empty_last_hop(&nodes)); let scorer = test_utils::TestScorer::with_fixed_penalty(0); // Test handling of an empty RouteHint passed in Invoice. - let route = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 5); assert_eq!(route.paths[0][0].pubkey, nodes[1]); @@ -2702,7 +2702,7 @@ mod tests { fn multi_hint_last_hops_test() { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[6]).with_route_hints(multi_hint_last_hops(&nodes)); + let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(multi_hint_last_hops(&nodes)); let scorer = test_utils::TestScorer::with_fixed_penalty(0); // Test through channels 2, 3, 5, 8. // Test shows that multiple hop hints are considered. @@ -2733,7 +2733,7 @@ mod tests { excess_data: Vec::new() }); - let route = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 4); assert_eq!(route.paths[0][0].pubkey, nodes[1]); @@ -2808,12 +2808,12 @@ mod tests { fn last_hops_with_public_channel_test() { let (secp_ctx, network_graph, _, _, logger) = build_graph(); let (_, our_id, _, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops_with_public_channel(&nodes)); + let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops_with_public_channel(&nodes)); let scorer = test_utils::TestScorer::with_fixed_penalty(0); // This test shows that public routes can be present in the invoice // which would be handled in the same manner. - let route = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 5); assert_eq!(route.paths[0][0].pubkey, nodes[1]); @@ -2863,8 +2863,8 @@ mod tests { // Simple test with outbound channel to 4 to test that last_hops and first_hops connect let our_chans = vec![get_channel_details(Some(42), nodes[3].clone(), InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)]; let mut last_hops = last_hops(&nodes); - let payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops.clone()); - let route = get_route(&our_id, &payee, &network_graph, Some(&our_chans.iter().collect::>()), 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops.clone()); + let route = get_route(&our_id, &payment_params, &network_graph, Some(&our_chans.iter().collect::>()), 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 2); assert_eq!(route.paths[0][0].pubkey, nodes[3]); @@ -2884,8 +2884,8 @@ mod tests { last_hops[0].0[0].fees.base_msat = 1000; // Revert to via 6 as the fee on 8 goes up - let payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops); - let route = get_route(&our_id, &payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops); + let route = get_route(&our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 4); assert_eq!(route.paths[0][0].pubkey, nodes[1]); @@ -2919,7 +2919,7 @@ mod tests { assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::::new()); // We can't learn any flags from invoices, sadly // ...but still use 8 for larger payments as 6 has a variable feerate - let route = get_route(&our_id, &payee, &network_graph, None, 2000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 2000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths[0].len(), 5); assert_eq!(route.paths[0][0].pubkey, nodes[1]); @@ -2977,10 +2977,10 @@ mod tests { htlc_minimum_msat: None, htlc_maximum_msat: last_hop_htlc_max, }]); - let payee = Payee::from_node_id(target_node_id).with_route_hints(vec![last_hops]); + let payment_params = PaymentParameters::from_node_id(target_node_id).with_route_hints(vec![last_hops]); let our_chans = vec![get_channel_details(Some(42), middle_node_id, InitFeatures::from_le_bytes(vec![0b11]), outbound_capacity_msat)]; let scorer = test_utils::TestScorer::with_fixed_penalty(0); - get_route(&source_node_id, &payee, &NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()), Some(&our_chans.iter().collect::>()), route_val, 42, &test_utils::TestLogger::new(), &scorer) + get_route(&source_node_id, &payment_params, &NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()), Some(&our_chans.iter().collect::>()), route_val, 42, &test_utils::TestLogger::new(), &scorer) } #[test] @@ -3034,7 +3034,7 @@ mod tests { let (secp_ctx, network_graph, mut net_graph_msg_handler, chain_monitor, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); // We will use a simple single-path route from // our node to node2 via node0: channels {1, 3}. @@ -3098,14 +3098,14 @@ mod tests { { // Attempt to route more than available results in a failure. if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route( - &our_id, &payee, &network_graph, None, 250_000_001, 42, Arc::clone(&logger), &scorer) { + &our_id, &payment_params, &network_graph, None, 250_000_001, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a sufficient route to the given destination"); } else { panic!(); } } { // Now, attempt to route an exact amount we have should be fine. - let route = get_route(&our_id, &payee, &network_graph, None, 250_000_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 250_000_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); let path = route.paths.last().unwrap(); assert_eq!(path.len(), 2); @@ -3134,14 +3134,14 @@ mod tests { { // Attempt to route more than available results in a failure. if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route( - &our_id, &payee, &network_graph, Some(&our_chans.iter().collect::>()), 200_000_001, 42, Arc::clone(&logger), &scorer) { + &our_id, &payment_params, &network_graph, Some(&our_chans.iter().collect::>()), 200_000_001, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a sufficient route to the given destination"); } else { panic!(); } } { // Now, attempt to route an exact amount we have should be fine. - let route = get_route(&our_id, &payee, &network_graph, Some(&our_chans.iter().collect::>()), 200_000_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, Some(&our_chans.iter().collect::>()), 200_000_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); let path = route.paths.last().unwrap(); assert_eq!(path.len(), 2); @@ -3181,14 +3181,14 @@ mod tests { { // Attempt to route more than available results in a failure. if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route( - &our_id, &payee, &network_graph, None, 15_001, 42, Arc::clone(&logger), &scorer) { + &our_id, &payment_params, &network_graph, None, 15_001, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a sufficient route to the given destination"); } else { panic!(); } } { // Now, attempt to route an exact amount we have should be fine. - let route = get_route(&our_id, &payee, &network_graph, None, 15_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 15_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); let path = route.paths.last().unwrap(); assert_eq!(path.len(), 2); @@ -3251,14 +3251,14 @@ mod tests { { // Attempt to route more than available results in a failure. if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route( - &our_id, &payee, &network_graph, None, 15_001, 42, Arc::clone(&logger), &scorer) { + &our_id, &payment_params, &network_graph, None, 15_001, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a sufficient route to the given destination"); } else { panic!(); } } { // Now, attempt to route an exact amount we have should be fine. - let route = get_route(&our_id, &payee, &network_graph, None, 15_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 15_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); let path = route.paths.last().unwrap(); assert_eq!(path.len(), 2); @@ -3283,14 +3283,14 @@ mod tests { { // Attempt to route more than available results in a failure. if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route( - &our_id, &payee, &network_graph, None, 10_001, 42, Arc::clone(&logger), &scorer) { + &our_id, &payment_params, &network_graph, None, 10_001, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a sufficient route to the given destination"); } else { panic!(); } } { // Now, attempt to route an exact amount we have should be fine. - let route = get_route(&our_id, &payee, &network_graph, None, 10_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 10_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); let path = route.paths.last().unwrap(); assert_eq!(path.len(), 2); @@ -3306,7 +3306,7 @@ mod tests { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[3]).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(InvoiceFeatures::known()); // Path via {node7, node2, node4} is channels {12, 13, 6, 11}. // {12, 13, 11} have the capacities of 100, {6} has a capacity of 50. @@ -3392,14 +3392,14 @@ mod tests { { // Attempt to route more than available results in a failure. if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route( - &our_id, &payee, &network_graph, None, 60_000, 42, Arc::clone(&logger), &scorer) { + &our_id, &payment_params, &network_graph, None, 60_000, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a sufficient route to the given destination"); } else { panic!(); } } { // Now, attempt to route 49 sats (just a bit below the capacity). - let route = get_route(&our_id, &payee, &network_graph, None, 49_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 49_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); let mut total_amount_paid_msat = 0; for path in &route.paths { @@ -3412,7 +3412,7 @@ mod tests { { // Attempt to route an exact amount is also fine - let route = get_route(&our_id, &payee, &network_graph, None, 50_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 50_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); let mut total_amount_paid_msat = 0; for path in &route.paths { @@ -3429,7 +3429,7 @@ mod tests { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[2]); + let payment_params = PaymentParameters::from_node_id(nodes[2]); // Path via node0 is channels {1, 3}. Limit them to 100 and 50 sats (total limit 50). update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { @@ -3458,7 +3458,7 @@ mod tests { }); { - let route = get_route(&our_id, &payee, &network_graph, None, 50_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 50_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); let mut total_amount_paid_msat = 0; for path in &route.paths { @@ -3475,7 +3475,7 @@ mod tests { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); // We need a route consisting of 3 paths: // From our node to node2 via node0, node7, node1 (three paths one hop each). @@ -3568,7 +3568,7 @@ mod tests { { // Attempt to route more than available results in a failure. if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route( - &our_id, &payee, &network_graph, None, 300_000, 42, Arc::clone(&logger), &scorer) { + &our_id, &payment_params, &network_graph, None, 300_000, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a sufficient route to the given destination"); } else { panic!(); } } @@ -3576,7 +3576,7 @@ mod tests { { // Now, attempt to route 250 sats (just a bit below the capacity). // Our algorithm should provide us with these 3 paths. - let route = get_route(&our_id, &payee, &network_graph, None, 250_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 250_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 3); let mut total_amount_paid_msat = 0; for path in &route.paths { @@ -3589,7 +3589,7 @@ mod tests { { // Attempt to route an exact amount is also fine - let route = get_route(&our_id, &payee, &network_graph, None, 290_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 290_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 3); let mut total_amount_paid_msat = 0; for path in &route.paths { @@ -3606,7 +3606,7 @@ mod tests { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[3]).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(InvoiceFeatures::known()); // We need a route consisting of 3 paths: // From our node to node3 via {node0, node2}, {node7, node2, node4} and {node7, node2}. @@ -3742,7 +3742,7 @@ mod tests { { // Attempt to route more than available results in a failure. if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route( - &our_id, &payee, &network_graph, None, 350_000, 42, Arc::clone(&logger), &scorer) { + &our_id, &payment_params, &network_graph, None, 350_000, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a sufficient route to the given destination"); } else { panic!(); } } @@ -3750,7 +3750,7 @@ mod tests { { // Now, attempt to route 300 sats (exact amount we can route). // Our algorithm should provide us with these 3 paths, 100 sats each. - let route = get_route(&our_id, &payee, &network_graph, None, 300_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 300_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 3); let mut total_amount_paid_msat = 0; @@ -3768,7 +3768,7 @@ mod tests { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[3]).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(InvoiceFeatures::known()); // This test checks that if we have two cheaper paths and one more expensive path, // so that liquidity-wise any 2 of 3 combination is sufficient, @@ -3908,7 +3908,7 @@ mod tests { { // Now, attempt to route 180 sats. // Our algorithm should provide us with these 2 paths. - let route = get_route(&our_id, &payee, &network_graph, None, 180_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 180_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 2); let mut total_value_transferred_msat = 0; @@ -3935,7 +3935,7 @@ mod tests { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[3]).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(InvoiceFeatures::known()); // We need a route consisting of 2 paths: // From our node to node3 via {node0, node2} and {node7, node2, node4}. @@ -4076,14 +4076,14 @@ mod tests { { // Attempt to route more than available results in a failure. if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route( - &our_id, &payee, &network_graph, None, 210_000, 42, Arc::clone(&logger), &scorer) { + &our_id, &payment_params, &network_graph, None, 210_000, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a sufficient route to the given destination"); } else { panic!(); } } { // Now, attempt to route 200 sats (exact amount we can route). - let route = get_route(&our_id, &payee, &network_graph, None, 200_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 200_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 2); let mut total_amount_paid_msat = 0; @@ -4114,7 +4114,7 @@ mod tests { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(PublicKey::from_slice(&[02; 33]).unwrap()).with_features(InvoiceFeatures::known()) + let payment_params = PaymentParameters::from_node_id(PublicKey::from_slice(&[02; 33]).unwrap()).with_features(InvoiceFeatures::known()) .with_route_hints(vec![RouteHint(vec![RouteHintHop { src_node_id: nodes[2], short_channel_id: 42, @@ -4180,7 +4180,7 @@ mod tests { // Get a route for 100 sats and check that we found the MPP route no problem and didn't // overpay at all. - let route = get_route(&our_id, &payee, &network_graph, None, 100_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 100_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 2); // Paths are somewhat randomly ordered, but: // * the first is channel 2 (1 msat fee) -> channel 4 -> channel 42 @@ -4202,7 +4202,7 @@ mod tests { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); // We need a route consisting of 3 paths: // From our node to node2 via node0, node7, node1 (three paths one hop each). @@ -4294,7 +4294,7 @@ mod tests { { // Attempt to route more than available results in a failure. if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route( - &our_id, &payee, &network_graph, None, 150_000, 42, Arc::clone(&logger), &scorer) { + &our_id, &payment_params, &network_graph, None, 150_000, 42, Arc::clone(&logger), &scorer) { assert_eq!(err, "Failed to find a sufficient route to the given destination"); } else { panic!(); } } @@ -4302,7 +4302,7 @@ mod tests { { // Now, attempt to route 125 sats (just a bit below the capacity of 3 channels). // Our algorithm should provide us with these 3 paths. - let route = get_route(&our_id, &payee, &network_graph, None, 125_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 125_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 3); let mut total_amount_paid_msat = 0; for path in &route.paths { @@ -4315,7 +4315,7 @@ mod tests { { // Attempt to route without the last small cheap channel - let route = get_route(&our_id, &payee, &network_graph, None, 90_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 90_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 2); let mut total_amount_paid_msat = 0; for path in &route.paths { @@ -4359,7 +4359,7 @@ mod tests { let net_graph_msg_handler = NetGraphMsgHandler::new(Arc::clone(&network_graph), None, Arc::clone(&logger)); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[6]); + let payment_params = PaymentParameters::from_node_id(nodes[6]); add_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6); update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate { @@ -4452,7 +4452,7 @@ mod tests { { // Now ensure the route flows simply over nodes 1 and 4 to 6. - let route = get_route(&our_id, &payee, &network_graph, None, 10_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 10_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); assert_eq!(route.paths[0].len(), 3); @@ -4488,7 +4488,7 @@ mod tests { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, _, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[2]); + let payment_params = PaymentParameters::from_node_id(nodes[2]); // We modify the graph to set the htlc_maximum of channel 2 to below the value we wish to // send. @@ -4521,7 +4521,7 @@ mod tests { { // Now, attempt to route 90 sats, which is exactly 90 sats at the last hop, plus the // 200% fee charged channel 13 in the 1-to-2 direction. - let route = get_route(&our_id, &payee, &network_graph, None, 90_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 90_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); assert_eq!(route.paths[0].len(), 2); @@ -4550,7 +4550,7 @@ mod tests { let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph(); let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known()); // We modify the graph to set the htlc_minimum of channel 2 and 4 as needed - channel 2 // gets an htlc_maximum_msat of 80_000 and channel 4 an htlc_minimum_msat of 90_000. We @@ -4584,7 +4584,7 @@ mod tests { // Now, attempt to route 90 sats, hitting the htlc_minimum on channel 4, but // overshooting the htlc_maximum on channel 2. Thus, we should pick the (absurdly // expensive) channels 12-13 path. - let route = get_route(&our_id, &payee, &network_graph, None, 90_000, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &payment_params, &network_graph, None, 90_000, 42, Arc::clone(&logger), &scorer).unwrap(); assert_eq!(route.paths.len(), 1); assert_eq!(route.paths[0].len(), 2); @@ -4617,10 +4617,10 @@ mod tests { let logger = Arc::new(test_utils::TestLogger::new()); let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()); let scorer = test_utils::TestScorer::with_fixed_penalty(0); - let payee = Payee::from_node_id(nodes[0]).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(nodes[0]).with_features(InvoiceFeatures::known()); { - let route = get_route(&our_id, &payee, &network_graph, Some(&[ + let route = get_route(&our_id, &payment_params, &network_graph, Some(&[ &get_channel_details(Some(3), nodes[0], InitFeatures::known(), 200_000), &get_channel_details(Some(2), nodes[0], InitFeatures::known(), 10_000), ]), 100_000, 42, Arc::clone(&logger), &scorer).unwrap(); @@ -4632,7 +4632,7 @@ mod tests { assert_eq!(route.paths[0][0].fee_msat, 100_000); } { - let route = get_route(&our_id, &payee, &network_graph, Some(&[ + let route = get_route(&our_id, &payment_params, &network_graph, Some(&[ &get_channel_details(Some(3), nodes[0], InitFeatures::known(), 50_000), &get_channel_details(Some(2), nodes[0], InitFeatures::known(), 50_000), ]), 100_000, 42, Arc::clone(&logger), &scorer).unwrap(); @@ -4654,12 +4654,12 @@ mod tests { fn prefers_shorter_route_with_higher_fees() { let (secp_ctx, network_graph, _, _, logger) = build_graph(); let (_, our_id, _, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes)); + let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes)); // Without penalizing each hop 100 msats, a longer path with lower fees is chosen. let scorer = test_utils::TestScorer::with_fixed_penalty(0); let route = get_route( - &our_id, &payee, &network_graph, None, 100, 42, + &our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer ).unwrap(); let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::>(); @@ -4672,7 +4672,7 @@ mod tests { // from nodes[2] rather than channel 6, 11, and 8, even though the longer path is cheaper. let scorer = test_utils::TestScorer::with_fixed_penalty(100); let route = get_route( - &our_id, &payee, &network_graph, None, 100, 42, + &our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer ).unwrap(); let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::>(); @@ -4721,12 +4721,12 @@ mod tests { fn avoids_routing_through_bad_channels_and_nodes() { let (secp_ctx, network_graph, _, _, logger) = build_graph(); let (_, our_id, _, nodes) = get_nodes(&secp_ctx); - let payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes)); + let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes)); // A path to nodes[6] exists when no penalties are applied to any channel. let scorer = test_utils::TestScorer::with_fixed_penalty(0); let route = get_route( - &our_id, &payee, &network_graph, None, 100, 42, + &our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer ).unwrap(); let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::>(); @@ -4738,7 +4738,7 @@ mod tests { // A different path to nodes[6] exists if channel 6 cannot be routed over. let scorer = BadChannelScorer { short_channel_id: 6 }; let route = get_route( - &our_id, &payee, &network_graph, None, 100, 42, + &our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer ).unwrap(); let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::>(); @@ -4750,7 +4750,7 @@ mod tests { // A path to nodes[6] does not exist if nodes[2] cannot be routed through. let scorer = BadNodeScorer { node_id: NodeId::from_pubkey(&nodes[2]) }; match get_route( - &our_id, &payee, &network_graph, None, 100, 42, + &our_id, &payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer ) { Err(LightningError { err, .. } ) => { @@ -4780,7 +4780,7 @@ mod tests { short_channel_id: 0, fee_msat: 225, cltv_expiry_delta: 0 }, ]], - payee: None, + payment_params: None, }; assert_eq!(route.get_total_fees(), 250); @@ -4813,7 +4813,7 @@ mod tests { short_channel_id: 0, fee_msat: 150, cltv_expiry_delta: 0 }, ]], - payee: None, + payment_params: None, }; assert_eq!(route.get_total_fees(), 200); @@ -4825,7 +4825,7 @@ mod tests { // In an earlier version of `Route::get_total_fees` and `Route::get_total_amount`, they // would both panic if the route was completely empty. We test to ensure they return 0 // here, even though its somewhat nonsensical as a route. - let route = Route { paths: Vec::new(), payee: None }; + let route = Route { paths: Vec::new(), payment_params: None }; assert_eq!(route.get_total_fees(), 0); assert_eq!(route.get_total_amount(), 0); @@ -4840,17 +4840,17 @@ mod tests { // Make sure that generally there is at least one route available let feasible_max_total_cltv_delta = 1008; - let feasible_payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes)) + let feasible_payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes)) .with_max_total_cltv_expiry_delta(feasible_max_total_cltv_delta); - let route = get_route(&our_id, &feasible_payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); + let route = get_route(&our_id, &feasible_payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer).unwrap(); let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::>(); assert_ne!(path.len(), 0); // But not if we exclude all paths on the basis of their accumulated CLTV delta let fail_max_total_cltv_delta = 23; - let fail_payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes)) + let fail_payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes)) .with_max_total_cltv_expiry_delta(fail_max_total_cltv_delta); - match get_route(&our_id, &fail_payee, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer) + match get_route(&our_id, &fail_payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer) { Err(LightningError { err, .. } ) => { assert_eq!(err, "Failed to find a path to the given destination"); @@ -4892,9 +4892,9 @@ mod tests { let src = &PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap(); seed = seed.overflowing_mul(0xdeadbeef).0; let dst = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap(); - let payee = Payee::from_node_id(dst); + let payment_params = PaymentParameters::from_node_id(dst); let amt = seed as u64 % 200_000_000; - if get_route(src, &payee, &graph, None, amt, 42, &test_utils::TestLogger::new(), &scorer).is_ok() { + if get_route(src, &payment_params, &graph, None, amt, 42, &test_utils::TestLogger::new(), &scorer).is_ok() { continue 'load_endpoints; } } @@ -4923,9 +4923,9 @@ mod tests { let src = &PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap(); seed = seed.overflowing_mul(0xdeadbeef).0; let dst = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap(); - let payee = Payee::from_node_id(dst).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(dst).with_features(InvoiceFeatures::known()); let amt = seed as u64 % 200_000_000; - if get_route(src, &payee, &graph, None, amt, 42, &test_utils::TestLogger::new(), &scorer).is_ok() { + if get_route(src, &payment_params, &graph, None, amt, 42, &test_utils::TestLogger::new(), &scorer).is_ok() { continue 'load_endpoints; } } @@ -4989,9 +4989,9 @@ mod benches { let src = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap(); seed *= 0xdeadbeef; let dst = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap(); - let payee = Payee::from_node_id(dst); + let payment_params = PaymentParameters::from_node_id(dst); let amt = seed as u64 % 1_000_000; - if get_route(&src, &payee, &graph, None, amt, 42, &DummyLogger{}, &scorer).is_ok() { + if get_route(&src, &payment_params, &graph, None, amt, 42, &DummyLogger{}, &scorer).is_ok() { path_endpoints.push((src, dst, amt)); continue 'load_endpoints; } @@ -5002,8 +5002,8 @@ mod benches { let mut idx = 0; bench.iter(|| { let (src, dst, amt) = path_endpoints[idx % path_endpoints.len()]; - let payee = Payee::from_node_id(dst); - assert!(get_route(&src, &payee, &graph, None, amt, 42, &DummyLogger{}, &scorer).is_ok()); + let payment_params = PaymentParameters::from_node_id(dst); + assert!(get_route(&src, &payment_params, &graph, None, amt, 42, &DummyLogger{}, &scorer).is_ok()); idx += 1; }); } @@ -5024,9 +5024,9 @@ mod benches { let src = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap(); seed *= 0xdeadbeef; let dst = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap(); - let payee = Payee::from_node_id(dst).with_features(InvoiceFeatures::known()); + let payment_params = PaymentParameters::from_node_id(dst).with_features(InvoiceFeatures::known()); let amt = seed as u64 % 1_000_000; - if get_route(&src, &payee, &graph, None, amt, 42, &DummyLogger{}, &scorer).is_ok() { + if get_route(&src, &payment_params, &graph, None, amt, 42, &DummyLogger{}, &scorer).is_ok() { path_endpoints.push((src, dst, amt)); continue 'load_endpoints; } @@ -5037,8 +5037,8 @@ mod benches { let mut idx = 0; bench.iter(|| { let (src, dst, amt) = path_endpoints[idx % path_endpoints.len()]; - let payee = Payee::from_node_id(dst).with_features(InvoiceFeatures::known()); - assert!(get_route(&src, &payee, &graph, None, amt, 42, &DummyLogger{}, &scorer).is_ok()); + let payment_params = PaymentParameters::from_node_id(dst).with_features(InvoiceFeatures::known()); + assert!(get_route(&src, &payment_params, &graph, None, amt, 42, &DummyLogger{}, &scorer).is_ok()); idx += 1; }); } -- 2.39.5