-
Notifications
You must be signed in to change notification settings - Fork 2.2k
server: prevent duplicate onion addresses in getinfo #10341
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?
server: prevent duplicate onion addresses in getinfo #10341
Conversation
Otherwise it can happen that we restart the tor controller and recreate the hidden service, adding the onion address multiple times.
Summary of ChangesHello @bitromortac, 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 resolves an issue where the LND server could accumulate duplicate Tor onion addresses in its node announcement, particularly when Tor health checks caused the hidden service to be re-created. By introducing a check for existing addresses before appending new ones, the change ensures that the node's advertised addresses remain clean and accurate, improving the stability and reliability of Tor-enabled LND nodes. Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 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
|
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 prevents duplicate onion addresses from being added to the node announcement by checking for existing addresses before appending a new one. The fix is simple and effective. To prevent future regressions, it would be beneficial to add a unit test that covers this specific scenario of a Tor controller restart leading to a duplicate address.
| newNodeAnn, err := s.genNodeAnnouncement( | ||
| nil, func(currentAnn *lnwire.NodeAnnouncement1) { | ||
| currentAnn.Addresses = append(currentAnn.Addresses, addr) | ||
| // Check if this address was already added. |
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.
| newNodeAnn, err := s.genNodeAnnouncement( | ||
| nil, func(currentAnn *lnwire.NodeAnnouncement1) { | ||
| currentAnn.Addresses = append(currentAnn.Addresses, addr) | ||
| // Check if this address was already added. |
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.
will the whole list be deleted during restart, so we only have like 1 address in there at least 1 onion address I mean ?
yyforyongyu
left a comment
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❤️
| // Check if this address was already added. | ||
| for _, anAddr := range currentAnn.Addresses { | ||
| if anAddr.String() == addr.String() { | ||
| return |
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.
nit: can use some debug log here
| } | ||
| } | ||
|
|
||
| currentAnn.Addresses = append( |
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.
It looks like Addresses should be a set (map) to avoid this duplicated addresses issue, but that's a larger PR.
|
@bitromortac, remember to re-request review from reviewers when ready |
Attempts to fix #10328.
The user's config is set to do periodic health checks for tor connections:
The issues seems to be the following. If
healthcheck.CheckTorServiceStatusreceivessyscall.EPIPEit restarts the tor controller, which re-creates the hidden service.createNewHiddenServicethen updates the node announcement, appending the new (old) onion service address, not checking if it's already present, which is fixed here.