Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onion format variation a-la @roasbeef (vs #593) #604

Closed
wants to merge 6 commits into from

Conversation

rustyrussell
Copy link
Collaborator

This splits the difference between #593 from @cdecker and comments from @Roasbeef

I based it on #593 so the differences are clear. It leaves realm 0 alone (naming it legacy), just defines realms 1-15.

These are TLVs, which in is a win for the final node since short_channel_id is unnecessary there.

(See #603 which explicitly describes that encoding smaller numbers with fewer than 8 bytes in a TLV is allowed).

The clarifications were tacked on after the fact, but they should really be
part of the conventions. I also updated the links to use the reference style,
which results in better text flow and makes it easier to read the source.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Introduces `frame`s and all related concepts such as `FRAME_SIZE`. It also
fixes a conceptual issue where `hops_data` would be used both for the section
of the overall packet as well as the wire format for individual payloads. This
separation now lends itself better to the incremental wrapping of the onion.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Signed-off-by: Christian Decker <decker.christian@gmail.com>
They were cluttering the spec document, and not easily integrated into the
tests for implementations. This just cleans up the spec and allows automated
testing going forward.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Signed-off-by: Christian Decker <decker.christian@gmail.com>
…e / TLV.

The TLV format leaves us with more room for the final node, which is nice
as that's where most proposals want to put more data in the onion.

It's break-even in for the non-final nodes, since amount_to_forward tends to
be < 6 bytes, and outgoing_cltv_value < 2.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
@t-bast
Copy link
Collaborator

t-bast commented May 6, 2019

I'm fine with this small tweak. If I'm not missing anything it achieves the same tradeoffs as @cdecker's proposal, in fact the only change is that the least significant bits of the realm are used to encode the number of frames instead of the most significant bits (and we commit to using TLV for all those 16 realm values which is what we decided anyway).

We have room for new messages in two different places:

  • in realms 0x01 to 0x0f by leveraging the TLV types that aren't yet used
  • in all the other realm values with complete liberty over the format of the hop payload

I think that this is clearly enough for the foreseeable future (and it achieves both backwards-compatibility and simplicity, which is very important to get it deployed smoothly).

In the longer term, we know we want to change a few things in a version 1 of the onion message (per-hop versioning for example). Version 1 can be an opportunity to provide even more room for new messages if developers can't achieve what they want with version 0.

All those reasons make this a good pragmatic proposal which could unblock trampoline/rendezvous routing and I think we should move forward. If we all agree with that, we only need test vectors for the new realm values and the feature bit and we should be good to go.

Copy link
Collaborator

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

This addresses my objection to bit-packing the packet type + number of frames into the realm byte, but it doesn't (to my current reading) address the small number of possible types for TLV in the onion.

I think a much smaller modification to the prior proposal is possible compared to the iteration in this PR. As is, it completely re-defines the current hop data payloads which results in additional code impact for all nodes involved in a route. I think completely re-defining the hop payload is an interesting idea that demonstrates the flexibility of TLV in the onion packets in general, but one that seems tangential to allowing nodes to add structure to the currently unused extra blob data.

The number of additional frames allocated to the current hop is determined by the 4 most significant bits of `num_frames_and_realm`, while the 4 least significant bits determine the payload format.
Therefore the number of frames allocated to the current hop is given by `num_frames = (num_frames_and_realm >> 4) + 1`.
For simplification we will use `hop_payload_len` to refer to `num_frames * FRAME_SIZE`.
The `hop_payload` consists of at least one `frame` followed by up to 15 additional `frame`s. For simplification we will use `hop_payload_len` to refer to `num_frames * FRAME_SIZE`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the entire byte is available, why restrict it to 15 instead of ~20 which lets nodes utilize all the available space?

@Roasbeef
Copy link
Collaborator

Roasbeef commented May 13, 2019 via email

@cdecker
Copy link
Collaborator

cdecker commented May 13, 2019

It has one small downside of having to keep a mapping of realm -> num_frames in the code processing the onion, whereas #593 was making that simply the first few bits, but like mentioned it's a minor thing.

@rustyrussell
Copy link
Collaborator Author

Closed in favor of revisions to #593

values also allows use of more than one frame.

1. tlv: `tlv_hop_data`
2. types:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than unroll these fields and take up 4 types, we can instead have them all packed under a single type. All the fields are fixed length, so there's no additional signalling overhead and we also save a few bytes as well. When allocating space in the TLV namespace we should prefer to pack several types into one, if all the types are related to a discrete use case. This model promotes more efficient utilization of the payload space.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well like we discussed in the IRC meeting some of the types would be omitted, for example in the last hop_payload. So while I agree that we may avoid defining types that must always be used in combination, we should also keep in mind that swapping out or omitting individual types is also an important feature here.

@cdecker
Copy link
Collaborator

cdecker commented Jun 10, 2019

Closed in favor of PR #619 as discussed during the IRC meeting on 2019/06/10.

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.

None yet

4 participants