Skip to content

Commit b496985

Browse files
committed
Allow arbitrary length path_id in encrypted_data
BOLT 4 allows the path_id in encrypted_data to be of an arbitrary length, but the code currently only allows 32 bytes. Update it to match the specification.
1 parent 8958209 commit b496985

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub(crate) struct ReceiveTlvs {
208208
/// If `path_id` is `Some`, it is used to identify the blinded path that this onion message is
209209
/// sending to. This is useful for receivers to check that said blinded path is being used in
210210
/// the right context.
211-
pub(super) path_id: Option<[u8; 32]>,
211+
pub(super) path_id: Option<Vec<u8>>,
212212
}
213213

214214
impl Writeable for ForwardTlvs {
@@ -224,9 +224,12 @@ impl Writeable for ForwardTlvs {
224224

225225
impl Writeable for ReceiveTlvs {
226226
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
227+
const EMPTY_PATH_ID: &Vec<u8> = &vec![];
228+
let path_id = self.path_id.as_ref().unwrap_or(EMPTY_PATH_ID);
229+
227230
// TODO: write padding
228231
encode_tlv_stream!(writer, {
229-
(6, self.path_id, option),
232+
(6, *path_id, optional_vec),
230233
});
231234
Ok(())
232235
}

lightning/src/onion_message/messenger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ where
334334
}
335335

336336
fn respond_with_onion_message<T: CustomOnionMessageContents>(
337-
&self, response: OnionMessageContents<T>, path_id: Option<[u8; 32]>,
337+
&self, response: OnionMessageContents<T>, path_id: Option<Vec<u8>>,
338338
reply_path: Option<BlindedPath>
339339
) {
340340
let sender = match self.node_signer.get_node_id(Recipient::Node) {

lightning/src/onion_message/packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ impl Readable for ControlTlvs {
275275
let mut _padding: Option<Padding> = None;
276276
let mut _short_channel_id: Option<u64> = None;
277277
let mut next_node_id: Option<PublicKey> = None;
278-
let mut path_id: Option<[u8; 32]> = None;
278+
let mut path_id: Option<Vec<u8>> = None;
279279
let mut next_blinding_override: Option<PublicKey> = None;
280280
decode_tlv_stream!(&mut r, {
281281
(1, _padding, option),
282282
(2, _short_channel_id, option),
283283
(4, next_node_id, option),
284-
(6, path_id, option),
284+
(6, path_id, optional_vec),
285285
(8, next_blinding_override, option),
286286
});
287287

0 commit comments

Comments
 (0)