mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 03:41:34 +00:00
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:
parent
0b0591fc34
commit
7b1c305000
1 changed files with 9 additions and 3 deletions
|
@ -616,12 +616,18 @@ func (s *Server) handleGetBlockByIndexCmd(p Peer, gbd *payload.GetBlockByIndex)
|
|||
count = payload.MaxHashesCount
|
||||
}
|
||||
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 {
|
||||
return err
|
||||
break
|
||||
}
|
||||
msg := NewMessage(CMDBlock, b)
|
||||
return p.EnqueueP2PMessage(msg)
|
||||
if err = p.EnqueueP2PMessage(msg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue