network: fix handleGetBlockByIndexCmd method

It returned an error in case if block wasn't found (it might be when our
chain is lower). Fixed. It also should return all requested blocks, not
the first one.
This commit is contained in:
Anna Shaleva 2020-07-31 14:51:51 +03:00
parent 0b0591fc34
commit 7b1c305000

View file

@ -616,12 +616,18 @@ func (s *Server) handleGetBlockByIndexCmd(p Peer, gbd *payload.GetBlockByIndex)
count = payload.MaxHashesCount count = payload.MaxHashesCount
} }
for i := gbd.IndexStart; i < gbd.IndexStart+uint32(count); i++ { for i := gbd.IndexStart; i < gbd.IndexStart+uint32(count); i++ {
b, err := s.chain.GetBlock(s.chain.GetHeaderHash(int(i))) hash := s.chain.GetHeaderHash(int(i))
if hash.Equals(util.Uint256{}) {
break
}
b, err := s.chain.GetBlock(hash)
if err != nil { if err != nil {
return err break
} }
msg := NewMessage(CMDBlock, b) msg := NewMessage(CMDBlock, b)
return p.EnqueueP2PMessage(msg) if err = p.EnqueueP2PMessage(msg); err != nil {
return err
}
} }
return nil return nil
} }