Skip to content

Commit

Permalink
Allow arbitrary length path_id in encrypted_data
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jkczyz committed Sep 12, 2023
1 parent a96a510 commit 4aa8fa1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lightning/src/blinded_path/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) struct ReceiveTlvs {
/// If `path_id` is `Some`, it is used to identify the blinded path that this onion message is
/// sending to. This is useful for receivers to check that said blinded path is being used in
/// the right context.
pub(crate) path_id: Option<[u8; 32]>,
pub(crate) path_id: Option<Vec<u8>>,
}

impl Writeable for ForwardTlvs {
Expand All @@ -45,9 +45,12 @@ impl Writeable for ForwardTlvs {

impl Writeable for ReceiveTlvs {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
const EMPTY_PATH_ID: &Vec<u8> = &vec![];
let path_id = self.path_id.as_ref().unwrap_or(EMPTY_PATH_ID);

// TODO: write padding
encode_tlv_stream!(writer, {
(6, self.path_id, option),
(6, *path_id, optional_vec),
});
Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion lightning/src/blinded_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,3 @@ impl_writeable!(BlindedHop, {
blinded_node_id,
encrypted_payload
});

2 changes: 1 addition & 1 deletion lightning/src/onion_message/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ where
}

fn respond_with_onion_message<T: CustomOnionMessageContents>(
&self, response: OnionMessageContents<T>, path_id: Option<[u8; 32]>,
&self, response: OnionMessageContents<T>, path_id: Option<Vec<u8>>,
reply_path: Option<BlindedPath>
) {
let sender = match self.node_signer.get_node_id(Recipient::Node) {
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/onion_message/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl Readable for ControlTlvs {
(1, _padding, option),
(2, _short_channel_id, option),
(4, next_node_id, option),
(6, path_id, option),
(6, path_id, optional_vec),
(8, next_blinding_override, option),
});
let _padding: Option<Padding> = _padding;
Expand Down

0 comments on commit 4aa8fa1

Please sign in to comment.