[SYNC] add logic handling of gRPC handling request over default block size. (#3746)

pull/3750/head
Jacky Wang 4 years ago committed by GitHub
parent 86cd2bdb0e
commit f17e0dde28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      node/node_syncing.go

@ -31,6 +31,10 @@ import (
// Constants related to doing syncing. // Constants related to doing syncing.
const ( const (
SyncFrequency = 60 SyncFrequency = 60
// getBlocksRequestHardCap is the hard capped message size at server side for getBlocks request.
// The number is 4MB (default gRPC message size) minus 2k reserved for message overhead.
getBlocksRequestHardCap = 4*1024*1024 - 2*1024
) )
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
@ -466,6 +470,7 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest, in
case downloader_pb.DownloaderRequest_BLOCK: case downloader_pb.DownloaderRequest_BLOCK:
var hash common.Hash var hash common.Hash
payloadSize := 0
withSig := request.GetBlocksWithSig withSig := request.GetBlocksWithSig
for _, bytes := range request.Hashes { for _, bytes := range request.Hashes {
hash.SetBytes(bytes) hash.SetBytes(bytes)
@ -478,10 +483,14 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest, in
} else { } else {
encoded, err = node.getEncodedBlockByHash(hash) encoded, err = node.getEncodedBlockByHash(hash)
} }
if err != nil {
if err == nil { continue
response.Payload = append(response.Payload, encoded) }
payloadSize += len(encoded)
if payloadSize > getBlocksRequestHardCap {
break
} }
response.Payload = append(response.Payload, encoded)
} }
case downloader_pb.DownloaderRequest_BLOCKHEIGHT: case downloader_pb.DownloaderRequest_BLOCKHEIGHT:

Loading…
Cancel
Save