network: don't request block we already have

GetBlockByIndex handler starts sending blocks right from the start index and
if that index is s.chain.BlockHeight() then we're requesting and receiving a
block we already have.
This commit is contained in:
Roman Khimov 2020-08-14 16:25:13 +03:00
parent c8cc91eeee
commit 8d19f0e6f5

View file

@ -704,7 +704,7 @@ func (s *Server) handleGetAddrCmd(p Peer) error {
// to sync up in blocks. A maximum of maxBlockBatch will // to sync up in blocks. A maximum of maxBlockBatch will
// send at once. // send at once.
func (s *Server) requestBlocks(p Peer) error { func (s *Server) requestBlocks(p Peer) error {
payload := payload.NewGetBlockByIndex(s.chain.BlockHeight(), -1) payload := payload.NewGetBlockByIndex(s.chain.BlockHeight()+1, -1)
return p.EnqueueP2PMessage(NewMessage(CMDGetBlockByIndex, payload)) return p.EnqueueP2PMessage(NewMessage(CMDGetBlockByIndex, payload))
} }