Skip to content

Commit c11be16

Browse files
Mark deprecated send_payment_with_route as test and fuzz only
This method has been deprecated for several versions in favor of ChannelManager::send_payment, and we want to remove it from the public API entirely prior to the 0.1 release. However, >150 tests use it so put off removing the method entirely.
1 parent 12920d8 commit c11be16

File tree

4 files changed

+62
-79
lines changed

4 files changed

+62
-79
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4519,24 +4519,32 @@ where
45194519
}
45204520
}
45214521

4522-
/// Sends a payment along a given route.
4523-
///
4524-
/// This method is *DEPRECATED*, use [`Self::send_payment`] instead. If you wish to fix the
4525-
/// route for a payment, do so by matching the [`PaymentId`] passed to
4526-
/// [`Router::find_route_with_id`].
4527-
///
4528-
/// Value parameters are provided via the last hop in route, see documentation for [`RouteHop`]
4529-
/// fields for more info.
4522+
// Deprecated send method, for testing use [`Self::send_payment`] and
4523+
// [`TestRouter::expect_find_route`] instead.
4524+
//
4525+
// [`TestRouter::expect_find_route`]: crate::util::test_utils::TestRouter::expect_find_route
4526+
#[cfg(any(test, fuzzing))]
4527+
pub fn send_payment_with_route(&self, route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId) -> Result<(), PaymentSendFailure> {
4528+
let best_block_height = self.best_block.read().unwrap().height;
4529+
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4530+
self.pending_outbound_payments
4531+
.send_payment_with_route(&route, payment_hash, recipient_onion, payment_id,
4532+
&self.entropy_source, &self.node_signer, best_block_height,
4533+
|args| self.send_payment_along_path(args))
4534+
}
4535+
4536+
/// Sends a payment to the route found using the provided [`RouteParameters`], retrying failed
4537+
/// payment paths based on the provided `Retry`.
45304538
///
45314539
/// May generate [`UpdateHTLCs`] message(s) event on success, which should be relayed (e.g. via
45324540
/// [`PeerManager::process_events`]).
45334541
///
45344542
/// # Avoiding Duplicate Payments
45354543
///
45364544
/// If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
4537-
/// method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
4538-
/// is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
4539-
/// [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
4545+
/// method will error with [`RetryableSendFailure::DuplicatePayment`]. Note, however, that once a
4546+
/// payment is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of
4547+
/// an [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
45404548
/// second payment with the same [`PaymentId`].
45414549
///
45424550
/// Thus, in order to ensure duplicate payments are not sent, you should implement your own
@@ -4550,43 +4558,18 @@ where
45504558
/// using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
45514559
/// [`ChannelManager::list_recent_payments`] for more information.
45524560
///
4553-
/// # Possible Error States on [`PaymentSendFailure`]
4554-
///
4555-
/// Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
4556-
/// each entry matching the corresponding-index entry in the route paths, see
4557-
/// [`PaymentSendFailure`] for more info.
4558-
///
4559-
/// In general, a path may raise:
4560-
/// * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
4561-
/// node public key) is specified.
4562-
/// * [`APIError::ChannelUnavailable`] if the next-hop channel is not available as it has been
4563-
/// closed, doesn't exist, or the peer is currently disconnected.
4564-
/// * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
4565-
/// relevant updates.
4566-
///
4567-
/// Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
4568-
/// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
4569-
/// different route unless you intend to pay twice!
4561+
/// Routes are automatically found using the [`Router] provided on startup. To fix a route for a
4562+
/// particular payment, match the [`PaymentId`] passed to [`Router::find_route_with_id`].
45704563
///
4571-
/// [`RouteHop`]: crate::routing::router::RouteHop
45724564
/// [`Event::PaymentSent`]: events::Event::PaymentSent
45734565
/// [`Event::PaymentFailed`]: events::Event::PaymentFailed
45744566
/// [`UpdateHTLCs`]: events::MessageSendEvent::UpdateHTLCs
45754567
/// [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
45764568
/// [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
4577-
#[cfg_attr(not(any(test, feature = "_test_utils")), deprecated(note = "Use `send_payment` instead"))]
4578-
pub fn send_payment_with_route(&self, route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId) -> Result<(), PaymentSendFailure> {
4579-
let best_block_height = self.best_block.read().unwrap().height;
4580-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4581-
self.pending_outbound_payments
4582-
.send_payment_with_route(&route, payment_hash, recipient_onion, payment_id,
4583-
&self.entropy_source, &self.node_signer, best_block_height,
4584-
|args| self.send_payment_along_path(args))
4585-
}
4586-
4587-
/// Similar to [`ChannelManager::send_payment_with_route`], but will automatically find a route based on
4588-
/// `route_params` and retry failed payment paths based on `retry_strategy`.
4589-
pub fn send_payment(&self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry) -> Result<(), RetryableSendFailure> {
4569+
pub fn send_payment(
4570+
&self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId,
4571+
route_params: RouteParameters, retry_strategy: Retry
4572+
) -> Result<(), RetryableSendFailure> {
45904573
let best_block_height = self.best_block.read().unwrap().height;
45914574
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
45924575
self.pending_outbound_payments
@@ -4801,8 +4784,26 @@ where
48014784
/// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
48024785
/// never reach the recipient.
48034786
///
4804-
/// See [`send_payment`] documentation for more details on the return value of this function
4805-
/// and idempotency guarantees provided by the [`PaymentId`] key.
4787+
/// See [`send_payment`] documentation for more details on the idempotency guarantees provided by
4788+
/// the [`PaymentId`] key.
4789+
///
4790+
/// # Possible Error States on [`PaymentSendFailure`]
4791+
///
4792+
/// Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
4793+
/// each entry matching the corresponding-index entry in the route paths, see
4794+
/// [`PaymentSendFailure`] for more info.
4795+
///
4796+
/// In general, a path may raise:
4797+
/// * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
4798+
/// node public key) is specified.
4799+
/// * [`APIError::ChannelUnavailable`] if the next-hop channel is not available as it has been
4800+
/// closed, doesn't exist, or the peer is currently disconnected.
4801+
/// * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
4802+
/// relevant updates.
4803+
///
4804+
/// Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
4805+
/// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
4806+
/// different route unless you intend to pay twice!
48064807
///
48074808
/// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
48084809
/// [`send_payment`] for more information about the risks of duplicate preimage usage.

lightning/src/ln/functional_test_utils.rs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ use crate::events::{ClaimedHTLC, ClosureReason, Event, HTLCDestination, MessageS
1717
use crate::events::bump_transaction::{BumpTransactionEvent, BumpTransactionEventHandler, Wallet, WalletSource};
1818
use crate::ln::types::ChannelId;
1919
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
20-
use crate::ln::channelmanager::{AChannelManager, ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, RecipientOnionFields, PaymentId, MIN_CLTV_EXPIRY_DELTA};
20+
use crate::ln::channelmanager::{AChannelManager, ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, RecipientOnionFields, PaymentId, MIN_CLTV_EXPIRY_DELTA};
2121
use crate::types::features::InitFeatures;
2222
use crate::ln::msgs;
2323
use crate::ln::msgs::{ChannelMessageHandler, OnionMessageHandler, RoutingMessageHandler};
24+
use crate::ln::outbound_payment::Retry;
2425
use crate::ln::peer_handler::IgnoringMessageHandler;
2526
use crate::onion_message::messenger::OnionMessenger;
2627
use crate::routing::gossip::{P2PGossipSync, NetworkGraph, NetworkUpdate};
2728
use crate::routing::router::{self, PaymentParameters, Route, RouteParameters};
2829
use crate::sign::{EntropySource, RandomBytes};
2930
use crate::util::config::{UserConfig, MaxDustHTLCExposure};
30-
use crate::util::errors::APIError;
3131
#[cfg(test)]
3232
use crate::util::logger::Logger;
3333
use crate::util::scid_utils;
@@ -2600,8 +2600,11 @@ pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
26002600

26012601
pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_paths: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret) -> PaymentId {
26022602
let payment_id = PaymentId(origin_node.keys_manager.backing.get_secure_random_bytes());
2603-
origin_node.node.send_payment_with_route(route, our_payment_hash,
2604-
RecipientOnionFields::secret_only(our_payment_secret), payment_id).unwrap();
2603+
origin_node.router.expect_find_route(route.route_params.clone().unwrap(), Ok(route.clone()));
2604+
origin_node.node.send_payment(
2605+
our_payment_hash, RecipientOnionFields::secret_only(our_payment_secret), payment_id,
2606+
route.route_params.unwrap(), Retry::Attempts(0)
2607+
).unwrap();
26052608
check_added_monitors!(origin_node, expected_paths.len());
26062609
pass_along_route(origin_node, expected_paths, recv_value, our_payment_hash, our_payment_secret);
26072610
payment_id
@@ -3103,30 +3106,6 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
31033106
(res.0, res.1, res.2, res.3)
31043107
}
31053108

3106-
pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) {
3107-
let payment_params = PaymentParameters::from_node_id(expected_route.last().unwrap().node.get_our_node_id(), TEST_FINAL_CLTV)
3108-
.with_bolt11_features(expected_route.last().unwrap().node.bolt11_invoice_features()).unwrap();
3109-
let route_params = RouteParameters::from_payment_params_and_value(payment_params, recv_value);
3110-
let network_graph = origin_node.network_graph.read_only();
3111-
let scorer = test_utils::TestScorer::new();
3112-
let seed = [0u8; 32];
3113-
let keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
3114-
let random_seed_bytes = keys_manager.get_secure_random_bytes();
3115-
let route = router::get_route(&origin_node.node.get_our_node_id(), &route_params, &network_graph,
3116-
None, origin_node.logger, &scorer, &Default::default(), &random_seed_bytes).unwrap();
3117-
assert_eq!(route.paths.len(), 1);
3118-
assert_eq!(route.paths[0].hops.len(), expected_route.len());
3119-
for (node, hop) in expected_route.iter().zip(route.paths[0].hops.iter()) {
3120-
assert_eq!(hop.pubkey, node.node.get_our_node_id());
3121-
}
3122-
3123-
let (_, our_payment_hash, our_payment_secret) = get_payment_preimage_hash!(expected_route.last().unwrap());
3124-
unwrap_send_err!(origin_node.node.send_payment_with_route(route, our_payment_hash,
3125-
RecipientOnionFields::secret_only(our_payment_secret), PaymentId(our_payment_hash.0)),
3126-
true, APIError::ChannelUnavailable { ref err },
3127-
assert!(err.contains("Cannot send value that would put us over the max HTLC value in flight our peer will accept")));
3128-
}
3129-
31303109
pub fn send_payment<'a, 'b, 'c>(origin: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
31313110
let res = route_payment(&origin, expected_route, recv_value);
31323111
claim_payment(&origin, expected_route, res.0);

lightning/src/ln/functional_tests.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,12 @@ fn fake_network_test() {
10921092
});
10931093
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;
10941094
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;
1095+
let payment_params = PaymentParameters::from_node_id(
1096+
nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV
1097+
).with_bolt11_features(nodes[1].node.bolt11_invoice_features()).unwrap();
1098+
let route_params = RouteParameters::from_payment_params_and_value(payment_params, 1000000);
10951099
let payment_preimage_1 = send_along_route(&nodes[1],
1096-
Route { paths: vec![Path { hops, blinded_tail: None }], route_params: None },
1100+
Route { paths: vec![Path { hops, blinded_tail: None }], route_params: Some(route_params.clone()) },
10971101
&vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0;
10981102

10991103
let mut hops = Vec::with_capacity(3);
@@ -1127,7 +1131,7 @@ fn fake_network_test() {
11271131
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;
11281132
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;
11291133
let payment_hash_2 = send_along_route(&nodes[1],
1130-
Route { paths: vec![Path { hops, blinded_tail: None }], route_params: None },
1134+
Route { paths: vec![Path { hops, blinded_tail: None }], route_params: Some(route_params) },
11311135
&vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1;
11321136

11331137
// Claim the rebalances...

lightning/src/ln/outbound_payment.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,9 @@ pub enum RetryableSendFailure {
478478
OnionPacketSizeExceeded,
479479
}
480480

481-
/// If a payment fails to send with [`ChannelManager::send_payment_with_route`], it can be in one
482-
/// of several states. This enum is returned as the Err() type describing which state the payment
483-
/// is in, see the description of individual enum states for more.
484-
///
485-
/// [`ChannelManager::send_payment_with_route`]: crate::ln::channelmanager::ChannelManager::send_payment_with_route
481+
/// If a payment fails to send to a route, it can be in one of several states. This enum is returned
482+
/// as the Err() type describing which state the payment is in, see the description of individual
483+
/// enum states for more.
486484
#[derive(Clone, Debug, PartialEq, Eq)]
487485
pub enum PaymentSendFailure {
488486
/// A parameter which was passed to send_payment was invalid, preventing us from attempting to
@@ -776,6 +774,7 @@ impl OutboundPayments {
776774
best_block_height, logger, pending_events, &send_payment_along_path)
777775
}
778776

777+
#[cfg(any(test, fuzzing))]
779778
pub(super) fn send_payment_with_route<ES: Deref, NS: Deref, F>(
780779
&self, route: &Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
781780
payment_id: PaymentId, entropy_source: &ES, node_signer: &NS, best_block_height: u32,

0 commit comments

Comments
 (0)