-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix ExtraData
field and use BigSize
encodine
#10027
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
Fix ExtraData
field and use BigSize
encodine
#10027
Conversation
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.
Summary of Changes
Hello @yyforyongyu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request refines the serialization of dynamic messages by adopting more efficient BigSize
encoding for certain monetary values and, critically, corrects the handling of ExtraData
fields. These changes ensure that ExtraData
accurately represents only unknown or unexpected TLV records, promoting better forward compatibility and adherence to protocol specifications.
Highlights
- Encoding Efficiency: Switched the encoding of
btcutil.Amount
fields (e.g.,DustLimit
,ChannelReserve
) within dynamic messages to useBigSize
encoding, improving serialization efficiency and reducing byte size for smaller values. - Correct ExtraData Handling: Refactored the encoding and decoding logic for
ExtraData
fields inDynAck
,DynCommit
, andDynPropose
messages. TheExtraData
field now correctly stores only unrecognized TLV records, adhering to the TLV extensibility principle, rather than inadvertently holding all TLV data. - TLV Type Update: The TLV type for
DALocalMusig2Pubnonce
inDynAck
messages has been updated from0
to14
. This change ensures proper type assignment and avoids potential conflicts with other TLV types. - New TLV Parsing Helper: Introduced a new helper function
ParseAndExtractExtraData
inlnwire/extra_bytes.go
to streamline the process of extracting known TLV records from a byte stream and isolating any truly 'extra' or unrecognized data. - Comprehensive Test Coverage: Added new dedicated tests for
DynAck
,DynCommit
, andDynPropose
messages to validate the updated encoding/decoding logic, including theBigSize
andExtraData
changes. Existing random message generation tests were also updated to reflect these changes and ensure correctExtraData
population.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request refactors the encoding of several dynamic commitment messages (DynAck
, DynCommit
, DynPropose
) to correctly handle ExtraData
and use more efficient BigSize
encoding for amount fields. The changes are a good improvement, fixing a bug where all TLV data was being packed into ExtraData
. The PR also adds comprehensive tests for the affected messages. I've found a critical issue in the decoding logic for DynCommit
and DynPropose
that would cause a panic or compilation error, and I've provided suggestions to fix it.
c74b17c
to
f77b4fb
Compare
/gemini review |
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.
Code Review
This PR introduces changes to the encoding from btcutil.Amount
to BigSize
for efficiency and fixes the wrong encoding used in the dyn msg set. The ExtraData
field is now correctly handled.
326f3d7
to
c4f2c13
Compare
/gemini review |
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.
Code Review
This pull request fixes a critical bug in the dynamic commitment message set and enhances encoding efficiency by using BigSize encoding for amount fields. The core issue of ExtraData
incorrectly containing known TLV fields is resolved across DynPropose
, DynAck
, and DynCommit
messages. The introduction of the ParseAndExtractExtraData
helper function greatly simplifies and clarifies the decoding logic, and the accompanying test changes are excellent.
c4f2c13
to
813baa2
Compare
/gemini review |
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.
Code Review
This pull request fixes an issue with ExtraData
encoding and improves efficiency by using BigSize
encoding. The new ParseAndExtractExtraData
function is a great addition for correctly decoding TLV streams. However, the new Encode
methods for DynAck
, DynCommit
, and DynPropose
incorrectly serialize known and unknown TLV records into separate streams, which would break wire compatibility. I've provided suggestions to merge all records into a single stream before encoding.
813baa2
to
ada9fff
Compare
ada9fff
to
cd15784
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.
See comment in review - i think the extradata encoding/decoding was correct before.
If we have known fields (like LocalNonce) that we extracted from ExtraTLV bytes - then what we should instead do is just to not explicitly write the LocalNonce bytes & instead just write the ExtraData bytes to disk & then on reading from disk, then we do an in-memory parse and populate LocalNonce from that.
cd15784
to
8b40fc9
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.
oops, forgot to click "review changes".
See comment in thread - just want to make sure we are on same page.
I think the confusion is coming in because legacy protocol messages had fixed fields followed by TLV stream. But now, we are going for a full TLV stream (minus the first channel ID field of course).
And so we need to ensure that the entire TLV stream is ordered (which includes our known fields and our unknown records)
68f6975
to
f44a195
Compare
f44a195
to
db8fcdf
Compare
/gemini review |
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.
Code Review
This PR fixes an encoding issue with ExtraData
and improves efficiency by using BigSize
encoding. The changes are well-implemented, and the addition of tests is valuable.
db8fcdf
to
4c2612d
Compare
/gemini review |
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.
Code Review
This pull request improves the correctness and clarity of TLV handling for dynamic commitment messages by fixing the ExtraData field and using BigSize encoding. The new ParseAndExtractExtraData helper function and the encode/decode tests are valuable additions. The feedback focuses on using more idiomatic Go buffer initialization in the new test files.
4c2612d
to
e170af2
Compare
/gemini review |
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.
Code Review
This pull request correctly fixes a significant issue with TLV serialization where known fields were being incorrectly packed into the ExtraData
field. The introduction of the ParseAndExtractExtraData
helper function centralizes the logic for separating known and unknown TLV records, which greatly improves correctness and maintainability across the dynamic commitment message set. The switch to BigSize
encoding for amount fields is also a good efficiency improvement. The new and updated tests are thorough and cover the changes well.
I have one suggestion regarding code formatting to better align with the project's style guide.
PS: There's a small typo in the PR title ("encodine" -> "encoding").
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.
lgtm after roasbeef nits addressed!
Love the hard coded byte tests. I guess for those we need to just watch out when we introduce known types for the records we currently define as unknown there.
Thanks for the updates to the commit order - things are much more clear to me now 🙏
|
||
// TestDynAckEncodeDecode checks that the Encode and Decode methods for DynAck | ||
// work as expected. | ||
func TestDynAckEncodeDecode(t *testing.T) { |
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.
lovely lovely
Previously we encode all the fields plus extra data to the field `ExtraData`, this is now fixed by encoding only unknown data to extra data. For known records, they are already encoded into the message fields.
`MilliSatoshi` itself is already a `BigSize`, we just need to change the decoding and encoding types to use that.
Similar to `ParseAndExtractCustomRecords`, we now add this helper method to make sure the extra data is parsed correctly.
It should be an optional record instead of an fn option. In addition, its tlv type is bumped to be 14 as this record is also included in the `DynCommit`. If we use tlv type 0, it will create a conflict in the msg `DynCommit`, which is fixed in the following commit.
This record was never added to the `DynCommit`, but it's inherited from the embedding msg `DynAck`.
Remove the unnecessary convertions as suggested by Gemini.
e170af2
to
18916da
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.
LGTM 🦀
This PR changes the encoding from
btcutil.Amount
toBigSize
for efficiency. It also fixes the wrong encoding used in the dyn msg set. For instance, the extra data field is meant to hold extra data, but it actually holds the full tlv data,before this change, notice the
ExtraData
holdsLocalNonce
,after,
I think we may have other places use the wrong encoding, will check.