Skip to content

smite: add update_add_htlc message codec#33

Open
kartikangiras wants to merge 1 commit intomorehouse:masterfrom
kartikangiras:update-add-htlc
Open

smite: add update_add_htlc message codec#33
kartikangiras wants to merge 1 commit intomorehouse:masterfrom
kartikangiras:update-add-htlc

Conversation

@kartikangiras
Copy link
Copy Markdown

Add support for Message Type: [UPDATE_ADD_HTLC] (type 128).

realtes to #5

///
/// This is typically a variable-length field containing the encrypted
/// route information that only the next hop can decrypt.
pub onion_routing_packet: Vec<u8>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The onion package is exactly of size 1366, so rather than Vec, using [u8; 1366] makes more sense as it will save heap memory and will also ensure no memory-related bugs are raised in future.

let amount_msat = WireFormat::read(&mut cursor)?;
let payment_hash: [u8; 32] = WireFormat::read(&mut cursor)?;
let cltv_expiry = WireFormat::read(&mut cursor)?;
let onion_routing_packet = Vec::<u8>::read(&mut cursor)?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, for onion_packet_routing decoding, as it is of fixed size, and to support the above comment let onion_routing_packet = <[u8; 1366]>::read(&mut cursor)?; using this for decoding will be more safe and better.

}

#[test]
fn decode_truncated_amount_msat() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the calculation of offsets in this test is a bit off and should be somewhere bw 40 to 47 (channelID 32 bytes + htlc_id 8 bytes and then this field for another 8 bytes).

}

#[test]
fn decode_truncated_payment_hash() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you missed htlc_id bytes, here too we have to add, so the offset should be bw 48 and 48+32)

}

#[test]
fn decode_truncated_cltv_expiry() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, here too the offset should be 80 or more for this test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants