Skip to content

Commit 4aa8fa1

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 a96a510 commit 4aa8fa1

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

lightning/src/blinded_path/message.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) struct ReceiveTlvs {
2929
/// If `path_id` is `Some`, it is used to identify the blinded path that this onion message is
3030
/// sending to. This is useful for receivers to check that said blinded path is being used in
3131
/// the right context.
32-
pub(crate) path_id: Option<[u8; 32]>,
32+
pub(crate) path_id: Option<Vec<u8>>,
3333
}
3434

3535
impl Writeable for ForwardTlvs {
@@ -45,9 +45,12 @@ impl Writeable for ForwardTlvs {
4545

4646
impl Writeable for ReceiveTlvs {
4747
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
48+
const EMPTY_PATH_ID: &Vec<u8> = &vec![];
49+
let path_id = self.path_id.as_ref().unwrap_or(EMPTY_PATH_ID);
50+
4851
// TODO: write padding
4952
encode_tlv_stream!(writer, {
50-
(6, self.path_id, option),
53+
(6, *path_id, optional_vec),
5154
});
5255
Ok(())
5356
}

lightning/src/blinded_path/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,3 @@ impl_writeable!(BlindedHop, {
138138
blinded_node_id,
139139
encrypted_payload
140140
});
141-

lightning/src/onion_message/messenger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ where
337337
}
338338

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

lightning/src/onion_message/packet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl Readable for ControlTlvs {
280280
(1, _padding, option),
281281
(2, _short_channel_id, option),
282282
(4, next_node_id, option),
283-
(6, path_id, option),
283+
(6, path_id, optional_vec),
284284
(8, next_blinding_override, option),
285285
});
286286
let _padding: Option<Padding> = _padding;

0 commit comments

Comments
 (0)