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.

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

server.go Outdated
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 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point! I decided to change the approach to deduplicate addresses in genNodeAnnouncement after modifiers were applied as this also removes previously added duplicate addresses. On start we recreate the node announcement, which will clean it up (I could reproduce the bug and verified that this works).

@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❤️

server.go Outdated
// 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

server.go Outdated
}
}

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

@ziggie1984
Copy link
Collaborator

@bitromortac can we finalize this one

@bitromortac bitromortac force-pushed the 2511-fix-tor-healthcheck branch from c638402 to 1d7d9e3 Compare November 26, 2025 09:54
@saubyk saubyk modified the milestones: v0.21.0, v0.20.1 Nov 26, 2025
Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

LGMT => please add release notes entry for 20.1 and also create a backport PR for the 20.x branch

Modifiers of the node announcement may add duplicate addresses, which we
remove here after the modifications were applied. This also ensures that
any previously added duplicate addresses are removed as well.
@bitromortac bitromortac force-pushed the 2511-fix-tor-healthcheck branch from 1d7d9e3 to b513efc Compare November 26, 2025 16:01
@yyforyongyu yyforyongyu merged commit 85a5bf2 into lightningnetwork:master Nov 27, 2025
67 of 70 checks passed
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