-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[1/2] lnwire: fix encoding customized TLV records #10072
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
base: master
Are you sure you want to change the base?
[1/2] lnwire: fix encoding customized TLV records #10072
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 addresses a critical bug in the lnwire
package where customized TLV records, particularly those in the 'extra data' fields of certain messages, were being incorrectly encoded. The changes involve a significant refactoring of the TLV handling logic, introducing a standardized approach for parsing and encoding these records. This ensures that all TLV data, whether known or unknown, is processed correctly, improving the reliability and forward compatibility of Lightning Network messages. Extensive new tests have been added to validate these fixes.
Highlights
- TLV Encoding Fix: Implemented a fix for incorrect encoding of customized TLV (Type-Length-Value) records within the 'extra data' field of various Lightning Network messages. This ensures that both known and unknown TLV fields are correctly handled during serialization and deserialization.
- Standardized TLV Parsing: Introduced a new helper function,
ParseAndExtractExtraData
, which centralizes the logic for separating known TLV records from arbitrary 'extra data' within a message's TLV stream. This promotes consistent and robust parsing across thelnwire
package. - TLV Type Correction: Corrected the TLV type for
DALocalMusig2Pubnonce
in theDynAck
message from0
to14
. This resolves a potential conflict with other TLV types and aligns with standard practices for assigning even-numbered types to optional fields. - Enhanced Test Coverage: Added comprehensive unit tests for the encode/decode functionality of several
lnwire
messages, includingAnnounceSignatures1/2
,ChannelAnnouncement1/2
,ChannelUpdate2
,DynAck
,DynCommit
, andDynPropose
. These tests verify byte-for-byte fidelity after a full encode-decode roundtrip, ensuring the correctness of the TLV handling. - Type Refinements: Updated the TLV record types for
DustLimit
andChannelReserve
in dynamic commitment messages (DynPropose
,DynCommit
) to usetlv.BigSizeT
forbtcutil.Amount
, providing a more appropriate and flexible encoding for these values.
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 introduces a fix for encoding customized TLV records in lnwire, specifically addressing an issue where known TLV fields were incorrectly encoded into the ExtraData
field of messages. The changes include adding unit tests and refactoring encoding/decoding methods to ensure correct serialization and preservation of unknown TLV fields. The code adheres to the LND Style Guide.
480167d
to
c3fbbc7
Compare
Fix the test for `ChannelUpdate2` and `ChannelAnnouncement2`.
This is used to create unknown random records by specifying the max known record type number.
This commit adds unit tests for `AnnounceSignatures1`, `AnnounceSignatures2`, and `ChannelAnnouncement1`. This further assures all the encoding and decoding methods are behaved as expected.
c3fbbc7
to
8023a29
Compare
Depending on #10027, this PR fixes the wrong encoding used in the extra data field. Followup PRs will be created to fix the rest of the msgs. The msgs in this PR are not used in production yet, and for other msgs, it's likely the error wasn't caught due to there's no interoperability test yet.
The commits are structured as follows,