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.
This commit is contained in:
parent
a730529b0c
commit
4d286dcfeb
1 changed files with 8 additions and 4 deletions
|
@ -284,6 +284,8 @@ func (s *Server) PeerCount() int {
|
||||||
// startProtocol starts a long running background loop that interacts
|
// startProtocol starts a long running background loop that interacts
|
||||||
// every ProtoTickInterval with the peer.
|
// every ProtoTickInterval with the peer.
|
||||||
func (s *Server) startProtocol(p Peer) {
|
func (s *Server) startProtocol(p Peer) {
|
||||||
|
var err error
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"addr": p.RemoteAddr(),
|
"addr": p.RemoteAddr(),
|
||||||
"userAgent": string(p.Version().UserAgent),
|
"userAgent": string(p.Version().UserAgent),
|
||||||
|
@ -292,10 +294,12 @@ func (s *Server) startProtocol(p Peer) {
|
||||||
}).Info("started protocol")
|
}).Info("started protocol")
|
||||||
|
|
||||||
s.discovery.RegisterGoodAddr(p.PeerAddr().String())
|
s.discovery.RegisterGoodAddr(p.PeerAddr().String())
|
||||||
err := s.requestHeaders(p)
|
if s.chain.HeaderHeight() < p.Version().StartHeight {
|
||||||
if err != nil {
|
err = s.requestHeaders(p)
|
||||||
p.Disconnect(err)
|
if err != nil {
|
||||||
return
|
p.Disconnect(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timer := time.NewTimer(s.ProtoTickInterval)
|
timer := time.NewTimer(s.ProtoTickInterval)
|
||||||
|
|
Loading…
Reference in a new issue