Use Less Intensive Search (#6848)

* use less intensive search
* Add mock method to implement Listener
* Merge refs/heads/master into lessIntensiveSearch
* Merge refs/heads/master into lessIntensiveSearch
This commit is contained in:
Nishant Das 2020-08-04 02:10:23 +08:00 committed by GitHub
parent d06dcd2eec
commit 69e0e302b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 2 deletions

View File

@ -47,6 +47,7 @@ go_library(
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/iputils:go_default_library",
"//shared/mathutil:go_default_library",
"//shared/p2putils:go_default_library",
"//shared/params:go_default_library",
"//shared/roughtime:go_default_library",

View File

@ -31,6 +31,7 @@ type Listener interface {
Ping(*enode.Node) error
RequestENR(*enode.Node) (*enode.Node, error)
LocalNode() *enode.LocalNode
AllNodes() []*enode.Node
}
// RefreshENR uses an epoch to refresh the enr entry for our node
@ -143,8 +144,10 @@ func (s *Service) createListener(
}
}
dv5Cfg := discover.Config{
PrivateKey: privKey,
PrivateKey: privKey,
ValidSchemes: enode.ValidSchemes,
}
dv5Cfg.Bootnodes = []*enode.Node{}
for _, addr := range s.cfg.Discv5BootStrapAddr {
bootNode, err := enode.Parse(enode.ValidSchemes, addr)

View File

@ -25,6 +25,10 @@ import (
type mockListener struct{}
func (mockListener) AllNodes() []*enode.Node {
panic("implement me")
}
func (mockListener) Self() *enode.Node {
panic("implement me")
}

View File

@ -6,6 +6,7 @@ import (
"github.com/libp2p/go-libp2p-core/network"
"github.com/prysmaticlabs/go-bitfield"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/mathutil"
"github.com/prysmaticlabs/prysm/shared/params"
)
@ -22,7 +23,12 @@ func (s *Service) FindPeersWithSubnet(index uint64) (bool, error) {
return false, nil
}
iterator := s.dv5Listener.RandomNodes()
nodes := enode.ReadNodes(iterator, lookupLimit)
// Select appropriate size for search.
maxSize := uint64(len(s.dv5Listener.AllNodes()))
min := int(mathutil.Min(maxSize, lookupLimit))
nodes := enode.ReadNodes(iterator, min)
exists := false
for _, node := range nodes {
if node.IP() == nil {