Skip to content

[1/2] discovery+lnwire: add support for DNS host name in NodeAnnouncement msg - #9455

Merged
ellemouton merged 8 commits into
lightningnetwork:masterfrom
moawnallah:supportDNSHostnameInNodeAnnouncement
Sep 3, 2025
Merged

ellemouton merged 8 commits into
lightningnetwork:masterfrom
moawnallah:supportDNSHostnameInNodeAnnouncement

Conversation

@moawnallah

@moawnallah moawnallah commented Jan 29, 2025 •

Copy link
Copy Markdown
Contributor

Change Description

Towards #6337.
Towards #9126.
Next #10159.

Steps to Test

Steps for reviewers to follow to test the change.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

@coderabbitai

coderabbitai Bot commented Jan 29, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Comment thread graph/db/addr.go Outdated
Comment thread sample-lnd.conf Outdated
@saubyk saubyk added this to the v0.20.0 milestone Feb 5, 2025
@moawnallah
moawnallah force-pushed the supportDNSHostnameInNodeAnnouncement branch 2 times, most recently from fb721bc to 4a8adcb Compare February 5, 2025 03:06
Comment thread lnrpc/lightning.proto Outdated
Comment thread cmd/commands/peersrpc_active.go
Comment thread config.go
@saubyk saubyk added this to lnd v0.20 May 1, 2025
@saubyk saubyk moved this to In progress in lnd v0.20 May 1, 2025
@moawnallah
moawnallah marked this pull request as draft May 2, 2025 17:32
@moawnallah
moawnallah force-pushed the supportDNSHostnameInNodeAnnouncement branch 5 times, most recently from c3a6a49 to d67c686 Compare May 3, 2025 12:20
@moawnallah moawnallah mentioned this pull request May 3, 2025
9 tasks
@moawnallah
moawnallah force-pushed the supportDNSHostnameInNodeAnnouncement branch 2 times, most recently from 3efa4b2 to 01c57c8 Compare May 3, 2025 15:19
@moawnallah

moawnallah commented May 5, 2025 •

Copy link
Copy Markdown
Contributor Author

This PR is not yet ready for review. It looks like more code paths need to be test-covered. I also understand the git commit structure is not still followed per latest feedback as I was trying to make CI happy. I will take a look at this PR soon.

@moawnallah
moawnallah force-pushed the supportDNSHostnameInNodeAnnouncement branch 2 times, most recently from d48d1fd to 98d2f2f Compare May 11, 2025 17:43
@moawnallah
moawnallah marked this pull request as ready for review May 11, 2025 18:58
@moawnallah

Copy link
Copy Markdown
Contributor Author

Thank you, @ellemouton, for your feedback on this PR.

I have restructured the commits and added unit tests for encoding/decoding the DNS hostname address, as well as for parsing it. Apologies for the significant delay between receiving your review and addressing it—I’ll do my best to minimize such gaps in the future, in line with the New Development Process.

Any follow-up feedback would be very much appreciated!

PS:
It looks like the failed CI tests not related to the changes in this PR also It doesn't look like we need to add itests for this feature change, no?

@moawnallah
moawnallah requested a review from ellemouton May 11, 2025 22:59

@ellemouton ellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR :)

I think its a good idea to test/ensure the following:

  1. make sure the node can handle providing its own DNS addr
  2. make sure the node can handle receiving a DNS addr from other nodes

Comment thread lnwire/dns_hostname_addr.go Outdated
Comment thread server_test.go Outdated
Comment thread server_test.go Outdated
Comment thread server_test.go Outdated
Comment thread server_test.go Outdated
Comment thread graph/db/addr_test.go Outdated
Comment thread config.go Outdated
Comment thread server.go Outdated
Comment thread server.go Outdated
Comment thread sample-lnd.conf Outdated

@ellemouton ellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We have to be quite careful since we always need to think about what our currently persisted data may look like. It is quite involved - so to help, I've put together this draft/rough PR to show you the various changes I think are needed: ellemouton#219

Let me know if that helps & if you have any questions.

perhaps it might be a good idea to split the saga up into 2: part 1 just doing what is covered in that example I shared (ie, just being able to handle network DNS addrs) & then a follow up that adds the new option to add our own DNS addrs.

Comment thread lnwire/lnwire.go Outdated
Comment thread lnwire/dns_addr.go
Comment thread lnwire/dns_addr.go Outdated

// Validate validates that the DNS hostname is not empty and contains only ASCII
// characters and of max length 255 characters according to BOLT specifications.
func (d *DNSAddr) Validate() error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

unresolving as still not addressed

Comment thread lnwire/dns_addr.go Outdated

// Validate validates that the DNS hostname is not empty and contains only ASCII
// characters and of max length 255 characters according to BOLT specifications.
func (d *DNSAddr) Validate() error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what i meant in the comment was that there should not even be an exported Validate method on the type.

rather have a helper like:

func validateDNS(hostname, port) error {
    ...
} 

that you call from within the constructor. Ie, it should not be possible to construct the type without validating it.

Comment thread graph/db/sql_store.go
Comment thread graph/db/addr.go Outdated
Comment thread graph/db/addr.go Outdated
Comment thread graph/db/addr_test.go Outdated
Comment thread lnwire/lnwire.go Outdated
"multiple DNS addresses. See " +
"Bolt 07")
}
dnsAddrIncluded = true

ghost Aug 4, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ok so i thought about this a bit more and I now agree with YY that this is not the place for the check of "dont add more than 1 DNS addr".

It is a tricky decision since the spec does say that the receiver "should ignore the rest of the data if more than one such addr exists".
BUT what we actually care about here is just being able to parse the wire message: ie, can we properly read the address_descriptor. Then the actual content of the fields can be checked elsewhere such as in netann (see ValidateChannelUpdateFields as an example).

