Skip to content

Commit 08cd6c6

Browse files
Support including invreqs when paying to a route
Add a new invoice request parameter to outbound_payments and channelmanager send-to-route internal utils. As of this commit the invreq will always be passed in as None, to be updated in future commits. Per <lightning/bolts#1149>, when paying a static invoice we need to include our original invoice request in the HTLC onion since the recipient wouldn't have received it previously.
1 parent 604eaaa commit 08cd6c6

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4179,14 +4179,14 @@ where
41794179
let _lck = self.total_consistency_lock.read().unwrap();
41804180
self.send_payment_along_path(SendAlongPathArgs {
41814181
path, payment_hash, recipient_onion: &recipient_onion, total_value,
4182-
cur_height, payment_id, keysend_preimage, session_priv_bytes
4182+
cur_height, payment_id, keysend_preimage, invoice_request: None, session_priv_bytes
41834183
})
41844184
}
41854185

41864186
fn send_payment_along_path(&self, args: SendAlongPathArgs) -> Result<(), APIError> {
41874187
let SendAlongPathArgs {
41884188
path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage,
4189-
session_priv_bytes
4189+
invoice_request, session_priv_bytes
41904190
} = args;
41914191
// The top-level caller should hold the total_consistency_lock read lock.
41924192
debug_assert!(self.total_consistency_lock.try_write().is_err());
@@ -4195,7 +4195,7 @@ where
41954195

41964196
let (onion_packet, htlc_msat, htlc_cltv) = onion_utils::create_payment_onion(
41974197
&self.secp_ctx, &path, &session_priv, total_value, recipient_onion, cur_height,
4198-
payment_hash, keysend_preimage, None, prng_seed
4198+
payment_hash, keysend_preimage, invoice_request, prng_seed
41994199
).map_err(|e| {
42004200
let logger = WithContext::from(&self.logger, Some(path.hops.first().unwrap().pubkey), None, Some(*payment_hash));
42014201
log_error!(logger, "Failed to build an onion for path for payment hash {}", payment_hash);

lightning/src/ln/outbound_payment.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ pub(super) struct SendAlongPathArgs<'a> {
716716
pub cur_height: u32,
717717
pub payment_id: PaymentId,
718718
pub keysend_preimage: &'a Option<PaymentPreimage>,
719+
pub invoice_request: Option<&'a InvoiceRequest>,
719720
pub session_priv_bytes: [u8; 32],
720721
}
721722

@@ -769,7 +770,7 @@ impl OutboundPayments {
769770
F: Fn(SendAlongPathArgs) -> Result<(), APIError>
770771
{
771772
let onion_session_privs = self.add_new_pending_payment(payment_hash, recipient_onion.clone(), payment_id, None, route, None, None, entropy_source, best_block_height)?;
772-
self.pay_route_internal(route, payment_hash, &recipient_onion, None, payment_id, None,
773+
self.pay_route_internal(route, payment_hash, &recipient_onion, None, None, payment_id, None,
773774
onion_session_privs, node_signer, best_block_height, &send_payment_along_path)
774775
.map_err(|e| { self.remove_outbound_if_all_failed(payment_id, &e); e })
775776
}
@@ -814,7 +815,7 @@ impl OutboundPayments {
814815
let onion_session_privs = self.add_new_pending_payment(payment_hash, recipient_onion.clone(),
815816
payment_id, Some(preimage), &route, None, None, entropy_source, best_block_height)?;
816817

817-
match self.pay_route_internal(route, payment_hash, &recipient_onion, Some(preimage),
818+
match self.pay_route_internal(route, payment_hash, &recipient_onion, Some(preimage), None,
818819
payment_id, None, onion_session_privs, node_signer, best_block_height, &send_payment_along_path
819820
) {
820821
Ok(()) => Ok(payment_hash),
@@ -962,7 +963,7 @@ impl OutboundPayments {
962963
}
963964

964965
let result = self.pay_route_internal(
965-
&route, payment_hash, &recipient_onion, keysend_preimage, payment_id,
966+
&route, payment_hash, &recipient_onion, keysend_preimage, None, payment_id,
966967
Some(route_params.final_value_msat), onion_session_privs, node_signer,
967968
best_block_height, &send_payment_along_path
968969
);
@@ -1242,7 +1243,7 @@ impl OutboundPayments {
12421243
})?;
12431244

12441245
let res = self.pay_route_internal(&route, payment_hash, &recipient_onion,
1245-
keysend_preimage, payment_id, None, onion_session_privs, node_signer,
1246+
keysend_preimage, None, payment_id, None, onion_session_privs, node_signer,
12461247
best_block_height, &send_payment_along_path);
12471248
log_info!(logger, "Sending payment with id {} and hash {} returned {:?}",
12481249
payment_id, payment_hash, res);
@@ -1396,7 +1397,7 @@ impl OutboundPayments {
13961397
}
13971398
};
13981399
let res = self.pay_route_internal(&route, payment_hash, &recipient_onion, keysend_preimage,
1399-
payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height,
1400+
None, payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height,
14001401
&send_payment_along_path);
14011402
log_info!(logger, "Result retrying payment id {}: {:?}", &payment_id, res);
14021403
if let Err(e) = res {
@@ -1508,7 +1509,8 @@ impl OutboundPayments {
15081509

15091510
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
15101511
match self.pay_route_internal(&route, payment_hash, &recipient_onion_fields,
1511-
None, payment_id, None, onion_session_privs, node_signer, best_block_height, &send_payment_along_path
1512+
None, None, payment_id, None, onion_session_privs, node_signer, best_block_height,
1513+
&send_payment_along_path
15121514
) {
15131515
Ok(()) => Ok((payment_hash, payment_id)),
15141516
Err(e) => {
@@ -1620,9 +1622,9 @@ impl OutboundPayments {
16201622

16211623
fn pay_route_internal<NS: Deref, F>(
16221624
&self, route: &Route, payment_hash: PaymentHash, recipient_onion: &RecipientOnionFields,
1623-
keysend_preimage: Option<PaymentPreimage>, payment_id: PaymentId, recv_value_msat: Option<u64>,
1624-
onion_session_privs: Vec<[u8; 32]>, node_signer: &NS, best_block_height: u32,
1625-
send_payment_along_path: &F
1625+
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
1626+
payment_id: PaymentId, recv_value_msat: Option<u64>, onion_session_privs: Vec<[u8; 32]>,
1627+
node_signer: &NS, best_block_height: u32, send_payment_along_path: &F
16261628
) -> Result<(), PaymentSendFailure>
16271629
where
16281630
NS::Target: NodeSigner,
@@ -1675,7 +1677,7 @@ impl OutboundPayments {
16751677
for (path, session_priv_bytes) in route.paths.iter().zip(onion_session_privs.into_iter()) {
16761678
let mut path_res = send_payment_along_path(SendAlongPathArgs {
16771679
path: &path, payment_hash: &payment_hash, recipient_onion, total_value,
1678-
cur_height, payment_id, keysend_preimage: &keysend_preimage,
1680+
cur_height, payment_id, keysend_preimage: &keysend_preimage, invoice_request,
16791681
session_priv_bytes
16801682
});
16811683
match path_res {
@@ -1760,7 +1762,7 @@ impl OutboundPayments {
17601762
F: Fn(SendAlongPathArgs) -> Result<(), APIError>,
17611763
{
17621764
self.pay_route_internal(route, payment_hash, &recipient_onion,
1763-
keysend_preimage, payment_id, recv_value_msat, onion_session_privs,
1765+
keysend_preimage, None, payment_id, recv_value_msat, onion_session_privs,
17641766
node_signer, best_block_height, &send_payment_along_path)
17651767
.map_err(|e| { self.remove_outbound_if_all_failed(payment_id, &e); e })
17661768
}

0 commit comments

Comments
 (0)