Skip to content

Commit bf87a59

Browse files
committed
Add a RecipientOnionFields argument to spontaneous payment sends
While most lightning nodes don't (currently) support providing a payment secret or payment metadata for spontaneous payments, there's no specific technical reason why we shouldn't support sending those fields to a recipient. Further, when we eventually move to allowing custom TLV entries in the recipient's onion TLV stream, we'll want to support it for spontaneous payments as well. Here we simply add the new `RecipientOnionFields` struct as an argument to the spontaneous payment send methods. We don't yet plumb it through the payment sending logic, which will come when we plumb the new struct through the sending logic to replace the existing payment secret arguments.
1 parent dddb2e2 commit bf87a59

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,7 +2717,7 @@ where
27172717
/// Note that `route` must have exactly one path.
27182718
///
27192719
/// [`send_payment`]: Self::send_payment
2720-
pub fn send_spontaneous_payment(&self, route: &Route, payment_preimage: Option<PaymentPreimage>, payment_id: PaymentId) -> Result<PaymentHash, PaymentSendFailure> {
2720+
pub fn send_spontaneous_payment(&self, route: &Route, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields, payment_id: PaymentId) -> Result<PaymentHash, PaymentSendFailure> {
27212721
let best_block_height = self.best_block.read().unwrap().height();
27222722
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
27232723
self.pending_outbound_payments.send_spontaneous_payment_with_route(
@@ -2734,7 +2734,7 @@ where
27342734
/// payments.
27352735
///
27362736
/// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
2737-
pub fn send_spontaneous_payment_with_retry(&self, payment_preimage: Option<PaymentPreimage>, payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry) -> Result<PaymentHash, RetryableSendFailure> {
2737+
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> {
27382738
let best_block_height = self.best_block.read().unwrap().height();
27392739
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
27402740
self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, payment_id,
@@ -8032,7 +8032,8 @@ mod tests {
80328032
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None);
80338033

80348034
// Next, send a keysend payment with the same payment_hash and make sure it fails.
8035-
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage), PaymentId(payment_preimage.0)).unwrap();
8035+
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
8036+
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
80368037
check_added_monitors!(nodes[0], 1);
80378038
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
80388039
assert_eq!(events.len(), 1);
@@ -8152,7 +8153,8 @@ mod tests {
81528153
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
81538154
None, nodes[0].logger, &scorer, &random_seed_bytes
81548155
).unwrap();
8155-
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage), PaymentId(payment_preimage.0)).unwrap();
8156+
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
8157+
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
81568158
check_added_monitors!(nodes[0], 1);
81578159
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
81588160
assert_eq!(events.len(), 1);
@@ -8185,7 +8187,8 @@ mod tests {
81858187
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
81868188
None, nodes[0].logger, &scorer, &random_seed_bytes
81878189
).unwrap();
8188-
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage), PaymentId(payment_preimage.0)).unwrap();
8190+
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
8191+
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
81898192
check_added_monitors!(nodes[0], 1);
81908193
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
81918194
assert_eq!(events.len(), 1);

lightning/src/ln/functional_tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9492,7 +9492,8 @@ fn test_keysend_payments_to_public_node() {
94929492
let route = find_route(&payer_pubkey, &route_params, &network_graph, None, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
94939493

94949494
let test_preimage = PaymentPreimage([42; 32]);
9495-
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage), PaymentId(test_preimage.0)).unwrap();
9495+
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage),
9496+
RecipientOnionFields::spontaneous_empty(), PaymentId(test_preimage.0)).unwrap();
94969497
check_added_monitors!(nodes[0], 1);
94979498
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
94989499
assert_eq!(events.len(), 1);
@@ -9527,7 +9528,8 @@ fn test_keysend_payments_to_private_node() {
95279528
).unwrap();
95289529

95299530
let test_preimage = PaymentPreimage([42; 32]);
9530-
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage), PaymentId(test_preimage.0)).unwrap();
9531+
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage),
9532+
RecipientOnionFields::spontaneous_empty(), PaymentId(test_preimage.0)).unwrap();
95319533
check_added_monitors!(nodes[0], 1);
95329534
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
95339535
assert_eq!(events.len(), 1);

lightning/src/ln/outbound_payment.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ pub struct RecipientOnionFields {
417417
///
418418
/// If you do not have one, the [`Route`] you pay over must not contain multiple paths as
419419
/// multi-path payments require a recipient-provided secret.
420+
///
421+
/// Note that for spontaneous payments most lightning nodes do not currently support MPP
422+
/// receives, thus you should generally never be providing a secret here for spontaneous
423+
/// payments.
420424
pub payment_secret: Option<PaymentSecret>,
421425
}
422426

lightning/src/ln/payment_tests.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,8 @@ fn claimed_send_payment_idempotent() {
10871087

10881088
// Further, if we try to send a spontaneous payment with the same payment_id it should
10891089
// also be rejected.
1090-
let send_result = nodes[0].node.send_spontaneous_payment(&route, None, payment_id);
1090+
let send_result = nodes[0].node.send_spontaneous_payment(
1091+
&route, None, RecipientOnionFields::spontaneous_empty(), payment_id);
10911092
match send_result {
10921093
Err(PaymentSendFailure::DuplicatePayment) => {},
10931094
_ => panic!("Unexpected send result: {:?}", send_result),
@@ -1161,7 +1162,8 @@ fn abandoned_send_payment_idempotent() {
11611162

11621163
// Further, if we try to send a spontaneous payment with the same payment_id it should
11631164
// also be rejected.
1164-
let send_result = nodes[0].node.send_spontaneous_payment(&route, None, payment_id);
1165+
let send_result = nodes[0].node.send_spontaneous_payment(
1166+
&route, None, RecipientOnionFields::spontaneous_empty(), payment_id);
11651167
match send_result {
11661168
Err(PaymentSendFailure::DuplicatePayment) => {},
11671169
_ => panic!("Unexpected send result: {:?}", send_result),
@@ -1671,7 +1673,9 @@ fn do_automatic_retries(test: AutoRetry) {
16711673
pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], amt_msat, payment_hash, Some(payment_secret), msg_events.pop().unwrap(), true, None);
16721674
claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage);
16731675
} else if test == AutoRetry::Spontaneous {
1674-
nodes[0].node.send_spontaneous_payment_with_retry(Some(payment_preimage), PaymentId(payment_hash.0), route_params, Retry::Attempts(1)).unwrap();
1676+
nodes[0].node.send_spontaneous_payment_with_retry(Some(payment_preimage),
1677+
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params,
1678+
Retry::Attempts(1)).unwrap();
16751679
pass_failed_attempt_with_retry_along_path!(channel_id_2, true);
16761680

16771681
// Open a new channel with liquidity on the second hop so we can find a route for the retry

0 commit comments

Comments
 (0)