Skip to content

Commit 7d68b60

Browse files
Support sending custom TLVs to blinded recipients.
1 parent 68d5e88 commit 7d68b60

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lightning/src/ln/msgs.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,7 @@ mod fuzzy_internal_msgs {
17371737
encrypted_tlvs: Vec<u8>,
17381738
intro_node_blinding_point: Option<PublicKey>, // Set if the introduction node of the blinded path is the final node
17391739
keysend_preimage: Option<PaymentPreimage>,
1740+
custom_tlvs: Vec<(u64, Vec<u8>)>,
17401741
}
17411742
}
17421743

@@ -2581,16 +2582,21 @@ impl Writeable for OutboundOnionPayload {
25812582
},
25822583
Self::BlindedReceive {
25832584
sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs,
2584-
intro_node_blinding_point, keysend_preimage,
2585+
intro_node_blinding_point, keysend_preimage, ref custom_tlvs,
25852586
} => {
2587+
// We need to update [`ln::outbound_payment::RecipientOnionFields::with_custom_tlvs`]
2588+
// to reject any reserved types in the experimental range if new ones are ever
2589+
// standardized.
2590+
let keysend_tlv = keysend_preimage.map(|preimage| (5482373484, preimage.encode()));
2591+
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter().chain(keysend_tlv.iter()).collect();
2592+
custom_tlvs.sort_unstable_by_key(|(typ, _)| *typ);
25862593
_encode_varint_length_prefixed_tlv!(w, {
25872594
(2, HighZeroBytesDroppedBigSize(*sender_intended_htlc_amt_msat), required),
25882595
(4, HighZeroBytesDroppedBigSize(*cltv_expiry_height), required),
25892596
(10, *encrypted_tlvs, required_vec),
25902597
(12, intro_node_blinding_point, option),
2591-
(18, HighZeroBytesDroppedBigSize(*total_msat), required),
2592-
(5482373484, keysend_preimage, option)
2593-
});
2598+
(18, HighZeroBytesDroppedBigSize(*total_msat), required)
2599+
}, custom_tlvs.iter());
25942600
},
25952601
}
25962602
Ok(())

lightning/src/ln/onion_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ pub(super) fn build_onion_payloads(
214214
encrypted_tlvs: blinded_hop.encrypted_payload.clone(),
215215
intro_node_blinding_point: blinding_point.take(),
216216
keysend_preimage: *keysend_preimage,
217+
custom_tlvs: recipient_onion.custom_tlvs.clone(),
217218
});
218219
} else {
219220
res.push(msgs::OutboundOnionPayload::BlindedForward {

0 commit comments

Comments
 (0)