Comment thread lnwire/writer.go Outdated
Comment on lines +424 to +425
case *DNSAddr:
if dnsAddrIncluded {

ghost Aug 6, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

so yeah, just confirming from above: i think let's let the lnwire package just do serialisation & deserialisation. The actual content of the fields & validity of the fields can be checked in netann

ghost Aug 15, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

. The actual content of the fields & validity of the fields can be checked in netann

Have validated the DNS fields according to bolt-07 on the netann layer applying this comment. I have made the validate DNS fields utility in locality with the actual DNS schema. If I have other place better to put this utility, I am open to it

@ellemouton

ghost commented Aug 7, 2025

Copy link
Copy Markdown
Collaborator

ok just spoke to @saubyk and he had a good idea: perhaps we are overcomplicating this & we can potentially get away with not unraveling anything we have already persisted on disk (ie, Opaque Addrs remain Opaque addrs even if they contain DNS addrs). I think this might be an ok solution given that nodes will occasionally send out new announcements & so things should eventually be correct.

Im going to start a convo offline just to first see what others think. In the mean time, defs take a look at the draft code i linked before to get an understanding of what that path looks like.

@moawnallah moawnallah changed the title discovery+lnwire: add support for DNS host name in NodeAnnouncement msg [1/2] discovery+lnwire: add support for DNS host name in NodeAnnouncement msg Aug 14, 2025
@moawnallah
moawnallah force-pushed the supportDNSHostnameInNodeAnnouncement branch from 3f1f50b to a9675a6 Compare August 14, 2025 14:01
@moawnallah

ghost commented Aug 14, 2025

Copy link
Copy Markdown
Contributor Author

so to help, I've put together this draft/rough PR to show you the various changes I think are needed: ellemouton#219

Thanks @ellemouton for providing this draft/rough PR. It was so helpful moving this PR forward. Will invite for a look after CI tests pass

perhaps it might be a good idea to split the saga up into 2: part 1 just doing what is covered in that example I shared (ie, just being able to handle network DNS addrs) & then a follow up that adds the new option to add our own DNS addrs.

I will follow-up with a PR regards the new option 👍

ghost left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great work @mohamedawnallah !! 🎉

I think this is pretty much g2g! just 2 comments about commits you can drop in this PR. I'll then make a follow up PR that updates the graph SQL migration accordingly :)

Comment thread graph/db/addr_test.go Outdated
Comment thread lnwire/lnwire.go Outdated
Comment thread discovery/chan_series.go
Comment thread discovery/gossiper.go

ghost left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good!

Thanks for the fast turn around here 🙏

Leaving one more comment re a unit test. Then please also remember to add a release note entry.

Leaving my ACK in the mean time since I'll be away next week

Comment thread lnwire/dns_addr.go
@moawnallah
moawnallah force-pushed the supportDNSHostnameInNodeAnnouncement branch 2 times, most recently from 8977287 to 035fac4 Compare August 15, 2025 13:10
@litbot-9000

ghost commented Aug 29, 2025

Copy link
Copy Markdown
Collaborator

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

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One question re the test, otherwise looks good.

Comment thread lnwire/writer_test.go
Comment thread lnwire/dns_addr.go Outdated
}

if len(hostname) > 255 {
return fmt.Errorf("DNS hostname length %d, exceeds limit of "+

ghost Sep 2, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: think we should define errors above and return fmt.Errorf("%w: ...") here, so it's easier to be tested below, error string matching is a bit fragile.

ghost Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nit: think we should define errors above and return fmt.Errorf("%w: ...") here, so it's easier to be tested below, error string matching is a bit fragile.

Addressed

ghost Sep 2, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cool we should return fmt.Errorf("%w: DNS hostname length %d", ...) - given the goal is to do error matching in the tests, we should also change it to require.ErrorIs instead of error string matching.

ghost Sep 3, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cool we should return fmt.Errorf("%w: DNS hostname length %d", ...) - given the goal is to do error matching in the tests, we should also change it to require.ErrorIs instead of error string matching.

Used wrapped errors with additional details. It seems eventually we need to match against error string i.e that part ("%w: DNS hostname length %d") since require.ErrorIs only checks if the error types match, not the exact error message content

Mohamed Awnallah and others added 3 commits September 2, 2025 17:51
In this commit, we remove `AddrLen` as prepration step
before adding DNS address type which will have a var length.

Co-authored-by: Elle Mouton <elle.mouton@gmail.com>
Co-authored-by: Elle Mouton <elle.mouton@gmail.com>

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM🚢 Left some nits - will merge once CI passed

Comment thread lnwire/dns_addr.go Outdated
Comment thread lnwire/dns_addr.go Outdated
}

if len(hostname) > 255 {
return fmt.Errorf("DNS hostname length %d, exceeds limit of "+

ghost Sep 2, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cool we should return fmt.Errorf("%w: DNS hostname length %d", ...) - given the goal is to do error matching in the tests, we should also change it to require.ErrorIs instead of error string matching.

Comment thread lnwire/dns_addr.go Outdated
Elle Mouton and others added 5 commits September 3, 2025 01:11
Check that the node ann doesnt contain more than 1 DNS addr.
This will ensure that we now start rejecting new node announcements
with multiple DNS addrs since this check is called in the gossiper
before persisting a node ann to our local graph.

It also validates the DNS fields according to BOLT #7 specs.
We may have already persisted node announcements that have multiple DNS
addresses since we may have received them before updating our code to
check for this. So here we just make sure not to send these on to our
peers.
The first byte of an opaque addr must be one that we dont understand
yet. We do this update in preparation for doing an on-the-fly parse of
persisted opaque addrs to see if they contain addrs that we now support.
For this to work, the first byte cant be 0x01 since this maps to a known
address.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants