Skip to content

p2p: make dial faster by streamlined discovery process #31678

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
p2p/enode: don't pass error in AsyncFilter check
Signed-off-by: Csaba Kiraly <[email protected]>
  • Loading branch information
cskiraly committed Jun 1, 2025
commit 33660b37a108b316157b24faecbc0e8fc19e2dd2
7 changes: 5 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,12 @@ func (s *Ethereum) setupDiscovery() error {
// Add DHT nodes from discv4.
if s.p2pServer.DiscoveryV4() != nil {
iter := s.p2pServer.DiscoveryV4().RandomNodes()
resolverFunc := func(ctx context.Context, enr *enode.Node) (*enode.Node, error) {
resolverFunc := func(ctx context.Context, enr *enode.Node) *enode.Node {
// RequestENR does not yet support context. It will simply time out.
return s.p2pServer.DiscoveryV4().RequestENR(enr)
// If the ENR can't be resolved, RequestENR will return nil. We don't
// care about the specific error here, so we ignore it.
nn, _ := s.p2pServer.DiscoveryV4().RequestENR(enr)
return nn
}
iter = enode.AsyncFilter(iter, resolverFunc, maxParallelENRRequests)
iter = enode.Filter(iter, eth.NewNodeFilter(s.blockchain))
Expand Down
4 changes: 2 additions & 2 deletions p2p/enode/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ type AsyncFilterIter struct {
cancel context.CancelFunc
closeOnce sync.Once
}
type AsyncFilterFunc func(context.Context, *Node) (*Node, error)
type AsyncFilterFunc func(context.Context, *Node) *Node

// AsyncFilter creates an iterator which checks nodes in parallel.
func AsyncFilter(it Iterator, check AsyncFilterFunc, workers int) Iterator {
Expand Down Expand Up @@ -192,7 +192,7 @@ func AsyncFilter(it Iterator, check AsyncFilterFunc, workers int) Iterator {
<-f.slots
// check the node async, in a separate goroutine
go func() {
if nn, err := check(ctx, n); err == nil {
if nn := check(ctx, n); nn != nil {
select {
case f.passed <- nn:
case <-ctx.Done(): // bale out if downstream is already closed and not calling Next
Expand Down