mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Discovery Fixes (#5050)
* connect to dv5 bootnodes * fix test * change polling period * ignore * Update beacon-chain/p2p/service.go * Update beacon-chain/p2p/service_test.go * fix test Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
This commit is contained in:
parent
edb6590764
commit
9d27449212
@ -132,7 +132,7 @@ func TestMultiAddrConversion_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStaticPeering_PeersAreAdded(t *testing.T) {
|
||||
cfg := &Config{Encoding: "ssz"}
|
||||
cfg := &Config{Encoding: "ssz", MaxPeers: 30}
|
||||
port := 3000
|
||||
var staticPeers []string
|
||||
var hosts []host.Host
|
||||
|
@ -26,11 +26,13 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
|
||||
"github.com/prysmaticlabs/prysm/shared"
|
||||
"github.com/prysmaticlabs/prysm/shared/runutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var _ = shared.Service(&Service{})
|
||||
|
||||
var pollingPeriod = 1 * time.Second
|
||||
// Check local table every 5 seconds for newly added peers.
|
||||
var pollingPeriod = 5 * time.Second
|
||||
|
||||
const prysmProtocolPrefix = "/prysm/0.0.0"
|
||||
|
||||
@ -158,7 +160,7 @@ func (s *Service) Start() {
|
||||
s.startupErr = err
|
||||
return
|
||||
}
|
||||
err = s.addBootNodesToExclusionList()
|
||||
err = s.connectToBootnodes()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not add bootnode to the exclusion list")
|
||||
s.startupErr = err
|
||||
@ -293,12 +295,8 @@ func (s *Service) Peers() *peers.Status {
|
||||
|
||||
// listen for new nodes watches for new nodes in the network and adds them to the peerstore.
|
||||
func (s *Service) listenForNewNodes() {
|
||||
bootNode, err := enode.Parse(enode.ValidSchemes, s.cfg.Discv5BootStrapAddr[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
runutil.RunEvery(s.ctx, pollingPeriod, func() {
|
||||
nodes := s.dv5Listener.Lookup(bootNode.ID())
|
||||
nodes := s.dv5Listener.LookupRandom()
|
||||
multiAddresses := convertToMultiAddr(nodes)
|
||||
s.connectWithAllPeers(multiAddresses)
|
||||
})
|
||||
@ -313,6 +311,11 @@ func (s *Service) connectWithAllPeers(multiAddrs []ma.Multiaddr) {
|
||||
for _, info := range addrInfos {
|
||||
// make each dial non-blocking
|
||||
go func(info peer.AddrInfo) {
|
||||
if len(s.Peers().Active()) >= int(s.cfg.MaxPeers) {
|
||||
log.WithFields(logrus.Fields{"peer": info.ID.String(),
|
||||
"reason": "at peer limit"}).Trace("Not dialing peer")
|
||||
return
|
||||
}
|
||||
if info.ID == s.host.ID() {
|
||||
return
|
||||
}
|
||||
@ -327,24 +330,17 @@ func (s *Service) connectWithAllPeers(multiAddrs []ma.Multiaddr) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) addBootNodesToExclusionList() error {
|
||||
func (s *Service) connectToBootnodes() error {
|
||||
nodes := make([]*enode.Node, 0, len(s.cfg.Discv5BootStrapAddr))
|
||||
for _, addr := range s.cfg.Discv5BootStrapAddr {
|
||||
bootNode, err := enode.Parse(enode.ValidSchemes, addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
multAddr, err := convertToSingleMultiAddr(bootNode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addrInfo, err := peer.AddrInfoFromP2pAddr(multAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// bootnode is never dialled, so ttl is tentatively 1 year
|
||||
s.exclusionList.Set(addrInfo.ID.String(), true, 1)
|
||||
nodes = append(nodes, bootNode)
|
||||
}
|
||||
|
||||
multiAddresses := convertToMultiAddr(nodes)
|
||||
s.connectWithAllPeers(multiAddresses)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -130,12 +130,20 @@ func TestListenForNewNodes(t *testing.T) {
|
||||
bootListener := createListener(ipAddr, pkey, cfg)
|
||||
defer bootListener.Close()
|
||||
|
||||
// Use shorter period for testing.
|
||||
currentPeriod := pollingPeriod
|
||||
pollingPeriod = 1 * time.Second
|
||||
defer func() {
|
||||
pollingPeriod = currentPeriod
|
||||
}()
|
||||
|
||||
bootNode := bootListener.Self()
|
||||
|
||||
cfg = &Config{
|
||||
BootstrapNodeAddr: []string{bootNode.String()},
|
||||
Discv5BootStrapAddr: []string{bootNode.String()},
|
||||
Encoding: "ssz",
|
||||
MaxPeers: 30,
|
||||
}
|
||||
var listeners []*discover.UDPv5
|
||||
var hosts []host.Host
|
||||
|
Loading…
Reference in New Issue
Block a user