Fix Peering Issues in Discovery (#6346)

* add current changes
* comment
* Merge branch 'master' into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* clean up
* add comment
* Merge refs/heads/master into fixPeeringIssues
* Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
* Merge refs/heads/master into fixPeeringIssues
This commit is contained in:
Nishant Das
2020-06-24 09:09:09 +08:00
committed by GitHub
parent 24d09f083f
commit e9057185a5
6 changed files with 30 additions and 18 deletions

View File

@@ -25,7 +25,7 @@ func (s *Service) InterceptAddrDial(_ peer.ID, m multiaddr.Multiaddr) (allow boo
// InterceptAccept tests whether an incipient inbound connection is allowed.
func (s *Service) InterceptAccept(n network.ConnMultiaddrs) (allow bool) {
if len(s.Peers().Active()) >= int(s.cfg.MaxPeers) {
if s.isPeerAtLimit() {
log.WithFields(logrus.Fields{"peer": n.RemoteMultiaddr(),
"reason": "at peer limit"}).Trace("Not accepting inbound dial")
return false

View File

@@ -13,7 +13,6 @@ import (
"github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// Listener defines the discovery V5 network interface that is used
@@ -133,14 +132,6 @@ func (s *Service) startDiscoveryV5(
// 5) Peer's fork digest in their ENR matches that of
// our localnodes.
func (s *Service) filterPeer(node *enode.Node) bool {
numOfConns := len(s.host.Network().Peers())
maxPeers := int(s.cfg.MaxPeers)
activePeers := len(s.Peers().Active())
if activePeers >= maxPeers || numOfConns >= maxPeers {
log.WithFields(logrus.Fields{"peer": node.String(),
"reason": "at peer limit"}).Trace("Not dialing peer")
return false
}
// ignore nodes with no ip address stored.
if node.IP() == nil {
return false
@@ -180,6 +171,17 @@ func (s *Service) filterPeer(node *enode.Node) bool {
return true
}
// This checks our set max peers in our config, and
// determines whether our currently connected and
// active peers are above our set max peer limit.
func (s *Service) isPeerAtLimit() bool {
numOfConns := len(s.host.Network().Peers())
maxPeers := int(s.cfg.MaxPeers)
activePeers := len(s.Peers().Active())
return activePeers >= maxPeers || numOfConns >= maxPeers
}
func parseBootStrapAddrs(addrs []string) (discv5Nodes []string) {
discv5Nodes, _ = parseGenericAddrs(addrs)
if len(discv5Nodes) == 0 {

View File

@@ -39,8 +39,11 @@ import (
var _ = shared.Service(&Service{})
// Check local table every 15 seconds for newly added peers.
var pollingPeriod = 15 * time.Second
// In the event that we are at our peer limit, we
// stop looking for new peers and instead poll
// for the current peer limit status for the time period
// defined below.
var pollingPeriod = 6 * time.Second
// Refresh rate of ENR set at twice per slot.
var refreshRate = slotutil.DivideSlotBy(2)
@@ -485,6 +488,13 @@ func (s *Service) listenForNewNodes() {
if s.ctx.Err() != nil {
break
}
if s.isPeerAtLimit() {
// Pause the main loop for a period to stop looking
// for new peers.
log.Trace("Not looking for peers, at peer limit")
time.Sleep(pollingPeriod)
continue
}
exists := iterator.Next()
if !exists {
break

View File

@@ -53,15 +53,15 @@ def prysm_deps():
build_file_generation = "off",
importpath = "github.com/prysmaticlabs/bazel-go-ethereum",
replace = "github.com/ethereum/go-ethereum",
sum = "h1:BgFL+G37WhgPOvkQveBXevApdusxtkrRoTzN9O3jnDM=",
version = "v0.0.0-20200615030327-5f59060ced70",
sum = "h1:6TlvcghiASejE0zd3ZEhd2ZQ+e+S2EALSgixivLzi8Q=",
version = "v0.0.0-20200622172343-b50bad5c6f58",
)
# Note: It is required to define com_github_ethereum_go_ethereum like this for some reason...
# Note: The keep directives help gazelle leave this alone.
go_repository(
name = "com_github_ethereum_go_ethereum",
commit = "5f59060ced70d1107fd3df26bf248c95af388738", # keep
commit = "b50bad5c6f5855d5821c9b6b6f0fee9c79aa350b", # keep
importpath = "github.com/ethereum/go-ethereum", # keep
# Note: go-ethereum is not bazel-friendly with regards to cgo. We have a
# a fork that has resolved these issues by disabling HID/USB support and

2
go.mod
View File

@@ -115,6 +115,6 @@ require (
k8s.io/utils v0.0.0-20200520001619-278ece378a50 // indirect
)
replace github.com/ethereum/go-ethereum => github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20200615030327-5f59060ced70
replace github.com/ethereum/go-ethereum => github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20200622172343-b50bad5c6f58
replace github.com/json-iterator/go => github.com/prestonvanloon/go v1.1.7-0.20190722034630-4f2e55fcf87b

4
go.sum
View File

@@ -890,8 +890,8 @@ github.com/prometheus/tsdb v0.10.0/go.mod h1:oi49uRhEe9dPUTlS3JRZOwJuVi6tmh10QSg
github.com/protolambda/zssz v0.1.3/go.mod h1:a4iwOX5FE7/JkKA+J/PH0Mjo9oXftN6P8NZyL28gpag=
github.com/protolambda/zssz v0.1.4 h1:4jkt8sqwhOVR8B1JebREU/gVX0Ply4GypsV8+RWrDuw=
github.com/protolambda/zssz v0.1.4/go.mod h1:a4iwOX5FE7/JkKA+J/PH0Mjo9oXftN6P8NZyL28gpag=
github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20200615030327-5f59060ced70 h1:BgFL+G37WhgPOvkQveBXevApdusxtkrRoTzN9O3jnDM=
github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20200615030327-5f59060ced70/go.mod h1:oP8FC5+TbICUyftkTWs+8JryntjIJLJvWvApK3z2AYw=
github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20200622172343-b50bad5c6f58 h1:6TlvcghiASejE0zd3ZEhd2ZQ+e+S2EALSgixivLzi8Q=
github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20200622172343-b50bad5c6f58/go.mod h1:oP8FC5+TbICUyftkTWs+8JryntjIJLJvWvApK3z2AYw=
github.com/prysmaticlabs/ethereumapis v0.0.0-20200617012222-f52a0eff2886 h1:0zB+DtS1NdwgYtto4JcvV3OX3m1wmM7ocjLvveNaMgA=
github.com/prysmaticlabs/ethereumapis v0.0.0-20200617012222-f52a0eff2886/go.mod h1:rs05kpTfWKl0KflsBWzBQFstoyPFMTWQTbxSAyGHe78=
github.com/prysmaticlabs/go-bitfield v0.0.0-20191017011753-53b773adde52/go.mod h1:hCwmef+4qXWjv0jLDbQdWnL0Ol7cS7/lCSS26WR+u6s=