From ee45d7739f63a8960f18cc288417080728108b15 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 7 Dec 2020 18:40:36 +0300 Subject: [PATCH] network: fix `requestTx()` 2 bugs were here: 1. If amount of tx is small, no messages were sent. 2. Correctly cut byte slice if last message is small. --- pkg/network/server.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index 077ce0db9..f36677d25 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -887,12 +887,15 @@ func (s *Server) requestTx(hashes ...util.Uint256) { return } - for i := 0; i < len(hashes)/payload.MaxHashesCount; i++ { + for i := 0; i <= len(hashes)/payload.MaxHashesCount; i++ { start := i * payload.MaxHashesCount stop := (i + 1) * payload.MaxHashesCount - if stop < len(hashes) { + if stop > len(hashes) { stop = len(hashes) } + if start == stop { + break + } msg := s.MkMsg(CMDGetData, payload.NewInventory(payload.TXType, hashes[start:stop])) // It's high priority because it directly affects consensus process, // even though it's getdata.