File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ import (
18
18
"github.com/ethereum/go-ethereum/rlp"
19
19
)
20
20
21
+ // This is the target maximum size of returned blocks for the
22
+ // getBlocks message. The reply message may exceed it
23
+ // if a single block is larger than the limit.
24
+ const maxBlockRespSize = 2 * 1024 * 1024
25
+
21
26
func errResp (code errCode , format string , v ... interface {}) error {
22
27
return fmt .Errorf ("%v - %v" , code , fmt .Sprintf (format , v ... ))
23
28
}
@@ -246,7 +251,10 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
246
251
if _ , err := msgStream .List (); err != nil {
247
252
return err
248
253
}
249
- var i int
254
+ var (
255
+ i int
256
+ totalsize common.StorageSize
257
+ )
250
258
for {
251
259
i ++
252
260
var hash common.Hash
@@ -260,8 +268,9 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
260
268
block := self .chainman .GetBlock (hash )
261
269
if block != nil {
262
270
blocks = append (blocks , block )
271
+ totalsize += block .Size ()
263
272
}
264
- if i == downloader .MaxBlockFetch {
273
+ if i == downloader .MaxBlockFetch || totalsize > maxBlockRespSize {
265
274
break
266
275
}
267
276
}
You can’t perform that action at this time.
0 commit comments