-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix externalhosts to advertise both IPv4 and IPv6 addresses #10145
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?
Conversation
Fixes lightningnetwork#8801 When a domain resolves to both IPv4 and IPv6 addresses, the node should advertise both protocols. Previously, only one address was returned due to using ResolveTCPAddr which returns a single address. This change: - Uses net.LookupHost to get all IP addresses for a domain - Creates addresses for each IP found (both IPv4 and IPv6) - Handles errors gracefully by continuing with other IPs if one fails - Returns error if no valid addresses are found - Updates function signature to return []net.Addr instead of single net.Addr
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 @wearedood, 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!
I've implemented a crucial fix to how external hosts are advertised, specifically addressing an issue where only a single IP address (either IPv4 or IPv6) was being returned, even when a domain resolved to both. My changes ensure that the system now correctly identifies and advertises all available IP addresses for a given host, supporting both IPv4 and IPv6 simultaneously. This was achieved by switching to net.LookupHost
to retrieve all IPs and then iterating through them to create and collect all valid network addresses. This enhancement improves network connectivity and robustness for dual-stack environments.
Highlights
- Dual-stack address advertisement: Previously, the system would only return a single IP address (either IPv4 or IPv6) when resolving a domain, even if the domain had both types of addresses. This change ensures that if a domain resolves to both IPv4 and IPv6, both are advertised.
- Updated function signature: The
LookupHost
function, which is responsible for resolving hostnames to network addresses, has been updated to return a slice ofnet.Addr
instead of a singlenet.Addr
. This allows it to return all resolved addresses. - Improved IP address resolution: The internal logic for resolving hostnames now uses Go's
net.LookupHost
function, which provides all IP addresses associated with a given hostname. It then iterates through these addresses, parsing each one and collecting them. - Enhanced error handling: The updated logic includes robust error handling. If parsing a specific IP address fails, it logs the error but continues processing other IPs. An error is only returned if no valid addresses can be found for the host.
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 or fill out our survey 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 correctly addresses the issue of advertising both IPv4 and IPv6 addresses for external hosts by using net.LookupHost
. The overall logic is sound. I've found a few issues, including a critical typo, a missing log statement, and some style guide violations related to line length and comments. Please address these points to improve the code quality and ensure it compiles correctly.
host, strconv.Itoa(defaultPeerPort), | ||
cfg.net.ResolveTCPAddr, | ||
) | ||
LookuLookupHost: func(host string) ([]net.Addr, error) { |
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.
cfg.net.ResolveTCPAddr, | ||
) | ||
LookuLookupHost: func(host string) ([]net.Addr, error) { | ||
// Use net.LookupHost to get all IP addresses for the host |
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.
This comment, and the ones on lines 1923 and 1937, explain what the code does rather than why. According to the style guide, comments should explain the 'why' if the code isn't self-explanatory. In this case, the code is clear, so these comments can be removed.1
Style Guide References
Footnotes
// Log the error but continue with other IPs | ||
continue |
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.
The comment here is inaccurate as no logging is performed. It's good practice to log such errors for debugging purposes. Also, per the style guide, comments should explain the 'why', not the 'what'.1
// Log the error and continue with other IPs.
srvrLog.Warnf("unable to parse address %s for host %s: %v", ip, host, err)
continue
Style Guide References
Footnotes
|
||
// Return error if no valid addresses were found | ||
if len(addrs) == 0 { | ||
return nil, fmt.Errorf("no valid addresses found for host %s", host) |
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.
This line exceeds the 80-character limit specified in the style guide. To adhere to the style guide, you can introduce a variable for the error message string.1
msg := "no valid addresses found for host %s"
return nil, fmt.Errorf(msg, host)
Style Guide References
Footnotes
@wearedood, remember to re-request review from reviewers when ready |
Fixes #8801
When a domain resolves to both IPv4 and IPv6 addresses, the node should advertise both protocols. Previously, only one address was returned due to using ResolveTCPAddr which returns a single address.
This change:
Change Description
Description of change / link to associated issue.
Steps to Test
Steps for reviewers to follow to test the change.
Pull Request Checklist
Testing
Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.