Skip to content

Commit addc4b6

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 c11be16 commit addc4b6

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
@@ -1237,7 +1237,7 @@ fn blinded_keysend() {
12371237
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(),
12381238
&[&chan_upd_1_2], &chanmon_cfgs[2].keys_manager);
12391239

1240-
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();
1240+
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();
12411241
check_added_monitors(&nodes[0], 1);
12421242

12431243
let expected_route: &[&[&Node]] = &[&[&nodes[1], &nodes[2]]];
@@ -1293,7 +1293,7 @@ fn blinded_mpp_keysend() {
12931293
RouteParameters::from_payment_params_and_value(pay_params, amt_msat)
12941294
};
12951295

1296-
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();
1296+
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();
12971297
check_added_monitors!(nodes[0], 2);
12981298

12991299
let expected_route: &[&[&Node]] = &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]];
@@ -1333,7 +1333,7 @@ fn invalid_keysend_payment_secret() {
13331333
&chanmon_cfgs[2].keys_manager
13341334
);
13351335

1336-
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();
1336+
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();
13371337
check_added_monitors(&nodes[0], 1);
13381338

13391339
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;
@@ -4784,47 +4786,21 @@ where
47844786
/// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
47854787
/// never reach the recipient.
47864788
///
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!
4807-
///
48084789
/// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
48094790
/// [`send_payment`] for more information about the risks of duplicate preimage usage.
48104791
///
4811-
/// [`send_payment`]: Self::send_payment
4812-
pub fn send_spontaneous_payment(&self, route: &Route, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields, payment_id: PaymentId) -> Result<PaymentHash, PaymentSendFailure> {
4813-
let best_block_height = self.best_block.read().unwrap().height;
4814-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4815-
self.pending_outbound_payments.send_spontaneous_payment_with_route(
4816-
route, payment_preimage, recipient_onion, payment_id, &self.entropy_source,
4817-
&self.node_signer, best_block_height, |args| self.send_payment_along_path(args))
4818-
}
4819-
4820-
/// Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
4821-
/// based on `route_params` and retry failed payment paths based on `retry_strategy`.
4792+
/// See [`send_payment`] documentation for more details on the idempotency guarantees provided by
4793+
/// the [`PaymentId`] key.
48224794
///
48234795
/// See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
48244796
/// payments.
48254797
///
4798+
/// [`send_payment`]: Self::send_payment
48264799
/// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
4827-
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> {
4800+
pub fn send_spontaneous_payment(
4801+
&self, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields,
4802+
payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
4803+
) -> Result<PaymentHash, RetryableSendFailure> {
48284804
let best_block_height = self.best_block.read().unwrap().height;
48294805
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
48304806
self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, recipient_onion,
@@ -14213,6 +14189,7 @@ mod tests {
1421314189
use crate::ln::functional_test_utils::*;
1421414190
use crate::ln::msgs::{self, ErrorAction};
1421514191
use crate::ln::msgs::ChannelMessageHandler;
14192+
use crate::ln::outbound_payment::Retry;
1421614193
use crate::prelude::*;
1421714194
use crate::routing::router::{PaymentParameters, RouteParameters, find_route};
1421814195
use crate::util::errors::APIError;
@@ -14330,8 +14307,10 @@ mod tests {
1433014307
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None);
1433114308

1433214309
// Next, send a keysend payment with the same payment_hash and make sure it fails.
14333-
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14334-
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
14310+
nodes[0].node.send_spontaneous_payment(
14311+
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(),
14312+
PaymentId(payment_preimage.0), route.route_params.clone().unwrap(), Retry::Attempts(0)
14313+
).unwrap();
1433514314
check_added_monitors!(nodes[0], 1);
1433614315
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1433714316
assert_eq!(events.len(), 1);
@@ -14453,12 +14432,10 @@ mod tests {
1445314432
let route_params = RouteParameters::from_payment_params_and_value(
1445414433
PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id(),
1445514434
TEST_FINAL_CLTV, false), 100_000);
14456-
let route = find_route(
14457-
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
14458-
None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
14435+
nodes[0].node.send_spontaneous_payment(
14436+
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(),
14437+
PaymentId(payment_preimage.0), route_params.clone(), Retry::Attempts(0)
1445914438
).unwrap();
14460-
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14461-
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
1446214439
check_added_monitors!(nodes[0], 1);
1446314440
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1446414441
assert_eq!(events.len(), 1);
@@ -14491,8 +14468,10 @@ mod tests {
1449114468
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
1449214469
None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
1449314470
).unwrap();
14494-
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14495-
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
14471+
let payment_hash = nodes[0].node.send_spontaneous_payment(
14472+
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(),
14473+
PaymentId(payment_preimage.0), route.route_params.clone().unwrap(), Retry::Attempts(0)
14474+
).unwrap();
1449614475
check_added_monitors!(nodes[0], 1);
1449714476
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1449814477
assert_eq!(events.len(), 1);
@@ -14530,8 +14509,10 @@ mod tests {
1453014509

1453114510
// To start (3), send a keysend payment but don't claim it.
1453214511
let payment_id_1 = PaymentId([44; 32]);
14533-
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14534-
RecipientOnionFields::spontaneous_empty(), payment_id_1).unwrap();
14512+
let payment_hash = nodes[0].node.send_spontaneous_payment(
14513+
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(), payment_id_1,
14514+
route.route_params.clone().unwrap(), Retry::Attempts(0)
14515+
).unwrap();
1453514516
check_added_monitors!(nodes[0], 1);
1453614517
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1453714518
assert_eq!(events.len(), 1);
@@ -14544,13 +14525,11 @@ mod tests {
1454414525
PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id(), TEST_FINAL_CLTV, false),
1454514526
100_000
1454614527
);
14547-
let route = find_route(
14548-
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
14549-
None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
14550-
).unwrap();
1455114528
let payment_id_2 = PaymentId([45; 32]);
14552-
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14553-
RecipientOnionFields::spontaneous_empty(), payment_id_2).unwrap();
14529+
nodes[0].node.send_spontaneous_payment(
14530+
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(), payment_id_2, route_params,
14531+
Retry::Attempts(0)
14532+
).unwrap();
1455414533
check_added_monitors!(nodes[0], 1);
1455514534
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1455614535
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)