-
Notifications
You must be signed in to change notification settings - Fork 407
Simplify Message Serialization and Parse TLV Suffix #1068
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
Simplify Message Serialization and Parse TLV Suffix #1068
Conversation
8de4670
to
f3a0830
Compare
Codecov Report
@@ Coverage Diff @@
## main #1068 +/- ##
==========================================
+ Coverage 90.87% 92.39% +1.52%
==========================================
Files 65 65
Lines 33229 43459 +10230
==========================================
+ Hits 30196 40153 +9957
- Misses 3033 3306 +273
Continue to review full report at Codecov.
|
678c3b7
to
030c25e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup! Minor comments, otherwise ACK
030c25e
to
27c6ee2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, commit 27c6ee2 refers to "previous commit" but the commit in question is a few commits back.
7acf5e3
to
41cf0c2
Compare
Reordered the commits a bit and updated writer docs. Note that at this point we should probably remove writer, but I'll leave that as a followup huge-diff change. |
In order to avoid significant malloc traffic, messages previously explicitly stated their serialized length allowing for Vec preallocation during the message serialization pipeline. This added some amount of complexity in the serialization code, but did avoid some realloc() calls. Instead, here, we drop all the complexity in favor of a fixed 2KiB buffer for all message serialization. This should not only be simpler with a similar reduction in realloc() traffic, but also may reduce heap fragmentation by allocating identically-sized buffers more often.
Going forward, all lightning messages have a TLV stream suffix, allowing new fields to be added as needed. In the P2P protocol, messages have an explicit length, so there is no implied length in the TLV stream itself. HTLCFailureMsg enum variants have messages in them, but without a size prefix or any explicit end. Thus, if a HTLCFailureMsg is read as a part of a ChannelManager, with a TLV stream at the end, there is no way to differentiate between the end of the message and the next field(s) in the ChannelManager. Here we add two new variant values for HTLCFailureMsg variants in the read path, allowing us to switch to the new values if/when we add new TLV fields in UpdateFailHTLC or UpdateFailMalformedHTLC so that older versions can still read the new TLV fields.
The network serialization format for all messages was changed some time ago to include a TLV suffix for all messages, however we never bothered to implement it as there isn't a lot of use validating a TLV stream with nothing to do with it. However, messages are increasingly utilizing the TLV suffix feature, and there are some compatibility concerns with messages written as a part of other structs having their format changed (see previous commit). Thus, here we go ahead and convert most message serialization to a new macro which includes a TLV suffix after a series of fields, simplifying several serialization implementations in the process.
41cf0c2
to
997dc5f
Compare
Squashed with no further changes, will land after CI.
|
See individual commits