Skip to content

Commit 3911bc6

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 0f2a9d8 commit 3911bc6

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
@@ -4096,14 +4096,14 @@ where
40964096
let _lck = self.total_consistency_lock.read().unwrap();
40974097
self.send_payment_along_path(SendAlongPathArgs {
40984098
path, payment_hash, recipient_onion: &recipient_onion, total_value,
4099-
cur_height, payment_id, keysend_preimage, session_priv_bytes
4099+
cur_height, payment_id, keysend_preimage, invoice_request: None, session_priv_bytes
41004100
})
41014101
}
41024102

41034103
fn send_payment_along_path(&self, args: SendAlongPathArgs) -> Result<(), APIError> {
41044104
let SendAlongPathArgs {
41054105
path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage,
4106-
session_priv_bytes
4106+
invoice_request, session_priv_bytes
41074107
} = args;
41084108
// The top-level caller should hold the total_consistency_lock read lock.
41094109
debug_assert!(self.total_consistency_lock.try_write().is_err());
@@ -4112,7 +4112,7 @@ where
41124112

41134113
let (onion_packet, htlc_msat, htlc_cltv) = onion_utils::create_payment_onion(
41144114
&self.secp_ctx, &path, &session_priv, total_value, recipient_onion, cur_height,
4115-
payment_hash, keysend_preimage, None, prng_seed
4115+
payment_hash, keysend_preimage, invoice_request, prng_seed
41164116
).map_err(|e| {
41174117
let logger = WithContext::from(&self.logger, Some(path.hops.first().unwrap().pubkey), None, Some(*payment_hash));
41184118
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
@@ -715,6 +715,7 @@ pub(super) struct SendAlongPathArgs<'a> {
715715
pub cur_height: u32,
716716
pub payment_id: PaymentId,
717717
pub keysend_preimage: &'a Option<PaymentPreimage>,
718+
pub invoice_request: Option<&'a InvoiceRequest>,
718719
pub session_priv_bytes: [u8; 32],
719720
}
720721

@@ -768,7 +769,7 @@ impl OutboundPayments {
768769
F: Fn(SendAlongPathArgs) -> Result<(), APIError>
769770
{
770771
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)?;
771-
self.pay_route_internal(route, payment_hash, &recipient_onion, None, payment_id, None,
772+
self.pay_route_internal(route, payment_hash, &recipient_onion, None, None, payment_id, None,
772773
onion_session_privs, node_signer, best_block_height, &send_payment_along_path)
773774
.map_err(|e| { self.remove_outbound_if_all_failed(payment_id, &e); e })
774775
}
@@ -813,7 +814,7 @@ impl OutboundPayments {
813814
let onion_session_privs = self.add_new_pending_payment(payment_hash, recipient_onion.clone(),
814815
payment_id, Some(preimage), &route, None, None, entropy_source, best_block_height)?;
815816

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

963964
let result = self.pay_route_internal(
964-
&route, payment_hash, &recipient_onion, keysend_preimage, payment_id,
965+
&route, payment_hash, &recipient_onion, keysend_preimage, None, payment_id,
965966
Some(route_params.final_value_msat), onion_session_privs, node_signer,
966967
best_block_height, &send_payment_along_path
967968
);
@@ -1236,7 +1237,7 @@ impl OutboundPayments {
12361237
})?;
12371238

12381239
let res = self.pay_route_internal(&route, payment_hash, &recipient_onion,
1239-
keysend_preimage, payment_id, None, onion_session_privs, node_signer,
1240+
keysend_preimage, None, payment_id, None, onion_session_privs, node_signer,
12401241
best_block_height, &send_payment_along_path);
12411242
log_info!(logger, "Sending payment with id {} and hash {} returned {:?}",
12421243
payment_id, payment_hash, res);
@@ -1390,7 +1391,7 @@ impl OutboundPayments {
13901391
}
13911392
};
13921393
let res = self.pay_route_internal(&route, payment_hash, &recipient_onion, keysend_preimage,
1393-
payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height,
1394+
None, payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height,
13941395
&send_payment_along_path);
13951396
log_info!(logger, "Result retrying payment id {}: {:?}", &payment_id, res);
13961397
if let Err(e) = res {
@@ -1502,7 +1503,8 @@ impl OutboundPayments {
15021503

15031504
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
15041505
match self.pay_route_internal(&route, payment_hash, &recipient_onion_fields,
1505-
None, payment_id, None, onion_session_privs, node_signer, best_block_height, &send_payment_along_path
1506+
None, None, payment_id, None, onion_session_privs, node_signer, best_block_height,
1507+
&send_payment_along_path
15061508
) {
15071509
Ok(()) => Ok((payment_hash, payment_id)),
15081510
Err(e) => {
@@ -1614,9 +1616,9 @@ impl OutboundPayments {
16141616

16151617
fn pay_route_internal<NS: Deref, F>(
16161618
&self, route: &Route, payment_hash: PaymentHash, recipient_onion: &RecipientOnionFields,
1617-
keysend_preimage: Option<PaymentPreimage>, payment_id: PaymentId, recv_value_msat: Option<u64>,
1618-
onion_session_privs: Vec<[u8; 32]>, node_signer: &NS, best_block_height: u32,
1619-
send_payment_along_path: &F
1619+
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
1620+
payment_id: PaymentId, recv_value_msat: Option<u64>, onion_session_privs: Vec<[u8; 32]>,
1621+
node_signer: &NS, best_block_height: u32, send_payment_along_path: &F
16201622
) -> Result<(), PaymentSendFailure>
16211623
where
16221624
NS::Target: NodeSigner,
@@ -1669,7 +1671,7 @@ impl OutboundPayments {
16691671
for (path, session_priv_bytes) in route.paths.iter().zip(onion_session_privs.into_iter()) {
16701672
let mut path_res = send_payment_along_path(SendAlongPathArgs {
16711673
path: &path, payment_hash: &payment_hash, recipient_onion, total_value,
1672-
cur_height, payment_id, keysend_preimage: &keysend_preimage,
1674+
cur_height, payment_id, keysend_preimage: &keysend_preimage, invoice_request,
16731675
session_priv_bytes
16741676
});
16751677
match path_res {
@@ -1754,7 +1756,7 @@ impl OutboundPayments {
17541756
F: Fn(SendAlongPathArgs) -> Result<(), APIError>,
17551757
{
17561758
self.pay_route_internal(route, payment_hash, &recipient_onion,
1757-
keysend_preimage, payment_id, recv_value_msat, onion_session_privs,
1759+
keysend_preimage, None, payment_id, recv_value_msat, onion_session_privs,
17581760
node_signer, best_block_height, &send_payment_along_path)
17591761
.map_err(|e| { self.remove_outbound_if_all_failed(payment_id, &e); e })
17601762
}

0 commit comments

Comments
 (0)