Skip to content

Conversation

@bitromortac
Copy link
Collaborator

Attempts to fix #10328.

The user's config is set to do periodic health checks for tor connections:

[tor]
tor.active=true
tor.v3=true
tor.skip-proxy-for-clearnet-targets=true
tor.streamisolation=false
healthcheck.torconnection.attempts=3
healthcheck.torconnection.timeout=10s
healthcheck.torconnection.backoff=30s
healthcheck.torconnection.interval=1m

The issues seems to be the following. If healthcheck.CheckTorServiceStatus receives syscall.EPIPE it restarts the tor controller, which re-creates the hidden service. createNewHiddenService then updates the node announcement, appending the new (old) onion service address, not checking if it's already present, which is fixed here.

Otherwise it can happen that we restart the tor controller and recreate
the hidden service, adding the onion address multiple times.
@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • Duplicate Onion Address Prevention: Implemented a check within the createNewHiddenService function to prevent the addition of duplicate Tor onion addresses to the node announcement.
  • Tor Health Check Reliability: Addresses an issue where Tor health checks could lead to the re-creation of hidden services and subsequent duplicate address entries if a syscall.EPIPE error occurred.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This comment explains what the code does, but not why. According to the style guide, comments should explain the why or the intention of the code.12

Suggested change
// Check if this address was already added.
// Avoid duplicate addresses from Tor restarts.

Style Guide References

Footnotes

newNodeAnn, err := s.genNodeAnnouncement(
nil, func(currentAnn *lnwire.NodeAnnouncement1) {
currentAnn.Addresses = append(currentAnn.Addresses, addr)
// Check if this address was already added.
Copy link
Collaborator

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 ?

@saubyk saubyk requested a review from yyforyongyu November 6, 2025 15:26
Copy link
Member

@yyforyongyu yyforyongyu left a 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
Copy link
Member

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(
Copy link
Member

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.

@lightninglabs-deploy
Copy link

@bitromortac, remember to re-request review from reviewers when ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: lncli getinfo uris spammed by 77 [email protected] entries

5 participants