From 7b1c3050002441f42fff7b74aca5512de88e7c18 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 31 Jul 2020 14:51:51 +0300 Subject: [PATCH] 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. --- pkg/network/server.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index 6df448d27..e681f335d 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -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 }