Support sending custom TLVs to blinded recipients.
authorValentine Wallace <vwallace@protonmail.com>
Wed, 27 Mar 2024 19:16:08 +0000 (15:16 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 27 Mar 2024 20:47:30 +0000 (16:47 -0400)
lightning/src/ln/msgs.rs
lightning/src/ln/onion_utils.rs

index 2efc3c1c051798eebcad6fc800502d85ab683659..89dff492067ed3c1b3dfa3b2dd9ea07b02f93ecc 100644 (file)
@@ -1737,6 +1737,7 @@ mod fuzzy_internal_msgs {
                        encrypted_tlvs: Vec<u8>,
                        intro_node_blinding_point: Option<PublicKey>, // Set if the introduction node of the blinded path is the final node
                        keysend_preimage: Option<PaymentPreimage>,
+                       custom_tlvs: Vec<(u64, Vec<u8>)>,
                }
        }
 
@@ -2581,16 +2582,21 @@ impl Writeable for OutboundOnionPayload {
                        },
                        Self::BlindedReceive {
                                sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs,
-                               intro_node_blinding_point, keysend_preimage,
+                               intro_node_blinding_point, keysend_preimage, ref custom_tlvs,
                        } => {
+                               // We need to update [`ln::outbound_payment::RecipientOnionFields::with_custom_tlvs`]
+                               // to reject any reserved types in the experimental range if new ones are ever
+                               // standardized.
+                               let keysend_tlv = keysend_preimage.map(|preimage| (5482373484, preimage.encode()));
+                               let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter().chain(keysend_tlv.iter()).collect();
+                               custom_tlvs.sort_unstable_by_key(|(typ, _)| *typ);
                                _encode_varint_length_prefixed_tlv!(w, {
                                        (2, HighZeroBytesDroppedBigSize(*sender_intended_htlc_amt_msat), required),
                                        (4, HighZeroBytesDroppedBigSize(*cltv_expiry_height), required),
                                        (10, *encrypted_tlvs, required_vec),
                                        (12, intro_node_blinding_point, option),
-                                       (18, HighZeroBytesDroppedBigSize(*total_msat), required),
-                                       (5482373484, keysend_preimage, option)
-                               });
+                                       (18, HighZeroBytesDroppedBigSize(*total_msat), required)
+                               }, custom_tlvs.iter());
                        },
                }
                Ok(())
index 53ef0729aa171ba56ff33ba73a55cb4ed922df83..6742d0ae2afe96b8ed31de5c7ac8ebfc97e5dbe5 100644 (file)
@@ -214,6 +214,7 @@ pub(super) fn build_onion_payloads(
                                                        encrypted_tlvs: blinded_hop.encrypted_payload.clone(),
                                                        intro_node_blinding_point: blinding_point.take(),
                                                        keysend_preimage: *keysend_preimage,
+                                                       custom_tlvs: recipient_onion.custom_tlvs.clone(),
                                                });
                                        } else {
                                                res.push(msgs::OutboundOnionPayload::BlindedForward {