From 4d286dcfeb9742b5483e382f6cc7fdb6d5777563 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 29 Nov 2019 11:46:01 +0300 Subject: [PATCH] network: check height before requesting headers Only request headers from the other peer if his height is bigger than ours. Otherwise we routinely ask 0-height newcomers for some random headers that they know nothing about. --- pkg/network/server.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index 3220b8934..3e6e333b5 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -284,6 +284,8 @@ func (s *Server) PeerCount() int { // startProtocol starts a long running background loop that interacts // every ProtoTickInterval with the peer. func (s *Server) startProtocol(p Peer) { + var err error + log.WithFields(log.Fields{ "addr": p.RemoteAddr(), "userAgent": string(p.Version().UserAgent), @@ -292,10 +294,12 @@ func (s *Server) startProtocol(p Peer) { }).Info("started protocol") s.discovery.RegisterGoodAddr(p.PeerAddr().String()) - err := s.requestHeaders(p) - if err != nil { - p.Disconnect(err) - return + if s.chain.HeaderHeight() < p.Version().StartHeight { + err = s.requestHeaders(p) + if err != nil { + p.Disconnect(err) + return + } } timer := time.NewTimer(s.ProtoTickInterval)