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.
This commit is contained in:
Evgenii Stratonikov 2020-12-07 18:40:36 +03:00
parent 074ba5f394
commit bd81b19a7a

View file

@ -839,12 +839,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 := NewMessage(CMDGetData, payload.NewInventory(payload.TXType, hashes[start:stop]))
// It's high priority because it directly affects consensus process,
// even though it's getdata.