Skip to content
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

cmd/utils, p2p: clean up discovery setup #27518

Merged
merged 8 commits into from
Jul 11, 2023

Conversation

lightclient
Copy link
Member

@lightclient lightclient commented Jun 19, 2023

While reading through the server, I noticed the setupDiscovery() function had a lot of branching and it seemed like an somewhat easy thing to simplify. It appears that the complication stems mostly from the fact that --nodiscover actually doesn't fully stop discovery. There are two cases where it will proceed:

  1. DNS discovery will currently proceed regardless of this flag, because
    it uses this new per-protocol discovery mechanism via the discmix
    iterator and it is set before the early return.
    Turns out this is actually not true, the dns URLs are nil'd out in the flags: https://discord.com/channels/420394352083337236/424272951366385664/1120690530792255548

  2. If light sync or server is specified, the flags interpreter will
    forcefully start discv5. This is, I think, why the function needed to
    be more complicated.

After this change, the DNS discovery will not proceed when --nodiscover is set. This made me think that it might be interesting to give users more control over their discovery mechanisms, e.g. DNS-only, DHT-only, etc (I think this will be possible now with the discv4 flag). Also, the geth command will exit if a light-mode flag is used with --nodiscover.

That should make it so --nodiscover really does mean no discovery!

While reading through the server, I noticed the `setupDiscovery()`
function had a lot of branching and it seemed like an somewhat easy
thing to simplify. It appears that the complication stems mostly from
the fact that `--nodiscover` actually doesn't fully stop discovery.
There are two cases where it will proceed:

1) DNS discovery will currently proceed regardless of this flag, because
   it uses this new per-protocol discovery mechanism via the discmix
   iterator and it is set before the early return.

2) If light sync or server is specified, the flags interpreter will
   forcefully start discv5. This is, I think, why the function needed to
   be more complicated.

After this change, the DNS discovery will not proceed `--nodiscover` is
set. This made me think that it might be interesting to give users more
control over their discovery mechanisms, e.g. DNS-only, DHT-only, etc.
Also, the geth command will exit if a light-mode flag is used with
`--nodiscover`.

That should make it so `--nodiscover` really does mean no discovery!
cmd/utils/flags.go Outdated Show resolved Hide resolved
@fjl fjl changed the title p2p,cmd: disable all discovery when --nodiscover is set p2p: disable all discovery when --nodiscover is set Jun 19, 2023
cmd/utils/flags.go Outdated Show resolved Hide resolved
p2p/server.go Outdated Show resolved Hide resolved
@fjl fjl changed the title p2p: disable all discovery when --nodiscover is set p2p: clean up discovery setup Jun 30, 2023
This moves the LegacyDiscoveryV5 flag into flags_legacy.go and also
cleans up some other deprecated flags issues.
@fjl fjl changed the title p2p: clean up discovery setup cmd/utils, p2p: clean up discovery setup Jul 11, 2023
@fjl fjl removed the status:triage label Jul 11, 2023
@fjl fjl merged commit 645b0db into ethereum:master Jul 11, 2023
@fjl fjl added this to the 1.12.1 milestone Jul 11, 2023
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
This simplifies the code that initializes the discovery a bit, and
adds new flags for enabling/disabling discv4 and discv5 separately.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants