Skip to content

Commit 351efc8

Browse files
Remove support for specifying route with send_spontaneous_payment
The old API is confusing and we want to remove it for 0.1.
1 parent 90b1e7d commit 351efc8

File tree

5 files changed

+72
-128
lines changed

5 files changed

+72
-128
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ fn blinded_keysend() {
12351235
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(),
12361236
&[&chan_upd_1_2], &chanmon_cfgs[2].keys_manager);
12371237

1238-
let payment_hash = nodes[0].node.send_spontaneous_payment_with_retry(Some(keysend_preimage), RecipientOnionFields::spontaneous_empty(), PaymentId(keysend_preimage.0), route_params, Retry::Attempts(0)).unwrap();
1238+
let payment_hash = nodes[0].node.send_spontaneous_payment(Some(keysend_preimage), RecipientOnionFields::spontaneous_empty(), PaymentId(keysend_preimage.0), route_params, Retry::Attempts(0)).unwrap();
12391239
check_added_monitors(&nodes[0], 1);
12401240

12411241
let expected_route: &[&[&Node]] = &[&[&nodes[1], &nodes[2]]];
@@ -1289,7 +1289,7 @@ fn blinded_mpp_keysend() {
12891289
RouteParameters::from_payment_params_and_value(pay_params, amt_msat)
12901290
};
12911291

1292-
let payment_hash = nodes[0].node.send_spontaneous_payment_with_retry(Some(keysend_preimage), RecipientOnionFields::spontaneous_empty(), PaymentId(keysend_preimage.0), route_params, Retry::Attempts(0)).unwrap();
1292+
let payment_hash = nodes[0].node.send_spontaneous_payment(Some(keysend_preimage), RecipientOnionFields::spontaneous_empty(), PaymentId(keysend_preimage.0), route_params, Retry::Attempts(0)).unwrap();
12931293
check_added_monitors!(nodes[0], 2);
12941294

12951295
let expected_route: &[&[&Node]] = &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]];
@@ -1327,7 +1327,7 @@ fn invalid_keysend_payment_secret() {
13271327
&chanmon_cfgs[2].keys_manager
13281328
);
13291329

1330-
let payment_hash = nodes[0].node.send_spontaneous_payment_with_retry(Some(keysend_preimage), RecipientOnionFields::spontaneous_empty(), PaymentId(keysend_preimage.0), route_params, Retry::Attempts(0)).unwrap();
1330+
let payment_hash = nodes[0].node.send_spontaneous_payment(Some(keysend_preimage), RecipientOnionFields::spontaneous_empty(), PaymentId(keysend_preimage.0), route_params, Retry::Attempts(0)).unwrap();
13311331
check_added_monitors(&nodes[0], 1);
13321332

13331333
let expected_route: &[&[&Node]] = &[&[&nodes[1], &nodes[2]]];

lightning/src/ln/channelmanager.rs

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ use crate::ln::channel_state::ChannelDetails;
5353
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
5454
#[cfg(any(feature = "_test_utils", test))]
5555
use crate::types::features::Bolt11InvoiceFeatures;
56-
use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
56+
use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, RouteParameters, Router};
57+
#[cfg(any(test, fuzzing))]
58+
use crate::routing::router::Route;
5759
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails};
5860
use crate::ln::msgs;
5961
use crate::ln::onion_utils;
@@ -4880,47 +4882,21 @@ where
48804882
/// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
48814883
/// never reach the recipient.
48824884
///
4883-
/// See [`send_payment`] documentation for more details on the idempotency guarantees provided by
4884-
/// the [`PaymentId`] key.
4885-
///
4886-
/// # Possible Error States on [`PaymentSendFailure`]
4887-
///
4888-
/// Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
4889-
/// each entry matching the corresponding-index entry in the route paths, see
4890-
/// [`PaymentSendFailure`] for more info.
4891-
///
4892-
/// In general, a path may raise:
4893-
/// * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
4894-
/// node public key) is specified.
4895-
/// * [`APIError::ChannelUnavailable`] if the next-hop channel is not available as it has been
4896-
/// closed, doesn't exist, or the peer is currently disconnected.
4897-
/// * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
4898-
/// relevant updates.
4899-
///
4900-
/// Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
4901-
/// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
4902-
/// different route unless you intend to pay twice!
4903-
///
49044885
/// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
49054886
/// [`send_payment`] for more information about the risks of duplicate preimage usage.
49064887
///
4907-
/// [`send_payment`]: Self::send_payment
4908-
pub fn send_spontaneous_payment(&self, route: &Route, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields, payment_id: PaymentId) -> Result<PaymentHash, PaymentSendFailure> {
4909-
let best_block_height = self.best_block.read().unwrap().height;
4910-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4911-
self.pending_outbound_payments.send_spontaneous_payment_with_route(
4912-
route, payment_preimage, recipient_onion, payment_id, &self.entropy_source,
4913-
&self.node_signer, best_block_height, |args| self.send_payment_along_path(args))
4914-
}
4915-
4916-
/// Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
4917-
/// based on `route_params` and retry failed payment paths based on `retry_strategy`.
4888+
/// See [`send_payment`] documentation for more details on the idempotency guarantees provided by
4889+
/// the [`PaymentId`] key.
49184890
///
49194891
/// See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
49204892
/// payments.
49214893
///
4894+
/// [`send_payment`]: Self::send_payment
49224895
/// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
4923-
pub fn send_spontaneous_payment_with_retry(&self, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields, payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry) -> Result<PaymentHash, RetryableSendFailure> {
4896+
pub fn send_spontaneous_payment(
4897+
&self, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields,
4898+
payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
4899+
) -> Result<PaymentHash, RetryableSendFailure> {
49244900
let best_block_height = self.best_block.read().unwrap().height;
49254901
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
49264902
self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, recipient_onion,
@@ -14330,6 +14306,7 @@ mod tests {
1433014306
use crate::ln::functional_test_utils::*;
1433114307
use crate::ln::msgs::{self, ErrorAction};
1433214308
use crate::ln::msgs::ChannelMessageHandler;
14309+
use crate::ln::outbound_payment::Retry;
1433314310
use crate::prelude::*;
1433414311
use crate::routing::router::{PaymentParameters, RouteParameters, find_route};
1433514312
use crate::util::errors::APIError;
@@ -14447,8 +14424,10 @@ mod tests {
1444714424
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None);
1444814425

1444914426
// Next, send a keysend payment with the same payment_hash and make sure it fails.
14450-
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14451-
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
14427+
nodes[0].node.send_spontaneous_payment(
14428+
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(),
14429+
PaymentId(payment_preimage.0), route.route_params.clone().unwrap(), Retry::Attempts(0)
14430+
).unwrap();
1445214431
check_added_monitors!(nodes[0], 1);
1445314432
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1445414433
assert_eq!(events.len(), 1);
@@ -14560,12 +14539,10 @@ mod tests {
1456014539
let route_params = RouteParameters::from_payment_params_and_value(
1456114540
PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id(),
1456214541
TEST_FINAL_CLTV, false), 100_000);
14563-
let route = find_route(
14564-
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
14565-
None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
14542+
nodes[0].node.send_spontaneous_payment(
14543+
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(),
14544+
PaymentId(payment_preimage.0), route_params.clone(), Retry::Attempts(0)
1456614545
).unwrap();
14567-
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14568-
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
1456914546
check_added_monitors!(nodes[0], 1);
1457014547
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1457114548
assert_eq!(events.len(), 1);
@@ -14598,8 +14575,10 @@ mod tests {
1459814575
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
1459914576
None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
1460014577
).unwrap();
14601-
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14602-
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
14578+
let payment_hash = nodes[0].node.send_spontaneous_payment(
14579+
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(),
14580+
PaymentId(payment_preimage.0), route.route_params.clone().unwrap(), Retry::Attempts(0)
14581+
).unwrap();
1460314582
check_added_monitors!(nodes[0], 1);
1460414583
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1460514584
assert_eq!(events.len(), 1);
@@ -14637,8 +14616,10 @@ mod tests {
1463714616

1463814617
// To start (3), send a keysend payment but don't claim it.
1463914618
let payment_id_1 = PaymentId([44; 32]);
14640-
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14641-
RecipientOnionFields::spontaneous_empty(), payment_id_1).unwrap();
14619+
let payment_hash = nodes[0].node.send_spontaneous_payment(
14620+
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(), payment_id_1,
14621+
route.route_params.clone().unwrap(), Retry::Attempts(0)
14622+
).unwrap();
1464214623
check_added_monitors!(nodes[0], 1);
1464314624
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1464414625
assert_eq!(events.len(), 1);
@@ -14651,13 +14632,11 @@ mod tests {
1465114632
PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id(), TEST_FINAL_CLTV, false),
1465214633
100_000
1465314634
);
14654-
let route = find_route(
14655-
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
14656-
None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
14657-
).unwrap();
1465814635
let payment_id_2 = PaymentId([45; 32]);
14659-
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14660-
RecipientOnionFields::spontaneous_empty(), payment_id_2).unwrap();
14636+
nodes[0].node.send_spontaneous_payment(
14637+
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(), payment_id_2, route_params,
14638+
Retry::Attempts(0)
14639+
).unwrap();
1466114640
check_added_monitors!(nodes[0], 1);
1466214641
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1466314642
assert_eq!(events.len(), 1);

lightning/src/ln/outbound_payment.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -815,33 +815,6 @@ impl OutboundPayments {
815815
.map(|()| payment_hash)
816816
}
817817

818-
pub(super) fn send_spontaneous_payment_with_route<ES: Deref, NS: Deref, F>(
819-
&self, route: &Route, payment_preimage: Option<PaymentPreimage>,
820-
recipient_onion: RecipientOnionFields, payment_id: PaymentId, entropy_source: &ES,
821-
node_signer: &NS, best_block_height: u32, send_payment_along_path: F
822-
) -> Result<PaymentHash, PaymentSendFailure>
823-
where
824-
ES::Target: EntropySource,
825-
NS::Target: NodeSigner,
826-
F: Fn(SendAlongPathArgs) -> Result<(), APIError>,
827-
{
828-
let preimage = payment_preimage
829-
.unwrap_or_else(|| PaymentPreimage(entropy_source.get_secure_random_bytes()));
830-
let payment_hash = PaymentHash(Sha256::hash(&preimage.0).to_byte_array());
831-
let onion_session_privs = self.add_new_pending_payment(payment_hash, recipient_onion.clone(),
832-
payment_id, Some(preimage), &route, None, None, entropy_source, best_block_height)?;
833-
834-
match self.pay_route_internal(route, payment_hash, &recipient_onion, Some(preimage), None,
835-
payment_id, None, onion_session_privs, node_signer, best_block_height, &send_payment_along_path
836-
) {
837-
Ok(()) => Ok(payment_hash),
838-
Err(e) => {
839-
self.remove_outbound_if_all_failed(payment_id, &e);
840-
Err(e)
841-
}
842-
}
843-
}
844-
845818
pub(super) fn send_payment_for_bolt12_invoice<
846819
R: Deref, ES: Deref, NS: Deref, NL: Deref, IH, SP, L: Deref
847820
>(

0 commit comments

Comments
 (0)