network: either request blocks or ping a peer, but not both

It makes to sense to do both actions, pings are made for a different purpose.

Relates to #430.
This commit is contained in:
Roman Khimov 2020-01-20 16:58:28 +03:00
parent 2348a460ea
commit 247cfa4165

View file

@ -207,11 +207,7 @@ func (p *TCPPeer) StartProtocol() {
// Try to sync in headers and block with the peer if his block height is higher then ours. // Try to sync in headers and block with the peer if his block height is higher then ours.
if p.LastBlockIndex() > p.server.chain.BlockHeight() { if p.LastBlockIndex() > p.server.chain.BlockHeight() {
err = p.server.requestBlocks(p) err = p.server.requestBlocks(p)
} } else if p.server.chain.HeaderHeight() >= p.LastBlockIndex() {
if err == nil {
timer.Reset(p.server.ProtoTickInterval)
}
if p.server.chain.HeaderHeight() >= p.LastBlockIndex() {
block, errGetBlock := p.server.chain.GetBlock(p.server.chain.CurrentBlockHash()) block, errGetBlock := p.server.chain.GetBlock(p.server.chain.CurrentBlockHash())
if errGetBlock != nil { if errGetBlock != nil {
err = errGetBlock err = errGetBlock
@ -223,6 +219,9 @@ func (p *TCPPeer) StartProtocol() {
} }
} }
} }
if err == nil {
timer.Reset(p.server.ProtoTickInterval)
}
case <-pingTimer.C: case <-pingTimer.C:
if p.GetPingSent() > defaultPingLimit { if p.GetPingSent() > defaultPingLimit {
err = errors.New("ping/pong timeout") err = errors.New("ping/pong timeout")