Skip to content

Commit b4aa32c

Browse files
Support including invreqs when building payment onions
Add a new invoice request parameter to onion_utils::create_payment_onion. As of this commit it 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 d343ea5 commit b4aa32c

6 files changed

+9
-8
lines changed

lightning/src/ln/blinded_payment_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ fn route_blinding_spec_test_vector() {
14461446
}),
14471447
};
14481448
let cur_height = 747_000;
1449-
let (bob_onion, _, _) = onion_utils::create_payment_onion(&secp_ctx, &path, &session_priv, amt_msat, &RecipientOnionFields::spontaneous_empty(), cur_height, &PaymentHash([0; 32]), &None, [0; 32]).unwrap();
1449+
let (bob_onion, _, _) = onion_utils::create_payment_onion(&secp_ctx, &path, &session_priv, amt_msat, &RecipientOnionFields::spontaneous_empty(), cur_height, &PaymentHash([0; 32]), &None, None, [0; 32]).unwrap();
14501450

14511451
struct TestEcdhSigner {
14521452
node_secret: SecretKey,

lightning/src/ln/channelmanager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -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, prng_seed
4115+
payment_hash, keysend_preimage, None, 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/max_payment_path_len_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn large_payment_metadata() {
110110
let secp_ctx = Secp256k1::signing_only();
111111
route_0_1.paths[0].hops[0].fee_msat = MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
112112
route_0_1.paths[0].hops[0].cltv_expiry_delta = DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
113-
let err = onion_utils::create_payment_onion(&secp_ctx, &route_0_1.paths[0], &test_utils::privkey(42), MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY, &recipient_onion_too_large_md, nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, &payment_hash, &None, [0; 32]).unwrap_err();
113+
let err = onion_utils::create_payment_onion(&secp_ctx, &route_0_1.paths[0], &test_utils::privkey(42), MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY, &recipient_onion_too_large_md, nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, &payment_hash, &None, None, [0; 32]).unwrap_err();
114114
match err {
115115
APIError::InvalidRoute { err } => {
116116
assert_eq!(err, "Route size too large considering onion data");
@@ -318,7 +318,7 @@ fn blinded_path_with_custom_tlv() {
318318
let secp_ctx = Secp256k1::signing_only();
319319
route.paths[0].hops[0].fee_msat = MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
320320
route.paths[0].hops[0].cltv_expiry_delta = DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
321-
let err = onion_utils::create_payment_onion(&secp_ctx, &route.paths[0], &test_utils::privkey(42), MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY, &recipient_onion_too_large_custom_tlv, nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, &payment_hash, &None, [0; 32]).unwrap_err();
321+
let err = onion_utils::create_payment_onion(&secp_ctx, &route.paths[0], &test_utils::privkey(42), MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY, &recipient_onion_too_large_custom_tlv, nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, &payment_hash, &None, None, [0; 32]).unwrap_err();
322322
match err {
323323
APIError::InvalidRoute { err } => {
324324
assert_eq!(err, "Route size too large considering onion data");

lightning/src/ln/onion_payment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ mod tests {
568568

569569
let (onion, amount_msat, cltv_expiry) = create_payment_onion(
570570
&secp_ctx, &path, &session_priv, total_amt_msat, &recipient_onion,
571-
cur_height, &payment_hash, &Some(preimage), prng_seed
571+
cur_height, &payment_hash, &Some(preimage), None, prng_seed
572572
).unwrap();
573573

574574
let msg = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, onion);

lightning/src/ln/onion_utils.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,8 @@ where
11631163
pub fn create_payment_onion<T: secp256k1::Signing>(
11641164
secp_ctx: &Secp256k1<T>, path: &Path, session_priv: &SecretKey, total_msat: u64,
11651165
recipient_onion: &RecipientOnionFields, cur_block_height: u32, payment_hash: &PaymentHash,
1166-
keysend_preimage: &Option<PaymentPreimage>, prng_seed: [u8; 32],
1166+
keysend_preimage: &Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
1167+
prng_seed: [u8; 32],
11671168
) -> Result<(msgs::OnionPacket, u64, u32), APIError> {
11681169
let onion_keys = construct_onion_keys(&secp_ctx, &path, &session_priv).map_err(|_| {
11691170
APIError::InvalidRoute { err: "Pubkey along hop was maliciously selected".to_owned() }
@@ -1174,7 +1175,7 @@ pub fn create_payment_onion<T: secp256k1::Signing>(
11741175
recipient_onion,
11751176
cur_block_height,
11761177
keysend_preimage,
1177-
None,
1178+
invoice_request,
11781179
)?;
11791180
let onion_packet = construct_onion_packet(onion_payloads, onion_keys, prng_seed, payment_hash)
11801181
.map_err(|_| APIError::InvalidRoute {

lightning/src/ln/payment_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4270,7 +4270,7 @@ fn peel_payment_onion_custom_tlvs() {
42704270

42714271
let (onion_routing_packet, first_hop_msat, cltv_expiry) = onion_utils::create_payment_onion(
42724272
&secp_ctx, &route.paths[0], &session_priv, amt_msat, &recipient_onion,
4273-
nodes[0].best_block_info().1, &payment_hash, &Some(keysend_preimage), prng_seed
4273+
nodes[0].best_block_info().1, &payment_hash, &Some(keysend_preimage), None, prng_seed
42744274
).unwrap();
42754275

42764276
let update_add = msgs::UpdateAddHTLC {

0 commit comments

Comments
 (0)