Skip to content

Conversation

erickcestari
Copy link
Contributor

Updates ChannelUpdate1 parsing to make htlc_maximum_msat mandatory, aligning with the updated BOLT specification and fixing a compatibility issue with other Lightning implementations.

The BOLT specification was updated to make the htlc_maximum_msat field mandatory in channel_update messages. The must_be_one bit in message_flags that previously indicated this field's presence is now a constant value that should be ignored by receivers.

During differential fuzzing between LND and C-Lightning, a compatibility issue was discovered:

  • LND: Accepts 130-byte channel_update messages (missing htlc_maximum_msat)
  • C-Lightning: Rejects these messages as malformed (expecting 138 bytes with mandatory htlc_maximum_msat)

context: lightning/bolts#999

This commit updates the ChannelUpdate1 message parsing to align with
the updated BOLT specification where htlc_maximum_msat is now a
mandatory field rather than optional.
Copy link

@gemini-code-assist gemini-code-assist bot left a 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 @erickcestari, 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 updates the ChannelUpdate1 message parsing in the lnwire package to align with the latest BOLT specification. The primary change makes the htlc_maximum_msat field mandatory during message decoding. This ensures consistency with the updated protocol and resolves a known compatibility issue with other Lightning implementations, such as C-Lightning, which already enforce the presence of this field.

Highlights

  • BOLT Specification Alignment: The ChannelUpdate1 decoding logic has been updated to reflect the latest BOLT specification, which mandates the presence of the htlc_maximum_msat field in channel_update messages.
  • Mandatory htlc_maximum_msat: The htlc_maximum_msat field is now unconditionally read during the decoding of ChannelUpdate1 messages, removing the previous conditional check based on MessageFlags.
  • Compatibility Fix: This modification addresses a compatibility issue where LND would accept 130-byte channel_update messages (missing htlc_maximum_msat), while C-Lightning would reject them as malformed, expecting the 138-byte message with the mandatory field.
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 updates ChannelUpdate1 to make htlc_maximum_msat mandatory during decoding, which aligns with the latest BOLT specs. The change itself is correct, but as I've noted in my review comment, it's incomplete. Other parts of the file need to be updated to ensure consistency between the encoding and decoding paths, which is critical to prevent bugs.

@Roasbeef
Copy link
Member

FWIW re already reject these by default:

// The maxHTLC flag is mandatory.
if !msg.MessageFlags.HasMaxHtlc() {
return fmt.Errorf("max htlc flag not set for channel "+
"update %v", spew.Sdump(msg))
}

@erickcestari
Copy link
Contributor Author

Ooops. Closing this pr...

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