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 BOLTs PR 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.
This commit is contained in:
Valentine Wallace 2024-06-28 13:45:28 -04:00
parent 9b3e30707e
commit 6a424536ac
No known key found for this signature in database
GPG key ID: FD3E106A2CE099B4
6 changed files with 9 additions and 8 deletions

View file

@ -1447,7 +1447,7 @@ fn route_blinding_spec_test_vector() {
}),
};
let cur_height = 747_000;
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();
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();
struct TestEcdhSigner {
node_secret: SecretKey,

View file

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

View file

@ -110,7 +110,7 @@ fn large_payment_metadata() {
let secp_ctx = Secp256k1::signing_only();
route_0_1.paths[0].hops[0].fee_msat = MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
route_0_1.paths[0].hops[0].cltv_expiry_delta = DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
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();
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();
match err {
APIError::InvalidRoute { err } => {
assert_eq!(err, "Route size too large considering onion data");
@ -318,7 +318,7 @@ fn blinded_path_with_custom_tlv() {
let secp_ctx = Secp256k1::signing_only();
route.paths[0].hops[0].fee_msat = MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
route.paths[0].hops[0].cltv_expiry_delta = DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
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();
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();
match err {
APIError::InvalidRoute { err } => {
assert_eq!(err, "Route size too large considering onion data");

View file

@ -569,7 +569,7 @@ mod tests {
let (onion, amount_msat, cltv_expiry) = create_payment_onion(
&secp_ctx, &path, &session_priv, total_amt_msat, &recipient_onion,
cur_height, &payment_hash, &Some(preimage), prng_seed
cur_height, &payment_hash, &Some(preimage), None, prng_seed
).unwrap();
let msg = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, onion);

View file

@ -1163,7 +1163,8 @@ where
pub fn create_payment_onion<T: secp256k1::Signing>(
secp_ctx: &Secp256k1<T>, path: &Path, session_priv: &SecretKey, total_msat: u64,
recipient_onion: &RecipientOnionFields, cur_block_height: u32, payment_hash: &PaymentHash,
keysend_preimage: &Option<PaymentPreimage>, prng_seed: [u8; 32],
keysend_preimage: &Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
prng_seed: [u8; 32],
) -> Result<(msgs::OnionPacket, u64, u32), APIError> {
let onion_keys = construct_onion_keys(&secp_ctx, &path, &session_priv).map_err(|_| {
APIError::InvalidRoute { err: "Pubkey along hop was maliciously selected".to_owned() }
@ -1174,7 +1175,7 @@ pub fn create_payment_onion<T: secp256k1::Signing>(
recipient_onion,
cur_block_height,
keysend_preimage,
None,
invoice_request,
)?;
let onion_packet = construct_onion_packet(onion_payloads, onion_keys, prng_seed, payment_hash)
.map_err(|_| APIError::InvalidRoute {

View file

@ -4271,7 +4271,7 @@ fn peel_payment_onion_custom_tlvs() {
let (onion_routing_packet, first_hop_msat, cltv_expiry) = onion_utils::create_payment_onion(
&secp_ctx, &route.paths[0], &session_priv, amt_msat, &recipient_onion,
nodes[0].best_block_info().1, &payment_hash, &Some(keysend_preimage), prng_seed
nodes[0].best_block_info().1, &payment_hash, &Some(keysend_preimage), None, prng_seed
).unwrap();
let update_add = msgs::UpdateAddHTLC {